Home > Tracks > Embedded Systems Programming

Modern Embedded Software Goes Beyond the RTOS

Miro Samek - Watch Now - Currently watching: 1

Some of the most difficult problems with real-time and embedded programing are related to concurrent code execution as well as code organization, which all too often degenerates into "spaghetti code". These problems are usually intermittent, subtle, hard-to-reproduce, hard-to-isolate, hard-to-debug, and hard-to-remove. They pose the highest risk to the project schedule.

This session presents a set of best practices of concurrent programming, which are collectively known as the active object (or actor) design pattern. In this pattern, applications are built from event-driven, non-blocking, asynchronous, encapsulated threads (active objects), with the internal behavior of each active object controlled by a state machine.

While active objects can be implemented manually on top of a traditional RTOS, a better way is to use an active object framework. You will see how this leads to inversion of control, enables architectural reuse, and allows the framework to automatically enforce the best practices.

In the second part, the session will introduce modern hierarchical state machines as the powerful "spaghetti reducers". You will see how state machines complement active objects and enable graphical modeling and automatic code generation.

The session will utilize hands-on demonstrations using EFM32 Pearl-Gecko ARM Cortex-M4 board, the QP/C real-time embedded framework and the QM modeling and code-generation tool.

M↓ MARKDOWN HELP
italicssurround text with
*asterisks*
boldsurround text with
**two asterisks**
hyperlink
[hyperlink](https://example.com)
or just a bare URL
code
surround text with
`backticks`
strikethroughsurround text with
~~two tilde characters~~
quote
prefix with
>

tgy
Score: 0 | 6 days ago | 1 reply

Great presentation. Very informational. Any possibility that you will post this in YouTube?

MiroSpeaker
Score: 0 | 6 days ago | no reply

I'll check with the Embedded Online Conference organizers, but yes, I'd like to eventually release the video in the QuantumLeaps YouTube channel.

bojankoce
Score: 0 | 1 week ago | no reply

Thank you very much, Mr Semek for a great talk and shared resources!

Hugo
Score: 0 | 1 week ago | 1 reply

What a great talk! Many thanks for all the insights and pointers to relevant material.

MiroSpeaker
Score: 0 | 1 week ago | no reply

I'm glad to hear that you found it useful. The presented best practices of concurrent programming can be applied at any level and you don't necessarily need the whole Active Object framework with hierarchical state machines to benefit. For example, you might more judiciously apply blocking, which would make your code more responsive. Or, you could be more careful with sharing of resources, which would save you from applying mutual exclusion mechanisms. Or, you might consider structuring your threads more around the event-loop and asynchronous messages. Any of these steps would improve the final design.

blair
Score: 0 | 1 week ago | 1 reply

Hi Miro, thanks for the presentation and for the online training material. I wonder if you'd care to comment about Rust's [RTFM]{https://blog.japaric.io/tags/rtfm/} as another approach to concurrency frameworks?

MiroSpeaker
Score: 0 | 1 week ago | no reply

Unfortunately I don't known Rust enough to pass any judgement on this approach. The RTFM seems to be bound to Cortex-M and the NVIC. The "tasks" seem to be one-shot processing units, which is in contrast to the (super)loop structure of the traditional RTOS tasks. The approach reminds me of my Super Simple Tasker.

DanR
Score: 0 | 2 weeks ago | 1 reply

Miro,
This was very enlightening. I see a need to abstract the AO framework from the business logic of the code, and then you pop the HSM on me for the aha moment, but I wish you'd spent more time on the HSM tools you are using, and talking about available frameworks.

Where do I go to learn more?

Thanks for a well plotted discussion! I want the sequel!

-dan'l

MiroSpeaker
Score: 1 | 1 week ago | no reply

I'm glad to hear that you would like to learn more. The presentation included some references on slides 19 and 20. You can also go to the "Key Concepts" section on state-machine.com.
Regarding other resources, Bruce Powell Douglass wrote numerous books on Real-Time UML, modeling, hierarchical state machines, and all related issues. Bruce is associated with IBM Rhapsody, which is the currently dominating tool in the industry.

Chandan
Score: 0 | 1 week ago | 1 reply

Miro, First thanks for talk. There was many aha moments. I want to discuss one thing related to FreeRTOS project. Suppose In my project around 5-6 threads want to send some data over SPI so I will add mutux for mutual execution but it gona block thread if mutux is not free.
Now if I want to use active object way of doing same, How can I implement same using FreeAct.

MiroSpeaker
Score: 0 | 1 week ago | no reply

In the presentation I was trying to describe a general active object-based approach to such situations. In your case, it would mean that you encapsulate the SPI inside one "SPIBroker" AO. Then all other AOs will post events (with event parameters holding the data to send) to the "SPIBroker". The "SPIBroker" will then also receive the data over SPI, package them into events and post the events to other interested AOs. That way you will realize the "share-nothing" principle. I hope this makes sense...

MiroSpeaker
Score: 0 | 2 weeks ago | no reply

Please join me for a live Q&A session on Zoom tomorrow (Friday 5/22 at 9:AM Eastern):
Time: May 22, 2020 09:00 AM Eastern Time (US and Canada)
Join Zoom Meeting
https://us04web.zoom.us/j/3244153051?pwd=MjRtbWVEczZtbG5uWWV4Ujl5K3lSZz09
Meeting ID: 324 415 3051
Password: 3ZBCrg

TK
Score: 1 | 2 weeks ago | 1 reply

You mentioned a hybrid architecture where you would use AOs and blocking RTOS threads together. Such as when you moved the button press to an AO, but left the blinking led as a blocking thread. Why would you want to use a hybrid in a practical application? AO doesn't seem to have any significant disadvantages that would lead to choosing a hybrid.

MiroSpeaker
Score: 1 | 2 weeks ago | no reply

Hybrid architecture is necessary for gradual transition from sequential to event-driven paradigm. Also, most existing middleware, such as communication stacks (TCP/IP, USB, CAN), are written with the blocking paradigm, so they need a blocking thread context. The hybrid architecture allows you to use all such software, while your application can be build with active objects.

One thing that was not emphasized enough in the presentation is that any mixing of sequential and event-driven paradigms must occur between threads. You can have one whole thread programmed sequentially, while other threads run event-loops of active objects. But you should never mix the two paradigms within the same thread.

MiroSpeaker
Score: 1 | 2 weeks ago | no reply

The "FreeAct" active object "framework" has been released to GitHub, if anyone wishes to play with it. It contains the working examples for the EFM32 board as well as the TivaC LaunchPad board. The code is licensed under the MIT open source license (the same as FreeRTOS.) Enjoy.

HardRealTime
Score: 1 | 2 weeks ago | 1 reply

Really, really good talk. Not a wasteful moment. I have 2 questions. What are some strategies to perform if the event queue becomes full? With respect of the button events (pressed and released) what are some techniques to share the events with other consumers; not just the BlinkyButton task?

MiroSpeaker
Score: 1 | 2 weeks ago | no reply

Regarding the event queue: most events should be reliably posted and processed, which means that a queue overflow should be treated as a system failure (similarly as stack overflow is commonly treated as a system failure in sequential systems that use more stack and more staks.) However, sometimes you can afford losing events (e.g., if you are interested only in the "last is best" updates). For such situations, an AO framework could provide an "extended post" operation variant that is allowed to lose events. There are some additional considerations, so that the other events will still have the delivery guarantees. The QP/C and QP/C++ frameworks provide such an "extened-post" variant.

Regarding "sharing" events, there is the publish-subscribe event delivery mechanism. In this mechanism events are multicast to all subscribers, so multiple AOs will receive the same event. Again, QP/C and QP/C++ framework provide publish-subscribe mechanism as well as the direct event posting mechanisms.

MiroSpeaker
Score: 2 | 2 weeks ago | no reply

The Active Object design pattern was presented here in the context of an RTOS. However, the pattern is also valuable and applicable to bigger systems based on embedded Linux or other POSIX-compliant OSes (e.g., QNX, VxWorks, Integrity with POSIX subsystem). In fact, in bigger systems Active Objects make even more sense.

DS
Score: 1 | 2 weeks ago | 1 reply

Excellent presentation full of detail! I appreciate that you took us into the code to implement AO in the examples. It is readily apparent from your presentation how clean the approach of using Active Objects is and how it can be used to make very maintainable systems.

MiroSpeaker
Score: 1 | 2 weeks ago | no reply

The little "FreeAct framework" that was built during the session could be actually useful. There are no state machines there yet, but they can be added quite easily (at least the traditional non-hierarchical FSMs). You can use the classic "nested switch statement" or "table-driven" FSM implementations.

Brian
Score: 1 | 2 weeks ago | 1 reply

Well done, Miro! That was a perfect introduction/comparison between "traditional" and "modern" design techniques for concurrency. It was very interesting to hear your take on event-driven modern state machines.

MiroSpeaker
Score: 1 | 2 weeks ago | no reply

I plan to release more lessons about state machines in my video course on YouTube. Stay tuned!

alexanderentinger
Score: 1 | 2 weeks ago | no reply

Thank you very much for the great presentation! ;)

dskokic
Score: 1 | 2 weeks ago | no reply

Thank you very much for excellent presentation! I will surely watch it again and do the practical work.

Jeremy
Score: 1 | 2 weeks ago | 1 reply

Hi Miro, perhaps I just need to keep watching to find the answer, but does the Active Object pattern require a dedicated thread/task for each object?

MiroSpeaker
Score: 0 | 2 weeks ago | 1 reply

If you base the active object framework on a traditional RTOS, you typically would map an active object to a thread (task). But, an active object framework does NOT need to be based on the traditional RTOS. In that case, you don't need to use the very expensive RTOS thread for an AO.

Jeremy
Score: 0 | 2 weeks ago | 1 reply

I see at the 52m mark of the video you just merged the 2 active objects into a single object. I could also envision a case where each event had an ActiveObjectID and could all be collected by a single event queue, but then dispatched to the appropriate active object based on the ID. The mind's turning here, and I suspect the rest of the video will address that ;).

MiroSpeaker
Score: 0 | 2 weeks ago | no reply

Yes, you have many options to implement active objects and you don't need to use an RTOS with thread per AO. One example is the QV kernel (called "vanilla" kernel in the PSiCC2 book). The other example is the QK kernel.

enrico.perera
Score: 1 | 2 weeks ago | no reply

Another great video by Miro !

DaveN
Score: 0 | 2 weeks ago | no reply

Zoom says "The host has another meeting in progress." Aaarrrgggg...

DaveN
Score: 0 | 2 weeks ago | 1 reply

Fabulous presentation Miro.
I am unable to join your Zoom meeting??

MiroSpeaker
Score: 0 | 2 weeks ago | no reply

I've updated the meeting link that Zoom is giving me. Please try again...
https://us04web.zoom.us/j/76823971531?pwd=RUlKckFGeHFMOWtiZVllOWY3OWtaQT09

tobbad
Score: 1 | 2 weeks ago | no reply

This was just great!
Thank you.

MiroSpeaker
Score: 0 | 2 weeks ago | no reply

If anyone is interested in discussing this session, please join the following Zoom meeting:
https://us04web.zoom.us/j/76823971531?pwd=RUlKckFGeHFMOWtiZVllOWY3OWtaQT09
Meeting ID: 324 415 3051
Password: 3ZBCrg
The Zoom meeting is now over. Thank you to all participants.

OUR SPONSORS