Set an alarm with the same time base as returned by esp_timer_get_time()

AloyseTech
Posts: 22
Joined: Mon Jul 22, 2019 2:29 pm

Set an alarm with the same time base as returned by esp_timer_get_time()

Postby AloyseTech » Fri Nov 15, 2019 4:19 pm

Hi,

How can I set an alarm to a given timestamp in microseconds with the same base as esp_timer_get_time() ?
It seems that esp_timer_get_time does not use timer group so they do not share the same time base.

Here is a pseudo code of what I need:

Code: Select all

void app_main()
{
    execAt = postParam(esp_timer_get_time()); //return a timestamp relative to the input at which an event must be triggered
    configure_alarm_at(execAt, handler);
}

void IRAM handler()
{
    execute();
}

AloyseTech
Posts: 22
Joined: Mon Jul 22, 2019 2:29 pm

Re: Set an alarm with the same time base as returned by esp_timer_get_time()

Postby AloyseTech » Fri Nov 15, 2019 6:51 pm

The esp_timer common components has a function called esp_timer_start_once(timer, relative_time_from_now)

It could be great to have a similar API called esp_timer_start_alarm(timer, absolute_time)

Implementation would be :

Code: Select all

esp_err_t IRAM_ATTR esp_timer_start_alarm(esp_timer_handle_t timer, uint64_t timestamp_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 = timestamp_us; // start_once use esp_timer_get_time() + timeout_us
    timer->period = 0;
#if WITH_PROFILING
    timer->times_armed++;
#endif
    esp_err_t err = timer_insert(timer);
    timer_list_unlock();
    return err;
}

Who is online

Users browsing this forum: No registered users and 123 guests