Skip to content

Commit 4bf995c

Browse files
committed
more waitus cleanups
1 parent 843f1a2 commit 4bf995c

2 files changed

Lines changed: 986 additions & 969 deletions

File tree

sys/common.spin

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,21 +285,26 @@ pri _waitms(m=long) | freq, c
285285
m := _muldiv64(m, freq, 1000)
286286
waitcnt(m + c)
287287

288-
'' pause for m microseconds
289-
pri _waitus(m=long) | freq, c, offset
288+
'' approximate a * q / 1000000
289+
'' we know 0 < a < 1000000
290+
'' and 0 < q < 352000000 is the clock frequency
291+
'' a good approximation of x / 1000000
292+
'' is (x>>20) + (x>>25) + (x>>26)
293+
'' or (x>>20) + (x>>24) - (x>>27)
294+
295+
pri _waitus(m=long) | freq, c, c2, offset
290296
c := _getcnt
291297
freq := __clkfreq_var
292298
repeat while m => 1000000
293299
waitcnt(c += freq)
294300
m -= 1000000
295301
if m > 0
296-
m := _muldiv64(m, freq, 1000000)
297-
if (__propeller__ == 1)
298-
' watch out for wrapping around
299-
if m > 20000
300-
waitcnt( c + m )
301-
else
302-
waitcnt( c + m )
302+
freq := (freq>>20) + (freq>>24) - (freq>>27)
303+
m *= freq
304+
c += m
305+
c2 := _getcnt + 80
306+
if c > c2
307+
waitcnt( c )
303308

304309

305310
' check to see if cnt > x

0 commit comments

Comments
 (0)