Cooperative Tasking Framework¶
Summary¶
This module provides the cooperative multitasking framework used by the ROMI project. It defines individual task objects, stores them in a priority-sorted task list, and schedules them according to either round-robin or priority-based rules.
Important classes¶
Task(run_fun, name="NoName", priority=0, period=None, profile=False, trace=False, shares=())Represents one cooperatively scheduled task. The task code must be written as a generator that yields its current state.
TaskList()Stores all tasks grouped by priority and provides scheduling methods.
Important methods¶
Task.schedule()Runs a task if it is ready, advances the generator to the next
yield, and optionally records profiling or state-trace information.Task.ready()Determines whether a task should run. Timed tasks check their next-run timestamp, while untimed tasks rely on
go_flag.Task.go()Sets the task’s ready flag so it will run as soon as the scheduler allows.
TaskList.append(task)Adds a task to the scheduler and inserts it into the correct priority group.
TaskList.rr_sched()Runs tasks in round-robin order.
TaskList.pri_sched()Runs the highest-priority ready task, using round-robin ordering among tasks of equal priority.
Important variables¶
Task.nameShort human-readable task name used in diagnostics.
Task.priorityInteger priority; higher values run first.
Task.periodTask period in microseconds when the task is time-triggered.
Task._next_runTimestamp for the next scheduled run of a timed task.
Task.go_flagBoolean flag indicating whether the task is ready to run.
Task._runsNumber of times the task has been run.
Task._run_sum/Task._slowestProfiling data used to compute average and maximum execution time.
Task._late_sum/Task._latestTiming data used to measure scheduler lateness for timed tasks.
TaskList.pri_listInternal list of task groups sorted by priority.
Global object¶
task_listThe project-wide task scheduler created at import time. This is the object used in
main.pyto append tasks and repeatedly callpri_sched().