fix(class/hub): change urb interval unit to us

Signed-off-by: sakumisu <1203593632@qq.com>
This commit is contained in:
sakumisu
2025-07-01 21:21:53 +08:00
parent 52ea7e8dcf
commit 832e4c45fb
4 changed files with 32 additions and 25 deletions

View File

@@ -416,7 +416,7 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
hub->int_buffer = g_hub_intbuf[hub->bus->busid][hub->index - 1]; hub->int_buffer = g_hub_intbuf[hub->bus->busid][hub->index - 1];
hub->int_timer = usb_osal_timer_create("hubint_tim", USBH_GET_URB_INTERVAL(hub->intin->bInterval, hport->speed), hub_int_timeout, hub, 0); hub->int_timer = usb_osal_timer_create("hubint_tim", USBH_GET_URB_INTERVAL(hub->intin->bInterval, hport->speed) / 1000, hub_int_timeout, hub, 0);
if (hub->int_timer == NULL) { if (hub->int_timer == NULL) {
USB_LOG_ERR("No memory to alloc int_timer\r\n"); USB_LOG_ERR("No memory to alloc int_timer\r\n");
return -USB_ERR_NOMEM; return -USB_ERR_NOMEM;

View File

@@ -47,7 +47,7 @@ extern "C" {
#define CLASS_INFO_DEFINE __attribute__((section(".usbh_class_info"))) __USED __ALIGNED(1) #define CLASS_INFO_DEFINE __attribute__((section(".usbh_class_info"))) __USED __ALIGNED(1)
#endif #endif
#define USBH_GET_URB_INTERVAL(interval, speed) (speed < USB_SPEED_HIGH ? interval : (1 << (interval - 1))) #define USBH_GET_URB_INTERVAL(interval, speed) (speed < USB_SPEED_HIGH ? (interval * 1000) : ((1 << (interval - 1)) * 125))
#define USBH_EP_INIT(ep, ep_desc) \ #define USBH_EP_INIT(ep, ep_desc) \
do { \ do { \

View File

@@ -186,33 +186,36 @@ usbh_submit_urb
.. code-block:: C .. code-block:: C
struct usbh_urb { struct usbh_urb {
void *hcpriv; usb_slist_t list;
struct usbh_hubport *hport; void *hcpriv;
struct usb_endpoint_descriptor *ep; struct usbh_hubport *hport;
uint8_t data_toggle; struct usb_endpoint_descriptor *ep;
struct usb_setup_packet *setup; uint8_t data_toggle;
uint8_t *transfer_buffer; uint8_t interval;
uint32_t transfer_buffer_length; struct usb_setup_packet *setup;
int transfer_flags; uint8_t *transfer_buffer;
uint32_t actual_length; uint32_t transfer_buffer_length;
uint32_t timeout; int transfer_flags;
int errorcode; uint32_t actual_length;
uint32_t num_of_iso_packets; uint32_t timeout;
uint32_t start_frame; int errorcode;
usbh_complete_callback_t complete; uint32_t num_of_iso_packets;
void *arg; uint32_t start_frame;
#if defined(__ICCARM__) || defined(__ICCRISCV__) || defined(__ICCRX__) usbh_complete_callback_t complete;
struct usbh_iso_frame_packet *iso_packet; void *arg;
#else #if defined(__ICCARM__) || defined(__ICCRISCV__) || defined(__ICCRX__)
struct usbh_iso_frame_packet iso_packet[0]; struct usbh_iso_frame_packet *iso_packet;
#endif #else
}; struct usbh_iso_frame_packet iso_packet[0];
#endif
};
- **hcpriv** 主机控制器驱动私有成员 - **hcpriv** 主机控制器驱动私有成员
- **hport** 当前 urb 使用的 hport - **hport** 当前 urb 使用的 hport
- **ep** 当前 urb 使用的 ep - **ep** 当前 urb 使用的 ep
- **data_toggle** 当前 data toggle - **data_toggle** 当前 data toggle
- **interval** urb 传输间隔,单位 us如果 interval 大于 1000us则需要使用软件定时器来维护
- **setup** setup 请求缓冲区端点0使用 - **setup** setup 请求缓冲区端点0使用
- **transfer_buffer** 传输的数据缓冲区 - **transfer_buffer** 传输的数据缓冲区
- **transfer_buffer_length** 传输长度 - **transfer_buffer_length** 传输长度

View File

@@ -48,4 +48,8 @@ usbh_hid
.. code-block:: C .. code-block:: C
hub->int_timer = usb_osal_timer_create("hubint_tim", USBH_GET_URB_INTERVAL(hub->intin->bInterval, hport->speed), hub_int_timeout, hub, 0); hub->int_timer = usb_osal_timer_create("hubint_tim", USBH_GET_URB_INTERVAL(hub->intin->bInterval, hport->speed) / 1000, hub_int_timeout, hub, 0);
.. note::
这里的 `USBH_GET_URB_INTERVAL` 是一个宏定义,用于根据 binterval 计算 URB 的传输间隔时间, 单位是 us而定时器最低是 ms ,因此需要除以 1000。对于小于等于 1ms 的不需要使用定时器。