Severson-Group / AMDC-Firmware

Embedded system code (C and Verilog) which runs the AMDC Hardware
http://docs.amdc.dev/firmware
BSD 3-Clause "New" or "Revised" License
30 stars 5 forks source link

Unneeded jitter on control tasks due to scheduler task execution ordering #272

Closed npetersen2 closed 2 years ago

npetersen2 commented 2 years ago

The AMDC v1 firmware uses a cooperative scheduling approach, meaning all system tasks run in the same time slice at the same priority. The relative ordering is determined by the order the tasks are registered with the scheduler--the first registered is always run first in each time slice.

This is ok, but causes extra jitter for tasks which are NOT the first one, since they must wait for the other tasks to run before they run.

This becomes problematic for controller tasks which rely on precise timing for proper control. When commands are ran from the CLI, the execution of the command handler takes some time, which causes jitter in the control task.

This could be easily avoided if the control task was the first task in the queue to run each time slice.

TODO

Fix this by adding a new scheduler task register function called scheduler_tcb_register_high_priority(task_control_block_t *tcb)

The original non-high-priority code puts the new task at the END of the linked list, while this new high-priority register function will place the new task at the HEAD of the linked list, thus it runs first.