Skip to content

Use weak symbols for time keeping so that they can get easily overridden for implementation of sleep #558

@msperl

Description

@msperl

Is your feature request related to a problem? Please describe.
Powerconsumption is quite high and to get dow some sort of sleep mode is needed (say using RTC 32 bit counters on SAMD21)
Unfortunately the only solution seems to be modifying the library itself to make this work.

So a cleaner solution would be adding weak symbols, so that a sketch can override some of the functionality if necessary

Describe the solution you'd like
Essentially it could look something as "simple" as this:

--- src/hal/hal.cpp.orig	2020-04-05 10:30:48.000000000 +0200
+++ src/hal/hal.cpp	2020-04-05 10:34:31.000000000 +0200
@@ -197,6 +197,7 @@
     // Nothing to do
 }

+u4_t hal_ticks () __attribute__((weak));
 u4_t hal_ticks () {
     // Because micros() is scaled down in this function, micros() will
     // overflow before the tick timer should, causing the tick timer to
@@ -257,6 +258,7 @@
 # define HAL_WAITUNTIL_DOWNCOUNT_THRESH ms2osticks(9) // but try to leave a little slack for final timing.
 #endif

+u4_t hal_waitUntil (u4_t time) __attribute__((weak));
 u4_t hal_waitUntil (u4_t time) {
     s4_t delta = delta_time(time);
     // check for already too late.
@@ -335,6 +337,7 @@
     return irqlevel;
 }

+void hal_sleep () __attribute__((weak));
 void hal_sleep () {
     // Not implemented
 }

For some other functions it may also be handy to get the "weak treatment".
I guess others may come up with other requests...

Describe alternatives you've considered
As said: modifying the library itself, but that is not really maintainable...

Other Ideas based on this
Providing a weak "default" implementation of onEvent with weak per event methods (e.g. onEvent_txcomplete, onEvent_joined, onEvent_rxcomplete) inside the library would then also be an option.
This would reduce the amount of code that needs to get written in each sketch.
But that is probably something for a separate feature request...

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions