urb中state成员的取值

本文详细解释了USB URB(Urban Transfer Request Block)操作中可能出现的各种错误代码及含义,帮助开发者理解并解决USB通信过程中遇到的问题。

from 13.3. USB Urbs: http://www.makelinux.net/ldd3/chp-13-sect-3

Valid values for this variable include:

0

The urb transfer was successful.

-ENOENT

The urb was stopped by a call to usb_kill_urb.

-ECONNRESET 

 

The urb was unlinked by a call to usb_unlink_urb, and the TRansfer_flags variable of the urb was set to URB_ASYNC_UNLINK.

-EINPROGRESS 

The urb is still being processed by the USB host controllers. If your driver ever sees this value, it is a bug in your driver.

-EPROTO 

One of the following errors occurred with this urb:

  • A bitstuff error happened during the transfer.

  • No response packet was received in time by the hardware.

-EILSEQ 

There was a CRC mismatch in the urb transfer.

-EPIPE 

The endpoint is now stalled. If the endpoint involved is not a control endpoint, this error can be cleared through a call to the function usb_clear_halt.

-ECOMM 

Data was received faster during the transfer than it could be written to system memory. This error value happens only for an IN urb.

-ENOSR 

Data could not be retrieved from the system memory during the transfer fast enough to keep up with the requested USB data rate. This error value happens only for an OUT urb.

-EOVERFLOW 

A "babble" error happened to the urb. A "babble" error occurs when the endpoint receives more data than the endpoint's specified maximum packet size.

-EREMOTEIO 

Occurs only if the URB_SHORT_NOT_OK flag is set in the urb's transfer_flags variable and means that the full amount of data requested by the urb was not received.

-ENODEV 

The USB device is now gone from the system.

-EXDEV 

Occurs only for a isochronous urb and means that the transfer was only partially completed. In order to determine what was transferred, the driver must look at the individual frame status.

-EINVAL 

Something very bad happened with the urb. The USB kernel documentation describes what this value means:

ISO madness, if this happens: Log off and go home

It also can happen if a parameter is incorrectly set in the urb stucture or if an incorrect function parameter in the usb_submit_urb call submitted the urb to the USB core.

-ESHUTDOWN 

There was a severe error with the USB host controller driver; it has now been disabled, or the device was disconnected from the system, and the urb was submitted after the device was removed. It can also occur if the configuration was changed for the device, while the urb was submitted to the device.

Generally, the error values -EPROTO, -EILSEQ, and -EOVERFLOW indicate hardware problems with the device, the device firmware, or the cable connecting the device to the computer.

 

USB设备通信中的URB(USB Request Block,USB请求块)是用于描述与USB设备通信所用的基本载体和核心数据结构。它是USB设备驱动程序与USB设备之间进行数据传输的关键机制,其作用类似于网络设备驱动中的`sk_buff`结构体[^1]。 URB以异步传输的方式实现与特定USB设备的特定端点之间的数据发送和接收。USB设备驱动程序可以根据需要为一个端点分配多个URB,也可以重用单个URB用于多个不同的端点。由于USB设备中的每个端点都可以处理一个URB队列,因此在队列清空之前,可以将多个URB发送到相同的端点。此外,URB可以在任何时候被提交它的驱动程序取消。如果USB设备被移除,URB也可以被USB核心取消。URB被动态创建,并包含一个内部引用计数,当最后一个用户释放它时,URB会被自动释放[^2]。 在Linux内核系统中,URB的典型运作流程包括以下几个步骤: 1. 创建一个URB。 2. 将创建的URB分配给一个特定USB设备的特定端点。 3. 将URB提交给USB核心。 4. URB被USB核心提交给特定设备的特定USB主机控制器驱动。 5. URB被USB主机控制器驱动处理,并被传送到设备。 URB通信过程在实际开发中尤为重要,例如在RK3588平台上,URB作为USB通信的核心机制,其详细过程对于深入理解USB设备通信机制至关重要。通过实际案例和详细代码演示,可以更好地掌握URB的应用,从而实现更高效、更稳定的USB应用开发[^3]。 以下是一个简单的URB初始化和提交的代码示例: ```c struct urb *urb = usb_alloc_urb(0, GFP_KERNEL); if (!urb) { // 处理内存分配失败的情况 } // 初始化URB,设置传输类型、设备、端点、数据缓冲区等 usb_fill_bulk_urb(urb, dev->udev, usb_sndbulkpipe(dev->udev, dev->bulk_out_endpoint), buffer, size, my_completion_handler, dev); // 提交URB到USB核心 int result = usb_submit_urb(urb, GFP_KERNEL); if (result) { // 处理提交失败的情况 } ``` 在上述代码中,`usb_alloc_urb`用于分配一个URB结构体,`usb_fill_bulk_urb`用于填充URB的字段,包括传输方向、数据缓冲区、完成处理函数等,最后通过`usb_submit_urb`将URB提交给USB核心进行处理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值