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