summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2021-06-04 09:49:33 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2021-06-04 09:49:33 (GMT)
commitfb18705b9b9cc10e15e56cea6697839f3779bdb6 (patch)
tree69be09af7327e72bb07c87e76e3859ccec1dae90
parent4ad827390227249ba69f1ae60671b20531fdd9e1 (diff)
manager/rtc: Experimental power saving technique
Currently the time is calculated 8 times per second from (relatively) slow python code. Optimize the power consumed by reducing the number of times we check for wall time updates to only once-per-second and use native code generation to reduce VM overhead when executing this critical code. At the time of writing the difference is battery life has not yet been measured (but we know the current master branch is worse than v0.4 and, in theory at least, this should close the gap). Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
-rw-r--r--wasp/drivers/nrf_rtc.py6
-rw-r--r--wasp/wasp.py1
2 files changed, 6 insertions, 1 deletions
diff --git a/wasp/drivers/nrf_rtc.py b/wasp/drivers/nrf_rtc.py
index 100bacd..e68b957 100644
--- a/wasp/drivers/nrf_rtc.py
+++ b/wasp/drivers/nrf_rtc.py
@@ -45,6 +45,7 @@ class RTC(object):
self._uptime = 0
self.set_localtime((2020, 3, 1, 3, 0, 0, 0, 0))
+ @micropython.native
def update(self):
"""Check for counter updates.
@@ -59,10 +60,12 @@ class RTC(object):
self.lastcount += split
self.lastcount &= (1 << 24) - 1
+ uptime = self._uptime
self._uptime += split
machine.mem32[0x200039c8] = self._uptime * 125
- return True
+ # Has the seconds count changed
+ return bool((self._uptime ^ uptime) & 0x08)
def set_localtime(self, t):
"""Set the current wall time.
@@ -103,6 +106,7 @@ class RTC(object):
localtime = self.get_localtime()
return localtime[3:6]
+ @micropython.native
def time(self):
"""Get time in the same format as time.time"""
return self.offset + (self._uptime >> 3)
diff --git a/wasp/wasp.py b/wasp/wasp.py
index 6c3e4ef..eaf3737 100644
--- a/wasp/wasp.py
+++ b/wasp/wasp.py
@@ -430,6 +430,7 @@ class Manager():
watch.touch.reset_touch_data()
+ @micropython.native
def _tick(self):
"""Handle the system tick.