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

About the QP 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-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-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 active object executes in a separate Zephyr thread (struct k_thread) and requires a private stack space.
As demonstrated in the provided examples, 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 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 port uses the native QF memory pool (::QMPool) to implement event pools.
  • The QP port does not mandate any specific method to manage the QP time events, but the provided examples use the Zephyr timer (struct k_timer) to tick periodically and invoke QP::QTimeEvt::TICK_X().

QP Source Files Needed in this QP Port

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

| | +-qf/
| | | +-qep_hsm.cpp
| | | +-qep_msm.cpp
| | | +-qf_act.cpp
| | | +-qf_actq.cpp  - NOT included (implemented in Zephyr)
| | | +-qf_defer.cpp
| | | +-qf_dyn.cpp
| | | +-qf_mem.cpp
| | | +-qf_ps.cpp
| | | +-qf_qeq.cpp
| | | +-qf_qmact.cpp
| | | +-qf_time.cpp
| |
| | +-qs/
| | | +-qs.cpp       - included only in the Spy build configuration
| | | +-qs_fp.cpp    - included only in the Spy build configuration
| +-zephyr
| | +-qep_port.hpp
| | +-qf_port.hpp
| | +-qf_port.cpp    - implementation of the Zephyr port
| | +-qs_port.hpp
Specifically, the QP source files qf_actq.cpp 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 examples/zephyr.

Ports to Third-Party OS