www.pudn.com > FSM_program.zip > READ.ME
State Oriented Programming
Hierarchical State Machines in C/C++
Miro Samek and Paul Y. Montgomery
The code accompanying the ESP article is organized into two
subdirectories: C and Cpp. Each subdirectory contains a Microsoft
Visual C++ v 5.0 project which may be used to build and run the
“digital watch” example discussed in the article. To compile and run
the example you should load the workspace (watch.dsw) into the Visual
C++ IDE. The Debug versions of both C and C++ projects define a
preprocessor macro HSM_INSTR and demonstrate simple instrumentation
of the state machines. For your convenience we have also included the
executable file (watch.exe), which may be executed directly. Events
may be injected into the watch state machine by typing numbers on
your keyboard: (0=MODE_EVT, 1=SET_EVT, 2=TICK_EVT).
To use the code in an embedded project you need to extract the files
hsm.h and hsm.c from the C subdirectory, or files hsm.h and hsm.cpp
from the Cpp subdirectory. The code has been compiled with a wide
variety of C and C++ compilers, including: VC++ and Borland compilers
for Windows, g++ compiler for Linux, ARM Software Development Toolkit
v. 2.0 and 2.5 C compilers, and Green Hills MULTI 2000 C and EC++
ARM/THUMB compilers. We have noticed one potential problem with one
aspect of the C++ implementation. Depending upon the compiler used,
you may encounter compilation warnings/errors in casting (upcasting)
event handlers to a Hsm member function pointer (EvtHndlr). This
upcasting is necessary to configure the state machine in the
constructor. In our code we use the cast form most commonly accepted
by different compilers:
(EvtHndlr)&::
newer C++ compilers (but not EC++ compilers) may accept construct:
reinterpret_cast(&::)
Your compiler may allow use of the simpler form:
(EvtHndlr)
since specifying class with the scope operator :: should not be
necessary inside the class method (the constructor).
Should you have any questions or comments please feel free to contact
us directly.
Sincerely,
miro@IntegriNautics.com
paulm@IntegriNautics.com