Let's say I have a finite-state-machine which looks like this:
while(1){
swtich(case){
case ONE:
do_thingone();
if(parameter1 == 0)
case = TWO;
break;
case TWO:
do_thingtwo();
do_thingthree();
if(parameter1 == 1)
case = ONE;
if(parameter0 == 0)
case = THREE;
break;
//and so on
}
}
With a boolean paramter p_master I want to change between two finite-state-machines with similar, yet different content.
while(1){
switch(state){
state STATE_0:
switch(case){
case ONE:
do_onething();
if(parameter1 == 0)
case = TWO;
break;
//case TWO:
}
break;
case STATE_1:
switch(case){
case ONE:
do_anotherthing();
if(parameter1 == 0)
case = TWO;
break;
//case TWO:
}
break;
}
}
I don't want to check and switch case via an
if(p_master == 0)
or vice versa every iteration, as I think this will create too much overhead (p_master only changes every 100th or 1000th iteration, it even is perfectly ok for it to never change at all!). Is there a more elegant way to change between a case and another than conditions ins the finite-state-machine loop?
Note: p_master can be triggered as an interrupt at CPU level!