当前位置: 技术问答>linux和unix
usb 驱动读数据问题 (100分) 请有usb驱动经验的高手指点!
来源: 互联网 发布时间:2016-05-05
本文导语: 我根据内核中的:usb-skeleton.c 改写了一个驱动,现在写数据没有问题,但就是读不到数据(没修改前读数据时,提示错误urb->status=-110,修改也没成功interval也没用),其中写数据部分没有改,读数据不成功才修改成...
我根据内核中的:usb-skeleton.c 改写了一个驱动,现在写数据没有问题,但就是读不到数据(没修改前读数据时,提示错误urb->status=-110,修改也没成功interval也没用),其中写数据部分没有改,读数据不成功才修改成如下:
static void my_read_interrupt_callback(struct urb *urb)
{
char *tmpDbg;
struct usb_skel *dev;
dbg("Enter my_read_interrupt_callback()");
dev = (struct usb_skel *)urb->context;
tmpDbg= (char*)(urb->transfer_buffer);
/* sync/async unlink faults aren't errors */
if ( urb->status &&
!(urb->status == -ENOENT || urb->status == -ECONNRESET || urb->status == -ESHUTDOWN)
) {
dbg("%s - nonzero read interrupt status received: %d", __FUNCTION__, urb->status);
}
else { dbg("The urb->status is %d",urb->status); }
dbg( "device buffer(callback): %X %X ",tmpDbg[0],tmpDbg[1]);
}
static ssize_t skel_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
{
struct usb_skel *dev;
int retval;
size_t bytes_read = min(count, (size_t)MAX_TRANSFER);
struct urb *urb = NULL;
dev = (struct usb_skel *)file->private_data;
mutex_lock(&dev->io_mutex);
if (!dev->interface) {
retval = -ENODEV;
goto exit;
}
urb = usb_alloc_urb(0, GFP_KERNEL);
if (!urb) {
retval = -ENOMEM;
goto exit;
}
usb_fill_int_urb(urb,dev->udev,usb_rcvintpipe(dev->udev, dev->bulk_in_endpointAddr),
dev->bulk_in_buffer,
bytes_read,
my_read_interrupt_callback,
dev,250 );
urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
retval = usb_submit_urb(urb, GFP_KERNEL);
err("The status of usb_submit_urb() is %d",retval);
if (!retval) {
if (copy_to_user(buffer, dev->bulk_in_buffer, bytes_read))
retval = -EFAULT;
else
retval = bytes_read;
}
exit:
mutex_unlock(&dev->io_mutex);
return retval;
}
执行时怎么不进入了my_read_interrupt_callback()函数?
并且还是读不到单片机返回的数据?
我单片机是cdc acm 设备
开始没修改读数据时,为什么urb->status=-110?
请大家指教!
static void my_read_interrupt_callback(struct urb *urb)
{
char *tmpDbg;
struct usb_skel *dev;
dbg("Enter my_read_interrupt_callback()");
dev = (struct usb_skel *)urb->context;
tmpDbg= (char*)(urb->transfer_buffer);
/* sync/async unlink faults aren't errors */
if ( urb->status &&
!(urb->status == -ENOENT || urb->status == -ECONNRESET || urb->status == -ESHUTDOWN)
) {
dbg("%s - nonzero read interrupt status received: %d", __FUNCTION__, urb->status);
}
else { dbg("The urb->status is %d",urb->status); }
dbg( "device buffer(callback): %X %X ",tmpDbg[0],tmpDbg[1]);
}
static ssize_t skel_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
{
struct usb_skel *dev;
int retval;
size_t bytes_read = min(count, (size_t)MAX_TRANSFER);
struct urb *urb = NULL;
dev = (struct usb_skel *)file->private_data;
mutex_lock(&dev->io_mutex);
if (!dev->interface) {
retval = -ENODEV;
goto exit;
}
urb = usb_alloc_urb(0, GFP_KERNEL);
if (!urb) {
retval = -ENOMEM;
goto exit;
}
usb_fill_int_urb(urb,dev->udev,usb_rcvintpipe(dev->udev, dev->bulk_in_endpointAddr),
dev->bulk_in_buffer,
bytes_read,
my_read_interrupt_callback,
dev,250 );
urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
retval = usb_submit_urb(urb, GFP_KERNEL);
err("The status of usb_submit_urb() is %d",retval);
if (!retval) {
if (copy_to_user(buffer, dev->bulk_in_buffer, bytes_read))
retval = -EFAULT;
else
retval = bytes_read;
}
exit:
mutex_unlock(&dev->io_mutex);
return retval;
}
执行时怎么不进入了my_read_interrupt_callback()函数?
并且还是读不到单片机返回的数据?
我单片机是cdc acm 设备
开始没修改读数据时,为什么urb->status=-110?
请大家指教!
|
在windows平台下可以正常通信,说明协议没问题。还是看看是不是代码问题吧。
|
只能up了。。