mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 23:08:14 +00:00
loop: use ticks_add, ticks_diff
This commit is contained in:
parent
f2a0132502
commit
5889d0c932
@ -13,7 +13,7 @@ if __debug__:
|
|||||||
|
|
||||||
paused_tasks = {} # {message interface: [task]}
|
paused_tasks = {} # {message interface: [task]}
|
||||||
schedule_counter = 0
|
schedule_counter = 0
|
||||||
scheduled_tasks = [] # heap: [(time, counter, task, value)]
|
scheduled_tasks = [] # heap: [(deadline, counter, task, value)]
|
||||||
MAX_SELECT_DELAY = const(1000000)
|
MAX_SELECT_DELAY = const(1000000)
|
||||||
|
|
||||||
# message interfaces:
|
# message interfaces:
|
||||||
@ -26,11 +26,11 @@ TOUCH_MOVE = const(2) # event
|
|||||||
TOUCH_END = const(4) # event
|
TOUCH_END = const(4) # event
|
||||||
|
|
||||||
|
|
||||||
def schedule_task(task, value=None, time=None):
|
def schedule_task(task, value=None, deadline=None):
|
||||||
global schedule_counter
|
global schedule_counter
|
||||||
if time is None:
|
if deadline is None:
|
||||||
time = utime.ticks_us()
|
deadline = utime.ticks_us()
|
||||||
heappush(scheduled_tasks, (time, schedule_counter, task, value))
|
heappush(scheduled_tasks, (deadline, schedule_counter, task, value))
|
||||||
schedule_counter += 1
|
schedule_counter += 1
|
||||||
|
|
||||||
|
|
||||||
@ -94,8 +94,8 @@ def run_forever():
|
|||||||
global log_delay_pos
|
global log_delay_pos
|
||||||
while True:
|
while True:
|
||||||
if scheduled_tasks:
|
if scheduled_tasks:
|
||||||
t, _, _, _ = scheduled_tasks[0]
|
deadline = scheduled_tasks[0][0]
|
||||||
delay = t - utime.ticks_us()
|
delay = utime.ticks_diff(deadline, utime.ticks_us())
|
||||||
else:
|
else:
|
||||||
delay = MAX_SELECT_DELAY
|
delay = MAX_SELECT_DELAY
|
||||||
if __debug__:
|
if __debug__:
|
||||||
@ -118,10 +118,10 @@ class Syscall():
|
|||||||
class Sleep(Syscall):
|
class Sleep(Syscall):
|
||||||
|
|
||||||
def __init__(self, delay_us):
|
def __init__(self, delay_us):
|
||||||
self.time = delay_us + utime.ticks_us()
|
self.deadline = utime.ticks_add(utime.ticks_us(), delay_us)
|
||||||
|
|
||||||
def handle(self, task):
|
def handle(self, task):
|
||||||
schedule_task(task, self, self.time)
|
schedule_task(task, self, self.deadline)
|
||||||
|
|
||||||
|
|
||||||
class Select(Syscall):
|
class Select(Syscall):
|
||||||
|
Loading…
Reference in New Issue
Block a user