arch/esp32: Introduce the ESP32_RTC option.

Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
This commit is contained in:
Abdelatif Guettouche 2022-07-11 15:29:22 +02:00 committed by Petro Karashchenko
parent 63cb11cc72
commit 770147ffe3
3 changed files with 53 additions and 60 deletions

View File

@ -211,44 +211,6 @@ config ESP32_XTAL_26MHz
endchoice # On-board Crystal Frequency
choice ESP32_RTC_CLK_SRC
prompt "RTC clock source"
default ESP32_RTC_CLK_SRC_INT_RC
---help---
Choose which clock is used as RTC clock source.
- "Internal 150kHz oscillator" option provides lowest deep sleep current
consumption, and does not require extra external components. However
frequency stability with respect to temperature is poor, so time may
drift in deep/light sleep modes.
- "External 32kHz crystal" provides better frequency stability, at the
expense of slightly higher (1uA) deep sleep current consumption.
- "External 32kHz oscillator" allows using 32kHz clock generated by an
external circuit. In this case, external clock signal must be connected
to 32K_XN pin. Amplitude should be <1.2V in case of sine wave signal,
and <1V in case of square wave signal. Common mode voltage should be
0.1 < Vcm < 0.5Vamp, where Vamp is the signal amplitude.
Additionally, 1nF capacitor must be connected between 32K_XP pin and
ground. 32K_XP pin can not be used as a GPIO in this case.
- "Internal 8.5MHz oscillator divided by 256" option results in higher
deep sleep current (by 5uA) but has better frequency stability than
the internal 150kHz oscillator. It does not require external components.
config ESP32_RTC_CLK_SRC_INT_RC
bool "Internal 150kHz RC oscillator"
config ESP32_RTC_CLK_SRC_EXT_XTAL
bool "External 32kHz crystal"
select ESP_SYSTEM_RTC_EXT_XTAL
config ESP32_RTC_CLK_SRC_EXT_OSC
bool "External 32kHz oscillator at 32K_XN pin"
config ESP32_RTC_CLK_SRC_INT_8MD256
bool "Internal 8.5MHz oscillator, divided by 256 (~33kHz)"
endchoice
config ESP32_RT_TIMER
bool "Real-time Timer"
default n
@ -483,6 +445,10 @@ config ESP32_RWDT
to have the RTC module reset, please, use the Timers' Module WDTs.
They will only reset Main System.
config ESP32_RTC
bool "Real Time Clock (RTC)"
default y
config ESP32_UART0
bool "UART 0"
default n
@ -1430,6 +1396,48 @@ config ESP32_FREERUN
endmenu # Timer/counter Configuration
endif # ESP32_TIMER
menu "RTC Configuration"
depends on ESP32_RTC
choice ESP32_RTC_CLK_SRC
prompt "RTC clock source"
default ESP32_RTC_CLK_SRC_INT_RC
---help---
Choose which clock is used as RTC clock source.
- "Internal 150kHz oscillator" option provides lowest deep sleep current
consumption, and does not require extra external components. However
frequency stability with respect to temperature is poor, so time may
drift in deep/light sleep modes.
- "External 32kHz crystal" provides better frequency stability, at the
expense of slightly higher (1uA) deep sleep current consumption.
- "External 32kHz oscillator" allows using 32kHz clock generated by an
external circuit. In this case, external clock signal must be connected
to 32K_XN pin. Amplitude should be <1.2V in case of sine wave signal,
and <1V in case of square wave signal. Common mode voltage should be
0.1 < Vcm < 0.5Vamp, where Vamp is the signal amplitude.
Additionally, 1nF capacitor must be connected between 32K_XP pin and
ground. 32K_XP pin can not be used as a GPIO in this case.
- "Internal 8.5MHz oscillator divided by 256" option results in higher
deep sleep current (by 5uA) but has better frequency stability than
the internal 150kHz oscillator. It does not require external components.
config ESP32_RTC_CLK_SRC_INT_RC
bool "Internal 150kHz RC oscillator"
config ESP32_RTC_CLK_SRC_EXT_XTAL
bool "External 32kHz crystal"
select ESP_SYSTEM_RTC_EXT_XTAL
config ESP32_RTC_CLK_SRC_EXT_OSC
bool "External 32kHz oscillator at 32K_XN pin"
config ESP32_RTC_CLK_SRC_INT_8MD256
bool "Internal 8.5MHz oscillator, divided by 256 (~33kHz)"
endchoice
endmenu # "RTC Configuration"
menu "LEDC configuration"
depends on ESP32_LEDC

