소스 검색

update(port/musb/usb_hc_musb): reenable pipe alloc & free

Signed-off-by: sakumisu <1203593632@qq.com>
sakumisu 1 개월 전
부모
커밋
b1bbc9d39d
1개의 변경된 파일12개의 추가작업 그리고 10개의 파일을 삭제
  1. 12 10
      port/musb/usb_hc_musb.c

+ 12 - 10
port/musb/usb_hc_musb.c

@@ -524,31 +524,36 @@ static uint8_t usbh_get_port_speed(struct usbh_bus *bus, const uint8_t port)
     return speed;
     return speed;
 }
 }
 
 
-#if 0
 static int musb_pipe_alloc(void)
 static int musb_pipe_alloc(void)
 {
 {
     int chidx;
     int chidx;
+    uintptr_t flags;
 
 
+    flags = usb_osal_enter_critical_section();
     for (chidx = 1; chidx < CONFIG_USB_MUSB_PIPE_NUM; chidx++) {
     for (chidx = 1; chidx < CONFIG_USB_MUSB_PIPE_NUM; chidx++) {
         if (!g_musb_hcd[bus->hcd.hcd_id].pipe_pool[chidx].inuse) {
         if (!g_musb_hcd[bus->hcd.hcd_id].pipe_pool[chidx].inuse) {
             g_musb_hcd[bus->hcd.hcd_id].pipe_pool[chidx].inuse = true;
             g_musb_hcd[bus->hcd.hcd_id].pipe_pool[chidx].inuse = true;
+            usb_osal_leave_critical_section(flags);
             return chidx;
             return chidx;
         }
         }
     }
     }
+    usb_osal_leave_critical_section(flags);
 
 
     return -1;
     return -1;
 }
 }
-#endif
 
 
 static void musb_pipe_free(struct musb_pipe *pipe)
 static void musb_pipe_free(struct musb_pipe *pipe)
 {
 {
+    uintptr_t flags;
+
+    flags = usb_osal_enter_critical_section();
     if (pipe->urb) {
     if (pipe->urb) {
         pipe->urb->hcpriv = NULL;
         pipe->urb->hcpriv = NULL;
         pipe->urb = NULL;
         pipe->urb = NULL;
     }
     }
-#if 0
+
     pipe->inuse = false;
     pipe->inuse = false;
-#endif
+    usb_osal_leave_critical_section(flags);
 }
 }
 
 
 __WEAK void usb_hc_low_level_init(struct usbh_bus *bus)
 __WEAK void usb_hc_low_level_init(struct usbh_bus *bus)
@@ -764,10 +769,9 @@ int usbh_submit_urb(struct usbh_urb *urb)
     if (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes) == USB_ENDPOINT_TYPE_CONTROL) {
     if (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes) == USB_ENDPOINT_TYPE_CONTROL) {
         chidx = 0;
         chidx = 0;
     } else {
     } else {
-        chidx = (urb->ep->bEndpointAddress & 0x0f);
-
-        if (chidx > (CONFIG_USB_MUSB_PIPE_NUM - 1)) {
-            return -USB_ERR_RANGE;
+        chidx = musb_pipe_alloc();
+        if (chidx == -1) {
+            return -USB_ERR_NOMEM;
         }
         }
     }
     }
 
 
@@ -873,8 +877,6 @@ static void musb_urb_waitup(struct usbh_urb *urb)
     struct musb_pipe *pipe;
     struct musb_pipe *pipe;
 
 
     pipe = (struct musb_pipe *)urb->hcpriv;
     pipe = (struct musb_pipe *)urb->hcpriv;
-    pipe->urb = NULL;
-    urb->hcpriv = NULL;
 
 
     if (urb->timeout) {
     if (urb->timeout) {
         usb_osal_sem_give(pipe->waitsem);
         usb_osal_sem_give(pipe->waitsem);