mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-08 21:13:39 +00:00
rp2040: replace sleep 'busy loop' with timer alarm
This commit is contained in:
@@ -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 {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user