Book description
Practical UML Statecharts in C/C++ Second Edition bridges the gap between high-level abstract concepts of the Unified Modeling Language (UML) and the actual programming aspects of modern hierarchical state machines (UML statecharts). The book describes a lightweight, open source, event-driven infrastructure, called QP that enables direct manual coding UML statecharts and concurrent event-driven applications in C or C++ without big tools.This book is presented in two parts. In Part I, you get a practical description of the relevant state machine concepts starting from traditional finite state automata to modern UML state machines followed by state machine coding techniques and state-machine design patterns, all illustrated with executable examples. In Part II, you find a detailed design study of a generic real-time framework indispensable for combining concurrent, event-driven state machines into robust applications. Part II begins with a clear explanation of the key event-driven programming concepts such as inversion of control (Hollywood Principle), blocking versus non-blocking code, run-to-completion (RTC) execution semantics, the importance of event queues, dealing with time, and the role of state machines to maintain the context from one event to the next. This background is designed to help software developers in making the transition from the traditional sequential to the modern event-driven programming, which can be one of the trickiest paradigm shifts.
The lightweight QP event-driven infrastructure goes several steps beyond the traditional real-time operating system (RTOS). In the simplest configuration, QP runs on bare-metal microprocessor, microcontroller, or DSP completely replacing the RTOS. QP can also work with almost any OS/RTOS to take advantage of the existing device drivers, communication stacks, and other middleware. The accompanying website to this book contains complete open source code for QP, ports to popular processors and operating systems, including 80x86, ARM Cortex-M3, MSP430, and Linux, as well as all examples described in the book.
Table of contents
- Preface
- Acknowledgments
- Copyright Page
- Introduction
-
I. Uml State Machines
- I. UML State Machines
-
1. Getting Started with UML State Machines and Event-Driven Programming
- 1.1. Installing the Accompanying Code
- 1.2. Let's Play
- 1.3. The main() Function
- 1.4. The Design of the “Fly ‘n’ Shoot” Game
- 1.5. Active Objects in the “Fly ‘n’ Shoot” Game
- 1.6. Events in the “Fly ‘n’ Shoot” Game
- 1.7. Coding Hierarchical State Machines
- 1.8. The Execution Model
- 1.9. Comparison to the Traditional Approach
- 1.10. Summary
-
2. A Crash Course in UML State Machines
- 2.1. The Oversimplification of the Event-Action Paradigm
- 2.2. Basic State Machine Concepts
-
2.3. UML Extensions to the Traditional FSM Formalism
- 2.3.1. Reuse of Behavior in Reactive Systems
- 2.3.2. Hierarchically Nested States
- 2.3.3. Behavioral Inheritance
- 2.3.4. Liskov Substitution Principle for States
- 2.3.5. Orthogonal Regions
- 2.3.6. Entry and Exit Actions
- 2.3.7. Internal Transitions
- 2.3.8. Transition Execution Sequence
- 2.3.9. Local versus External Transitions
- 2.3.10. Event Types in the UML
- 2.3.11. Event Deferral
- 2.3.12. Pseudostates
- 2.3.13. UML Statecharts and Automatic Code Synthesis
- 2.3.14. The Limitations of the UML State Diagrams
- 2.3.15. UML State Machine Semantics: An Exhaustive Example
- 2.4. Designing A UML State Machine
- 2.5. Summary
- 3. Standard State Machine Implementations
-
4. Hierarchical Event Processor Implementation
- 4.1. Key Features of the QEP Event Processor
- 4.2. QEP Structure
- 4.3. Events
- 4.4. Hierarchical State-Handler Functions
- 4.4.3. Hierarchical State-Handler Function Example in C++
-
4.5. Hierarchical State Machine Class
- 4.5.1. Hierarchical State Machine in C (Structure QHsm)
- 4.5.2. Hierarchical State Machine in C++ (Class QHsm)
- 4.5.3. The Top State and the Initial Pseudostate
- 4.5.4. Entry/Exit Actions and Nested Initial Transitions
- 4.5.5. Reserved Events and Helper Macros in QEP
- 4.5.6. Topmost Initial Transition (QHsm_init())
- 4.5.7. Dispatching Events (QHsm_dispatch(), General Structure)
- 4.5.8. Executing a Transition in the State Machine (QHsm_dispatch(), Transition)
-
4.6. Summary of Steps for Implementing HSMs with QEP
- 4.6.1. Step 1: Enumerating Signals
- 4.6.2. Step 2: Defining Events
- 4.6.3. Step 3: Deriving the Specific State Machine
- 4.6.4. Step 4: Defining the Initial Pseudostate
- 4.6.5. Step 5: Defining the State-Handler Functions
- 4.6.6. Coding Entry and Exit Actions
- 4.6.7. Coding Initial Transitions
- 4.6.8. Coding Internal Transitions
- 4.6.9. Coding Regular Transitions
- 4.6.10. Coding Guard Conditions
-
4.7. Pitfalls to Avoid While Coding State Machines with QEP
- 4.7.1. Incomplete State Handlers
- 4.7.2. Ill-Formed State Handlers
- 4.7.3. State Transition Inside Entry or Exit Action
- 4.7.4. Incorrect Casting of Event Pointers
- 4.7.5. Accessing Event Parameters in Entry/Exit Actions or Initial Transitions
- 4.7.6. Targeting a Nonsubstate in the Initial Transition
- 4.7.7. Code Outside the switch Statement
- 4.7.8. Suboptimal Signal Granularity
- 4.7.9. Violating the Run-to-Completion Semantics
- 4.7.10. Inadvertent Corruption of the Current Event
- 4.8. Porting and Configuring QEP
- 4.9. Summary
- 5. State Patterns
-
II. Real-Time Framework
- II. Real-Time Framework
- 6. Real-Time Framework Concepts
-
7. Real-Time Framework Implementation
-
7.1. Key Features of the QF Real-Time Framework
- 7.1.1. Source Code
- 7.1.2. Portability
- 7.1.3. Scalability
- 7.1.4. Support for Modern State Machines
- 7.1.5. Direct Event Posting and Publish-Subscribe Event Delivery
- 7.1.6. Zero-Copy Event Memory Management
- 7.1.7. Open-Ended Number of Time Events
- 7.1.8. Native Event Queues
- 7.1.9. Native Memory Pool
- 7.1.10. Built-in “Vanilla” Scheduler
- 7.1.11. Tight Integration with the QK Preemptive Kernel
- 7.1.12. Low-Power Architecture
- 7.1.13. Assertion-Based Error Handling
- 7.1.14. Built-in Software Tracing Instrumentation
- 7.2. QF Structure
- 7.3. Critical Sections in QF
- 7.4. Active Objects
- 7.5. Event Management in QF
- 7.6. Event Delivery Mechanisms in QF
- 7.7. Time Management
- 7.8. Native QF Event Queue
- 7.9. Native QF Memory Pool
- 7.10. Native QF Priority Set
- 7.11. Native Cooperative “Vanilla” Kernel
- 7.12. QP Reference Manual
- 7.13. Summary
-
7.1. Key Features of the QF Real-Time Framework
-
8. Porting and Configuring QF
-
8.1. The QP Platform Abstraction Layer
- 8.1.1. Building QP Applications
- 8.1.2. Building QP Libraries
- 8.1.3. Directories and Files
- 8.1.4. The qep_port.h Header File
-
8.1.5. The qf_port.h Header File
- Types of Platform-Specific QActive Data Members
- Base Class for Derivation of QActive
- The Maximum Number of Active Objects in the Application
- Various Object Sizes Within the QF Framework
- QF Critical Section Mechanism
- Include Files Used by this QF Port
- Interface Used Only Inside QF, But Not in Applications
- Active Object Event Queue Operations
- QF Event Pool Operations
- 8.1.6. The qf_port.c Source File
- 8.1.7. The qp_port.h Header File
- 8.1.8. Platform-Specific QF Callback Functions
- 8.1.9. System Clock Tick (Calling QF_tick())
- 8.1.10. Building the QF Library
- 8.2. Porting the Cooperative “Vanilla” Kernel
- 8.3. QF Port to μC/OS-II (Conventional RTOS)
- 8.4. QF Port to Linux (Conventional POSIX-Compliant OS)
- 8.5. Summary
-
8.1. The QP Platform Abstraction Layer
- 9. Developing QP Applications
- 10. Preemptive Run-to-Completion Kernel
-
11. Software Tracing for Event-Driven Systems
- 11.1. Software Tracing Concepts
- 11.2. Quantum Spy Software-Tracing System
- 11.3. QS Target Component
- 11.3.7. QS Trace Buffer
- 11.3.8. Dictionary Trace Records
- 11.3.9. Application-Specific QS Trace Records
- 11.3.10. Porting and Configuring QS
- 11.4. The QSPY Host Application
- 11.5. Exporting Trace Data to MATLAB
-
11.6. Adding QS Software Tracing to a QP Application
- 11.6.1. Initializing QS and Setting Up the Filters
- 11.6.2. Defining Platform-Specific QS Callbacks
- 11.6.3. Generating QS Timestamps with the QS_onGetTime() Callback
- 11.6.4. Generating QS Dictionary Records from Active Objects
- 11.6.5. Adding Application-Specific Trace Records
- 11.6.6. “QSPY Reference Manual”
- 11.7. Summary
-
12. QP-nano: How Small Can You Go?
- 12.1. Key Features of QP-nano
-
12.2. Implementing the “Fly ‘n’ Shoot” Example with QP-nano
- 12.2.1. The main() function
- 12.2.2. The qpn_port.h Header File
- 12.2.3. Signals, Events, and Active Objects in the “Fly ‘n’ Shoot” Game
- 12.2.4. Implementing the Ship Active Object in QP-nano
- 12.2.5. Time Events in QP-nano
- 12.2.6. Board Support Package for “Fly ‘n’ Shoot” Application in QP-nano
- 12.2.7. Building the “Fly ‘n’ Shoot” QP-nano Application
- 12.3. QP-nano Structure
- 12.4. Event Queues in QP-nano
- 12.5. The Cooperative “Vanilla” Kernel in QP-nano
- 12.6. The Preemptive Run-to-Completion QK-nano Kernel
- 12.7. The PELICAN Crossing Example
- 12.8. Summary
- A. Licensing Policy for QP and QP-nano
- B. Guide to Notation
- Bibliography
Product information
- Title: Practical UML Statecharts in C/C++, 2nd Edition
- Author(s):
- Release date: October 2008
- Publisher(s): CRC Press
- ISBN: 9781482249262
You might also like
book
Real-Time UML Workshop for Embedded Systems, 2nd Edition
Written as a workbook with a set of guided exercises that teach by example, this book …
book
Hands-On Design Patterns with C++
A comprehensive guide with extensive coverage on concepts such as OOP, functional programming, generic programming, and …
book
Getting Started with Simulink
Written by an experienced engineer, this book will help you utilize the great user-friendly features of …
book
The Inverse Method: Parametric Verification of Real-time Embedded Systems
This book introduces state-of-the-art verification techniques for real-time embedded systems, based on the inverse method for …