我刚开始为dds生成器编写自己的Linux驱动程序。
我想在der Kernel调用probe函数时将2个批量消息写入生成器。但我不知道如何调用usb_bulk_msg函数。我希望你能我。
同步
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;
}
最佳答案
内核是一个不言自明的项目,因此通常您可以在内核代码中找到正确的答案。
功能用法
include/linux/usb.h :在这里您可以看到此功能的签名
extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
void *data, int len, int *actual_length,
int timeout);
drivers/usb/core/message.c :在这里您可以看到此函数的漂亮说明(参数,返回值,使用方法)
/**
* 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 site。
如果您是USB驱动程序开发的新手,那么您可能也对某些教程感兴趣:
在评论中回答问题
我知道两种解决方法:
将设备的供应商ID和产品ID作为
quirks
参数提供给usbhid
模块。您可以通过内核cmdline传递此参数。编辑/etc/default/grub
文件,在usbhid.quirks=0xdead:0xbeef:0x4
中添加类似GRUB_CMDLINE_LINUX_DEFAULT
的内容,然后执行以下操作:$ sudo update-grub
然后重启。
使用
ignore_device
选项为您的设备创建udev规则。但是似乎该选项在udev的新版本中已被删除,因此您可能无法使用它。 细节:
[1] https://unix.stackexchange.com/questions/55495/prevent-usbhid-from-claiming-usb-device/55590#55590
[2] http://ubuntuforums.org/showthread.php?t=1175001&p=7548820#post7548820
关于c - 批量邮件传输USB Linux,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28566091/