Optimal State Machine Implementation in C

Employment-education

This new video lesson about state machines explains the "optimal" state machine implementation in C.

You will start with designing a simple "domain specific language" (DSL) for specifying state machines and then you will turn it into a C program. You will then generalize the implementation into a reusable "event processor" to include this optimal state machine implementation strategy directly in the Micro-C-AO active object framework that you've been building in this segment of lessons.

This lesson includes quite a bit of coding with the intent to give you some "pair programming" experience as you witness gradual transformation of the design into C.

Also, you will see and compare other state machine DSL based on the SMC (State Machine Compiler).

Finally, you will see a technique of measuring code execution speed on ARM Cortex-M CPUs by means of the Cycle Counter register in the DWT (Data Watchpoint and Trace) hardware block.

This lesson comes with two project downloads (see https://www.state-machine.com/video-course/#Videos ):

- the "optimal" implementation of the TimeBomb state machine and the updated uC/AO active object framework.

- the implementation of the TimeBomb state machine based on the SMC (State Machine Compiler)

Posted Jul 27, 2021, 8:24 PM UTC

354
Forty-Bot•

the optimal state machine uses the PC :)

4
R3spectedScholar•

What do you think about the ROOM language? Is it widely used? (Haven't watched the video as I'm on mobile, so apologies if it's already in the video.)

2
active-objectOP•

ROOM (Real-Time Object-Oriented Modeling) was ahead of its time. It consists of mainly two components: "ROOM-actors" and "ROOM-charts".

Some variations of these two components do show up in various designs, but they are more re-inventions and adaptations rather than the original ROOM. For example, many elements of "ROOM-charts" have been adapted into UML state-machines.

Overall I can't say that ROOM is widely used in embedded systems. But there are real gems in ROOM that are applicable and very beneficial in deeply embedded systems. These useful ideas are:

  • actors (a.k.a. active objects) as opposed to "naked threads", with strict encapsulation and no sharing of resources
  • asynchronous, event-driven communication among these active objects; and
  • hierarchical state machines to handle events inside the active objects.

The video "Optimal State Machine Implementation in C" shows only traditional, non-hierarchical state machines with entry/exit actions. But the implementation technique is generalizable to hierarchical state machines. This will be presented in the upcoming videos in the series.

1
AutoModeratorMOD•

To respect Reddit's Self-Promotion rules, AutoModerator will submit your content for you in a little bit. Thank you for your patience.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

0