There some jobs in an electronic-machine system, the micro-controller need to process these in sequence, and each job will taken some time (eg: motor run to some position) jobs: A->B->C->D
Before, we use MCU like AVR, which only have one thread, we manage these jobs in a state-machine, the code pattern as follows:
void flow()
{
if (checkCondition())
{
return;
}
switch(state)
{
case A:
actionA();
state = B;
break;
case B:
actionB();
state = C;
break;
...
}
}
In this pattern, the function flow() is called in a loop, once the state changed, some waiting condition flags will be set, then these flags will be checked in the checkCondition(). Disadvantage of this pattern: when there are too many jobs, the code will be splited into pieces by the "case". Now, we plan to reconstitute the software based on STM32+RTOS, and we think the previous pattern might not be the best practice in multi-thread.
What's the best practice to manage these jobs in multi-thread system?
Aucun commentaire:
Enregistrer un commentaire