cpu/esp32: introduce pseudomodule esp_rtc_timer
It is possible to use different timers as RTC timer for the periph_rtc module. Either the 48-bit RTC hardware timer is used directly or the PLL driven 64-bit system timer emulates a RTC timer. The latter one is much more accurate. Pseudomodule esp_rtc_timer controlls which timer is used. Only if esp_rtc_timer is enabled explicitly, the 48-bit RTC hardware timer is used. Otherwise the 64-bit sytstem timer is used to emulate the RTC timer.
This commit is contained in:
parent
9cf103e055
commit
21b2c8d334
@ -85,6 +85,7 @@ PSEUDOMODULES += esp_idf_newlib
|
||||
PSEUDOMODULES += esp_log_colored
|
||||
PSEUDOMODULES += esp_log_tagged
|
||||
PSEUDOMODULES += esp_log_startup
|
||||
PSEUDOMODULES += esp_rtc_timer
|
||||
PSEUDOMODULES += esp_spi_ram
|
||||
PSEUDOMODULES += esp_spiffs
|
||||
PSEUDOMODULES += esp_wifi_any
|
||||
|
||||
@ -20,11 +20,12 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* If RTC_TIMER_USED is 0, the microsecond system timer is used to emulate an
|
||||
* RTC, otherwise the RTC timer is used. Advantage of using RTC over system
|
||||
* timer is that it also continues in deep sleep and after software reset.
|
||||
* If module esp_rtc_timer is enabled, the 48-bit RTC hardware timer is used
|
||||
* directly. Otherwise the PLL driven 64-bit microsecond system timer is used
|
||||
* to emulate a RTC timer (default). This emulated RTC timer results into much
|
||||
* better accuracy. The Advantage of using RTC hardware timer over sytem timer
|
||||
* is that it would also continue in deep sleep mode.
|
||||
*/
|
||||
#define RTC_TIMER_USED 1
|
||||
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
@ -178,7 +179,7 @@ int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg)
|
||||
* system timer for alarms. The Advantage of using RTC over system timer
|
||||
* is that it also continues in deep sleep and after software reset.
|
||||
*/
|
||||
#if 0 /* TODO should be RTC_TIMER_USED */
|
||||
#if 0 /* TODO should be MODULE_ESP_RTC_TIMER */
|
||||
|
||||
/* determine the offset of alarm time to current time in RTC time */
|
||||
uint64_t _rtc_time_alarm;
|
||||
@ -207,7 +208,7 @@ int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg)
|
||||
xt_set_interrupt_handler(CPU_INUM_RTC, _rtc_timer_handler, NULL);
|
||||
xt_ints_on(BIT(CPU_INUM_RTC));
|
||||
|
||||
#else
|
||||
#else
|
||||
|
||||
/* determine the offset of alarm time to the RTC set time */
|
||||
uint64_t _rtc_time_alarm;
|
||||
@ -246,7 +247,7 @@ int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg)
|
||||
TIMER_SYSTEM.config.level_int_en = 1;
|
||||
TIMER_SYSTEM.config.alarm_en = 1;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -256,7 +257,7 @@ void rtc_clear_alarm(void)
|
||||
_rtc_alarm_cb = NULL;
|
||||
_rtc_alarm_arg = NULL;
|
||||
|
||||
#if 0 /* TODO should be RTC_TIMER_USED, see rtc_set_alarm */
|
||||
#if 0 /* TODO should be MODULE_ESP_RTC_TIMER, see rtc_set_alarm */
|
||||
|
||||
/* disable RTC timer alarm and disable the RTC timer interrupt */
|
||||
RTCCNTL.slp_timer1.main_timer_alarm_en = 0;
|
||||
@ -267,7 +268,7 @@ void rtc_clear_alarm(void)
|
||||
|
||||
/* disable the the CPU interrupt */
|
||||
|
||||
#else
|
||||
#else
|
||||
|
||||
/* reset the bit in interrupt enable */
|
||||
TIMER_SYSTEM_GROUP.int_ena.val |= TIMER_SYSTEM_INT_MASK;
|
||||
@ -281,18 +282,22 @@ void rtc_clear_alarm(void)
|
||||
|
||||
xt_ints_on(BIT(CPU_INUM_RTC));
|
||||
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
static time_t _sys_get_time (void)
|
||||
{
|
||||
return _sys_time_set + (_rtc_get_time_raw() - _rtc_time_set) / RTC_TIMER_CLK_HZ;
|
||||
#if MODULE_ESP_RTC_TIMER
|
||||
return _sys_time_set +
|
||||
(_rtc_time_to_us(_rtc_get_time_raw() - _rtc_time_set) / US_PER_SEC);
|
||||
#else
|
||||
return _sys_time_set +
|
||||
((_sys_time_off_us + system_get_time_64() - _sys_time_set_us) / US_PER_SEC);
|
||||
#endif
|
||||
}
|
||||
|
||||
static uint64_t _rtc_get_time_raw(void)
|
||||
{
|
||||
#if RTC_TIMER_USED
|
||||
|
||||
/* trigger timer register update */
|
||||
RTCCNTL.time_update.update = 1;
|
||||
/* wait until values in registers are valid */
|
||||
@ -314,7 +319,7 @@ static void IRAM_ATTR _rtc_timer_handler(void* arg)
|
||||
{
|
||||
irq_isr_enter();
|
||||
|
||||
#if 0 /* TODO should be RTC_TIMER_USED */
|
||||
#if 0 /* TODO should be MODULE_ESP_RTC_TIMER */
|
||||
|
||||
/* check for RTC timer interrupt */
|
||||
if (RTCCNTL.int_st.rtc_main_timer) {
|
||||
@ -328,7 +333,7 @@ static void IRAM_ATTR _rtc_timer_handler(void* arg)
|
||||
/* clear all interrupts */
|
||||
RTCCNTL.int_clr.val = 0x1ff;
|
||||
|
||||
#else
|
||||
#else
|
||||
|
||||
/* check for RTC timer interrupt */
|
||||
if (TIMER_SYSTEM_GROUP.int_st_timers.val & TIMER_SYSTEM_INT_MASK) {
|
||||
@ -349,7 +354,7 @@ static void IRAM_ATTR _rtc_timer_handler(void* arg)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
irq_isr_exit();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user