summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZixun LI <[email protected]>2026-03-29 15:22:49 +0200
committerGitHub <[email protected]>2026-03-29 15:22:49 +0200
commitc64452cda50f126a339f776b5cdc3762ca82ff6e (patch)
tree098a8191426904ffb099c4b5dfc9e38cfb7286ab
parentbf8f0ec2a24339510810e2d1d473da8dfa187950 (diff)
parent653e6300a3dafbfb9f448879eaf874dca3e86a12 (diff)
Merge pull request #3566 from Precidata/async-cleanup
Couple of random cleanup patches following async PR
-rw-r--r--src/device/usbd.c6
-rw-r--r--src/host/usbh.c13
-rw-r--r--src/osal/osal_mynewt.h27
-rw-r--r--src/tusb_option.h4
4 files changed, 36 insertions, 14 deletions
diff --git a/src/device/usbd.c b/src/device/usbd.c
index 42903576c..3c14175f6 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -803,10 +803,8 @@ void tud_task_ext(uint32_t timeout_ms, bool in_isr) {
break;
}
-#if CFG_TUSB_OS != OPT_OS_NONE && CFG_TUSB_OS != OPT_OS_PICO
- // return if there is no more events, for application to run other background
- if (osal_queue_empty(_usbd_q)) { return; }
-#endif
+ // allow to exit tud_task() if there is no event in the next run
+ timeout_ms = 0;
}
}
diff --git a/src/host/usbh.c b/src/host/usbh.c
index 75df6bf60..8f80800e9 100644
--- a/src/host/usbh.c
+++ b/src/host/usbh.c
@@ -374,7 +374,8 @@ bool usbh_defer_func_ms_async(uint32_t ms, tusb_defer_func_t func, uintptr_t par
TU_LOG_USBH("USBH schedule function after %u ms\r\n", (unsigned int)ms);
_usbh_data.call_after.func = func;
_usbh_data.call_after.arg = param;
- _usbh_data.call_after.at_ms = tusb_time_millis_api() + ms;
+ // add one to ensure we wait at least 'ms' milliseconds
+ _usbh_data.call_after.at_ms = tusb_time_millis_api() + ms + 1;
return true;
}
@@ -610,11 +611,19 @@ bool tuh_task_event_ready(void) {
}
#if CFG_TUH_HUB
- if (!osal_queue_empty(_usbh_daq)) {
+ if (_usbh_data.enumerating_daddr == TUSB_INDEX_INVALID_8 &&
+ !osal_queue_empty(_usbh_daq)) {
return true;
}
#endif
+ if (_usbh_data.call_after.func) {
+ int32_t remain_ms = (int32_t)(_usbh_data.call_after.at_ms - tusb_time_millis_api());
+ if (remain_ms <= 0) {
+ return true;
+ }
+ }
+
return false;
}
diff --git a/src/osal/osal_mynewt.h b/src/osal/osal_mynewt.h
index 94124ca81..335d53491 100644
--- a/src/osal/osal_mynewt.h
+++ b/src/osal/osal_mynewt.h
@@ -123,6 +123,24 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_unlock(osal_mutex_t mutex_hd
return os_mutex_release(mutex_hdl) == OS_OK;
}
+TU_ATTR_ALWAYS_INLINE static inline os_time_t _osal_ms2tick(uint32_t msec) {
+ if (msec == OSAL_TIMEOUT_WAIT_FOREVER) {
+ return OS_TIMEOUT_NEVER;
+ }
+ if (msec == 0) {
+ return 0;
+ }
+
+ os_time_t ticks = os_time_ms_to_ticks32(msec);
+
+ // If 1 tick > 1 ms, still wait at least 1 tick for non-zero timeout.
+ if (ticks == 0) {
+ ticks = 1;
+ }
+
+ return ticks;
+}
+
//--------------------------------------------------------------------+
// QUEUE API
//--------------------------------------------------------------------+
@@ -161,10 +179,11 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_delete(osal_queue_t qhdl) {
}
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec) {
- (void) msec; // os_eventq_get() does not take timeout, always behave as msec = WAIT_FOREVER
-
- struct os_event* ev;
- ev = os_eventq_get(&qhdl->evq);
+ struct os_eventq* evq = &qhdl->evq;
+ struct os_event* ev = os_eventq_poll(&evq, 1, _osal_ms2tick(msec));
+ if (!ev) {
+ return false;
+ }
memcpy(data, ev->ev_arg, qhdl->item_sz); // copy message
os_memblock_put(&qhdl->mpool, ev->ev_arg); // put back mem block
diff --git a/src/tusb_option.h b/src/tusb_option.h
index 74a556605..dd7af76f6 100644
--- a/src/tusb_option.h
+++ b/src/tusb_option.h
@@ -534,10 +534,6 @@
#define CFG_TUSB_OS OPT_OS_NONE
#endif
-#ifndef CFG_TUSB_OS_HAS_SCHEDULER
- #define CFG_TUSB_OS_HAS_SCHEDULER (CFG_TUSB_OS != OPT_OS_NONE && CFG_TUSB_OS != OPT_OS_PICO)
-#endif
-
#ifndef CFG_TUSB_OS_INC_PATH
#ifndef CFG_TUSB_OS_INC_PATH_DEFAULT
#define CFG_TUSB_OS_INC_PATH_DEFAULT