QP/C: A Tailored, Compact, and Customizable Real-Time Operating System (RTOS) for Resource-Constrained MCUs

Does embedded development often make you feel like you’re flying solo? With various interrupts, task scheduling, state machines… it can be overwhelming in a moment. Don’t worry, today I want to recommend a powerful tool—QP/C (Real-Time Event Framework), which will help your projects understand event-driven programming instantly, boosting efficiency.

What is QP/C?QP/C, short for QP/C Real-Time Event Framework, is a lightweight asynchronous, event-driven Active Object (also known as Actor) model framework. Essentially, it is a compact and customizable real-time operating system (RTOS) specifically designed for resource-constrained MCUs. It excels at hierarchical state machines, adhering to the UML 2.5 standard to define behaviors.

What can it help you with?

  • • Break down complex logic into self-contained Active Objects, achieving decoupling and clarity.
  • • Provide deterministic scheduling to meet hard real-time requirements.
  • • Support event queuing and publish/subscribe mechanisms, perfectly separating data and control.
  • • Comes with QM modeling tools and QTools, significantly increasing development efficiency.

What pain points does it solve?

  1. 1. Is task stack management cumbersome? QP/C automatically handles it with event queues.
  2. 2. Writing a lot of switch-case and goto for state machines? The framework makes states and transitions clear at a glance.
  3. 3. Confused by multi-tasking priorities, deadlocks, and starvation? Built-in priority scheduling ensures safety and peace of mind.
  4. 4. Poor portability? The same code easily runs on different MCUs.

Overview of the QP Framework Family

Version Language Safety Features Licensing
QP/C C11 Selected Assertions GPLv3 / Commercial
QP/C++ C++17 Selected Assertions GPLv3 / Commercial
SafeQP/C C11 Complete Safety Functions Commercial (Certification Package)
SafeQP/C++ C++17 Complete Safety Functions Commercial (Certification Package)

How to Install and Use

  1. 1. Clone the repository:
    git clone https://github.com/QuantumLeaps/qpc --recurse-submodules --depth 1
  2. 2. Enter the directory and configure the cross-compiler according to the README.
  3. 3. Run the example “Blinky” application; just a few lines of code can light up the LED.
  4. 4. Encapsulate your logic into an Active Object and let QP/C handle the scheduling.

Example Code (Minimal Version):

#include "qpc.h"

typedef struct BlinkyTag {
    QActive super;
    QTimeEvt timeEvt;
} Blinky;

static QState Blinky_initial(Blinky *me){
    return Q_TRAN(&Blinky_blink);
}

static QState Blinky_blink(Blinky *me){
    switch(Q_SIG(me)){
        case Q_ENTRY_SIG:
            HAL_LED_ON();
            QTimeEvt_postIn(&me->timeEvt, Q_ACTIVE_CAST(QActive, me),50);
            return Q_HANDLED();
        case Q_TIMEOUT_SIG:
            HAL_LED_TOGGLE();
            QTimeEvt_postIn(&me->timeEvt, Q_ACTIVE_CAST(QActive, me),50);
            return Q_HANDLED();
     }
     return Q_SUPER(&QHSM_top);
}

int main(void){
    QF_init();
    static Blinky blinky;
    QActive_ctor(&blinky.super, Q_STATE_CAST(QStateHandler,&Blinky_initial));
    QActive_start(&blinky.super,1U,(void*)&blinky.timeEvt,sizeof(blinky.timeEvt),0U,0);
    ...
}

Pros and Cons Comparison Table

Pros Cons
Low memory footprint, customizable Steeper learning curve
Strong determinism in priority scheduling, excellent hard real-time experience More configuration points than bare scheduler
Supports hierarchical state machines, clear logic Fewer community examples compared to RTOS
UML modeling toolchain, high development efficiency Commercial licensing requires additional budget

ConclusionQP/C is truly a practical tool for embedded systems, bringing order to complex state machines and task scheduling under event-driven paradigms. Whether you are a hobbyist who loves tinkering or working on commercial projects with high stability requirements, you can benefit from it. For deeper insights and more complete functionalities, head over to the project link below!

Project Link: https://github.com/QuantumLeaps/qpc

Leave a Comment