Add PNVRAM support to avoid forgetting the time during a reboot.
This commit is contained in:
parent
b0dec58769
commit
c1f8823f61
4 changed files with 17 additions and 5 deletions
2
TODO.md
2
TODO.md
|
@ -47,7 +47,7 @@ applications.
|
||||||
### Bootloader
|
### Bootloader
|
||||||
|
|
||||||
* [X] OTA bootloader update
|
* [X] OTA bootloader update
|
||||||
* [ ] RTC time measurement whilst in bootloader
|
* [X] RTC time measurement whilst in bootloader
|
||||||
|
|
||||||
### MicroPython
|
### MicroPython
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 7786926950902cf4ce49a93894f69a205d6fd325
|
Subproject commit d8d7d76b17e188420f66705f0b319f6e80a328f2
|
|
@ -1 +1 @@
|
||||||
Subproject commit 5424de70d7cfb1d53828b54cd1df509c3f0fee74
|
Subproject commit 8ea321106823866adcb6c4881b4045939b56cc3a
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
""" Real Time Clock based on the nRF-family low power counter """
|
""" Real Time Clock based on the nRF-family low power counter """
|
||||||
|
|
||||||
|
import machine
|
||||||
import time
|
import time
|
||||||
|
|
||||||
#class Stim(object):
|
#class Stim(object):
|
||||||
|
@ -20,6 +21,15 @@ class RTC(object):
|
||||||
|
|
||||||
def __init__(self, counter):
|
def __init__(self, counter):
|
||||||
self.counter = counter
|
self.counter = counter
|
||||||
|
|
||||||
|
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._uptime = 0
|
||||||
self.set_localtime((2020, 3, 1, 3, 0, 0, 0, 0))
|
self.set_localtime((2020, 3, 1, 3, 0, 0, 0, 0))
|
||||||
|
|
||||||
|
@ -34,6 +44,7 @@ class RTC(object):
|
||||||
self.lastcount += split
|
self.lastcount += split
|
||||||
self.lastcount &= (1 << 24) - 1
|
self.lastcount &= (1 << 24) - 1
|
||||||
self._uptime += split
|
self._uptime += split
|
||||||
|
machine.mem32[0x200039c8] = self._uptime * 125
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -52,6 +63,7 @@ class RTC(object):
|
||||||
|
|
||||||
lt = time.mktime(t)
|
lt = time.mktime(t)
|
||||||
self.offset = lt - (self._uptime >> 3)
|
self.offset = lt - (self._uptime >> 3)
|
||||||
|
machine.mem32[0x200039c4] = self.offset
|
||||||
|
|
||||||
def get_localtime(self):
|
def get_localtime(self):
|
||||||
self.update()
|
self.update()
|
||||||
|
|
Loading…
Reference in a new issue