Skip to content

PRO TIP Block youtube.com at the DNS level — Pi-hole, NextDNS or your hosts file — but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

#39 State Machines Part-5: Optimal Implementation in C

28.5K views on YouTube

This lesson continues the subject of STATE MACHINES. Today you will learn 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 the 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 for 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 projects:
– 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)

——-
Resources:

Companion web page for this video course:
https://www.state-machine.com/quickstart

GitHub repository for projects for this video course:
https://github.com/QuantumLeaps/modern-embedded-programming-course

Transcript of this lesson:
https://www.state-machine.com/course/lesson39.txt

Music credits:
————–
The background music comes from:
https://www.bensound.com/royalty-free-music/track/straight