Hey there!
Today we shall discuss about the scheduler, in this case its for AVR.
During this summer vacation I was working on a project which needed multitasking to serve UI program. So I had to design a preemptive multitasking scheduler. If you ask why preemptive, I chose preemptive because there were tasks which would never terminate (infinite loop functions).
I assume you know what multitasking is, now lets see what is scheduler and how it works...
Scheduler:
It is a program that schedules the execution of the tasks. When there are at least 3 or more tasks and there is a need for multitasking a scheduler needs to be implemented. It is usually written as ISR.
Consider 3 tasks T1, T2, T3 namely. Assuming all tasks are of equal priority, initially the scheduler allows mcu to execute T1, after a certain or specified amount of time is elapsed the timer interrupts the execution and switches over to the ISR, before the scheduler takes over the context is saved to the specified location in the stack of RAM. Now the scheduler updates the program counter of mcu with the memory location of T2 and the task T2 gets executed and same goes for T3. As the context is being saved in stack, when all tasks are executed at least one time the scheduler sets the status of task to 'running'. Now to execute T1 again the stack pointer of mcu is updated with the location of context of T1 in the stack, then context restore routine runs. When T1 runs again the T1 assumes that it is not interrupted as the registers are updated with the same values as before and T1 runs.
The above example is also called as round-robin method of task execution.
I have provided link below to view the partial code of scheduler I have written.
Here is the video in which the blinking of there LED's are different tasks.
Comments
Post a Comment