I'm starting to work on a simple non-preemptive task scheduler, written in C, to run on an MSP430 microcontroller. Its strictly for learning purposes. I'm trying to work out an issue and thought maybe someone here can point me in the right direction.
This will be a very simple task scheduler. At the heart is an array of structures with each structure representing a task. Each structure has three elements.
(1) Function pointer that points to the task
(2) Integer to hold the period (how often to run the task)
(3) Integer to hold the elapsed time (how long since the task was run last)
I'm stuck at how to define the function pointer. Each function to be scheduled might have a different set of parameters and return value. But the structure has to have a specific type of function pointer in its definition. Let me write out the definition of the structure to clarify ...
typedef struct TaskList
{
void (*prt_task)(void);
int period;
int elapsed_time;
} TaskList;
My function pointer is for a function with no parameters and no return value. How can I handle a more general case where the function may have any return value or parameters?
If it helps to explain the rest of the scheduler, here it is ...
Basically its nothing more than a global array of structures as explained above. Each structure represents a task by pointing to the task, and telling us how often to run the task, and how long since it was run last. Time is of course measured in timer ticks.
Tasks are scheduled by adding them to the array.
The ISR for the timer is called periodically (when the timer reaches a defined count). The ISR goes through each structure in the array, in a loop, looking for tasks with elapsed_time = period. Those with elapsed_time = period are run, and the elapsed time is incremented for the rest.
This will be a very simple task scheduler. At the heart is an array of structures with each structure representing a task. Each structure has three elements.
(1) Function pointer that points to the task
(2) Integer to hold the period (how often to run the task)
(3) Integer to hold the elapsed time (how long since the task was run last)
I'm stuck at how to define the function pointer. Each function to be scheduled might have a different set of parameters and return value. But the structure has to have a specific type of function pointer in its definition. Let me write out the definition of the structure to clarify ...
typedef struct TaskList
{
void (*prt_task)(void);
int period;
int elapsed_time;
} TaskList;
My function pointer is for a function with no parameters and no return value. How can I handle a more general case where the function may have any return value or parameters?
If it helps to explain the rest of the scheduler, here it is ...
Basically its nothing more than a global array of structures as explained above. Each structure represents a task by pointing to the task, and telling us how often to run the task, and how long since it was run last. Time is of course measured in timer ticks.
Tasks are scheduled by adding them to the array.
The ISR for the timer is called periodically (when the timer reaches a defined count). The ISR goes through each structure in the array, in a loop, looking for tasks with elapsed_time = period. Those with elapsed_time = period are run, and the elapsed time is incremented for the rest.
Last edited: