kopia lustrzana https://github.com/espressif/esp-idf
esp_hw_support: esp_clk should use spinlock instead of mutex
esp_clk used to be protected using _lock_t (i.e., a FreeRTOS Mutex). However, esp_clk API is current called from from critical sections, thus mutex should not be used (as they can be blocking). This commit updates esp_clk to use spinlocks for critical sections instead. Note: Added a small fix to exclude esp_clk.c from bootloader builds in the legacy build system (this is already the case in CMake).pull/9840/head
rodzic
e80057035a
commit
9ea9192efb
|
@ -4,6 +4,7 @@ COMPONENT_ADD_LDFRAGMENTS := linker.lf
|
|||
|
||||
ifdef IS_BOOTLOADER_BUILD
|
||||
COMPONENT_OBJEXCLUDE += clk_ctrl_os.o \
|
||||
esp_clk.o \
|
||||
intr_alloc.o \
|
||||
sleep_modes.o \
|
||||
sleep_gpio.o \
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <sys/param.h>
|
||||
#include <sys/lock.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "esp_attr.h"
|
||||
#include "soc/rtc.h"
|
||||
|
||||
|
@ -44,7 +45,7 @@ extern uint32_t g_ticks_per_us_app;
|
|||
#endif
|
||||
#endif
|
||||
|
||||
static _lock_t s_esp_rtc_time_lock;
|
||||
static portMUX_TYPE s_esp_rtc_time_lock = portMUX_INITIALIZER_UNLOCKED;
|
||||
static RTC_DATA_ATTR uint64_t s_esp_rtc_time_us = 0, s_rtc_last_ticks = 0;
|
||||
|
||||
inline static int IRAM_ATTR s_get_cpu_freq_mhz(void)
|
||||
|
@ -86,7 +87,7 @@ void IRAM_ATTR ets_update_cpu_frequency(uint32_t ticks_per_us)
|
|||
|
||||
uint64_t esp_rtc_get_time_us(void)
|
||||
{
|
||||
_lock_acquire(&s_esp_rtc_time_lock);
|
||||
portENTER_CRITICAL_SAFE(&s_esp_rtc_time_lock);
|
||||
const uint32_t cal = esp_clk_slowclk_cal_get();
|
||||
const uint64_t rtc_this_ticks = rtc_time_get();
|
||||
const uint64_t ticks = rtc_this_ticks - s_rtc_last_ticks;
|
||||
|
@ -107,7 +108,7 @@ uint64_t esp_rtc_get_time_us(void)
|
|||
((ticks_high * cal) << (32 - RTC_CLK_CAL_FRACT));
|
||||
s_esp_rtc_time_us += delta_time_us;
|
||||
s_rtc_last_ticks = rtc_this_ticks;
|
||||
_lock_release(&s_esp_rtc_time_lock);
|
||||
portEXIT_CRITICAL_SAFE(&s_esp_rtc_time_lock);
|
||||
return s_esp_rtc_time_us;
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue