Summary: In this lab you will write your own task scheduler for the MSP430.
Write a simple scheduler in C for a microcontroller. The scheduler should be cooperative and event driven. When the scheduler is executes, it should hand over processor control by calling the primary function of the process which:
This behavior may result in lower priority processes never receiving attention from the processor. It is up to the programmer of the individual processes to ensure that the process returns to the scheduler in a timely matter.
The scheduler should maintain a list of all processes, in order of priority. For each process, the following information should be kept:
The scheduler should support the following functions to facilitate scheduling. The processes the scheduler managed can be known and created at compile time. Extra credit will be provided for implementing the functions that allow for dynamic process creation [hint: this requires the use of function pointers]. While the processes are known at compile time, the creation and use of semaphores and the setting of priorities should be possible at runtime.
Most of the functions are related to setting up the relationship between processes (priorities, semaphores, etc). None of these methods should be called from inside an interrupt because the interaction of interrupts with the scheduler data structure cannot be guaranteed. More advanced discussions of operating systems will explain atomic instructions and how they handle this impasse.
unsigned int create_new_process(void (*f)(void), unsigned int priority) [fact check how to pass function names as pointers]
parameters:
#define may be useful for making these process_ids human readable. One process_id should be reserved as an error code if something goes wrong. For example 0x0000 might be returned if the maximum number of processes has already been reached.unsigned intcreate_binary_semaphore(unsigned int process, unsigned int state)
parameters:
void set_semaphore(unsigned int process, unsigned int semaphore, unsigned int state)
parameters:
void set_priority(unsigned int process, unsigned int new_priority)
parameters:
void schedule(void)
The main() function calls schedule once the system has been set up. Schedule then handles all further negotiation of the processes. More advanced schedulers will actually adjust the stack pointer and the context data of each function call to allow seemless transition between processes. This process requires writing part of the scheduler in assembly to avoid the automatic adjustments C will make on its own. In this case, you need only call each function normally from inside schedule().
"A how-to document for writing a process scheduler for a microcontroller in C."