mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/get_time_in_less_than_microsecond' into 'master'
esp_timer: inline is initialized check See merge request espressif/esp-idf!10080
This commit is contained in:
commit
7da6d6c1b5
@ -78,7 +78,7 @@ struct esp_timer {
|
||||
LIST_ENTRY(esp_timer) list_entry;
|
||||
};
|
||||
|
||||
static bool is_initialized(void);
|
||||
static inline bool is_initialized(void);
|
||||
static esp_err_t timer_insert(esp_timer_handle_t timer);
|
||||
static esp_err_t timer_remove(esp_timer_handle_t timer);
|
||||
static bool timer_armed(esp_timer_handle_t timer);
|
||||
@ -361,7 +361,7 @@ static void IRAM_ATTR timer_alarm_handler(void* arg)
|
||||
}
|
||||
}
|
||||
|
||||
static IRAM_ATTR bool is_initialized(void)
|
||||
static IRAM_ATTR inline bool is_initialized(void)
|
||||
{
|
||||
return s_timer_task != NULL;
|
||||
}
|
||||
@ -529,15 +529,6 @@ int64_t IRAM_ATTR esp_timer_get_next_alarm(void)
|
||||
return next_alarm;
|
||||
}
|
||||
|
||||
int64_t IRAM_ATTR esp_timer_get_time(void)
|
||||
{
|
||||
if(is_initialized()) {
|
||||
return esp_timer_impl_get_time();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Provides strong definition for system time functions relied upon
|
||||
// by core components.
|
||||
#if WITH_FRC
|
||||
|
@ -103,7 +103,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;
|
||||
|
||||
// Time in microseconds from startup to the moment
|
||||
// when timer counter was last equal to 0. This variable is updated each time
|
||||
@ -178,6 +178,9 @@ void esp_timer_impl_unlock(void)
|
||||
|
||||
int64_t IRAM_ATTR esp_timer_impl_get_time(void)
|
||||
{
|
||||
if (s_alarm_handler == NULL) {
|
||||
return 0;
|
||||
}
|
||||
uint32_t timer_val;
|
||||
uint64_t time_base;
|
||||
uint32_t ticks_per_us;
|
||||
@ -209,6 +212,8 @@ int64_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);
|
||||
|
@ -97,7 +97,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;
|
||||
@ -146,9 +146,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 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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user