esp_timer: do init check in timer implementation

This commit is contained in:
Renz Bagaporo
2020-08-18 16:15:53 +08:00
committed by KonstantinKondrashov
parent 0fa3ff8bf0
commit e70f240e12
4 changed files with 20 additions and 14 deletions

View File

@@ -43,7 +43,7 @@ static intr_handle_t s_timer_interrupt_handle;
/* Function from the upper layer to be called when the interrupt happens.
* Registered in esp_timer_impl_init.
*/
static intr_handler_t s_alarm_handler;
static intr_handler_t s_alarm_handler = NULL;
/* Spinlock used to protect access to the hardware registers. */
portMUX_TYPE s_time_update_lock = portMUX_INITIALIZER_UNLOCKED;
@@ -65,9 +65,14 @@ 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);
}
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);