Просмотр исходного кода

update ehci iso struct and api

sakumisu 2 лет назад
Родитель
Сommit
53fe0f2cd5
3 измененных файлов с 46 добавлено и 45 удалено
  1. 11 11
      port/ehci/usb_ehci_priv.h
  2. 32 32
      port/ehci/usb_hc_ehci.c
  3. 3 2
      port/ehci/usb_hc_ehci.h

+ 11 - 11
port/ehci/usb_ehci_priv.h

@@ -27,10 +27,9 @@
 #error Unsupported frame size list size
 #endif
 
-#define CONFIG_USB_EHCI_QH_NUM       CONFIG_USBHOST_PIPE_NUM
-#define CONFIG_USB_EHCI_QTD_NUM      (CONFIG_USBHOST_PIPE_NUM * 3)
-#define CONFIG_USB_EHCI_ITD_NUM      10
-#define CONFIG_USB_EHCI_ITD_POOL_NUM 2
+#define CONFIG_USB_EHCI_QH_NUM  CONFIG_USBHOST_PIPE_NUM
+#define CONFIG_USB_EHCI_QTD_NUM (CONFIG_USBHOST_PIPE_NUM * 3)
+#define CONFIG_USB_EHCI_ITD_NUM 20
 
 extern uint8_t usbh_get_port_speed(const uint8_t port);
 
@@ -52,11 +51,10 @@ struct ehci_pipe {
     struct usbh_hubport *hport;
     struct ehci_qh_hw *qh;
     struct usbh_urb *urb;
-    uint8_t used_itd_num;
-    uint8_t id;
     uint8_t mf_unmask;
     uint8_t mf_valid;
-    usb_slist_t iso_list;
+    uint8_t iso_packet_idx;
+    uint8_t remain_itd_num;
 };
 
 struct ehci_qh_hw {
@@ -71,21 +69,23 @@ struct ehci_qtd_hw {
 
 struct ehci_itd_hw {
     struct ehci_itd hw;
+    struct usbh_urb *urb;
+    struct ehci_pipe *pipe;
+    uint16_t start_frame;
+    usb_slist_t list;
 } __attribute__((aligned(32)));
 
 struct ehci_hcd {
     bool ehci_qh_used[CONFIG_USB_EHCI_QH_NUM];
     bool ehci_qtd_used[CONFIG_USB_EHCI_QTD_NUM];
-    bool ehci_itd_pool_used[CONFIG_USB_EHCI_ITD_POOL_NUM];
+    bool ehci_itd_used[CONFIG_USB_EHCI_ITD_NUM];
     struct ehci_pipe pipe_pool[CONFIG_USB_EHCI_QH_NUM];
 };
 
 extern struct ehci_hcd g_ehci_hcd;
 extern uint32_t g_framelist[];
 
-int ehci_itd_pool_alloc(void);
-void ehci_itd_pool_free(uint8_t id);
-int ehci_iso_pipe_init(struct ehci_pipe *pipe, struct usbh_iso_frame_packet *iso_packet, uint32_t num_of_iso_packets);
+int ehci_iso_pipe_init(struct ehci_pipe *pipe, struct usbh_urb *urb);
 void ehci_remove_itd_urb(struct usbh_urb *urb);
 void ehci_scan_isochronous_list(void);
 

+ 32 - 32
port/ehci/usb_hc_ehci.c

@@ -994,27 +994,23 @@ int usbh_pipe_alloc(usbh_pipe_t *pipe, const struct usbh_endpoint_cfg *ep_cfg)
     ppipe->dev_addr = ep_cfg->hport->dev_addr;
     ppipe->hport = ep_cfg->hport;
 
-    // if ((ppipe->speed == USB_SPEED_HIGH) && (ppipe->ep_type == USB_ENDPOINT_TYPE_ISOCHRONOUS)) {
-    //     if (ep_cfg->ep_interval == 0x01) { /* transfer interval 1 mf */
-    //         ppipe->mf_unmask = 0xff;
-    //         ppipe->mf_valid = 8;
-    //     } else if (ep_cfg->ep_interval == 0x02) { /* transfer interval 2 mf */
-    //         ppipe->mf_unmask = 0x55;
-    //         ppipe->mf_valid = 4;
-    //     } else if (ep_cfg->ep_interval == 0x03) { /* transfer interval 4 mf */
-    //         ppipe->mf_unmask = 0x44;
-    //         ppipe->mf_valid = 2;
-    //     } else if (ep_cfg->ep_interval == 0x04) { /* transfer interval 8 mf */
-    //         ppipe->mf_unmask = 0x01;
-    //         ppipe->mf_valid = 1;
-    //     }
-
-    //     ppipe->id = ehci_itd_pool_alloc();
-    //     if (ppipe->id == -1) {
-    //         printf("fail to alloc itd pool\r\n");
-    //         return -1;
-    //     }
-    // }
+#ifdef CONFIG_USB_EHCI_ISO
+    if ((ppipe->speed == USB_SPEED_HIGH) && (ppipe->ep_type == USB_ENDPOINT_TYPE_ISOCHRONOUS)) {
+        if (ep_cfg->ep_interval == 0x01) { /* transfer interval 1 mf */
+            ppipe->mf_unmask = 0xff;
+            ppipe->mf_valid = 8;
+        } else if (ep_cfg->ep_interval == 0x02) { /* transfer interval 2 mf */
+            ppipe->mf_unmask = 0x55;
+            ppipe->mf_valid = 4;
+        } else if (ep_cfg->ep_interval == 0x03) { /* transfer interval 4 mf */
+            ppipe->mf_unmask = 0x44;
+            ppipe->mf_valid = 2;
+        } else if (ep_cfg->ep_interval == 0x04) { /* transfer interval 8 mf */
+            ppipe->mf_unmask = 0x01;
+            ppipe->mf_valid = 1;
+        }
+    }
+#endif
     /* restore variable */
     ppipe->inuse = true;
     ppipe->waitsem = waitsem;
@@ -1042,11 +1038,7 @@ int usbh_pipe_free(usbh_pipe_t pipe)
     }
 
     flags = usb_osal_enter_critical_section();
-
     ehci_pipe_free(ppipe);
-    // if (ppipe->ep_type == 0x01) {
-    //     ehci_itd_pool_free(ppipe->id);
-    // }
     usb_osal_leave_critical_section(flags);
     return 0;
 }
