Fix a bug where the channel might not be released
This commit is contained in:
@@ -144,6 +144,7 @@ void usb_dc_low_level_init(uint8_t busid)
|
||||
{
|
||||
esp_err_t ret;
|
||||
void *reg_base = (void*)g_usbdev_bus[busid].reg_base;
|
||||
(void)reg_base;
|
||||
usb_phy_config_t phy_config = {
|
||||
.controller = USB_PHY_CTRL_OTG,
|
||||
.otg_mode = USB_OTG_MODE_DEVICE,
|
||||
@@ -170,6 +171,7 @@ void usb_dc_low_level_init(uint8_t busid)
|
||||
void usb_dc_low_level_deinit(uint8_t busid)
|
||||
{
|
||||
void *reg_base = (void*)g_usbdev_bus[busid].reg_base;
|
||||
(void)reg_base;
|
||||
if (s_interrupt_handle[GET_USB_INDEX(reg_base)]) {
|
||||
esp_intr_free(s_interrupt_handle[GET_USB_INDEX(reg_base)]);
|
||||
s_interrupt_handle[GET_USB_INDEX(reg_base)] = NULL;
|
||||
@@ -190,6 +192,7 @@ static void usb_hc_interrupt_cb(void *arg_pv)
|
||||
void usb_hc_low_level_init(struct usbh_bus *bus)
|
||||
{
|
||||
void *reg_base = (void*)bus->hcd.reg_base;
|
||||
(void)reg_base;
|
||||
// Host Library defaults to internal PHY
|
||||
usb_phy_config_t phy_config = {
|
||||
.controller = USB_PHY_CTRL_OTG,
|
||||
@@ -219,6 +222,7 @@ void usb_hc_low_level_init(struct usbh_bus *bus)
|
||||
void usb_hc_low_level_deinit(struct usbh_bus *bus)
|
||||
{
|
||||
void *reg_base = (void*)bus->hcd.reg_base;
|
||||
(void)reg_base;
|
||||
if (s_interrupt_handle[GET_USB_INDEX(reg_base)]) {
|
||||
esp_intr_free(s_interrupt_handle[GET_USB_INDEX(reg_base)]);
|
||||
s_interrupt_handle[GET_USB_INDEX(reg_base)] = NULL;
|
||||
|
||||
@@ -306,9 +306,6 @@ static inline void dwc2_chan_transfer(struct usbh_bus *bus, uint8_t ch_num, uint
|
||||
{
|
||||
__IO uint32_t tmpreg;
|
||||
uint8_t is_oddframe;
|
||||
struct dwc2_chan *chan;
|
||||
|
||||
chan = &g_dwc2_hcd[bus->hcd.hcd_id].chan_pool[ch_num];
|
||||
|
||||
/* Initialize the HCTSIZn register */
|
||||
USB_OTG_HC(ch_num)->HCTSIZ = (size & USB_OTG_HCTSIZ_XFRSIZ) |
|
||||
@@ -489,6 +486,10 @@ static void dwc2_chan_free(struct dwc2_chan *chan)
|
||||
size_t flags;
|
||||
|
||||
flags = usb_osal_enter_critical_section();
|
||||
if (chan->urb) {
|
||||
chan->urb->hcpriv = NULL;
|
||||
chan->urb = NULL;
|
||||
}
|
||||
chan->inuse = false;
|
||||
usb_osal_leave_critical_section(flags);
|
||||
}
|
||||
@@ -998,11 +999,6 @@ int usbh_submit_urb(struct usbh_urb *urb)
|
||||
return -USB_ERR_BUSY;
|
||||
}
|
||||
|
||||
chidx = dwc2_chan_alloc(bus);
|
||||
if (chidx == -1) {
|
||||
return -USB_ERR_NOMEM;
|
||||
}
|
||||
|
||||
if (urb->ep->bEndpointAddress & 0x80) {
|
||||
/* Check if pipe rx fifo is overflow */
|
||||
if (USB_GET_MAXPACKETSIZE(urb->ep->wMaxPacketSize) > (g_dwc2_hcd[bus->hcd.hcd_id].user_params.host_rx_fifo_size * 4)) {
|
||||
@@ -1022,6 +1018,11 @@ int usbh_submit_urb(struct usbh_urb *urb)
|
||||
}
|
||||
}
|
||||
|
||||
chidx = dwc2_chan_alloc(bus);
|
||||
if (chidx == -1) {
|
||||
return -USB_ERR_NOMEM;
|
||||
}
|
||||
|
||||
flags = usb_osal_enter_critical_section();
|
||||
|
||||
chan = &g_dwc2_hcd[bus->hcd.hcd_id].chan_pool[chidx];
|
||||
@@ -1094,8 +1095,6 @@ int usbh_kill_urb(struct usbh_urb *urb)
|
||||
|
||||
dwc2_halt(bus, chan->chidx);
|
||||
|
||||
chan->urb = NULL;
|
||||
urb->hcpriv = NULL;
|
||||
urb->errorcode = -USB_ERR_SHUTDOWN;
|
||||
|
||||
if (urb->timeout) {
|
||||
@@ -1114,8 +1113,6 @@ static inline void dwc2_urb_waitup(struct usbh_urb *urb)
|
||||
struct dwc2_chan *chan;
|
||||
|
||||
chan = (struct dwc2_chan *)urb->hcpriv;
|
||||
chan->urb = NULL;
|
||||
urb->hcpriv = NULL;
|
||||
|
||||
if (urb->timeout) {
|
||||
usb_osal_sem_give(chan->waitsem);
|
||||
|
||||
@@ -99,6 +99,10 @@ static void ehci_qh_free(struct usbh_bus *bus, struct ehci_qh_hw *qh)
|
||||
size_t flags;
|
||||
|
||||
flags = usb_osal_enter_critical_section();
|
||||
if (qh->urb) {
|
||||
qh->urb->hcpriv = NULL;
|
||||
qh->urb = NULL;
|
||||
}
|
||||
qtd = EHCI_ADDR2QTD(qh->first_qtd);
|
||||
|
||||
while (qtd) {
|
||||
@@ -616,8 +620,6 @@ static void ehci_urb_waitup(struct usbh_bus *bus, struct usbh_urb *urb)
|
||||
struct ehci_qh_hw *qh;
|
||||
|
||||
qh = (struct ehci_qh_hw *)urb->hcpriv;
|
||||
qh->urb = NULL;
|
||||
urb->hcpriv = NULL;
|
||||
|
||||
qh->remove_in_iaad = 0;
|
||||
|
||||
@@ -1335,9 +1337,7 @@ int usbh_kill_urb(struct usbh_urb *urb)
|
||||
EHCI_HCOR->usbcmd |= (EHCI_USBCMD_PSEN | EHCI_USBCMD_ASEN);
|
||||
|
||||
qh = (struct ehci_qh_hw *)urb->hcpriv;
|
||||
urb->hcpriv = NULL;
|
||||
urb->errorcode = -USB_ERR_SHUTDOWN;
|
||||
qh->urb = NULL;
|
||||
|
||||
if (urb->timeout) {
|
||||
usb_osal_sem_give(qh->waitsem);
|
||||
|
||||
@@ -477,6 +477,10 @@ static int musb_pipe_alloc(void)
|
||||
|
||||
static void musb_pipe_free(struct musb_pipe *pipe)
|
||||
{
|
||||
if (pipe->urb) {
|
||||
pipe->urb->hcpriv = NULL;
|
||||
pipe->urb = NULL;
|
||||
}
|
||||
#if 0
|
||||
pipe->inuse = false;
|
||||
#endif
|
||||
@@ -771,9 +775,7 @@ int usbh_kill_urb(struct usbh_urb *urb)
|
||||
flags = usb_osal_enter_critical_section();
|
||||
|
||||
pipe = (struct musb_pipe *)urb->hcpriv;
|
||||
urb->hcpriv = NULL;
|
||||
urb->errorcode = -USB_ERR_SHUTDOWN;
|
||||
pipe->urb = NULL;
|
||||
|
||||
if (urb->ep->bEndpointAddress & 0x80) {
|
||||
HWREGH(USB_BASE + MUSB_RXIE_OFFSET) &= ~(1 << (urb->ep->bEndpointAddress & 0x0f));
|
||||
@@ -800,8 +802,6 @@ static void musb_urb_waitup(struct usbh_urb *urb)
|
||||
struct musb_pipe *pipe;
|
||||
|
||||
pipe = (struct musb_pipe *)urb->hcpriv;
|
||||
pipe->urb = NULL;
|
||||
urb->hcpriv = NULL;
|
||||
|
||||
if (urb->timeout) {
|
||||
usb_osal_sem_give(pipe->waitsem);
|
||||
|
||||
@@ -72,6 +72,10 @@ static void rp2040_pipe_free(struct rp2040_pipe *pipe)
|
||||
size_t flags;
|
||||
|
||||
flags = usb_osal_enter_critical_section();
|
||||
if (pipe->urb) {
|
||||
pipe->urb->hcpriv = NULL;
|
||||
pipe->urb = NULL;
|
||||
}
|
||||
pipe->inuse = false;
|
||||
usb_osal_leave_critical_section(flags);
|
||||
}
|
||||
@@ -590,9 +594,8 @@ int usbh_kill_urb(struct usbh_urb *urb)
|
||||
flags = usb_osal_enter_critical_section();
|
||||
|
||||
pipe = (struct rp2040_pipe *)urb->hcpriv;
|
||||
urb->hcpriv = NULL;
|
||||
urb->errorcode = -USB_ERR_SHUTDOWN;
|
||||
pipe->urb = NULL;
|
||||
|
||||
usb_hw_clear->int_ep_ctrl = 1 << pipe->chidx;
|
||||
usb_hw_clear->buf_status = 1 << (pipe->chidx * 2 + 0);
|
||||
usb_hw_clear->buf_status = 1 << (pipe->chidx * 2 + 1);
|
||||
@@ -615,8 +618,6 @@ static void rp2040_urb_waitup(struct usbh_urb *urb)
|
||||
struct rp2040_pipe *pipe;
|
||||
|
||||
pipe = (struct rp2040_pipe *)urb->hcpriv;
|
||||
pipe->urb = NULL;
|
||||
urb->hcpriv = NULL;
|
||||
|
||||
if (urb->timeout) {
|
||||
usb_osal_sem_give(pipe->waitsem);
|
||||
|
||||
Reference in New Issue
Block a user