Skip to content
0:00 / 0:00

#hierarchicalstatemachine#statecharts#qp/c

#40 State Machines Part-6: What is a Hierarchical State Machine?

Quantum Leaps, LLC

74K subscribers • 20 videos on Hallway

YouTube
  • Recommended by 2 people: 2 in engineering communities.
  • A classic. People kept recommending it from 2021 to 2025.
  • Linked in the descriptionQuantumLeaps/modern-embedded-programming-course
  • Made by the vendor. The company whose product it covers made or sponsored it.

Intermediate. Assumes working knowledge.

29K views5 years ago2 recommendations

Systems programmingSoftware designDesign patternsSoftware architectureEmbedded systems

An introduction to hierarchical state machines, how they differ from finite state machines, and how to implement them in C.

This lesson continues the subject of STATE MACHINES. Today you will get the first glimpse of the modern hierarchical state machines. You will learn what hierarchical state machines are and how they differ from the traditional finite state machines. You will also get an idea of how to implement state hierarchy in C and you'll see which aspects are easy and which are harder to implement. Finally, you'll port your TimeBomb application from the toy Micro-C-AO framework to the professional QP/C framework, where hierarchical state machines are fully supported. This lesson comes with two projects: - the partial implementation of state hierarchy with the uC/AO active object framework. - the full implementation of state hierarchy with the QP/C active object framework. ------- Resources: Companion web page for this video course: state-machine.com/quickstart GitHub repository for projects for this video course: github.com/QuantumLeaps/modern-embedded-programming-course Transcript of this lesson: state-machine.com/course/lesson40.txt Music credits: The background music comes from: bensound.com/royalty-free-music/track/straight

Why it's here

2 people recommend this

What people say. Recommended as part of a comprehensive playlist explaining state machine implementations and hierarchical state charts for embedded systems.

u/active-objectin r/embedded • Recommends

On “Do you use HSM (Hierarcical State Machines)?”

Yes, I've been using and advocating HSMs for the past 20 years. I've found them to be very useful in even the smallest embedded MCUs (e.g., see my article "UML Statecharts at $10.99") Regarding the overhead of ENTRY, EXIT, INIT, etc. it can be small, but you need the right HSM implementation in C or C++. (The boost::sml suggested in the other comment is NOT the right implementation for deeply embedded systems, like ARM Cortex-M MCUs). Here, I would recommend my YouTube video "Optimal State Machine Implementation in C". While you are at it, you might want to also watch the following YouTube videos about Hierarchical State Machines: * What is a Hierarchical State Machine? * [Automatic Co…

u/active-objectin r/embedded • Recommends

On “What is your way to go for state machines in C++?”

All these questions about state machine implementations, specifically for embedded systems are covered in the "State Machines" playlist on YouTube. Among others, you'll find there an overview of implementation techniques, from nested-switch statements, state-tables, and state-machine DSLs with "state machine compilers", to implementations based on function pointers and classes. You will also see a discussion of modern hierarchical state machines, their precise semantics, and their implementation. Speaking of which, for implementing state machines in C++ I would recommend the technique where you *inherit* a state machine base class (as opposed to containing a state machine). That way,…

u/toptylerin r/embedded • Recommends

On “How do I design an HSM”

Here's a link to the YouTube series: [video Edit: also: QM = Quantum Platform Modeler (nothing to do with quantum mechanics, just the name of a tool to help with state machine creation and code generation), HSM = Hierarchical state machine, DRY = "don't repeat yourself" (a general programming principle which suggests that reducing code duplication should be preferred)

u/active-objectin r/embedded • Recommends

On “Is preemptive RTOS costing you too much?”

I'm not sure if you appreciate what's on offer here. I repeat, QK provides preemptive, priority-based scheduling compatible with RMS/RMA, just as "useful" as most other traditional RTOS kernels. Except, QK provides it at a fraction of the cost of RAM and CPU. The non-blocking limitation is irrelevant for event-driven tasks, which can be quite sophisticated. In fact, QK is part of the larger Active Object framework (called QP), which utilizes Hierarchical State Machines for the tasks. In many ways, this approach is more powerful and useful than the traditional blocking RTOS. Concurrency experts often apply the non-blocking event-driven paradigm by drastically limiting blocking in their tas…

u/active-objectin r/embedded • Recommends

On “Handling non state events in State machine based architecture”

The most likely type of state machine used in superloop is the "input-driven state machine" \-- which is a state machine where each state starts with an IF-statement (a.k.a. guard condition). The "input-driven state machines" (a.k.a. polled state machines) are generally difficult to turn into Hierarchical State Machines because there are no events to propagate to the higher-level states. In "event-driven" programming, the biggest simplification comes from improving the quality of the generated events. In your case, the DMA-complete event is still very low quality. I would try to handle such an "event" in an ISR (e.g., re-start the DMA with a new buffer). Instead, the ISR could prod…

u/active-objectin r/embedded • Recommends

On “Generic HSM implementation in C”

Hierarchical state machine videos: \- What is a Hierarchical State Machine? \- Semantics of Hierarchical State Machines

u/active-objectin r/embedded • Recommends

On “State Machines in embedded?”

Here is the YouTube playlist that explains state machines in the context of embedded systems: * State Machines Part-1: What is a state machine? * State Machines Part-2: Guard conditions * State Machines Part-3: Input-Driven State Machines * State Machines Part-4: State Tables and Entry/Exit Actions * State Machines Part-5: Optimal Implementation in C * State Machines Part-6: What is a Hierarchical State Machine? * State Machines Part-7:Automatic Code Generation * State Machines Part-8: Semantics of Hierarchical State Machines

u/active-objectin r/embedded • Recommends

#40 State Machines Part-6: What is a Hierarchical State Machine?

u/active-objectin r/embedded • Mentions

On “Starting a journey in Embedded systems.”

The course has currently 48 lessons, out of which maybe 4-5 use the QP framework to illustrate fundamental concepts that are simply hard to find anywhere else. You might call it "focused on QP", but it is less than 10% of the lessons. By this definition, you might also label this course as focused on MicroC/OS-2 because this RTOS is also used in a couple of lessons (see the "uC/AO" active object framework in lessons 34, 35, and 36). Or, you can call it focused on FreeRTOS because of the "FreeAct" framework. The problem is that this is supposed to be "Modern Embedded Systems Programming", which means certain concepts. For example, where else could you find truly functional hierarchical st…

u/active-objectin r/embedded • Mentions

On “New video: What is a Hierarchical State Machine?”

I thought that the video link was provided by YouTube (I clicked their link "share on Reddit"). But here it is again: [video Thanks a lot for your help, \--Miro

u/Fiebboin r/embedded • Mentions

On “Which books would you recommend to a embedded engineer to increase his expertise in the field?”

Take a look at Miro Samek's outstanding Modern Embedded Systems Programming Course. It's a hands-on course that starts from the very basics and carries you to some very advanced topics. Can't recommend it enough.