mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-25 03:22:43 +00:00
esp_timer: allow querying the timer before esp_timer_init is called
This commit is contained in:
committed by
Cao Sen Miao
parent
98d34e5f6d
commit
b5fe84a250
@@ -65,9 +65,6 @@ uint64_t IRAM_ATTR esp_timer_impl_get_counter_reg(void)
|
||||
|
||||
int64_t IRAM_ATTR esp_timer_impl_get_time(void)
|
||||
{
|
||||
if (s_alarm_handler == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return systimer_hal_get_time(SYSTIMER_COUNTER_0);
|
||||
}
|
||||
|
||||
@@ -100,6 +97,23 @@ void esp_timer_impl_advance(int64_t time_us)
|
||||
portEXIT_CRITICAL_SAFE(&s_time_update_lock);
|
||||
}
|
||||
|
||||
esp_err_t esp_timer_impl_early_init(void)
|
||||
{
|
||||
systimer_hal_init(&systimer_hal);
|
||||
|
||||
#if !SOC_SYSTIMER_FIXED_TICKS_US
|
||||
assert(rtc_clk_xtal_freq_get() == 40 && "update the step for xtal to support other XTAL:APB frequency ratios");
|
||||
systimer_hal_set_steps_per_tick(&systimer_hal, 0, 2); // for xtal
|
||||
systimer_hal_set_steps_per_tick(&systimer_hal, 1, 1); // for pll
|
||||
#endif
|
||||
|
||||
systimer_hal_enable_counter(&systimer_hal, SYSTIMER_LL_COUNTER_CLOCK);
|
||||
systimer_hal_select_alarm_mode(&systimer_hal, SYSTIMER_LL_ALARM_CLOCK, SYSTIMER_ALARM_MODE_ONESHOT);
|
||||
systimer_hal_connect_alarm_counter(&systimer_hal, SYSTIMER_LL_ALARM_CLOCK, SYSTIMER_LL_COUNTER_CLOCK);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_timer_impl_init(intr_handler_t alarm_handler)
|
||||
{
|
||||
s_alarm_handler = alarm_handler;
|
||||
@@ -117,11 +131,6 @@ esp_err_t esp_timer_impl_init(intr_handler_t alarm_handler)
|
||||
goto err_intr_alloc;
|
||||
}
|
||||
|
||||
systimer_hal_init();
|
||||
systimer_hal_enable_counter(SYSTIMER_COUNTER_0);
|
||||
systimer_hal_select_alarm_mode(SYSTIMER_ALARM_2, SYSTIMER_ALARM_MODE_ONESHOT);
|
||||
systimer_hal_connect_alarm_counter(SYSTIMER_ALARM_2, SYSTIMER_COUNTER_0);
|
||||
|
||||
/* TODO: if SYSTIMER is used for anything else, access to SYSTIMER_INT_ENA_REG has to be
|
||||
* protected by a shared spinlock. Since this code runs as part of early startup, this
|
||||
* is practically not an issue.
|
||||
|
||||
Reference in New Issue
Block a user