I am in the final stages of development of a simple embedded system. The device performs PID coefficient estimation and then instantiates a PID controller with the estimated coefficients.
The architecture of the program is cooperative multitasking. The file main.c defines a series of void task_...(void)
functions and calls them one after the other upon each timer tick.
I would like to perform the operation void task_pid_tune(void)
for as long as it takes. Then, I want to perform the operation pid_configure(coefficients)
once. From then on, I want to perform the operation pid_run()
instead of the previous two.
Currently all 4 tasks (pid_tune()
is not implemented yet) run in an extremely simple way
while( wait_for_timer_tick() )
{
task1();
task2();
task3();
task4();
}
I would prefer to keep it that way, instead of writing logic inside this function. I am writing in C99
. I am fine with static and global variables, as well as public getters.
Please advise how shall I implement communication between void task_pid_tune(void)
and void task_pid_run(void)
. Please keep in mind that the latter will be called much more often than the former, hence performance is important in that case.
Clarification.
No task is allowed to be blocking. In other words, all scheduled tasks must return before the next timer tick.
Consequently, the required execution order is:
task1();
task2();
task3();
task4();
task_pid_tune();
// this loops until pid tuning is ready
// that is, pid_tune() samples some signal once per system tick
// and at some point, it gets happy and provides estimated pid coefficients
task1();
task2();
task3();
task4();
task_pid_configure(); // this runs only one
task1();
task2();
task3();
task4();
task_pid_run();
// This loops forever.
void task_pid_tune(void)
is a blocking call, can't you just wait until it returns, then callpid_configure(coefficients)
, wait until it returns, and then drop into your loop?