summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2026-03-02 20:07:16 +0700
committerhathach <[email protected]>2026-03-02 20:07:16 +0700
commitd9a7d1023c1fd38981ecbfc9fbb37bc14c4f85a1 (patch)
treec066544441b32b8d8c31bb9801a41c61b3f509c5
parent4df7ef54396e1695aa9504aef9dfe4263569c3f6 (diff)
improve timeout adjustment, exit tuh_task() by timeout_ms = 0
-rw-r--r--src/host/usbh.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/host/usbh.c b/src/host/usbh.c
index 5cf0096f2..e161d212e 100644
--- a/src/host/usbh.c
+++ b/src/host/usbh.c
@@ -659,8 +659,8 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr) {
// Process call_after_ms function if ms is reached
tusb_defer_func_t after_cb = _usbh_data.call_after.func;
if (after_cb) {
- int32_t ms = (int32_t)(_usbh_data.call_after.at_ms - tusb_time_millis_api());
- if (ms <= 0) {
+ int32_t remain_ms = (int32_t)(_usbh_data.call_after.at_ms - tusb_time_millis_api());
+ if (remain_ms <= 0) {
// delay expired, run callback now
TU_LOG_USBH("USBH invoke scheduled function\r\n");
_usbh_data.call_after.func = NULL;
@@ -669,9 +669,11 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr) {
// above after_cb() can re-schedule another function, we need to re-check and reduce timeout of
// the main event timeout to make sure we aren't blocking more than call_after timeout.
- if (_usbh_data.call_after.func != NULL &&
- timeout_ms > (uint32_t)(_usbh_data.call_after.at_ms - tusb_time_millis_api())) {
- timeout_ms = (uint32_t)ms;
+ if (_usbh_data.call_after.func != NULL) {
+ remain_ms = (int32_t) (_usbh_data.call_after.at_ms - tusb_time_millis_api());
+ if (remain_ms > 0 && timeout_ms > (uint32_t)remain_ms) {
+ timeout_ms = (uint32_t)remain_ms;
+ }
}
}
@@ -789,16 +791,8 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr) {
break;
}
- #if CFG_TUSB_OS_HAS_SCHEDULER
- // return if there are no more events, to allow application to run other backgrounds
- if (osal_queue_empty(_usbh_q)
- #if CFG_TUH_HUB
- && osal_queue_empty(_usbh_daq)
- #endif
- ) {
- return;
- }
- #endif
+ // allow to exit tuh_task() if there is no event in the next run
+ timeout_ms = 0;
}
}