-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use weak symbols for time keeping so that they can get easily overridden for implementation of sleep #558
Comments
There is more of architectural decision here, basically implementation of HAL must be and is paltform dependent, its API must be universal. It should be provided so, that choosing a platform in the library chooses the appropriate HAL implementation. What you are suggesting is, basically, one of the ways to implement separation between library generic HAL API, default implementation and platform dependency. weak functions look good for the platform/project dependent callbacks and in your particular example only hal_ticks() should be __weak with other timing functions left intact. As for the low power, several things must be considered and provisioned in the library.
For the purpose of the examples and providing self-contained solution, this should be done to
|
We can discuss the logic and implementation by e-mail, if you want. I will be implementing something like this for our company project, where LMIC is just a part of a much bigger picture, anyway. You can get in touch with me at [email protected], |
The primary purpose of this PR is to fix #524, allowing the LMIC to run without disabling interrupts at all, and without requiring any changes to underlying BSPs. When configured for interrupts, interrupts simply cause the current time stamp to be captured. The secondary ISR is run as part of os_runloop_once(). This should also fix #503, and address #528, #558, #548, and others. In addition, since we're updating the radio driver, I addressed #524. In testing, I discovered a subtle bug with one of our applications that uses LMIC_sendAlive() -- there was a path when sending piggybacked MAC data with a poll that would result in trying to take the port 0 path instead. This caused problems with ChirpStack and TTN, at least. (This is #570.) Finally, updated to use Arduino IDE 1.8.12 in test. Version of library changes to v3.1.0.20.
The basic architectural problem is that the design of the IBM LMIC is just wrong in this area; on an Arduino (or most other systems) you can't sleep from inside a device driver. You have to post a sleep request that is handled (as it were) in the |
I assume this means 'querying from within loop()'? |
Not really. This means indicating from within the loop() that the library is fine if outer logic will decide to go to sleep. For this to happen you shouldn't use os_runloop() which becomes the main loop of the system. Your main loop should call os_runloop_once() periodically instead.
This is where hal_sleep() is called in os_runloop_once(). You can change the implementation of hal_sleep() to posting such indication. As for the best practices, some libraries I know of, keep a global bitmask, where every driver module can set its own bit to 1 to indicate that it is busy and reset it to 0 to indicate that it is ok to go to sleep. The outer main loop considers this bitmap at the end of each run and, if it is all zeros, executes sleep+wait-for-event/wait-for-interrupt processor instruction. Like this:
|
Suggest add WEAK to hal.cpp |
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:
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...
The text was updated successfully, but these errors were encountered: