QP/C++  7.3.0
Real-Time Embedded Framework
No Matches
Zephyr Project

About the QP/C++ Port to Zephyr

This directory contains a generic platform-independent QP/C++ port to the Zephyr RTOS.

Typically, you should not need to change the files in this directory to adapt the QP/C++-Zephyr port on any CPU/Compiler to which Zephyr has been ported, because all the CPU and compiler specifics are handled by the Zephyr RTOS.

The QP/C++-Zephyr port works as follows:

  • The critical section used in this port is based on k_spin_lock()/k_spin_unlock() Zephyr API. This is the modern Zephyr critical section API, which is ready for SMP (symmetric multiprocessing).
  • Each QP/C++ active object executes in a separate Zephyr thread (struct k_thread) and requires a private stack space.
As demonstrated in the examples/zephyr folder, the private stacks for active objects in this port must be allocated with the Zephyr K_THREAD_STACK_DEFINE() macro. Also, the stack size passed to QACTIVE_START() must be calculated with the Zephyr K_THREAD_STACK_SIZEOF() macro. Failure to use these macros can lead to memory corruption in the application.
  • The active object event queue is implemented with the Zephyr message queue (struct k_msgq).
The Zephyr message queue currently supports only the FIFO policy and does NOT support the LIFO policy. For that reason, the QActive_postLIFO_() implementation in this port uses the FIFO policy. A feature request has been filed in the Zephyr project for adding the LIFO policy, so perhaps this can be improved, if the feature is added.
  • The QP/C++ port uses Zephyr scheduler locking (k_sched_lock()/k_sched_unlock()), which locks all threads indiscriminately. Currently Zephyr does not provide a selective scheduler locking.
  • The QP/C++ port uses the native QF memory pool (::QMPool) to implement event pools.
  • The QP/C++ port does not mandate any specific method to manage the QP/C++ time events, but the provided examples use the Zephyr timer (struct k_timer) to tick periodically and invoke QF_TICK_X().

QP/C++ Source Files Needed in this QP/C++ Port

It is important to note that NOT all QP/C++ source files should be included. Here is the list of QP/C++ source files needed:

| +--qf/
| | qep_hsm.c
| | qep_msm.c
| | qf_act.c
| | qf_actq.c // NOT included (implemented in Zephyr)
| | qf_defer.c
| | qf_dyn.c
| | qf_mem.c
| | qf_ps.c
| | qf_qeq.c
| | qf_qmact.c
| | qf_time.c
| |
| +--qs/
| | qs.c // included only in the Spy build configuration
| | qs_fp.c // included only in the Spy build configuration
| +--zephyr
| | qp_port.h
| | qs_port.h
| | qf_port.c // implementation of the Zephyr port
Specifically, the QP/C++ source files qf_actq.c must NOT be included in the build, because this functionality is taken from Zephyr.

Examples for the Zephyr port

The example projects for this port are located in the examples/zephyr folder.

Ports to General-Purpose OSes