QP-nano  6.9.0
Real-Time Embedded Framework

General Comments

The QP-nano distribution contains many example projects to demonstrate various QP-nano features. Each example project is described on its own dedicated page that you can find using several criteria (see Cross-Reference). The example projects have the following main goals:

  • to help you learn how to use QP-nano — the examples show the intended way of using QP-nano features and structuring QP-nano applications.
  • to provide you with a starting point for your own projects — the examples are complete working projects, with correctly pre-configured tools, such as compiler options, linker script, debugger setup, etc.
It is highly recommended that you create your own projects by copying and modifying existing example projects rather than starting your QP-nano projects from scratch.

Example Code Structure

Starting with QP-nano release 5.4.0, all examples are bundled into the QP-nano download, as opposed to being distributed as separate QP Development Kits (QDKs). The main benefit is of this approach is that it greatly reduces chances of mistakes in combining the mainline QP-nano code with various QDKs. The downside is that the QP-nano distribution becomes quite large and that examples can't be added or updated independently from the QP-nano baseline code.

All examples are located in sub-directories of the examples top-level folder, with the hierarchical organization outlined below:

  • examples
    • arm-cm — Native examples for ARM-Cortex-M (bare-metal) [A]

      • blinky_ek-tm4c123gxl — Blinky example for EK-TM4C123GXL board
        • qk — Version for the preemptive QK kernel
          • arm — build with ARM toolset
          • gnu — build with GNU toolset
          • iar — build with IAR toolset
        • qv — Version for the cooperative QV kernel
          • arm — build with ARM toolset
          • gnu — build with GNU toolset
          • iar — build with IAR toolset
        • ... — source code independent on the toolset

    • workstation — Examples for Workstations [B]

      • blinky — Blinky example for workstations (console app)
      • dpp — DPP example for workstations (console app)
      • . . . — Other examples for workstations (console app)

  • A Native examples are located in sub-directories named after the CPU architecture, such as arm-cm for ARM Cortex-M. Under that directory, the sub-directories blinky_ek-tm4c123gxl contain the specific example on the specified board, such as "Blinky" on the EK-TM4C123GXL board here. In the specific example folder, you find sub-folders for the QK and QV kernels, respectively.

  • B Examples for Workstations are located in sub-directory workstation. These examples can be built on Windows, Linux and MacOS.

Because the QP-nano distribution contains all examples, the number of sub-directories and files in the examples folder may seem daunting. However, knowing the structure of the examples folder, you can simply delete the sub-directories that are not interesting to you.

Example Applications

To demonstrate QP-nano features on an embedded board, you need to create an application that does "something interesting". Instead of inventing this "something interesting" for each and every example, the example projects implement one of the three example applications, which are described on the separate pages:

With the exception of the game application, all other example applications can be implemented on a board with just a couple of LEDs. The "Fly 'n' Shoot" Game application is a bit more involved and requires a small graphic display on the board.

Beyond these basic applications for demonstrating and testing the various QP-nano ports, the QP-nano distribution contains all examples described in the book Practical UML Statecharts in C/C++, 2nd Edition

See also
Examples for Workstations (Windows/POSIX)

Development Boards

While some provided examples can run on your desktop computer, most embedded example projects require special hardware in form of Development Boards, which you need to acquire to be able to run the examples. The boards chosen for the examples are generally inexpensive and self-contained with no need for external hardware (such as external JTAG debuggers or power supplies).

Development Tools

Most provided examples require special embedded cross-development tools, such as embedded compilers, linkers, debuggers and IDEs, which you need to acquire independently from the QP-nano distribution. Generally, the examples work with the free (size limited) evaluation versions of the commercial tools. The examples list the versions of tools they were developed and tested with. Please refer to the cross-reference section Development Tools to see which embedded toolsets are used.

Build Configurations

