diff options
| author | sakumisu <[email protected]> | 2022-02-07 18:41:01 +0800 |
|---|---|---|
| committer | sakumisu <[email protected]> | 2022-02-07 21:00:59 +0800 |
| commit | 74d96498f9d81db8198b7aeadc024276703f0ea9 (patch) | |
| tree | 8d0f73b5e753210015c7b2e27ae683a7ff482162 | |
| parent | b288752500e0015b082c57b81f002c61d50ee8e1 (diff) | |
update usbh_ep_free function
| -rw-r--r-- | port/synopsys/usb_hc_synopsys.c | 65 |
1 files changed, 51 insertions, 14 deletions
diff --git a/port/synopsys/usb_hc_synopsys.c b/port/synopsys/usb_hc_synopsys.c index 09517f45..beb8204b 100644 --- a/port/synopsys/usb_hc_synopsys.c +++ b/port/synopsys/usb_hc_synopsys.c @@ -104,6 +104,25 @@ static void usb_synopsys_chan_free(struct usb_synopsys_priv *priv, int chidx) } /**************************************************************************** + * Name: usb_synopsys_chan_freeall + * + * Description: + * Free all channels. + * + ****************************************************************************/ + +static inline void usb_synopsys_chan_freeall(struct usb_synopsys_priv *priv) +{ + uint8_t chidx; + + /* Free all host channels */ + + for (chidx = 2; chidx < CONFIG_USBHOST_CHANNELS; chidx++) { + usb_synopsys_chan_free(priv, chidx); + } +} + +/**************************************************************************** * Name: usb_synopsys_chan_waitsetup * * Description: @@ -407,10 +426,24 @@ int usbh_ep_alloc(usbh_epinfo_t *ep, const struct usbh_endpoint_cfg *ep_cfg) usb_osal_mutex_give(g_usbhost.exclsem); return 0; } + int usbh_ep_free(usbh_epinfo_t ep) { - uint8_t chidx = (uint8_t)ep; - usb_synopsys_chan_free(&g_usbhost, chidx); + int ret; + + ret = usb_osal_mutex_take(g_usbhost.exclsem); + if (ret < 0) { + return ret; + } + if ((uintptr_t)ep < CONFIG_USBHOST_CHANNELS) { + usb_synopsys_chan_free(&g_usbhost, (int)ep); + } else { + struct usb_synopsys_ctrlinfo *ep0 = (struct usb_synopsys_ctrlinfo *)ep; + usb_synopsys_chan_free(&g_usbhost, ep0->inndx); + usb_synopsys_chan_free(&g_usbhost, ep0->outndx); + } + + usb_osal_mutex_give(g_usbhost.exclsem); return 0; } @@ -679,16 +712,13 @@ int usb_ep_cancel(usbh_epinfo_t ep) return 0; } -void HAL_Delay(uint32_t Delay) -{ - usb_osal_msleep(Delay); -} - void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd) { - g_usbhost.connected = true; - extern void usbh_event_notify_handler(uint8_t event, uint8_t rhport); - usbh_event_notify_handler(USBH_EVENT_ATTACHED, 1); + if (!g_usbhost.connected) { + g_usbhost.connected = true; + extern void usbh_event_notify_handler(uint8_t event, uint8_t rhport); + usbh_event_notify_handler(USBH_EVENT_ATTACHED, 1); + } } /** @@ -698,9 +728,12 @@ void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd) */ void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd) { - g_usbhost.connected = false; - extern void usbh_event_notify_handler(uint8_t event, uint8_t rhport); - usbh_event_notify_handler(USBH_EVENT_REMOVED, 1); + if (g_usbhost.connected) { + g_usbhost.connected = false; + usb_synopsys_chan_freeall(&g_usbhost); + extern void usbh_event_notify_handler(uint8_t event, uint8_t rhport); + usbh_event_notify_handler(USBH_EVENT_REMOVED, 1); + } } void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum, HCD_URBStateTypeDef urb_state) @@ -713,7 +746,6 @@ void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum, if (urb_state != URB_NOTREADY) { if (urb_state == URB_ERROR) { chan->result = -EIO; - HAL_HCD_HC_Halt(hhcd, chnum); } else if (urb_state == URB_STALL) { chan->result = -EPERM; } else if (urb_state == URB_DONE) { @@ -747,3 +779,8 @@ void USBH_IRQHandler(void) /* USER CODE END OTG_HS_IRQn 1 */ } + +void HAL_Delay(uint32_t Delay) +{ + usb_osal_msleep(Delay); +} |
