Book Review, Event-Driven Embedded Systems, Worth Reading

The book is Practical UML Statecharts in C/C++, Second Edition: Event-Driven Programming for Embedded Systems. Why do I think this is so important? It just is, so trust me, OK.

First, don’t let the title scare you. If you are writing embedded systems software, you need to read this book.

The book is all about building state machines for embedded systems. I am afraid the whole UML part is a bit of buzzword bingo. They thought a title with UML in it would sell better. If you have a prejudice against UML set it aside and keep reading. It is the book about the Quantum Platform, an embedded RTOS  sold by a company called Quantum Leaps.

The author, Miro Samec, came up with the operating system and concepts in the book. I must admit, I am a bit of a raving fan boy. I have recommended the book to anyone who will listen, and forced some people who worked for me to read it. (Sorry Frank.)

Stacking rings as states

Stacking rings as state

The text builds the ideas of Statecharts. For those who do not know, a statechart is simply a way to build a hierarchical state machine. In my brain, I see the statechart like my kid’s  stacking rings toy. Each ring is a state. To get to the top state or ring, all the lower rings must be in place. To get from the top to the bottom, all the rings in between must be removed.

A jump from bottom to top is not allowed. The software must move from the bottom state through the intermediate states, to the top state, which will handle the event. This means that entry code or exit code in each state must be executed. A higher level state is contained inside the parent state. The way it works is smooth and clean, but different enough that it is hard to grasp at first.

Events are very important to making all this work. An event is the atomic element to pass messages from one statechart to the others. Events are handled by a state. The statechart will keep moving from state to state until an event is handled. That is hugely oversimplified, but it gives you an idea.

The Quantum Framework has all the code needed to handle the events, and build the state charts. Like all good frameworks, you write your application code, and the framework handles all the plumbing. The book calls this the “Hollywood Pattern”, don’t call us, we’ll call you. Nice stuff.

Even if you do not buy or use the Quantum Platform, or even buy into the concept of state charts, you should buy the book. Why? Because Miro has a couple of chapters on “other” ways to implement statemachines in C and C++. They are worth the price of the book.

As you travel through your career as a software and firmware engineer, you will see a whole lot of code. Some of it will be statemachines implemented as switch statements, tables and other constructs. Some of the code you see will not be a statemachine, but really should. Knowing five ways to build a statemachine and the “bad” things about each way is gold.

If you want a taste before you buy, read this article from EE Times, Build a Super Simple Tasker. Hints are given at many of the ideas from the book.

So, in case you haven’t guessed, my multicore ideas are also based on the book and event-driven programming. The event driven model solves the requirements nicely, and even helps answer the one big question, “what about interrupts?”

The legal disclaimer I am required to say as a blogger, I did not get the book for free. I bought the first edition, and thought it was good enough that I bought the second edition. Both purchased with my own hard-won cash. The link above is not an affiliate link.

Have you read it? What did you think, please comment if you liked the book, or hated it.

Advertisements

One comment on “Book Review, Event-Driven Embedded Systems, Worth Reading

  1. […] have requirement would be to have the software idle the processor when no processing is needed. The event-driven programming model is great for a low power application. No events to handle means no […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s