The Interface Viewpoint focuses on defining and describing the interfaces between QP Framework and the outside layers, such as the underlying operating system (OS Abstraction Layer) and the QP Application.
The OS Abstraction Layer (OSAL) shown in Figure SDS-OSAL, insulates QP Framework from the underlying Operating System (OS), such as one of the built-in real-time kernels, 3rd-party RTOS, or a General-Purpose OS. The OSAL provides both the abstract Operating System API (OSAL API), see Figure SDS-OSAL [2A], and the implementation of this API for the specific OS (Figure SDS-OSAL [2B]). The main idea of an OSAL is that the OSAL API is fixed and is used used inside the QP Framework source code, while the OSAL implementation (called the "QP port") depends on the specific underlying OS. In other words, there is a separate "QP port" for every supported real-time kernel, 3rd-party RTOS or GPOS. The main focus of this section is to describe the design of the OSAL API, with the specific examples are taken from various "QP ports" implementing the OSAL API.
Critical section is a non-blocking mutual exclusion mechanism that protects a sequence of instructions from preemption. QP Framework, just like any other system-level software, must internally use critical sections to guarantee concurrency-safe operation. The critical section implementation depends on the underlying OS, so the QP OSAL must provide an efficient critical section abstraction to insulate QP Framework from the specifics of teh underlying OS.
For example, in single-core embedded systems, critical sections are typically implemented by disabling interrupts upon the entry to the section and re-enabling them upon the exit. This is effective because in such systems interrupts are the only way preemption can be initiated (both interrupt preemption but also thread preemption in a real-time kernel). However, other systems (e.g., multicore) might use a different critical section mechanism (e.g. spin-lock). Some other systems (e.g., general purpose OS) might implement user-space critical sections with the traditional mutual-exclusion mechanism, such as a mutex. The critical section abstraction in QP OSAL must accommodate all such critical section implementations.
Critical Section API
These macros support two main types of critical section implementations:
QF_CRIT_STAT
);QF_CRIT_STAT
).Internally, QP Framework uses the critical section macros in the following generic way:
[1]
If the macro QF_CRIT_STAT
is not-empty, it allocates a local critical-section-status variable. Otherwise, if the macro is empty, the line does nothing.
[2]
the macro QF_CRIT_ENTRY()
enters critical section, which saves the critical section status into the status-variable (if it was defined at step [1]
)
[3]
this code executes inside the critical section protection
[4]
the macro QF_CRIT_EXIT()
exits critical section, which restores the critical section status from the status variable (if it was defined at step [1]
)
Example save-and-restore critical section status macros (MSP430 CPU):
TBD...