Event-Driven Programming with the QP Framework
High-performance, event-driven architectures built on hierarchical state machines for responsive embedded systems.
Overview
Most embedded systems are inherently event-driven. Timers expire, new data arrives across a communications interface, a peripheral interrupts the CPU and needs attention. How are these events generated, delivered, and processed? How are challenges such as “event storms” and out-of-order event processing addressed?
While an event-driven architecture is a natural fit for many embedded systems, if the architecture and implementation are wrong, the system can quickly devolve into a mess of spaghetti code. “Bags of flags,” complex nested if/else logic, and 1,500-line switch statements can result in an unmaintainable mess.
But it doesn’t need to be this way. By understanding and embracing the key principles of event-driven systems, developers can design systems that are highly responsive, easy to understand, maintain, and extend, and that facilitate highly independent, concurrent development within the team.
This course is a 5-day deep dive into harnessing event-driven programming and UML statecharts (also known as “state machines with superpowers”) to build responsive, robust embedded systems. While many of the topics are implementation-agnostic, the Quantum Platform™ (QP) event-driven framework is the centerpiece of the course. QP provides components that facilitate the event-handling, modeling, tracing, debugging, and testing of event-driven systems. You could hand-roll a bare-metal or RTOS-based event-driven system, but it would fall short of the capabilities of a QP-based system.
The course culminates in a capstone project, with students working in small teams to build a functioning product from a set of requirements. Students will use QP’s modeling, design, testing, and debugging tools to bring a product to life in a matter of hours.
The course combines lecture and instruction with hands-on labs using real embedded hardware. All instruction is based on the C programming language, although the QP framework includes both C and C++ versions, allowing the team to choose the programming language that best meets its needs.
Ontera's courses are taught on-site on real target hardware. Students build, download and debug on an Arm Cortex M33 target processor, and they keep all course materials and the development board so that they can always revisit topics and labs.
Who This Course Is For
This course is suitable for embedded engineers who are comfortable writing C or C++ code. Students typically have roles such as firmware engineer, systems engineer, and test engineer.
Students require no prior experience with event-driven programming or the QP framework.
OS-Agnostic, MCU agnostic
The QP framework runs on a wide selection of microcontrollers and processors, and can run on top of an OS (such as Zephyr, ThreadX, FreeRTOS or even Linux) or with no OS at all ("bare metal").
Course Curriculum
Detailed course curriculum can be provided upon request.
Event-Driven Programming
Event-driven programming is contrasted with the traditional sequential-programming paradigm commonly used in bare-metal and RTOS-based systems. Tradeoffs, limitations, and use cases are discussed through practical examples. Students are introduced to events: what they look like, how they are generated, and how they are processed.
Active Objects
Students are introduced to the active-object computing model, including the defining properties of active objects and the benefits of such an architecture. Multithreading, encapsulation, queuing theory, and preemptive and nonpreemptive scheduling are discussed.
UML Statecharts
When most engineers hear “state machine,” they think of the classic flat “bubbles with arrows” state machine they learned about for an hour at some point in university. For a simple LED blinker program, this might suffice. But UML statecharts are a supercharged variant of state machines, adding powerful functionality without introducing unnecessary complexity. Features such as hierarchical states, event processing, guard conditions, entry and exit actions, and much more are discussed.
The second part of this section focuses on QP’s most important component—the Quantum Event Processor (QEP). Many engineers implement state machines using nested switch statements or the classic State Design Pattern approach. The result is often a difficult-to-maintain mess of cascading case statements, flags, duplicated logic, and special cases. QEP provides a modern approach to handling incoming events with hierarchical state machines. Armed with an understanding of UML statecharts, students learn how to design QP state machines that have a small footprint, deliver high performance, and are easy to understand and maintain. A deep dive into hierarchical event handling wraps up the section.
Developing Quantum Platform (QP) Applications
One of the many advantages of an event-driven framework is that all events flow through the framework. QP provides object-oriented components and APIs that facilitate event garbage collection, point-to-point and publish-subscribe event distribution, timing, error handling, and more. By extending base classes provided by the framework, engineers can create customized events and state-based Active Objects that fulfill their system requirements.
Modeling and Code Generation
Everyone has experienced this: the code is out of date with the design documentation. The design is done once, then comes the code, and for years afterward the design documents are never revisited or updated. The best documentation for how the code works is… well, the code itself. Not to mention that it was never clear whether the code actually matched the original design in the first place.
What if the design were never out of date? What if the design were the code? That is the whole idea behind modeling and code generation. By working at a higher level of abstraction in a modeling tool, engineers can be more productive, eliminate certain types of errors, and ensure that the design is never out of date because the source code is generated directly from the model.
QP’s Quantum Modeler (QM) UML statechart modeling tool enables engineers to model statecharts in a highly expressive, information-dense graphical representation without imposing arbitrary restrictions. States can be any size, at any location, and with any name. State transitions can be drawn wherever the designer wishes. Tedious boilerplate code for state transitions, entry and exit actions, and other common operations is generated automatically by the tool. Engineers only need to add or modify code where custom behavior is required. And the tool is UML-aware, so any attempt to do something “naughty” is disallowed (or at least flagged) by the tool. We’re more than a quarter of the way into the 21st century; let’s not keep developing code like we did in the days of punch cards, slide rules, and green-bar paper (which have their own nostalgic charm).
Tracing, Testing and Debugging
This section covers QP’s built-in tracing and testing capabilities. The QSPY component provides a very high level of visibility into the system, always under the control of the user. Everything of interest is included and nothing more. Watch events move through the system, observe state changes as the system runs, and even monitor changes to any piece of data in the system (e.g., a temperature, a pressure, or a button press).
The QUTest component builds upon these tracing capabilities, enabling comprehensive testing through bidirectional communication between the host and device under test. Testing can be automated and integrated into your CI/CD workflow. And QP’s dual-hosting capability means that a large part of your application can be designed, developed, and tested before the custom hardware is even available.
Design Patterns
Every embedded system has its own unique purpose and business logic. But beneath the surface, most systems face many of the same implementation challenges. A design pattern is a proven, recognizable approach to solving a recurring software design problem. This section introduces students to common design challenges in event-driven architectures and shows how they can be solved using the features of the QP framework.
Our Instructors
Our courses are taught by experts who have written real-time kernels, designed mission-critical systems, testified in U.S. federal court, and reverse-engineered proprietary kernels from object code. Throughout each course, topics are connected to real life examples pulled directly from the instructors' experience.
Our instructors have taught teams at every major silicon vendor, more than a dozen medical device companies, and numerous firms working in defense / aerospace, transportation, industrial control, instrumentation, robotics and energy.
Get in touch for full details on syllabus, pricing and training dates.
Contact Us About This Course(Note: this course is only taught privately on-site at customer location; no public or online trainings are offered.)