esp_timer: alias esp_timer_get_time

alias esp_timer_get_time to improve performance
This commit is contained in:
morris 2020-03-31 18:44:37 +08:00
parent 2d1885b906
commit 890fc0fe67
6 changed files with 14 additions and 12 deletions

View file

@ -73,7 +73,7 @@ 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
*/
uint64_t esp_timer_impl_get_time(void);
int64_t esp_timer_impl_get_time(void);
/**
* @brief Get minimal timer period, in microseconds

View file

@ -278,7 +278,7 @@ static void timer_process_alarm(esp_timer_dispatch_t dispatch_method)
(void) dispatch_method;
timer_list_lock();
uint64_t now = esp_timer_impl_get_time();
int64_t now = esp_timer_impl_get_time();
esp_timer_handle_t it = LIST_FIRST(&s_timers);
while (it != NULL &&
it->alarm < now) {
@ -502,8 +502,3 @@ int64_t IRAM_ATTR esp_timer_get_next_alarm(void)
timer_list_unlock();
return next_alarm;
}
int64_t IRAM_ATTR esp_timer_get_time(void)
{
return (int64_t) esp_timer_impl_get_time();
}

View file

@ -176,7 +176,7 @@ void esp_timer_impl_unlock(void)
portEXIT_CRITICAL(&s_time_update_lock);
}
uint64_t IRAM_ATTR esp_timer_impl_get_time(void)
int64_t IRAM_ATTR esp_timer_impl_get_time(void)
{
uint32_t timer_val;
uint64_t time_base;
@ -209,6 +209,8 @@ uint64_t IRAM_ATTR esp_timer_impl_get_time(void)
return result;
}
int64_t esp_timer_get_time(void) __attribute__((alias("esp_timer_impl_get_time")));
void IRAM_ATTR esp_timer_impl_set_alarm(uint64_t timestamp)
{
portENTER_CRITICAL_SAFE(&s_time_update_lock);

View file

@ -144,11 +144,13 @@ uint64_t IRAM_ATTR esp_timer_impl_get_counter_reg(void)
return result.val;
}
uint64_t IRAM_ATTR esp_timer_impl_get_time(void)
int64_t IRAM_ATTR esp_timer_impl_get_time(void)
{
return esp_timer_impl_get_counter_reg() / TICKS_PER_US;
}
int64_t esp_timer_get_time(void) __attribute__((alias("esp_timer_impl_get_time")));
void IRAM_ATTR esp_timer_impl_set_alarm(uint64_t timestamp)
{
portENTER_CRITICAL_SAFE(&s_time_update_lock);

View file

@ -63,11 +63,14 @@ uint64_t IRAM_ATTR esp_timer_impl_get_counter_reg(void)
return systimer_hal_get_counter_value(SYSTIMER_COUNTER_0);
}
uint64_t IRAM_ATTR esp_timer_impl_get_time(void)
int64_t IRAM_ATTR esp_timer_impl_get_time(void)
{
return systimer_hal_get_time(SYSTIMER_COUNTER_0);
}
// Xtensa architecture doesn't have tail call optimization, using alias here can improve performance somehow
int64_t esp_timer_get_time(void) __attribute__((alias("esp_timer_impl_get_time")));
void IRAM_ATTR esp_timer_impl_set_alarm(uint64_t timestamp)
{
portENTER_CRITICAL_SAFE(&s_time_update_lock);

View file

@ -113,8 +113,8 @@ TEST_CASE("esp_timer_impl_set_alarm stress test", "[esp_timer]")
{
SemaphoreHandle_t done = (SemaphoreHandle_t) arg;
uint64_t start = esp_timer_impl_get_time();
uint64_t now = start;
int64_t start = esp_timer_impl_get_time();
int64_t now = start;
int count = 0;
const int delays[] = {50, 5000, 10000000};
const int delays_count = sizeof(delays)/sizeof(delays[0]);