QP/C++  8.0.0
Real-Time Embedded Framework
Loading...
Searching...
No Matches
qp_port.hpp
Go to the documentation of this file.
1//! @file
2//! @brief Sample QP/C++ port
3//!
4//! @details
5//! This is just an example of a QF port for a generic C99 compiler.
6//! Other specific QF ports will define the QF facilities differently.
7
8#ifndef QP_PORT_HPP_
9#define QP_PORT_HPP_
10
11#include <cstdint> // Exact-width types. C++11 Standard
12
13//! @brief No-return specifier for the Q_onError() callback function.
14//!
15//! @details
16//! If the `Q_NORETURN` macro is undefined, the default definition uses
17//! the C++11 specifier `[[ noreturn ]]`.
18//!
19//! @note
20//! The `Q_NORETURN` macro can be defined in the QP port (typically in
21//! `qep_port.hpp`). If such definition is provided the default won't be used.
22#define Q_NORETURN [[ noreturn ]] void
23
24// QF configuration for the data members of the QActive class ----------------
25//! QP::QActive event queue type used in various QP/C++ ports.
26#define QACTIVE_EQUEUE_TYPE QEQueue
27
28//! QP::QActive "OS-object" type used in various QP/C++ ports.
29#define QACTIVE_OS_OBJ_TYPE void*
30
31//! QP::QActive "thread" type used in various QP/C++ ports.
32#define QACTIVE_THREAD_TYPE void const *
33
34// interrupt disabling mechanism ---------------------------------------------
35//! Disable interrupts
36#define QF_INT_DISABLE() intDisable()
37
38//! Enable interrupts
39#define QF_INT_ENABLE() intEnable()
40
41// QF critical section mechanism ---------------------------------------------
42//! Define the critical section status that was present before entering
43//! the critical section.
44//!
45//! @details
46//! For critical sections that are allowed to nest, the critical section
47//! status must be saved and restored at the end. This macro provides the
48//! storage for saving the status.
49//!
50//! @note
51//! This macro might be empty, in which case the critical section status
52//! is not saved or restored. Such critical sections won't be able to nest.
53//! Also, note that the macro should be invoked without the closing semicolon.
54#define QF_CRIT_STAT std::uint32_t crit_stat_;
55
56//! Enter the critical section
57//!
58//! @details
59//! If the critical section status is provided, the macro saves the
60//! critical section status from before entering the critical section.
61//! Otherwise, the macro just unconditionally enters the critical section
62//! without saving the status.
63#define QF_CRIT_ENTRY() (crit_stat_ = critEntry())
64
65//! Exit the critical section
66//!
67//! @details
68//! If the critical section status is provided, the macro restores the
69//! critical section status saved by QF_CRIT_ENTRY(). Otherwise, the macro
70//! just unconditionally exits the critical section.
71#define QF_CRIT_EXIT() critExit(crit_stat_)
72
73extern "C" {
74
75void intDisable(void);
76void intEnable(void);
77std::uint32_t critEntry(void);
78void critExit(std::uint32_t stat);
79std::uint32_t QK_get_IPSR(void);
80
81} // extern "C"
82
83
84#ifdef QF_MEM_ISOLATE
85
86 ///! Memory isolation requires the context-switch
87 #define QF_ON_CONTEXT_SW 1U
88
89 //! Memory System setting
90 #define QF_MEM_SYS() QF_onMemSys()
91
92 //! Memory Application setting
93 #define QF_MEM_APP() QF_onMemApp()
94
95#endif ///! def QF_MEM_ISOLATE
96
97// QV-specific ---------------------------------------------------------------
98//! Macro to put the CPU to sleep **safely** in the non-preemptive
99//! QV kernel (to be called from QV::onIdle()).
100#define QV_CPU_SLEEP() \
101do { \
102 __disable_interrupt(); \
103 QF_INT_ENABLE(); \
104 __WFI(); \
105 __enable_interrupt(); \
106} while (false)
107
108
109// QK-specific ---------------------------------------------------------------
110/*! Check if the code executes in the ISR context */
111#define QK_ISR_CONTEXT_() (QK_priv_.intNest != 0U)
112
113//! Define the ISR entry sequence
114#define QK_ISR_ENTRY() \
115do { \
116 QF_INT_DISABLE(); \
117 ++QK_priv_.intNest; \
118 QF_QS_ISR_ENTRY(QK_priv_.intNest, QK_currPrio_); \
119 QF_INT_ENABLE(); \
120} while (false)
121
122/*! Define the ISR exit sequence */
123#define QK_ISR_EXIT() \
124do { \
125 QF_INT_DISABLE(); \
126 --QK_priv_.intNest; \
127 if (QK_priv_.intNest == 0U) { \
128 if (QK_sched_() != 0U) { \
129 QK_activate_(); \
130 } \
131 } \
132 QF_INT_ENABLE(); \
133} while (false)
134
135// QXK-specific --------------------------------------------------------------
136//! Check if the code executes in the ISR context
137#define QXK_ISR_CONTEXT_() (QXK_get_IPSR() != 0U)
138
139//! Trigger context switch (used internally in QXK only)
140#define QXK_CONTEXT_SWITCH_() (trigPendSV())
141
142//! Define the ISR entry sequence
143#define QXK_ISR_ENTRY() ((void)0)
144
145//! Define the ISR exit sequence
146#define QXK_ISR_EXIT() do { \
147 QF_INT_DISABLE(); \
148 if (QXK_sched_() != 0U) { \
149 *Q_UINT2PTR_CAST(uint32_t, 0xE000ED04U) = (1U << 28U);\
150 } \
151 QF_INT_ENABLE(); \
152 QXK_ARM_ERRATUM_838869(); \
153} while (false)
154
155// include files -------------------------------------------------------------
156#include "qequeue.hpp" // QK kernel uses the native QP event queue
157#include "qmpool.hpp" // QK kernel uses the native QP memory pool
158#include "qp.hpp" // %QP Framework
159#include "qk.hpp" // QK kernel
160
161#endif // QP_PORT_HPP_
QP natvie, platform-independent, thread-safe event queue interface Backward Traceability
QK/C++ (preemptive non-blocking kernel) platform-independent public interface.
QP native, platform-independent memory pool QP::QMPool interface. Backward Traceability
QP/C++ platform-independent public interface.
void intDisable(void)
void intEnable(void)
std::uint32_t critEntry(void)
std::uint32_t QK_get_IPSR(void)
void critExit(std::uint32_t stat)