View File

@ -58,8 +58,6 @@ endif
CHIP_CSRCS += esp32_pm.c
endif
CHIP_CSRCS += esp32_rtc.c
ifeq ($(CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP),y)
CHIP_CSRCS += esp32_imm.c
endif
@ -177,9 +175,12 @@ ifeq ($(CONFIG_ESP32_AES_ACCELERATOR),y)
CHIP_CSRCS += esp32_aes.c
endif
ifeq ($(CONFIG_ESP32_RTC),y)
CHIP_CSRCS += esp32_rtc.c
ifeq ($(CONFIG_RTC_DRIVER),y)
CHIP_CSRCS += esp32_rtc_lowerhalf.c
endif
endif
ifeq ($(CONFIG_ESP32_WIRELESS),y)
WIRELESS_DRV_UNPACK = esp-wireless-drivers-3rdparty

View File

@ -157,13 +157,11 @@
.fe_pd = (val), \
}
#ifdef CONFIG_RTC_DRIVER
/* The magic data for the struct esp32_rtc_backup_s that is in RTC slow
* memory.
*/
# define MAGIC_RTC_SAVE (UINT64_C(0x11223344556677))
#endif
#define MAGIC_RTC_SAVE UINT64_C(0x11223344556677)
/* RTC Memory & Store Register usage */
@ -228,8 +226,6 @@ struct esp32_rtc_sleep_pd_config_s
uint32_t fe_pd : 1; /* Set to 1 to power down Wi-Fi in sleep */
};
#ifdef CONFIG_RTC_DRIVER
#ifdef CONFIG_RTC_ALARM
struct alm_cbinfo_s
{
@ -248,8 +244,6 @@ struct esp32_rtc_backup_s
int64_t reserved0;
};
#endif
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
@ -268,7 +262,7 @@ static void esp32_rtc_clk_32k_enable(int ac, int res, int bias);
static void IRAM_ATTR esp32_rtc_clk_8m_enable(bool clk_8m_en, bool d256_en);
static uint32_t IRAM_ATTR esp32_rtc_clk_slow_freq_get_hz(void);
#ifdef CONFIG_RTC_DRIVER
#ifdef CONFIG_RTC_ALARM
static void IRAM_ATTR esp32_rt_cb_handler(void *arg);
#endif
@ -286,8 +280,6 @@ static struct esp32_rtc_priv_s esp32_rtc_priv =
.rtc_dboost_fpd = 1
};
#ifdef CONFIG_RTC_DRIVER
/* Callback to use when the alarm expires */
#ifdef CONFIG_RTC_ALARM
@ -301,15 +293,11 @@ static RTC_DATA_ATTR struct esp32_rtc_backup_s rtc_saved_data;
static struct esp32_rtc_backup_s *g_rtc_save;
static bool g_rt_timer_enabled = false;
#endif
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef CONFIG_RTC_DRIVER
volatile bool g_rtc_enabled = false;
#endif
/****************************************************************************
* Private Functions
@ -747,7 +735,7 @@ static void esp32_select_rtc_slow_clk(enum esp32_slow_clk_sel_e slow_clk)
putreg32((uint32_t)cal_val, RTC_SLOW_CLK_CAL_REG);
}
#ifdef CONFIG_RTC_DRIVER
#ifdef CONFIG_RTC_ALARM
/****************************************************************************
* Name: esp32_rt_cb_handler
@ -788,7 +776,7 @@ static void IRAM_ATTR esp32_rt_cb_handler(void *arg)
}
}
#endif /* CONFIG_RTC_DRIVER */
#endif /* CONFIG_RTC_ALARM */
/****************************************************************************
* Public Functions
@ -1884,8 +1872,6 @@ uint64_t IRAM_ATTR esp32_rtc_get_boot_time(void)
+ (((uint64_t)getreg32(RTC_BOOT_TIME_HIGH_REG)) << 32);
}
#ifdef CONFIG_RTC_DRIVER
/****************************************************************************
* Name: up_rtc_time
*
@ -2271,5 +2257,3 @@ int up_rtc_timer_init(void)
return OK;
}
#endif /* CONFIG_RTC_DRIVER */