esp_timer: Added esp_timer_get_period/expiry_time APIs

Added the following new APIs to the esp_timer module:
- esp_timer_get_period(): Returns the period of a timer in microseconds.
- esp_timer_get_expiry_time(): Returns the timeout value of a one-shot timer in microseconds.

Signed-off-by: Sudeep Mohanty <sudeep.mohanty@espressif.com>
This commit is contained in:
Sudeep Mohanty
2021-11-08 14:53:52 +05:30
parent f788c337b1
commit 5806e57773
2 changed files with 68 additions and 0 deletions

View File

@@ -623,6 +623,41 @@ int64_t IRAM_ATTR esp_timer_get_next_alarm_for_wake_up(void)
return next_alarm;
}
esp_err_t IRAM_ATTR esp_timer_get_period(esp_timer_handle_t timer, uint64_t *period)
{
if (timer == NULL || period == NULL) {
return ESP_ERR_INVALID_ARG;
}
esp_timer_dispatch_t dispatch_method = timer->flags & FL_ISR_DISPATCH_METHOD;
timer_list_lock(dispatch_method);
*period = timer->period;
timer_list_unlock(dispatch_method);
return ESP_OK;
}
esp_err_t IRAM_ATTR esp_timer_get_expiry_time(esp_timer_handle_t timer, uint64_t *expiry)
{
if (timer == NULL || expiry == NULL) {
return ESP_ERR_INVALID_ARG;
}
if (timer->period > 0) {
/* Return error for periodic timers */
return ESP_ERR_NOT_SUPPORTED;
}
esp_timer_dispatch_t dispatch_method = timer->flags & FL_ISR_DISPATCH_METHOD;
timer_list_lock(dispatch_method);
*expiry = timer->alarm;
timer_list_unlock(dispatch_method);
return ESP_OK;
}
bool esp_timer_is_active(esp_timer_handle_t timer)
{
return timer_armed(timer);