diff options
-rw-r--r-- | core/cortex-m/timer.c | 11 | ||||
-rw-r--r-- | include/timer.h | 3 |
2 files changed, 10 insertions, 4 deletions
diff --git a/core/cortex-m/timer.c b/core/cortex-m/timer.c index 10c83c8921..be2d0d416c 100644 --- a/core/cortex-m/timer.c +++ b/core/cortex-m/timer.c @@ -37,11 +37,16 @@ static void expire_timer(task_id_t tskid) task_set_event(tskid, TASK_EVENT_TIMER, 0); } -int timestamp_expired(timestamp_t deadline) +int timestamp_expired(timestamp_t deadline, const timestamp_t *now) { - timestamp_t now = get_time(); + timestamp_t now_val; - return ((int64_t)(now.val - deadline.val) >= 0); + if (!now) { + now_val = get_time(); + now = &now_val; + } + + return ((int64_t)(now->val - deadline.val) >= 0); } void process_timers(int overflow) diff --git a/include/timer.h b/include/timer.h index 796318a1d0..ed076d5199 100644 --- a/include/timer.h +++ b/include/timer.h @@ -34,9 +34,10 @@ int timer_cancel(task_id_t tskid); * Check if a timestamp has passed / expired * * @param deadline deadline timer value to check + * @param now pointer to value of time_now() if known, else NULL * @return 0 if deadline has not yet passed, 1 if it has passed */ -int timestamp_expired(timestamp_t deadline); +int timestamp_expired(timestamp_t deadline, const timestamp_t *now); /* Busy-wait the selected number of microseconds. Note that calling this * with us>1000 may impact system performance; use usleep for longer delays. */ |