mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-15 14:36:45 +00:00
esp_timer: Fix System time jumps back ~54secs
Closes: https://github.com/espressif/esp-idf/issues/2513
This commit is contained in:

committed by
bot

parent
f52b877199
commit
696d6867b4
@@ -59,12 +59,12 @@ struct esp_timer {
|
||||
LIST_ENTRY(esp_timer) list_entry;
|
||||
};
|
||||
|
||||
static bool is_initialized();
|
||||
static bool is_initialized(void);
|
||||
static esp_err_t timer_insert(esp_timer_handle_t timer);
|
||||
static esp_err_t timer_remove(esp_timer_handle_t timer);
|
||||
static bool timer_armed(esp_timer_handle_t timer);
|
||||
static void timer_list_lock();
|
||||
static void timer_list_unlock();
|
||||
static void timer_list_lock(void);
|
||||
static void timer_list_unlock(void);
|
||||
|
||||
#if WITH_PROFILING
|
||||
static void timer_insert_inactive(esp_timer_handle_t timer);
|
||||
@@ -103,7 +103,7 @@ esp_err_t esp_timer_create(const esp_timer_create_args_t* args,
|
||||
if (!is_initialized()) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
if (args->callback == NULL) {
|
||||
if (args == NULL || args->callback == NULL || out_handle == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
esp_timer_handle_t result = (esp_timer_handle_t) calloc(1, sizeof(*result));
|
||||
@@ -122,33 +122,48 @@ esp_err_t esp_timer_create(const esp_timer_create_args_t* args,
|
||||
|
||||
esp_err_t IRAM_ATTR esp_timer_start_once(esp_timer_handle_t timer, uint64_t timeout_us)
|
||||
{
|
||||
if (timer == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (!is_initialized() || timer_armed(timer)) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
timer_list_lock();
|
||||
timer->alarm = esp_timer_get_time() + timeout_us;
|
||||
timer->period = 0;
|
||||
#if WITH_PROFILING
|
||||
timer->times_armed++;
|
||||
#endif
|
||||
return timer_insert(timer);
|
||||
esp_err_t err = timer_insert(timer);
|
||||
timer_list_unlock();
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t IRAM_ATTR esp_timer_start_periodic(esp_timer_handle_t timer, uint64_t period_us)
|
||||
{
|
||||
if (timer == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (!is_initialized() || timer_armed(timer)) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
timer_list_lock();
|
||||
period_us = MAX(period_us, esp_timer_impl_get_min_period_us());
|
||||
timer->alarm = esp_timer_get_time() + period_us;
|
||||
timer->period = period_us;
|
||||
#if WITH_PROFILING
|
||||
timer->times_armed++;
|
||||
#endif
|
||||
return timer_insert(timer);
|
||||
esp_err_t err = timer_insert(timer);
|
||||
timer_list_unlock();
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t IRAM_ATTR esp_timer_stop(esp_timer_handle_t timer)
|
||||
{
|
||||
if (timer == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (!is_initialized() || !timer_armed(timer)) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
@@ -163,16 +178,17 @@ esp_err_t esp_timer_delete(esp_timer_handle_t timer)
|
||||
if (timer_armed(timer)) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
timer_list_lock();
|
||||
timer->event_id = EVENT_ID_DELETE_TIMER;
|
||||
timer->alarm = esp_timer_get_time() + 50;
|
||||
timer->alarm = esp_timer_get_time();
|
||||
timer->period = 0;
|
||||
timer_insert(timer);
|
||||
timer_list_unlock();
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static IRAM_ATTR esp_err_t timer_insert(esp_timer_handle_t timer)
|
||||
{
|
||||
timer_list_lock();
|
||||
#if WITH_PROFILING
|
||||
timer_remove_inactive(timer);
|
||||
#endif
|
||||
@@ -195,7 +211,6 @@ static IRAM_ATTR esp_err_t timer_insert(esp_timer_handle_t timer)
|
||||
if (timer == LIST_FIRST(&s_timers)) {
|
||||
esp_timer_impl_set_alarm(timer->alarm);
|
||||
}
|
||||
timer_list_unlock();
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -246,12 +261,12 @@ static IRAM_ATTR bool timer_armed(esp_timer_handle_t timer)
|
||||
return timer->alarm > 0;
|
||||
}
|
||||
|
||||
static IRAM_ATTR void timer_list_lock()
|
||||
static IRAM_ATTR void timer_list_lock(void)
|
||||
{
|
||||
portENTER_CRITICAL(&s_timer_lock);
|
||||
}
|
||||
|
||||
static IRAM_ATTR void timer_list_unlock()
|
||||
static IRAM_ATTR void timer_list_unlock(void)
|
||||
{
|
||||
portEXIT_CRITICAL(&s_timer_lock);
|
||||
}
|
||||
@@ -322,7 +337,7 @@ static void IRAM_ATTR timer_alarm_handler(void* arg)
|
||||
}
|
||||
}
|
||||
|
||||
static IRAM_ATTR bool is_initialized()
|
||||
static IRAM_ATTR bool is_initialized(void)
|
||||
{
|
||||
return s_timer_task != NULL;
|
||||
}
|
||||
@@ -473,7 +488,7 @@ esp_err_t esp_timer_dump(FILE* stream)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
int64_t IRAM_ATTR esp_timer_get_next_alarm()
|
||||
int64_t IRAM_ATTR esp_timer_get_next_alarm(void)
|
||||
{
|
||||
int64_t next_alarm = INT64_MAX;
|
||||
timer_list_lock();
|
||||
@@ -485,7 +500,7 @@ int64_t IRAM_ATTR esp_timer_get_next_alarm()
|
||||
return next_alarm;
|
||||
}
|
||||
|
||||
int64_t IRAM_ATTR esp_timer_get_time()
|
||||
int64_t IRAM_ATTR esp_timer_get_time(void)
|
||||
{
|
||||
return (int64_t) esp_timer_impl_get_time();
|
||||
}
|
||||
|
Reference in New Issue
Block a user