Where finite-state machine code belong in µC?
I am working in automotive industry.

You often see such endless loops in situations where the CPU should reset - just like this:

if(some_error_occurred)
{
    while(1);
}


Car electronics have a so-called watchdog. The CPU must send a signal to the watchdog every few millieseconds. Otherwise the watchdog will reset the CPU.

Because the CPU is stuck in the endless loop in the example above the signal is no longer sent and the CPU is reset.

However normally 99% of all CPUs in automotive industry do not have a "regular" end. This means the whole code of the CPU could be written the following way:

initialize_cpu();
perform_initial_actions();
while(1)
{
    perform_cyclic_actions_endlessly();
}


Because there is no "end" of the program a while loop at the "end" of the program cannot exist.