Add PNVRAM support to avoid forgetting the time during a reboot.

This commit is contained in:
Daniel Thompson 2020-05-09 14:18:39 +01:00
parent b0dec58769
commit c1f8823f61
4 changed files with 17 additions and 5 deletions

View file

@ -47,7 +47,7 @@ applications.
### Bootloader
* [X] OTA bootloader update
* [ ] RTC time measurement whilst in bootloader
* [X] RTC time measurement whilst in bootloader
### MicroPython

@ -1 +1 @@
Subproject commit 7786926950902cf4ce49a93894f69a205d6fd325
Subproject commit d8d7d76b17e188420f66705f0b319f6e80a328f2

@ -1 +1 @@
Subproject commit 5424de70d7cfb1d53828b54cd1df509c3f0fee74
Subproject commit 8ea321106823866adcb6c4881b4045939b56cc3a

View file

@ -3,6 +3,7 @@
""" Real Time Clock based on the nRF-family low power counter """
import machine
import time
#class Stim(object):
@ -20,8 +21,17 @@ class RTC(object):
def __init__(self, counter):
self.counter = counter
self._uptime = 0
self.set_localtime((2020, 3, 1, 3, 0, 0, 0, 0))
if machine.mem32[0x200039c0] == 0x1abe11ed and \
machine.mem32[0x200039dc] == 0x10adab1e:
self.lastcount = self.counter.counter()
self.offset = machine.mem32[0x200039c4]
self._uptime = machine.mem32[0x200039c8] // 125
else:
machine.mem32[0x200039c0] = 0x1abe11ed
machine.mem32[0x200039dc] = 0x10adab1e
self._uptime = 0
self.set_localtime((2020, 3, 1, 3, 0, 0, 0, 0))
def update(self):
newcount = self.counter.counter()
@ -34,6 +44,7 @@ class RTC(object):
self.lastcount += split
self.lastcount &= (1 << 24) - 1
self._uptime += split
machine.mem32[0x200039c8] = self._uptime * 125
return True
@ -52,6 +63,7 @@ class RTC(object):
lt = time.mktime(t)
self.offset = lt - (self._uptime >> 3)
machine.mem32[0x200039c4] = self.offset
def get_localtime(self):
self.update()