Since this forum mentions my book ("Practical Statecharts in C/C++")
and the website (
www.state-machine.com), I'd like to clarify some
misconceptions about state machines, UML, and tools.
For starters, I'd recommend reading a few articles about modern state
machines in embedded systems (see also
www.state-machine.com/resources/papers.htm).
1. The articles "Who Moved My State" (
http://www.ddj.com/cpp/
184401643) and "Back to Basics" (
http://www.ddj.com/cpp/184401737)
explain what state machines are and what kind of programming problem
they address. You learn how state machine can become very powerful
"spaghetti-code reducers" and how they are fundamentally different
from flowcharts. The article gives also some guidelines for designing
state machines and concrete C and C++ code examples (the code is
available for download at
http://www.state-machine.com/writings/cuj.htm).
2. The article "Déjà vu" (
http://www.ddj.com/cpp/184401665) introduces
the more advanced concept of hierarchical state nesting and shows how
it counteracts the "state and transition explosion" problem of
traditional non-hierarchical state machines. The source code
accompanying this article is available for download at
http://www.state-machine.com/writings/cuj.htm.
3. The article "UML at $10.99" (
http://www.ddj.com/embedded/188101799)
shows that contrary to widespread misconceptions, modern hierarchical
state machines are applicable to the tiniest, deeply embedded
microcontrollers. This article shows an tiny state machine framework
and real-time kernel running in a USB Toolstick from Silicon Labs
(8051-based C8051F300 MCU), with just 8K of flash ROM and 256 bytes or
RAM.
The bottom line is that to use state machines effectively, you first
need to make a paradigm shift from the traditional sequential
programming (such as a traditional RTOS or just a "superloop") to
event-driven programming. Event-driven programming leads to inversion
of control (a.k.a. the Hollywood Principle: "Don't call us, we'll call
you") between the application and the event-driven infrastructure.
This inversion of control, in turn, means that the event-driven
infrastructure for executing state machines naturally takes a form of
an application framework.
Which brings us to the tools based on state machines. As it turns out,
virtually all such code-generating tools have an event-driven
framework buried inside (e.g., the Rhapsody tool generates code for
either the OXF or the IDF framework). In fact, the framework is the
most important enabler of automatic code generation.
But you don't need a big tool to use an event-driven framework. You
just need the framework. For example, the QP family of very
lightweight, open source frameworks (
https://sourceforge.net/projects/
qpc/) are designed for manual coding of hierarchical state machines .
The code you need to write directly in C or C++ is actually simpler
than the state machine specification for the SMC compiler (https://
sourceforge.net/projects/smc/) mentioned in this forum. SMC is not
hierarchical.
Miro Samek
http://www.state-machine.com