diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-02-08 21:43:37 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-03-04 16:49:01 +0200 |
commit | a4c8ef9d16d45c58bbfc0aba451e4c197c552f0f (patch) | |
tree | 06ed7026e1718111efcdbe05807d5d3ba6393360 /esp8266/modpybrtc.c | |
parent | 57884996b9938141447c3440f8089516de90c0ec (diff) | |
download | micropython-a4c8ef9d16d45c58bbfc0aba451e4c197c552f0f.tar.gz micropython-a4c8ef9d16d45c58bbfc0aba451e4c197c552f0f.zip |
esp8266: Reset "virtual RTC" on power on.
Initialize RTC period coefficients, etc. if RTC RAM doesn't contain valid
values. time.time() then will return number of seconds since power-on, unless
set to different timebase.
This reuses MEM_MAGIC for the purpose beyond its initial purpose (but the whole
modpybrtc.c need to be eventually reworked completely anyway).
Diffstat (limited to 'esp8266/modpybrtc.c')
-rw-r--r-- | esp8266/modpybrtc.c | 14 |
1 files changed, 14 insertions, 0 deletions
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); |