I've been working with mostly 8 bit MCUs, where most RTOSes are too much overhead.
Most of the applications I've worked one have just been a periodic interrupt with if/else chains for all the processing logic, and then the MCU goes back to sleep.
This has worked well for a lot of things and has a really minimal overhead. But for one system, I'm getting to the point where there are so many control flags that I'm ready to call my own system "spaghetti". It would be horrifying for someone new to pick up this system and implement some new functionality.
(I have a dual color LED, that must have like 8 different states and timing dependent blinking patterns depending on what state the rest of the system is at. It's a horrifying exercise, for what should be so simple...)
I was looking at maybe doing a finite state machine, and trying to weed out so many control flags.
One conceptual problem I am seeing is the use of timers in a state machine. Currently, I have one hardware timer and then a bunch of variable defined timers counters that increment / deincrement, a control flag variable goes to 0/1, and so we go through the if/else chain.
In my planning stage for a more strict state machine, would you just use more hardware timers and trigger the external interrupts as events to go back to the state machine?
My gut reaction (whether right or not) is using as many external interrupts as possible for the state machine is you 1)introduce all kinds of potential interrupt priority issues that bring their own set of problems, where currently the timing is very deterministic but the control logic is simply confusing and 2) you are using more current running a bunch of timers vs. just handling the timer logic as variables.
I see how you could still increment/deincrement variable timers across your state machine, but isn't that anti-ethical to the state machine pattern?
I'm pretty comfortable with the function pointers vs. switch statement debate on how you code the state machine, or if you want to use a transition table, etc.
I'm specifically wondering how folks have handled the timer management aspect of their state machines in a graceful way.