@@ -1072,7 +1064,7 @@ int usbh_submit_urb(struct usbh_urb *urb)
         return -ENODEV;
     }
 
-    if (pipe->urb) {
+    if (pipe->urb && (pipe->ep_type != USB_ENDPOINT_TYPE_ISOCHRONOUS)) {
         return -EBUSY;
     }
 
@@ -1109,7 +1101,9 @@ int usbh_submit_urb(struct usbh_urb *urb)
             }
             break;
         case USB_ENDPOINT_TYPE_ISOCHRONOUS:
-            //ehci_iso_pipe_init(pipe, urb->iso_packet, urb->num_of_iso_packets);
+#ifdef CONFIG_USB_EHCI_ISO
+            ehci_iso_pipe_init(pipe, urb);
+#endif
             break;
         default:
             break;
@@ -1173,7 +1167,9 @@ int usbh_kill_urb(struct usbh_urb *urb)
             qh = EHCI_ADDR2QH(qh->hw.hlp);
         }
     } else {
-        //ehci_remove_itd_urb(urb);
+#ifdef CONFIG_USB_EHCI_ISO
+        ehci_remove_itd_urb(urb);
+#endif
     }
 
     EHCI_HCOR->usbcmd |= (EHCI_USBCMD_PSEN | EHCI_USBCMD_ASEN);
@@ -1230,13 +1226,17 @@ void USBH_IRQHandler(void)
     if (usbsts & EHCI_USBSTS_INT) {
         ehci_scan_async_list();
         ehci_scan_periodic_list();
-        //ehci_scan_isochronous_list();
+#ifdef CONFIG_USB_EHCI_ISO
+        ehci_scan_isochronous_list();
+#endif
     }
 
     if (usbsts & EHCI_USBSTS_ERR) {
         ehci_scan_async_list();
         ehci_scan_periodic_list();
-        //ehci_scan_isochronous_list();
+#ifdef CONFIG_USB_EHCI_ISO
+        ehci_scan_isochronous_list();
+#endif
     }
 
     if (usbsts & EHCI_USBSTS_PCD) {
@@ -1263,8 +1263,8 @@ void USBH_IRQHandler(void)
                     for (uint8_t index = 0; index < CONFIG_USB_EHCI_QTD_NUM; index++) {
                         g_ehci_hcd.ehci_qtd_used[index] = false;
                     }
-                    for (uint8_t index = 0; index < CONFIG_USB_EHCI_ITD_POOL_NUM; index++) {
-                        g_ehci_hcd.ehci_itd_pool_used[index] = false;
+                    for (uint8_t index = 0; index < CONFIG_USB_EHCI_ITD_NUM; index++) {
+                        g_ehci_hcd.ehci_itd_used[index] = false;
                     }
                 }
                 usbh_roothub_thread_wakeup(port + 1);

+ 3 - 2
port/ehci/usb_hc_ehci.h

@@ -1,6 +1,7 @@
 /*
- * Copyright (c) 2022, sakumisu
- *
+ * Copyright 2020 The Apache Software Foundation
+ * Copyright 2022 sakumisu
+ * 
  * SPDX-License-Identifier: Apache-2.0
  */
 #ifndef USB_HC_EHCI_H