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:
Gunar Schorcht 2019-08-08 17:12:53 +02:00
parent 9cf103e055
commit 21b2c8d334
2 changed files with 22 additions and 16 deletions

View File

@ -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

View File

@ -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;
@ -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;
@ -286,13 +287,17 @@ void rtc_clear_alarm(void)
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) {