I don't think it matters much.
The reason for the state machines, is to spead the execution over time. Say you have a code:
void task() {
do_a;
while(c) {
do_b;
}
do_c;
}
The problem is that you need to run many different tasks at the same time and sequential execution will not work well. Thus, you create processing functions for each of your tasks. Each processing function advances the corresponding task by a little then yields the execution so other tasks could work too. You then create a super loop which moves through all the tasks and gives opportunity to each. In the simplest way:
while() {
process_task_one();
process_task_two();
process_task_thee();
}
Now, we have to crump our sequencial execution piece by piece into the single function which will be called repeatedly. There's number of ways to do it, which are called state machines, while, in fact, they're not FSMs. The most common way:
void process_task_one() {
switch (state) {
case STATE_IDLE:
break;
case STATE_START:
do_a();
state = STATE_LOOP;
break;
case STATE_LOOP:
if (c) {
do_b();
} else {
state = STATE_STOP;
}
break;
case STATE_STOP:
do_c();
state = STATE_IDLE;
return;
}
}
Now setting the state to STATE_START will execute the sequence, so you start your task as:
int start_task_one() {
if (state != STATE_IDLE) return 0; // already running
state = STATE_START;
return 1;
}
But you can do it in a multitude of other ways as well. For example, you can represent the state by a function pointer:
void (*process_task_one)();
void process_start() {
do_a();
process_task_one = &process_loop;
}
void process_loop() {
if (c) {
do_b();
} else {
process_task_one = &process_stop;
}
}
void process_stop() {
do_c();
process_task_one = &process_idle;
}
void process_idle() {
}
Whether you have a formal entry/exit code, or how you set your states is completely immaterial. The relationship with theoretical FSMs is not of foremost importance neither. The only requirement is that the processing is fast enough and it does the same as the corresponding sequential code would do. These are the two aspects you need to concentrate on.