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>
This commit is contained in:
parent
4ad8273902
commit
fb18705b9b
2 changed files with 6 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -430,6 +430,7 @@ class Manager():
|
|||
|
||||
watch.touch.reset_touch_data()
|
||||
|
||||
@micropython.native
|
||||
def _tick(self):
|
||||
"""Handle the system tick.
|
||||
|
||||
|
|
Loading…
Reference in a new issue