QP examples QP ports are provided in the following three build configurations:

  • Debug — this configuration is built with full debugging information and minimal optimization. When the QP framework finds no events to process, the framework busy-idles until there are new events to process.
  • Release — this configuration is built with no debugging information and high optimization. Single-stepping and debugging at the source-code level is effectively impossible due to the lack of debugging information and optimized code, but the debugger can be used to download and start the executable. When the QP framework finds no events to process, the framework puts the CPU to sleep until there are new events to process.
Why do you need multiple build configurations?
The different phases of embedded software life cycle pose different challenges. During the development and maintenance phase, for example, the emphasis is on the ease of debugging and verifying the correctness of the code, which require lower levels of optimization and special scaffolding code. In contrast, for releasing the code in the final product, the emphasis is on small memory footprint and CPU time efficiency, which require high-level of optimization and removal of any scaffolding code. To address these conflicting needs, the same source code is compiled into multiple build configurations that differ in the use of compiler options and activation of the scaffolding code.

QM Models

Many example projects contain code auto-generated by the QM modeling tool. Such projects always contain the corresponding QM model file, which you can open in QM, modify, and re-generate the code.

The auto-generated files are saved as read-only. This protects them from inadvertent modifications, which will get lost when the files are re-generated by QM (or QMC). All modifications to the auto-generated code should be done in the QM model, not in the code.

Third-Party Code

The QP-nano example projects often need to use various additional code, such as MCU register definition files, startup code, device drivers, etc., which are provided by Third-Party vendors. All such code is located in the 3rd_party top-level folder.

As far as possible, the code in the 3rd_party folder has been left unchanged from the original source. (Any modified code is clearly identified by top-level comments that detail the applied changes.) For that reason, the Third-Party code might produce compilation warnings in your builds.

The code in the 3rd_party folder comes from various sources, and Quantum Leaps, LLC expressly makes no claims of ownership to any of this code, even though some of the code might be customized or modified by Quantum Leaps.

The Third-Party software components included in the 3rd_party folder are licensed under a variety of different licensing terms that are defined by the respective owners of this software and are spelled out in the README.txt or LICENSE.txt files included in the respective sub-folders.

Creating your Own QP-nano Projects

Perhaps the most important fact of life to remember is that in embedded systems nothing works until everything works. This means that you should always start with a working system and gradually evolve it, changing one thing at a time and making sure that it keeps working every step of the way.

Keeping this in mind, the provided QP-nano application examples, such as the super-simple Blinky, or a bit more advanced Dining Philosophers Problem (DPP) or "Fly 'n' Shoot" Game, allow you to get started with a working project rather than starting from scratch. You should also always try one of the provided example projects on the same evaluation board that it was designed for, before making any changes.

Only after convincing yourself that the example project works "as is", you can think about creating your own projects. At this point, the easiest and recommended way is to copy the existing working example project folder (such as the Blinky example) and rename it.

After copying the project folder, you still need to change the name of the project/workspace. The easiest and safest way to do this is to open the project/workspace in the corresponding IDE and use the Save As... option to save the project under a different name. You can do this also with the QM model file, which you can open in QM and "Save As" a different model.

By copying and re-naming an existing, working project, as opposed to creating a new one from scratch, you inherit the correct compiler and linker options an other project settings, which will help you get started much faster.

Next Steps and Further Reading About QP and QM

To work with QP-nano effectively, you need to learn a bit more about active objects and state machines. Below is a list of links to enable you to further your knowledge:

  1. The book “Practical UML Statecharts in C/C++, 2nd Edition” [PSiCC2] and the companion web-page to the book (https://www.state-machine.com/psicc2/
  2. Free Support Forum for QP/QM (https://sourceforge.net/p/qpc/discussion/668726 )
  3. QP Code Downloads summary (https://www.state-machine.com/downloads )
  4. QP Application Notes (https://www.state-machine.com/doc/an )
  5. "State Space" Blog (http://embeddedgurus.com/state-space/ )