rp2040: replace sleep 'busy loop' with timer alarm

This commit is contained in:
Kenneth Bell
2022-05-11 20:39:41 +01:00
committed by Ron Evans
parent fa673f0827
commit 8f40b107d9
3 changed files with 72 additions and 0 deletions
+13
View File
@@ -12,6 +12,9 @@ import (
// machineTicks is provided by package machine.
func machineTicks() uint64
// machineLightSleep is provided by package machine.
func machineLightSleep(uint64)
type timeUnit uint64
// ticks returns the number of ticks (microseconds) elapsed since power up.
@@ -32,6 +35,16 @@ func sleepTicks(d timeUnit) {
if d == 0 {
return
}
if hasScheduler {
// With scheduler, sleepTicks may return early if an interrupt or
// event fires - so scheduler can schedule any go routines now
// eligible to run
machineLightSleep(uint64(d))
return
}
// Busy loop
sleepUntil := ticks() + d
for ticks() < sleepUntil {
}