Browse Source

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

Signed-off-by: sakumisu <1203593632@qq.com>
sakumisu 6 months ago
parent
commit
832e4c45fb
4 changed files with 32 additions and 25 deletions
  1. 1 1
      class/hub/usbh_hub.c
  2. 1 1
      core/usbh_core.h
  3. 25 22
      docs/source/api/api_port.rst
  4. 5 1
      docs/source/demo/usbh_hid.rst

+ 1 - 1
class/hub/usbh_hub.c

@@ -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_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) {
         USB_LOG_ERR("No memory to alloc int_timer\r\n");
         return -USB_ERR_NOMEM;

+ 1 - 1
core/usbh_core.h

@@ -47,7 +47,7 @@ extern "C" {
 #define CLASS_INFO_DEFINE __attribute__((section(".usbh_class_info"))) __USED __ALIGNED(1)
 #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)                                            \
     do {                                                                     \

+ 25 - 22
docs/source/api/api_port.rst

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

+ 5 - 1
docs/source/demo/usbh_hid.rst

@@ -48,4 +48,8 @@ usbh_hid
 
 .. 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 的不需要使用定时器。