From f615202b9b60a8a0151f6c9de049f024a68766d2 Mon Sep 17 00:00:00 2001 From: Cédric Berger Date: Sun, 22 Mar 2026 14:02:50 +0100 Subject: We must wait at least the requested amount --- src/host/usbh.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/host/usbh.c b/src/host/usbh.c index 75df6bf60..cc6ff9e6e 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; } -- cgit v1.3.1 From ace993c21bf613c8ffadf36406e5c23ce844e940 Mon Sep 17 00:00:00 2001 From: Cédric Berger Date: Sun, 22 Mar 2026 14:07:13 +0100 Subject: False positive in tuh_task_event_ready() --- src/host/usbh.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/host/usbh.c b/src/host/usbh.c index cc6ff9e6e..78ed3e639 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -611,7 +611,8 @@ 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 -- cgit v1.3.1 From 3a262cb6ea8b070bd2fb6e32d2f754315077bd42 Mon Sep 17 00:00:00 2001 From: Cédric Berger Date: Sun, 22 Mar 2026 14:09:41 +0100 Subject: False negative in tuh_task_event_ready() --- src/host/usbh.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/host/usbh.c b/src/host/usbh.c index 78ed3e639..8f80800e9 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -617,6 +617,13 @@ bool tuh_task_event_ready(void) { } #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; } -- cgit v1.3.1 From db7722dee8410f27f6ea7dfcbfaf44e2f88cccf3 Mon Sep 17 00:00:00 2001 From: Cédric Berger Date: Sun, 22 Mar 2026 14:12:50 +0100 Subject: Simplify tud_task() like in tuh_task() --- src/device/usbd.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src') 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; } } -- cgit v1.3.1 From 04701bf91804448359aa0b8c4757704c644c748b Mon Sep 17 00:00:00 2001 From: Cédric Berger Date: Sun, 22 Mar 2026 14:17:01 +0100 Subject: Remove unused define --- src/tusb_option.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src') 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 -- cgit v1.3.1 From 653e6300a3dafbfb9f448879eaf874dca3e86a12 Mon Sep 17 00:00:00 2001 From: HiFiPhile Date: Fri, 27 Mar 2026 15:44:24 +0100 Subject: osal/mynewt: fix queue receive tiemout Signed-off-by: HiFiPhile --- src/osal/osal_mynewt.h | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src') 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 -- cgit v1.3.1