summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAngus Gratton <[email protected]>2023-11-01 15:45:44 +1100
committerAngus Gratton <[email protected]>2023-11-23 14:42:51 +1100
commit68894398af9e8a096c700b7a4e8c127e53a2d6bc (patch)
tree17fdbcf35afd247c2089224fdc108a9b119d6f1b /src
parent08f9ed67c92421cbd0bc09270d2f363886681866 (diff)
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 <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/device/usbd.c15
-rw-r--r--src/host/usbh.c2
-rw-r--r--src/tusb_option.h12
3 files changed, 25 insertions, 4 deletions
diff --git a/src/device/usbd.c b/src/device/usbd.c
index 50941c46f..2b6d07a96 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -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);
+ }
}
//--------------------------------------------------------------------+
diff --git a/src/host/usbh.c b/src/host/usbh.c
index d8fff9905..2fdc8216d 100644
--- a/src/host/usbh.c
+++ b/src/host/usbh.c
@@ -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);
}
//--------------------------------------------------------------------+
diff --git a/src/tusb_option.h b/src/tusb_option.h
index a29eb8a3a..aedc02dbc 100644
--- a/src/tusb_option.h
+++ b/src/tusb_option.h
@@ -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
//------------------------------------------------------------------