88 def __init__(self, run_fun, name="NoName", priority=0, period=None,
89 profile=False, trace=False, shares=()):
151 stime = utime.ticks_us()
158 etime = utime.ticks_us()
163 runt = utime.ticks_diff(etime, stime)
201 late = utime.ticks_diff(utime.ticks_us(), self.
_next_run)
222 if new_period
is None:
225 self.
period = int(new_period) * 1000
243 tr_str =
'Task ' + self.
name +
':'
249 total_time += item[0] / 1000000.0
250 tr_str +=
'{: 12.6f}: {: 2d} -> {:d}\n'.format (total_time,
254 tr_str +=
' not traced'
270 rst = f
"{self.name:<16s}{self.priority: 4d}"
272 rst += f
"{(self.period / 1000.0): 10.1f}"
275 rst += f
"{self._runs: 8d}"
280 rst += f
"{avg_dur: 10.3f}{(self._slowest / 1000.0): 10.3f}"
282 rst += f
"{avg_late: 10.3f}{(self._latest / 1000.0): 10.3f}"
318 new_pri = task.priority
321 if pri[0] == new_pri:
334 self.
pri_list.sort(key=
lambda pri: pri[0], reverse=
True)
368 while tries < length:
369 ran = pri[pri[1]].schedule()
380 ret_str =
'TASK PRI PERIOD RUNS AVG DUR MAX ' \
381 'DUR AVG LATE MAX LATE\n'
384 ret_str += str(task) +
'\n'
Implements multitasking with scheduling and some performance logging.
set_period(self, new_period)
This method sets the period between runs of the task to the given number of milliseconds,...
reset_profile(self)
This method resets the variables used for execution time profiling.
__repr__(self)
This method converts the task to a string for diagnostic use.
__init__(self, run_fun, name="NoName", priority=0, period=None, profile=False, trace=False, shares=())
Initialize a task object so it may be run by the scheduler.
get_trace(self)
This method returns a string containing the task's transition trace.
bool ready(self)
This method checks if the task is ready to run.
go(self)
Method to set a flag so that this task indicates that it's ready to run.
name
The name of the task, hopefully a short and descriptive string.
bool go_flag
Flag which is set true when the task is ready to be run by the scheduler.
priority
The task's priority, an integer with higher numbers meaning higher priority.
bool schedule(self)
This method is called by the scheduler; it attempts to run this task.
A list of tasks used internally by the task scheduler.
__repr__(self)
Create some diagnostic text showing the tasks in the task list.
pri_sched(self)
Run tasks according to their priorities.
list pri_list
The list of priority lists.
rr_sched(self)
Run tasks in order, ignoring the tasks' priorities.
__init__(self)
Initialize the task list.
append(self, task)
Append a task to the task list.