esp_timer: add internal function to adjust time

This commit is contained in:
Ivan Grokhotkov 2018-04-03 18:13:22 +08:00
parent 48379b8bbe
commit 487210221b
2 changed files with 21 additions and 0 deletions

View file

@ -311,6 +311,18 @@ void IRAM_ATTR esp_timer_impl_update_apb_freq(uint32_t apb_ticks_per_us)
portEXIT_CRITICAL_ISR(&s_time_update_lock);
}
void esp_timer_impl_advance(int64_t time_us)
{
assert(time_us > 0 && "negative adjustments not supported yet");
portENTER_CRITICAL(&s_time_update_lock);
uint64_t count = REG_READ(FRC_TIMER_COUNT_REG(1));
REG_WRITE(FRC_TIMER_LOAD_REG(1), 0);
s_time_base_us += count / s_timer_ticks_per_us + time_us;
esp_timer_impl_set_alarm(esp_timer_get_next_alarm());
portEXIT_CRITICAL(&s_time_update_lock);
}
esp_err_t esp_timer_impl_init(intr_handler_t alarm_handler)
{
s_alarm_handler = alarm_handler;

View file

@ -60,6 +60,15 @@ void esp_timer_impl_set_alarm(uint64_t timestamp);
*/
void esp_timer_impl_update_apb_freq(uint32_t apb_ticks_per_us);
/**
* @brief Adjust current esp_timer time by a certain value
*
* Called from light sleep code to synchronize esp_timer time with RTC time.
*
* @param time_us adjustment to apply to esp_timer time, in microseconds
*/
void esp_timer_impl_advance(int64_t time_us);
/**
* @brief Get time, in microseconds, since esp_timer_impl_init was called
* @return timestamp in microseconds