diff options
| author | danicampora <danicampora@gmail.com> | 2024-09-05 22:47:38 +0200 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-09-06 20:48:13 +1000 |
| commit | 3ca01eccae528a74fec8b1731f472d41018e5225 (patch) | |
| tree | 26ddb687cd01cfbadef1d77ca2edf6e7c06636a8 | |
| parent | 1c0dc2ac3e35d6afe8099af121065c307bf6defd (diff) | |
zephyr/mphalport: Make mp_hal_wait_sem() always call k_poll().
Also even in the case of a zero timeout given.
Signed-off-by: danicampora <danicampora@gmail.com>
| -rw-r--r-- | ports/zephyr/mphalport.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/ports/zephyr/mphalport.c b/ports/zephyr/mphalport.c index fa64c4afc..2c9503284 100644 --- a/ports/zephyr/mphalport.c +++ b/ports/zephyr/mphalport.c @@ -54,15 +54,11 @@ void mp_hal_wait_sem(struct k_sem *sem, uint32_t timeout_ms) { mp_handle_pending(true); MP_THREAD_GIL_EXIT(); k_timeout_t wait; + uint32_t dt = mp_hal_ticks_ms() - t0; if (timeout_ms == (uint32_t)-1) { wait = K_FOREVER; } else { - uint32_t dt = mp_hal_ticks_ms() - t0; - if (dt >= timeout_ms) { - MP_THREAD_GIL_ENTER(); - return; - } - wait = K_MSEC(timeout_ms - dt); + wait = K_MSEC((timeout_ms > dt) ? (timeout_ms - dt) : 0); } k_poll(wait_events, sem ? 2 : 1, wait); if (wait_events[0].state == K_POLL_STATE_SIGNALED) { @@ -73,5 +69,9 @@ void mp_hal_wait_sem(struct k_sem *sem, uint32_t timeout_ms) { MP_THREAD_GIL_ENTER(); return; } + if (dt >= timeout_ms) { + MP_THREAD_GIL_ENTER(); + return; + } } } |
