您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ usb_sndbulkpipe函数代码示例

51自学网 2021-06-03 09:21:21
  C++
这篇教程C++ usb_sndbulkpipe函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中usb_sndbulkpipe函数的典型用法代码示例。如果您正苦于以下问题:C++ usb_sndbulkpipe函数的具体用法?C++ usb_sndbulkpipe怎么用?C++ usb_sndbulkpipe使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了usb_sndbulkpipe函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: usbpn_probe

int usbpn_probe(struct usb_interface *intf, const struct usb_device_id *id){	static const char ifname[] = "usbpn%d";	const struct usb_cdc_union_desc *union_header = NULL;	const struct usb_host_interface *data_desc;	struct usb_interface *data_intf;	struct usb_device *usbdev = interface_to_usbdev(intf);	struct net_device *dev;	struct usbpn_dev *pnd;	u8 *data;	int phonet = 0;	int len, err;	data = intf->altsetting->extra;	len = intf->altsetting->extralen;	while (len >= 3) {		u8 dlen = data[0];		if (dlen < 3)			return -EINVAL;		/* bDescriptorType */		if (data[1] == USB_DT_CS_INTERFACE) {			/* bDescriptorSubType */			switch (data[2]) {			case USB_CDC_UNION_TYPE:				if (union_header || dlen < 5)					break;				union_header =					(struct usb_cdc_union_desc *)data;				break;			case 0xAB:				phonet = 1;				break;			}		}		data += dlen;		len -= dlen;	}	if (!union_header || !phonet)		return -EINVAL;	data_intf = usb_ifnum_to_if(usbdev, union_header->bSlaveInterface0);	if (data_intf == NULL)		return -ENODEV;	/* Data interface has one inactive and one active setting */	if (data_intf->num_altsetting != 2)		return -EINVAL;	if (data_intf->altsetting[0].desc.bNumEndpoints == 0 &&	    data_intf->altsetting[1].desc.bNumEndpoints == 2)		data_desc = data_intf->altsetting + 1;	else	if (data_intf->altsetting[0].desc.bNumEndpoints == 2 &&	    data_intf->altsetting[1].desc.bNumEndpoints == 0)		data_desc = data_intf->altsetting;	else		return -EINVAL;	dev = alloc_netdev(sizeof(*pnd) + sizeof(pnd->urbs[0]) * rxq_size,				ifname, usbpn_setup);	if (!dev)		return -ENOMEM;	pnd = netdev_priv(dev);	SET_NETDEV_DEV(dev, &intf->dev);	netif_stop_queue(dev);	pnd->dev = dev;	pnd->usb = usb_get_dev(usbdev);	pnd->intf = intf;	pnd->data_intf = data_intf;	spin_lock_init(&pnd->tx_lock);	spin_lock_init(&pnd->rx_lock);	/* Endpoints */	if (usb_pipein(data_desc->endpoint[0].desc.bEndpointAddress)) {		pnd->rx_pipe = usb_rcvbulkpipe(usbdev,			data_desc->endpoint[0].desc.bEndpointAddress);		pnd->tx_pipe = usb_sndbulkpipe(usbdev,			data_desc->endpoint[1].desc.bEndpointAddress);	} else {		pnd->rx_pipe = usb_rcvbulkpipe(usbdev,			data_desc->endpoint[1].desc.bEndpointAddress);		pnd->tx_pipe = usb_sndbulkpipe(usbdev,			data_desc->endpoint[0].desc.bEndpointAddress);	}	pnd->active_setting = data_desc - data_intf->altsetting;	err = usb_driver_claim_interface(&usbpn_driver, data_intf, pnd);	if (err)		goto out;	/* Force inactive mode until the network device is brought UP */	usb_set_interface(usbdev, union_header->bSlaveInterface0,				!pnd->active_setting);	usb_set_intfdata(intf, pnd);	err = register_netdev(dev);	if (err) {		usb_driver_release_interface(&usbpn_driver, data_intf);		goto out;//.........这里部分代码省略.........
开发者ID:12rafael,项目名称:jellytimekernel,代码行数:101,


示例2: acm_probe

//.........这里部分代码省略.........	acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL);	if (!acm->ctrlurb) {		dev_dbg(&intf->dev, "out of memory (ctrlurb kmalloc)/n");		goto alloc_fail5;	}	for (i = 0; i < num_rx_buf; i++) {		struct acm_ru *rcv = &(acm->ru[i]);		if (!(rcv->urb = usb_alloc_urb(0, GFP_KERNEL))) {			dev_dbg(&intf->dev, "out of memory (read urbs usb_alloc_urb)/n");			goto alloc_fail7;		}		rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;		rcv->instance = acm;	}	for (i = 0; i < num_rx_buf; i++) {		struct acm_rb *buf = &(acm->rb[i]);		if (!(buf->base = usb_buffer_alloc(acm->dev, readsize, GFP_KERNEL, &buf->dma))) {			dev_dbg(&intf->dev, "out of memory (read bufs usb_buffer_alloc)/n");			goto alloc_fail7;		}	}	acm->writeurb = usb_alloc_urb(0, GFP_KERNEL);	if (!acm->writeurb) {		dev_dbg(&intf->dev, "out of memory (writeurb kmalloc)/n");		goto alloc_fail7;	}	usb_set_intfdata (intf, acm);	i = device_create_file(&intf->dev, &dev_attr_bmCapabilities);	if (i < 0)		goto alloc_fail8;	if (cfd) { /* export the country data */		acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL);		if (!acm->country_codes)			goto skip_countries;		acm->country_code_size = cfd->bLength - 4;		memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, cfd->bLength - 4);		acm->country_rel_date = cfd->iCountryCodeRelDate;		i = device_create_file(&intf->dev, &dev_attr_wCountryCodes);		if (i < 0) {			kfree(acm->country_codes);			goto skip_countries;		}		i = device_create_file(&intf->dev, &dev_attr_iCountryCodeRelDate);		if (i < 0) {			kfree(acm->country_codes);			goto skip_countries;		}	}skip_countries:	usb_fill_int_urb(acm->ctrlurb, usb_dev, usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress),			 acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, epctrl->bInterval);	acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;	acm->ctrlurb->transfer_dma = acm->ctrl_dma;	usb_fill_bulk_urb(acm->writeurb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress),			  NULL, acm->writesize, acm_write_bulk, acm);	acm->writeurb->transfer_flags |= URB_NO_FSBR | URB_NO_TRANSFER_DMA_MAP;	dev_info(&intf->dev, "ttyACM%d: USB ACM device/n", minor);	acm_set_control(acm, acm->ctrlout);	acm->line.dwDTERate = cpu_to_le32(9600);	acm->line.bDataBits = 8;	acm_set_line(acm, &acm->line);	usb_driver_claim_interface(&acm_driver, data_interface, acm);	usb_get_intf(control_interface);	tty_register_device(acm_tty_driver, minor, &control_interface->dev);	acm_table[minor] = acm;	return 0;alloc_fail8:	usb_free_urb(acm->writeurb);alloc_fail7:	for (i = 0; i < num_rx_buf; i++)		usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma);	for (i = 0; i < num_rx_buf; i++)		usb_free_urb(acm->ru[i].urb);	usb_free_urb(acm->ctrlurb);alloc_fail5:	acm_write_buffers_free(acm);alloc_fail4:	usb_buffer_free(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);alloc_fail2:	kfree(acm);alloc_fail:	return -ENOMEM;}
开发者ID:Tigrouzen,项目名称:k1099,代码行数:101,


示例3: usbnet_get_endpoints

/* handles CDC Ethernet and many other network "bulk data" interfaces */int usbnet_get_endpoints(struct usbnet *dev, struct usb_interface *intf){	int				tmp;	struct usb_host_interface	*alt = NULL;	struct usb_host_endpoint	*in = NULL, *out = NULL;	struct usb_host_endpoint	*status = NULL;	for (tmp = 0; tmp < intf->num_altsetting; tmp++) {		unsigned	ep;		in = out = status = NULL;		alt = intf->altsetting + tmp;		/* take the first altsetting with in-bulk + out-bulk;		 * remember any status endpoint, just in case;		 * ignore other endpoints and altsettings.		 */		for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {			struct usb_host_endpoint	*e;			int				intr = 0;			e = alt->endpoint + ep;			switch (e->desc.bmAttributes) {			case USB_ENDPOINT_XFER_INT:				if (!usb_endpoint_dir_in(&e->desc))					continue;				intr = 1;				/* FALLTHROUGH */			case USB_ENDPOINT_XFER_BULK:				break;			default:				continue;			}			if (usb_endpoint_dir_in(&e->desc)) {				if (!intr && !in)					in = e;				else if (intr && !status)					status = e;			} else {				if (!out)					out = e;			}		}		if (in && out)			break;	}	if (!alt || !in || !out)		return -EINVAL;	if (alt->desc.bAlternateSetting != 0 ||	    !(dev->driver_info->flags & FLAG_NO_SETINT)) {		tmp = usb_set_interface (dev->udev, alt->desc.bInterfaceNumber,				alt->desc.bAlternateSetting);		if (tmp < 0)			return tmp;	}	dev->in = usb_rcvbulkpipe (dev->udev,			in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);	dev->out = usb_sndbulkpipe (dev->udev,			out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);	dev->status = status;	return 0;}
开发者ID:LucasFeliciano21,项目名称:BeagleBoard-Stable_Linux,代码行数:65,


示例4: skel_write

static ssize_t skel_write(struct file *file, const char *user_buffer, size_t count, loff_t *ppos){	struct usb_skel *dev;	int retval = 0;	struct urb *urb = NULL;	char *buf = NULL;	size_t writesize = min(count, (size_t)MAX_TRANSFER);	dev = (struct usb_skel *)file->private_data;	/* verify that we actually have some data to write */	if (count == 0)		goto exit;	/* limit the number of URBs in flight to stop a user from using up all RAM */	if (down_interruptible(&dev->limit_sem)) {		retval = -ERESTARTSYS;		goto exit;	}	spin_lock_irq(&dev->err_lock);	if ((retval = dev->errors) < 0) {		/* any error is reported once */		dev->errors = 0;		/* to preserve notifications about reset */		retval = (retval == -EPIPE) ? retval : -EIO;	}	spin_unlock_irq(&dev->err_lock);	if (retval < 0)		goto error;	/* create a urb, and a buffer for it, and copy the data to the urb */	urb = usb_alloc_urb(0, GFP_KERNEL);	if (!urb) {		retval = -ENOMEM;		goto error;	}	buf = usb_buffer_alloc(dev->udev, writesize, GFP_KERNEL, &urb->transfer_dma);	if (!buf) {		retval = -ENOMEM;		goto error;	}	if (copy_from_user(buf, user_buffer, writesize)) {		retval = -EFAULT;		goto error;	}	/* this lock makes sure we don't submit URBs to gone devices */	mutex_lock(&dev->io_mutex);	if (!dev->interface) {		/* disconnect() was called */		mutex_unlock(&dev->io_mutex);		retval = -ENODEV;		goto error;	}	/* initialize the urb properly */	usb_fill_bulk_urb(urb, dev->udev,			  usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr),			  buf, writesize, skel_write_bulk_callback, dev);	urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;	usb_anchor_urb(urb, &dev->submitted);	/* send the data out the bulk port */	retval = usb_submit_urb(urb, GFP_KERNEL);	mutex_unlock(&dev->io_mutex);	if (retval) {		err("%s - failed submitting write urb, error %d", __func__, retval);		goto error_unanchor;	}	/* release our reference to this urb, the USB core will eventually free it entirely */	usb_free_urb(urb);	return writesize;error_unanchor:	usb_unanchor_urb(urb);error:	if (urb) {		usb_buffer_free(dev->udev, writesize, buf, urb->transfer_dma);		usb_free_urb(urb);	}	up(&dev->limit_sem);exit:	return retval;}
开发者ID:johnny,项目名称:CobraDroidBeta,代码行数:90,


示例5: empeg_write

static int empeg_write (struct usb_serial_port *port, const unsigned char *buf, int count){	struct usb_serial *serial = port->serial;	struct urb *urb;	const unsigned char *current_position = buf;	unsigned long flags;	int status;	int i;	int bytes_sent = 0;	int transfer_size;	dbg("%s - port %d", __FUNCTION__, port->number);	while (count > 0) {		/* try to find a free urb in our list of them */		urb = NULL;		spin_lock_irqsave (&write_urb_pool_lock, flags);		for (i = 0; i < NUM_URBS; ++i) {			if (write_urb_pool[i]->status != -EINPROGRESS) {				urb = write_urb_pool[i];				break;			}		}		spin_unlock_irqrestore (&write_urb_pool_lock, flags);		if (urb == NULL) {			dbg("%s - no more free urbs", __FUNCTION__);			goto exit;		}		if (urb->transfer_buffer == NULL) {			urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC);			if (urb->transfer_buffer == NULL) {				dev_err(&port->dev, "%s no more kernel memory.../n", __FUNCTION__);				goto exit;			}		}		transfer_size = min (count, URB_TRANSFER_BUFFER_SIZE);		memcpy (urb->transfer_buffer, current_position, transfer_size);		usb_serial_debug_data(debug, &port->dev, __FUNCTION__, transfer_size, urb->transfer_buffer);		/* build up our urb */		usb_fill_bulk_urb (			urb,			serial->dev,			usb_sndbulkpipe(serial->dev,				port->bulk_out_endpointAddress), 			urb->transfer_buffer,			transfer_size,			empeg_write_bulk_callback,			port);		/* send it down the pipe */		status = usb_submit_urb(urb, GFP_ATOMIC);		if (status) {			dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d/n", __FUNCTION__, status);			bytes_sent = status;			break;		}		current_position += transfer_size;		bytes_sent += transfer_size;		count -= transfer_size;		bytes_out += transfer_size;	}exit:	return bytes_sent;} 
开发者ID:BackupTheBerlios,项目名称:tew632-brp-svn,代码行数:78,


示例6: init_card

static int init_card(struct snd_usb_caiaqdev *dev){	char *c;	struct usb_device *usb_dev = dev->chip.dev;	struct snd_card *card = dev->chip.card;	int err, len;		if (usb_set_interface(usb_dev, 0, 1) != 0) {		log("can't set alt interface./n");		return -EIO;	}	usb_init_urb(&dev->ep1_in_urb);	usb_init_urb(&dev->midi_out_urb);	usb_fill_bulk_urb(&dev->ep1_in_urb, usb_dev, 			  usb_rcvbulkpipe(usb_dev, 0x1),			  dev->ep1_in_buf, EP1_BUFSIZE, 			  usb_ep1_command_reply_dispatch, dev);	usb_fill_bulk_urb(&dev->midi_out_urb, usb_dev, 			  usb_sndbulkpipe(usb_dev, 0x1),			  dev->midi_out_buf, EP1_BUFSIZE, 			  snd_usb_caiaq_midi_output_done, dev);		init_waitqueue_head(&dev->ep1_wait_queue);	init_waitqueue_head(&dev->prepare_wait_queue);		if (usb_submit_urb(&dev->ep1_in_urb, GFP_KERNEL) != 0)		return -EIO;	err = send_command(dev, EP1_CMD_GET_DEVICE_INFO, NULL, 0);	if (err)		return err;	if (!wait_event_timeout(dev->ep1_wait_queue, dev->spec_received, HZ))		return -ENODEV;	usb_string(usb_dev, usb_dev->descriptor.iManufacturer,		   dev->vendor_name, CAIAQ_USB_STR_LEN);		usb_string(usb_dev, usb_dev->descriptor.iProduct,		   dev->product_name, CAIAQ_USB_STR_LEN);		usb_string(usb_dev, usb_dev->descriptor.iSerialNumber,		   dev->serial, CAIAQ_USB_STR_LEN);	/* terminate serial string at first white space occurence */	c = strchr(dev->serial, ' ');	if (c)		*c = '/0';		strcpy(card->driver, MODNAME);	strcpy(card->shortname, dev->product_name);	len = snprintf(card->longname, sizeof(card->longname),		       "%s %s (serial %s, ",		       dev->vendor_name, dev->product_name, dev->serial);	if (len < sizeof(card->longname) - 2)		len += usb_make_path(usb_dev, card->longname + len,				     sizeof(card->longname) - len);	card->longname[len++] = ')';	card->longname[len] = '/0';	setup_card(dev);	return 0;}
开发者ID:acassis,项目名称:emlinux-ssd1935,代码行数:68,


示例7: hdm_enqueue

/** * hdm_enqueue - receive a buffer to be used for data transfer * @iface: interface to enqueue to * @channel: ID of the channel * @mbo: pointer to the buffer object * * This allocates a new URB and fills it according to the channel * that is being used for transmission of data. Before the URB is * submitted it is stored in the private anchor list. * * Returns 0 on success. On any error the URB is freed and a error code * is returned. * * Context: Could in _some_ cases be interrupt! */static int hdm_enqueue(struct most_interface *iface, int channel,		       struct mbo *mbo){	struct most_dev *mdev;	struct most_channel_config *conf;	struct device *dev;	int retval = 0;	struct urb *urb;	unsigned long length;	void *virt_address;	if (unlikely(!iface || !mbo))		return -EIO;	if (unlikely(iface->num_channels <= channel || channel < 0))		return -ECHRNG;	mdev = to_mdev(iface);	conf = &mdev->conf[channel];	dev = &mdev->usb_device->dev;	if (!mdev->usb_device)		return -ENODEV;	urb = usb_alloc_urb(NO_ISOCHRONOUS_URB, GFP_ATOMIC);	if (!urb)		return -ENOMEM;	if ((conf->direction & MOST_CH_TX) && mdev->padding_active[channel] &&	    hdm_add_padding(mdev, channel, mbo)) {		retval = -EIO;		goto _error;	}	urb->transfer_dma = mbo->bus_address;	virt_address = mbo->virt_address;	length = mbo->buffer_length;	if (conf->direction & MOST_CH_TX) {		usb_fill_bulk_urb(urb, mdev->usb_device,				  usb_sndbulkpipe(mdev->usb_device,						  mdev->ep_address[channel]),				  virt_address,				  length,				  hdm_write_completion,				  mbo);		if (conf->data_type != MOST_CH_ISOC)			urb->transfer_flags |= URB_ZERO_PACKET;	} else {		usb_fill_bulk_urb(urb, mdev->usb_device,				  usb_rcvbulkpipe(mdev->usb_device,						  mdev->ep_address[channel]),				  virt_address,				  length + conf->extra_len,				  hdm_read_completion,				  mbo);	}	urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;	usb_anchor_urb(urb, &mdev->busy_urbs[channel]);	retval = usb_submit_urb(urb, GFP_KERNEL);	if (retval) {		dev_err(dev, "URB submit failed with error %d./n", retval);		goto _error_1;	}	return 0;_error_1:	usb_unanchor_urb(urb);_error:	usb_free_urb(urb);	return retval;}
开发者ID:acton393,项目名称:linux,代码行数:88,


示例8: whiteheat_attach

static int whiteheat_attach(struct usb_serial *serial){	struct usb_serial_port *command_port;	struct whiteheat_command_private *command_info;	struct whiteheat_hw_info *hw_info;	int pipe;	int ret;	int alen;	__u8 *command;	__u8 *result;	command_port = serial->port[COMMAND_PORT];	pipe = usb_sndbulkpipe(serial->dev,			command_port->bulk_out_endpointAddress);	command = kmalloc(2, GFP_KERNEL);	if (!command)		goto no_command_buffer;	command[0] = WHITEHEAT_GET_HW_INFO;	command[1] = 0;	result = kmalloc(sizeof(*hw_info) + 1, GFP_KERNEL);	if (!result)		goto no_result_buffer;	/*	 * When the module is reloaded the firmware is still there and	 * the endpoints are still in the usb core unchanged. This is the	 * unlinking bug in disguise. Same for the call below.	 */	usb_clear_halt(serial->dev, pipe);	ret = usb_bulk_msg(serial->dev, pipe, command, 2,						&alen, COMMAND_TIMEOUT_MS);	if (ret) {		dev_err(&serial->dev->dev, "%s: Couldn't send command [%d]/n",			serial->type->description, ret);		goto no_firmware;	} else if (alen != 2) {		dev_err(&serial->dev->dev, "%s: Send command incomplete [%d]/n",			serial->type->description, alen);		goto no_firmware;	}	pipe = usb_rcvbulkpipe(serial->dev,				command_port->bulk_in_endpointAddress);	/* See the comment on the usb_clear_halt() above */	usb_clear_halt(serial->dev, pipe);	ret = usb_bulk_msg(serial->dev, pipe, result,			sizeof(*hw_info) + 1, &alen, COMMAND_TIMEOUT_MS);	if (ret) {		dev_err(&serial->dev->dev, "%s: Couldn't get results [%d]/n",			serial->type->description, ret);		goto no_firmware;	} else if (alen != sizeof(*hw_info) + 1) {		dev_err(&serial->dev->dev, "%s: Get results incomplete [%d]/n",			serial->type->description, alen);		goto no_firmware;	} else if (result[0] != command[0]) {		dev_err(&serial->dev->dev, "%s: Command failed [%d]/n",			serial->type->description, result[0]);		goto no_firmware;	}	hw_info = (struct whiteheat_hw_info *)&result[1];	dev_info(&serial->dev->dev, "%s: Firmware v%d.%02d/n",		 serial->type->description,		 hw_info->sw_major_rev, hw_info->sw_minor_rev);	command_info = kmalloc(sizeof(struct whiteheat_command_private),								GFP_KERNEL);	if (command_info == NULL) {		dev_err(&serial->dev->dev,			"%s: Out of memory for port structures/n",			serial->type->description);		goto no_command_private;	}	mutex_init(&command_info->mutex);	command_info->port_running = 0;	init_waitqueue_head(&command_info->wait_command);	usb_set_serial_port_data(command_port, command_info);	command_port->write_urb->complete = command_port_write_callback;	command_port->read_urb->complete = command_port_read_callback;	kfree(result);	kfree(command);	return 0;no_firmware:	/* Firmware likely not running */	dev_err(&serial->dev->dev,		"%s: Unable to retrieve firmware version, try replugging/n",		serial->type->description);	dev_err(&serial->dev->dev,		"%s: If the firmware is not running (status led not blinking)/n",		serial->type->description);	dev_err(&serial->dev->dev,		"%s: please contact [email
C++ usb_sndctrlpipe函数代码示例
C++ usb_set_serial_port_data函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。