I was naively going to use a busy-wait delay for stuff under 100us
That's fine. I'd do:
var sleepTime = 0;
function utilTimerReschedule(time) { sleeptime = time; }
function handleIRQ() {
do {
handleTimer();
while (sleepTime<100us and not_going_for_too_long);
}
Do I need to handle long intervals
No - just schedule for the maximum and Espruino will just do the handler, realise nothing is needed, and do nothing.
IRAM
Wow, that sucks. Could be a pain trying to track that all down, although not as bad as if it executed JS!
setTimeout
Ahh, no - so setTimeout executes JS, but since the JS takes a while to execute I provided some utility stuff that you can use for doing pulses/etc via IRQ. Main one is digitalPulse, but also Waveform uses it for recording/playing back sound, and it's also used for analogWrite(...,{soft:true})
jshSleep
On STM32, jshSleep should put the processor to sleep for the amount of time given, so that it wakes either after that time or when there's an IRQ from Serial, GPIO, Utility Timer, SysTick, etc. If setDeepSleep is 1 and there's nothing in the utility timer then it'll go into proper low power sleep.
If it's given 0xFFF..FFF then that means it should only wake up if there's an IRQ - not after a time period.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
That's fine. I'd do:
No - just schedule for the maximum and Espruino will just do the handler, realise nothing is needed, and do nothing.
Wow, that sucks. Could be a pain trying to track that all down, although not as bad as if it executed JS!
Ahh, no - so setTimeout executes JS, but since the JS takes a while to execute I provided some utility stuff that you can use for doing pulses/etc via IRQ. Main one is
digitalPulse
, but alsoWaveform
uses it for recording/playing back sound, and it's also used foranalogWrite(...,{soft:true})
On STM32, jshSleep should put the processor to sleep for the amount of time given, so that it wakes either after that time or when there's an IRQ from Serial, GPIO, Utility Timer, SysTick, etc. If setDeepSleep is 1 and there's nothing in the utility timer then it'll go into proper low power sleep.
If it's given 0xFFF..FFF then that means it should only wake up if there's an IRQ - not after a time period.