3 ms·
Personally I no longer use pure state machines, as they can become beasts and end up being a royal pain to maintain. Instead, I use 'duff devices' variations o
by buserror 9y ago
Personally I no longer use pure state machines, as they can become beasts and end up being a royal pain to maintain.
Instead, I use 'duff devices' variations of it (in C) which breaks down the machine into code that looks 'linear' enough, but is in fact, a state machine without the drawbacks.
I've implemented quite a few protocol stacks using that 'trick' and it's still very nice to read/maintain -- the good thing is that it roughtly looks like a coroutine/thread, without any runtime requirements, so will work just fine on embedded systems as well. Same as coroutine/state machines, don't make your 'states' too 'long' or CPU intensive, you'll have the same consequences.
There's an implementation floating around called 'protothreads' [0], but you can really do pretty much the same with a handful of macros.
[0]: http://dunkels.com/adam/pt/ http://dunkels.com/adam/pt/