add in_isr to all hcd event functions

This commit is contained in:
hathach 2020-09-05 15:45:03 +07:00
parent 90c8c14652
commit b8b95e8494
6 changed files with 32 additions and 30 deletions

View File

@ -140,7 +140,7 @@ void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr);
void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr);
//--------------------------------------------------------------------+
// Event API (Implemented by device stack)
// Event API (implemented by stack)
//--------------------------------------------------------------------+
// Called by DCD to notify device stack

View File

@ -489,10 +489,10 @@ static void port_connect_status_change_isr(uint8_t hostid)
if (ehci_data.regs->portsc_bm.current_connect_status)
{
hcd_port_reset(hostid);
hcd_event_device_attach(hostid);
hcd_event_device_attach(hostid, true);
}else // device unplugged
{
hcd_event_device_remove(hostid);
hcd_event_device_remove(hostid, true);
}
}
@ -512,7 +512,7 @@ static void qhd_xfer_complete_isr(ehci_qhd_t * p_qhd)
{
// end of request
// call USBH callback
hcd_event_xfer_complete(p_qhd->dev_addr, tu_edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), XFER_RESULT_SUCCESS, p_qhd->total_xferred_bytes);
hcd_event_xfer_complete(p_qhd->dev_addr, tu_edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), p_qhd->total_xferred_bytes, XFER_RESULT_SUCCESS, true);
p_qhd->total_xferred_bytes = 0;
}
}
@ -599,7 +599,7 @@ static void qhd_xfer_error_isr(ehci_qhd_t * p_qhd)
}
// call USBH callback
hcd_event_xfer_complete(p_qhd->dev_addr, tu_edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), error_event, p_qhd->total_xferred_bytes);
hcd_event_xfer_complete(p_qhd->dev_addr, tu_edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), p_qhd->total_xferred_bytes, error_event, true);
p_qhd->total_xferred_bytes = 0;
}

View File

@ -109,20 +109,6 @@ tusb_speed_t hcd_port_speed_get(uint8_t hostid);
// HCD closes all opened endpoints belong to this device
void hcd_device_close(uint8_t rhport, uint8_t dev_addr);
//--------------------------------------------------------------------+
// Event function
//--------------------------------------------------------------------+
void hcd_event_handler(hcd_event_t const* event, bool in_isr);
// Helper to send device attach event
void hcd_event_device_attach(uint8_t rhport);
// Helper to send device removal event
void hcd_event_device_remove(uint8_t rhport);
// Helper to send USB transfer event
void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
//--------------------------------------------------------------------+
// Endpoints API
//--------------------------------------------------------------------+
@ -145,6 +131,22 @@ bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t
// tusb_error_t hcd_pipe_cancel();
//--------------------------------------------------------------------+
// Event API (implemented by stack)
//--------------------------------------------------------------------+
// Called by HCD to notify stack
extern void hcd_event_handler(hcd_event_t const* event, bool in_isr);
// Helper to send device attach event
extern void hcd_event_device_attach(uint8_t rhport, bool in_isr);
// Helper to send device removal event
extern void hcd_event_device_remove(uint8_t rhport, bool in_isr);
// Helper to send USB transfer event
extern void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, uint32_t xferred_bytes, xfer_result_t result, bool in_isr);
#ifdef __cplusplus
}
#endif

View File

@ -223,7 +223,7 @@ void hub_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_
event.attach.hub_port = port;
hcd_event_handler(&event, true);
break; // handle one port at a time, next port if any will be handled in the next cycle
break; // TODO handle one port at a time, next port if any will be handled in the next cycle
}
}
// NOTE: next status transfer is queued by usbh.c after handling this request

View File

@ -599,7 +599,7 @@ static void done_queue_isr(uint8_t hostid)
hcd_event_xfer_complete(p_ed->dev_addr,
tu_edpt_addr(p_ed->ep_number, p_ed->pid == OHCI_PID_IN),
event, xferred_bytes);
xferred_bytes, event, true);
}
td_head = (ohci_td_item_t*) td_head->next;
@ -632,10 +632,10 @@ void hcd_int_handler(uint8_t hostid)
{
// TODO reset port immediately, without this controller will got 2-3 (debouncing connection status change)
OHCI_REG->rhport_status[0] = OHCI_RHPORT_PORT_RESET_STATUS_MASK;
hcd_event_device_attach(0);
hcd_event_device_attach(hostid, true);
}else
{
hcd_event_device_remove(0);
hcd_event_device_remove(hostid, true);
}
}

View File

@ -268,7 +268,7 @@ void hcd_event_handler(hcd_event_t const* event, bool in_isr)
}
// interrupt caused by a TD (with IOC=1) in pipe of class class_code
void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, uint8_t result, uint32_t xferred_bytes)
void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, uint32_t xferred_bytes, xfer_result_t result, bool in_isr)
{
usbh_device_t* dev = &_usbh_devices[ dev_addr ];
@ -276,7 +276,7 @@ void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, uint8_t result,
{
dev->control.pipe_status = result;
// usbh_devices[ pipe_hdl.dev_addr ].control.xferred_bytes = xferred_bytes; not yet neccessary
osal_semaphore_post( dev->control.sem_hdl, true );
osal_semaphore_post( dev->control.sem_hdl, true ); // FIXME post within ISR
}
else
{
@ -293,11 +293,11 @@ void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, uint8_t result,
}
};
hcd_event_handler(&event, true);
hcd_event_handler(&event, in_isr);
}
}
void hcd_event_device_attach(uint8_t rhport)
void hcd_event_device_attach(uint8_t rhport, bool in_isr)
{
hcd_event_t event =
{
@ -308,10 +308,10 @@ void hcd_event_device_attach(uint8_t rhport)
event.attach.hub_addr = 0;
event.attach.hub_port = 0;
hcd_event_handler(&event, true);
hcd_event_handler(&event, in_isr);
}
void hcd_event_device_remove(uint8_t hostid)
void hcd_event_device_remove(uint8_t hostid, bool in_isr)
{
hcd_event_t event =
{
@ -322,7 +322,7 @@ void hcd_event_device_remove(uint8_t hostid)
event.attach.hub_addr = 0;
event.attach.hub_port = 0;
hcd_event_handler(&event, true);
hcd_event_handler(&event, in_isr);
}