|
|
@@ -72,9 +72,6 @@ uint64_t IRAM_ATTR esp_timer_impl_get_counter_reg(void)
|
|
|
|
|
|
int64_t IRAM_ATTR esp_timer_impl_get_time(void)
|
|
|
{
|
|
|
- if (unlikely(s_alarm_handler == NULL)) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
return systimer_hal_get_counter_value(&systimer_hal, SYSTIMER_LL_COUNTER_CLOCK) / SYSTIMER_LL_TICKS_PER_US;
|
|
|
}
|
|
|
|
|
|
@@ -119,6 +116,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;
|
|
|
@@ -137,16 +151,6 @@ esp_err_t esp_timer_impl_init(intr_handler_t alarm_handler)
|
|
|
goto err_intr_alloc;
|
|
|
}
|
|
|
|
|
|
- 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);
|
|
|
-
|
|
|
/* 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.
|