From 4ba19abeb690b7fd276b6ed9721c538dd54bfda3 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 3 Apr 2018 18:12:47 +0800 Subject: [PATCH] esp_timer: add a function to get next alarm time --- components/esp32/esp_timer.c | 12 ++++++++++++ components/esp32/include/esp_timer.h | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/components/esp32/esp_timer.c b/components/esp32/esp_timer.c index 6987b4c64..72bd9dd73 100644 --- a/components/esp32/esp_timer.c +++ b/components/esp32/esp_timer.c @@ -455,6 +455,18 @@ esp_err_t esp_timer_dump(FILE* stream) return ESP_OK; } +int64_t IRAM_ATTR esp_timer_get_next_alarm() +{ + int64_t next_alarm = INT64_MAX; + timer_list_lock(); + esp_timer_handle_t it = LIST_FIRST(&s_timers); + if (it) { + next_alarm = it->alarm; + } + timer_list_unlock(); + return next_alarm; +} + int64_t IRAM_ATTR esp_timer_get_time() { return (int64_t) esp_timer_impl_get_time(); diff --git a/components/esp32/include/esp_timer.h b/components/esp32/include/esp_timer.h index 07e237214..ff5c13ab4 100644 --- a/components/esp32/include/esp_timer.h +++ b/components/esp32/include/esp_timer.h @@ -189,6 +189,13 @@ esp_err_t esp_timer_delete(esp_timer_handle_t timer); */ int64_t esp_timer_get_time(); +/** + * @brief Get the timestamp when the next timeout is expected to occur + * @return Timestamp of the nearest timer event, in microseconds. + * The timebase is the same as for the values returned by esp_timer_get_time. + */ +int64_t esp_timer_get_next_alarm(); + /** * @brief Dump the list of timers to a stream *