diff --git a/libraries/mbed/common/us_ticker_api.c b/libraries/mbed/common/us_ticker_api.c index f98b56a9e8..716e78103a 100644 --- a/libraries/mbed/common/us_ticker_api.c +++ b/libraries/mbed/common/us_ticker_api.c @@ -117,6 +117,16 @@ void us_ticker_remove_event(ticker_event_t *obj) { __enable_irq(); } -timestamp_t us_ticker_get_next_timestamp(void) { - return head->timestamp; +int us_ticker_get_next_timestamp(timestamp_t *timestamp) { + int ret = 0; + + /* if head is NULL, there are no pending events */ + __disable_irq(); + if (head != NULL) { + *timestamp = head->timestamp; + ret = 1; + } + __enable_irq(); + + return ret; } diff --git a/libraries/mbed/hal/us_ticker_api.h b/libraries/mbed/hal/us_ticker_api.h index 543c4da934..1fa93170ec 100644 --- a/libraries/mbed/hal/us_ticker_api.h +++ b/libraries/mbed/hal/us_ticker_api.h @@ -43,7 +43,7 @@ void us_ticker_irq_handler(void); void us_ticker_insert_event(ticker_event_t *obj, timestamp_t timestamp, uint32_t id); void us_ticker_remove_event(ticker_event_t *obj); -timestamp_t us_ticker_get_next_timestamp(void); +int us_ticker_get_next_timestamp(timestamp_t *timestamp); #ifdef __cplusplus }