Mon Jul 22 14:11:22 EDT 2013
Implementing abstract state machines in software
One of the practical challenges for implementing state machines in
software is time delays. In software, FSMs are necessarily
event-based (either poll or interrupt). I.e. computation is started
when the environment changes.
However, it is often hard to provide a strong time base. Though this
is often required in practice: many digital protocols require time
How to abstract this properly? I.e. how to write a state machine in
an abstract way such that both event routing and timing is done
in a convenient way?
It seems that a combination of two approaches would work:
- A way for a FSM to request a delay to the host
- A way for the FSM to inspect time passed (access to timer).
It doesn't seem worth the hassle to try to implement a "thread-like"
FSM api in C. This task is best left to a generator.
This all fits into a more general idea of not using interrupts and/or
threads in application development to provide a more predictable task
In this scheme, interrupts could still be used to drive simple
buffering in case DMA is not available, but use should probably only
be generalized to single producer-consumer structures.