Add optional hooks for DCD and HCD events

These are intended to allow bare metal platforms with one-shot scheduling
capabilities to schedule the TinyUSB task handlers whenever they know there is
work for them to do.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
This commit is contained in:
Angus Gratton 2023-11-01 15:45:44 +11:00 committed by Angus Gratton
parent 08f9ed67c9
commit 68894398af
3 changed files with 25 additions and 4 deletions

View File

@ -1079,6 +1079,7 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
//--------------------------------------------------------------------+
TU_ATTR_FAST_FUNC void dcd_event_handler(dcd_event_t const * event, bool in_isr)
{
bool send = false;
switch (event->event_id)
{
case DCD_EVENT_UNPLUGGED:
@ -1086,7 +1087,7 @@ TU_ATTR_FAST_FUNC void dcd_event_handler(dcd_event_t const * event, bool in_isr)
_usbd_dev.addressed = 0;
_usbd_dev.cfg_num = 0;
_usbd_dev.suspended = 0;
osal_queue_send(_usbd_q, event, in_isr);
send = true;
break;
case DCD_EVENT_SUSPEND:
@ -1097,7 +1098,7 @@ TU_ATTR_FAST_FUNC void dcd_event_handler(dcd_event_t const * event, bool in_isr)
if ( _usbd_dev.connected )
{
_usbd_dev.suspended = 1;
osal_queue_send(_usbd_q, event, in_isr);
send = true;
}
break;
@ -1106,7 +1107,7 @@ TU_ATTR_FAST_FUNC void dcd_event_handler(dcd_event_t const * event, bool in_isr)
if ( _usbd_dev.connected )
{
_usbd_dev.suspended = 0;
osal_queue_send(_usbd_q, event, in_isr);
send = true;
}
break;
@ -1129,15 +1130,21 @@ TU_ATTR_FAST_FUNC void dcd_event_handler(dcd_event_t const * event, bool in_isr)
dcd_event_t const event_resume = { .rhport = event->rhport, .event_id = DCD_EVENT_RESUME };
osal_queue_send(_usbd_q, &event_resume, in_isr);
CFG_TUD_EVENT_HOOK(&event_resume, in_isr);
}
// skip osal queue for SOF in usbd task
break;
default:
osal_queue_send(_usbd_q, event, in_isr);
send = true;
break;
}
if (send) {
osal_queue_send(_usbd_q, event, in_isr);
CFG_TUD_EVENT_HOOK(event, in_isr);
}
}
//--------------------------------------------------------------------+

View File

@ -780,6 +780,7 @@ void usbh_defer_func(osal_task_func_t func, void *param, bool in_isr) {
event.func_call.param = param;
osal_queue_send(_usbh_q, &event, in_isr);
CFG_TUH_EVENT_HOOK(event, in_isr);
}
//--------------------------------------------------------------------+
@ -936,6 +937,7 @@ TU_ATTR_FAST_FUNC void hcd_event_handler(hcd_event_t const* event, bool in_isr)
}
osal_queue_send(_usbh_q, event, in_isr);
CFG_TUH_EVENT_HOOK(event, in_isr);
}
//--------------------------------------------------------------------+

View File

@ -485,6 +485,18 @@
#define tuc_int_handler(_p)
#endif
//--------------------------------------------------------------------+
// Optional event hook functions for platform integration (defaults)
//--------------------------------------------------------------------+
#ifndef CFG_TUD_EVENT_HOOK
#define CFG_TUD_EVENT_HOOK(EVENT, IN_ISR)
#endif
#ifndef CFG_TUH_EVENT_HOOK
#define CFG_TUH_EVENT_HOOK(EVENT, IN_ISR)
#endif
//------------------------------------------------------------------
// Configuration Validation
//------------------------------------------------------------------