首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >批量消息传输USB

批量消息传输USB
EN

Stack Overflow用户
提问于 2015-02-17 16:23:32
回答 1查看 3.7K关注 0票数 2

我刚刚开始为dds生成器编写自己的Linux驱动程序。

当der调用探测函数时,我想向生成器写入2个大容量消息。但是我不知道如何调用usb_bulk_msg函数。我希望你能帮我。

hsync

代码语言:javascript
复制
static int dds_probe(struct usb_interface *interface, const struct usb_device_id *id)
{
int retval = 0;

retval = usb_bulk_msg();

dev_info(&interface->dev, "DDS generator is now attached\n");
return 0;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-17 18:59:07

内核是一个自我解释的项目,所以通常你可以在内核代码中找到答案。

功能使用

include/linux/usb.h:在这里您可以看到这个函数的签名

代码语言:javascript
复制
extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
                        void *data, int len, int *actual_length,
                        int timeout);

在这里您可以看到对这个函数的很好的描述(参数,返回值,如何使用它)

代码语言:javascript
复制
/**
 * usb_bulk_msg - Builds a bulk urb, sends it off and waits for completion
 * @usb_dev: pointer to the usb device to send the message to
 * @pipe: endpoint "pipe" to send the message to
 * @data: pointer to the data to send
 * @len: length in bytes of the data to send
 * @actual_length: pointer to a location to put the actual length transferred
 *                 in bytes
 * @timeout: time in msecs to wait for the message to complete before
 *           timing out (if 0 the wait is forever)
 *
 * Context: !in_interrupt ()
 *
 * This function sends a simple bulk message to a specified endpoint
 * and waits for the message to complete, or timeout.
 *
 * Don't use this function from within an interrupt context, like a bottom half
 * handler.  If you need an asynchronous message, or need to send a message
 * from within interrupt context, use usb_submit_urb() If a thread in your
 * driver uses this call, make sure your disconnect() method can wait for it to
 * complete.  Since you don't have a handle on the URB used, you can't cancel
 * the request.
 *
 * Because there is no usb_interrupt_msg() and no USBDEVFS_INTERRUPT ioctl,
 * users are forced to abuse this routine by using it to submit URBs for
 * interrupt endpoints.  We will take the liberty of creating an interrupt URB
 * (with the default interval) if the target is an interrupt endpoint.
 *
 * Return:
 * If successful, 0. Otherwise a negative error number. The number of actual
 * bytes transferred will be stored in the @actual_length parameter.
 *
 */

示例

如果您需要一些如何使用此函数的示例,您也可以在内核代码中找到它们,例如使用LXR站点

如果您是USB驱动程序开发的新手,您可能还会对一些教程感兴趣:

在评论中回答问题

当我插入生成器时,内核执行我的驱动程序,然后usbcore加载usbhid驱动程序,因为生成器是hid设备,下一次usbcore不执行我的“驱动程序”。

我知道有两种方法可以解决这个问题:

  1. 使用usbhid驱动程序的“古怪的”param。 提供设备的供应商ID和产品ID作为quirks param到usbhid模块。您可以通过内核cmdline传递这个param。编辑/etc/default/grub文件,将类似usbhid.quirks=0xdead:0xbeef:0x4的内容添加到GRUB_CMDLINE_LINUX_DEFAULT中,然后执行以下操作: $ sudo更新-grub 那就重新启动。
  2. 使用udev。 使用ignore_device选项为设备创建udev规则。但是这个选项似乎在udev的新版本中被删除了,所以您可能无法使用它。

详细信息:

1

2

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28566091

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档