mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 02:27:48 +00:00
runtime: fix sleep duration for long sleeps
Long sleep durations weren't implemented correctly, by simply casting to a smaller number of bits. What we want is a saturating downcast, which is what I've used here instead. This should fix https://github.com/tinygo-org/tinygo/issues/3356.
This commit is contained in:
committed by
Ron Evans
parent
faf455283d
commit
8872d5ebfc
@@ -43,8 +43,8 @@ func TestBinarySize(t *testing.T) {
|
||||
tests := []sizeTest{
|
||||
// microcontrollers
|
||||
{"hifive1b", "examples/echo", 3884, 280, 0, 2268},
|
||||
{"microbit", "examples/serial", 2852, 360, 8, 2272},
|
||||
{"wioterminal", "examples/pininterrupt", 7337, 1491, 116, 6912},
|
||||
{"microbit", "examples/serial", 2844, 360, 8, 2272},
|
||||
{"wioterminal", "examples/pininterrupt", 7349, 1491, 116, 6912},
|
||||
|
||||
// TODO: also check wasm. Right now this is difficult, because
|
||||
// wasm binaries are run through wasm-opt and therefore the
|
||||
|
||||
@@ -273,6 +273,9 @@ func nanosecondsToTicks(ns int64) timeUnit {
|
||||
func sleepTicks(d timeUnit) {
|
||||
for d != 0 {
|
||||
ticks := uint32(d)
|
||||
if d > 0xffff_ffff {
|
||||
ticks = 0xffff_ffff
|
||||
}
|
||||
if !timerSleep(ticks) {
|
||||
// Bail out early to handle a non-time interrupt.
|
||||
return
|
||||
|
||||
@@ -266,6 +266,9 @@ func nanosecondsToTicks(ns int64) timeUnit {
|
||||
func sleepTicks(d timeUnit) {
|
||||
for d != 0 {
|
||||
ticks := uint32(d)
|
||||
if d > 0xffff_ffff {
|
||||
ticks = 0xffff_ffff
|
||||
}
|
||||
if !timerSleep(ticks) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -78,6 +78,9 @@ func buffered() int {
|
||||
func sleepTicks(d timeUnit) {
|
||||
for d != 0 {
|
||||
ticks := uint32(d) & 0x7fffff // 23 bits (to be on the safe side)
|
||||
if d > 0x7fffff {
|
||||
ticks = 0x7fffff
|
||||
}
|
||||
rtc_sleep(ticks)
|
||||
d -= timeUnit(ticks)
|
||||
}
|
||||
|
||||
@@ -81,6 +81,9 @@ func buffered() int {
|
||||
func sleepTicks(d timeUnit) {
|
||||
for d != 0 {
|
||||
ticks := uint32(d) & 0x7fffff // 23 bits (to be on the safe side)
|
||||
if d > 0x7fffff {
|
||||
ticks = 0x7fffff
|
||||
}
|
||||
rtc_sleep(ticks)
|
||||
d -= timeUnit(ticks)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user