summaryrefslogtreecommitdiffstatshomepage
path: root/esp8266
diff options
context:
space:
mode:
Diffstat (limited to 'esp8266')
-rw-r--r--esp8266/esp_mphal.c1
-rw-r--r--esp8266/esp_mphal.h1
-rw-r--r--esp8266/modpybrtc.c14
3 files changed, 16 insertions, 0 deletions
diff --git a/esp8266/esp_mphal.c b/esp8266/esp_mphal.c
index f5e9468e57..1a46c5f243 100644
--- a/esp8266/esp_mphal.c
+++ b/esp8266/esp_mphal.c
@@ -37,6 +37,7 @@ extern void ets_delay_us();
void mp_hal_init(void) {
ets_wdt_disable(); // it's a pain while developing
+ mp_hal_rtc_init();
uart_init(UART_BIT_RATE_115200, UART_BIT_RATE_115200);
}
diff --git a/esp8266/esp_mphal.h b/esp8266/esp_mphal.h
index 5c7b816355..f063fb8493 100644
--- a/esp8266/esp_mphal.h
+++ b/esp8266/esp_mphal.h
@@ -31,6 +31,7 @@
void ets_isr_mask(unsigned);
void mp_hal_init(void);
+void mp_hal_rtc_init(void);
void mp_hal_feed_watchdog(void);
uint32_t mp_hal_ticks_us(void);
diff --git a/esp8266/modpybrtc.c b/esp8266/modpybrtc.c
index 02377985c7..594c34b157 100644
--- a/esp8266/modpybrtc.c
+++ b/esp8266/modpybrtc.c
@@ -49,6 +49,20 @@ typedef struct _pyb_rtc_obj_t {
// singleton RTC object
STATIC const pyb_rtc_obj_t pyb_rtc_obj = {{&pyb_rtc_type}};
+void mp_hal_rtc_init(void) {
+ uint32_t magic;
+
+ system_rtc_mem_read(MEM_USER_MAGIC_ADDR, &magic, sizeof(magic));
+ if (magic != MEM_MAGIC) {
+ magic = MEM_MAGIC;
+ system_rtc_mem_write(MEM_USER_MAGIC_ADDR, &magic, sizeof(magic));
+ uint32_t cal = system_rtc_clock_cali_proc();
+ int64_t delta = 0;
+ system_rtc_mem_write(MEM_CAL_ADDR, &cal, sizeof(cal));
+ system_rtc_mem_write(MEM_DELTA_ADDR, &delta, sizeof(delta));
+ }
+}
+
STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
// check arguments
mp_arg_check_num(n_args, n_kw, 0, 0, false);