QP/C++  7.0.1
Real-Time Embedded Framework
qxk.hpp
Go to the documentation of this file.
1//============================================================================
2// QP/C++ Real-Time Embedded Framework (RTEF)
3// Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
4//
5// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
6//
7// This software is dual-licensed under the terms of the open source GNU
8// General Public License version 3 (or any later version), or alternatively,
9// under the terms of one of the closed source Quantum Leaps commercial
10// licenses.
11//
12// The terms of the open source GNU General Public License version 3
13// can be found at: <www.gnu.org/licenses/gpl-3.0>
14//
15// The terms of the closed source Quantum Leaps commercial licenses
16// can be found at: <www.state-machine.com/licensing>
17//
18// Redistributions in source code must retain this top-level comment block.
19// Plagiarizing this software to sidestep the license obligations is illegal.
20//
21// Contact information:
22// <www.state-machine.com>
23// <info@state-machine.com>
24//============================================================================
31
32#ifndef QXK_HPP
33#define QXK_HPP
34
35#include "qequeue.hpp" // QXK kernel uses the native QF event queue
36#include "qmpool.hpp" // QXK kernel uses the native QF memory pool
37#include "qpset.hpp" // QXK kernel uses the native QF priority set
38
39//============================================================================
40// QF configuration for QXK -- data members of the QActive class...
41
42// QXK event-queue used for AOs
43#define QF_EQUEUE_TYPE QEQueue
44
45// QXK OS-object used to store the private stack poiner for extended threads.
46// (The private stack pointer is NULL for basic-threads).
47//
48#define QF_OS_OBJECT_TYPE void*
49
50// QXK thread type used to store the private Thread-Local Storage pointer.
51#define QF_THREAD_TYPE void*
52
54#define QXK_TLS(type_) (static_cast<type_>(QXK_current()->m_thread))
55
56
57//============================================================================
58namespace QP {
59 class QActive; // forward declaration
60} // namespace QP
61
62//============================================================================
63extern "C" {
64
66struct QXK_Attr {
67 QP::QActive * volatile curr;
68 QP::QActive * volatile next;
69 std::uint8_t volatile actPrio;
70 std::uint8_t volatile lockPrio;
71 std::uint8_t volatile lockHolder;
72 std::uint8_t volatile intNest;
75};
76
78extern QXK_Attr QXK_attr_;
79
81std::uint_fast8_t QXK_sched_(void) noexcept;
82
84// the currently executing AOs.
85//
86void QXK_activate_(void);
87
89QP::QActive *QXK_current(void) noexcept;
90
91#ifdef QXK_ON_CONTEXT_SW
92
114
115#endif // QXK_ON_CONTEXT_SW
116
117} // extern "C"
118
119//============================================================================
120namespace QP {
121
123using QSchedStatus = std::uint_fast16_t;
124
125//============================================================================
136class QXK {
137public:
139 static QSchedStatus schedLock(std::uint_fast8_t const ceiling) noexcept;
140
142 static void schedUnlock(QSchedStatus const stat) noexcept;
143
154 static void onIdle(void);
155};
156
157} // namespace QP
158
159
160//============================================================================
161// interface used only inside QF, but not in applications
162
163#ifdef QP_IMPL
164
165 #ifndef QXK_ISR_CONTEXT_
167 // (ISR vs. thread).
170 #define QXK_ISR_CONTEXT_() \
171 (QXK_attr_.intNest != 0U)
172 #endif // QXK_ISR_CONTEXT_
173
174 // QXK-specific scheduler locking
176 // that needs to be preserved to allow nesting of locks.
177 //
178 #define QF_SCHED_STAT_ QSchedStatus lockStat_;
179
181 #define QF_SCHED_LOCK_(prio_) do { \
182 if (QXK_ISR_CONTEXT_()) { \
183 lockStat_ = 0xFFU; \
184 } else { \
185 lockStat_ = QXK::schedLock((prio_)); \
186 } \
187 } while (false)
188
190 #define QF_SCHED_UNLOCK_() do { \
191 if (lockStat_ != 0xFFU) { \
192 QXK::schedUnlock(lockStat_); \
193 } \
194 } while (false)
195
196 // QXK-specific native event queue operations...
197 #define QACTIVE_EQUEUE_WAIT_(me_) \
198 Q_ASSERT_ID(110, (me_)->m_eQueue.m_frontEvt != nullptr)
199
200 #define QACTIVE_EQUEUE_SIGNAL_(me_) do { \
201 QXK_attr_.readySet.insert( \
202 static_cast<std::uint_fast8_t>((me_)->m_dynPrio)); \
203 if (!QXK_ISR_CONTEXT_()) { \
204 if (QXK_sched_() != 0U) { \
205 QXK_activate_(); \
206 } \
207 } \
208 } while (false)
209
210 // QXK-specific native QF event pool operations...
211 #define QF_EPOOL_TYPE_ QMPool
212 #define QF_EPOOL_INIT_(p_, poolSto_, poolSize_, evtSize_) \
213 (p_).init((poolSto_), (poolSize_), (evtSize_))
214 #define QF_EPOOL_EVENT_SIZE_(p_) ((p_).m_blockSize)
215 #define QF_EPOOL_GET_(p_, e_, m_, qs_id_) \
216 ((e_) = static_cast<QEvt *>((p_).get((m_), (qs_id_))))
217 #define QF_EPOOL_PUT_(p_, e_, qs_id_) ((p_).put((e_), (qs_id_)))
218
219#endif // QP_IMPL
220
221#endif // QXK_HPP
QActive active object (based on QP::QHsm implementation)
Definition: qf.hpp:136
QXK services.
Definition: qxk.hpp:136
static QSchedStatus schedLock(std::uint_fast8_t const ceiling) noexcept
QXK selective scheduler lock.
Definition: qxk.cpp:232
static void schedUnlock(QSchedStatus const stat) noexcept
QXK selective scheduler unlock.
Definition: qxk.cpp:287
static void onIdle(void)
QXK idle callback (customized in BSPs for QXK)
namespace associated with the QP/C++ framework
Definition: exa_native.dox:1
std::uint_fast16_t QSchedStatus
The scheduler lock status.
Definition: qk.hpp:110
platform-independent fast "raw" thread-safe event queue interface
platform-independent memory pool QP::QMPool interface.
platform-independent priority sets of 8 or 64 elements.
std::uint8_t volatile lockPrio
lock prio (0 == no-lock)
Definition: qxk.hpp:70
std::uint8_t volatile lockHolder
prio of the lock holder
Definition: qxk.hpp:71
void QXK_onContextSw(QP::QActive *prev, QP::QActive *next)
QXK context switch callback (customized in BSPs for QXK)
QP::QActive * idleThread
pointer to the idle thread
Definition: qxk.hpp:73
void QXK_activate_(void)
QXK activator activates the next active object. The activated AO preempts.
Definition: qxk.cpp:417
std::uint_fast8_t QXK_sched_(void) noexcept
QXK scheduler finds the highest-priority thread ready to run.
Definition: qxk.cpp:340
QP::QActive *volatile next
next thread to execute
Definition: qxk.hpp:68
std::uint8_t volatile actPrio
prio of the active basic thread
Definition: qxk.hpp:69
QP::QPSet readySet
ready-set of all threads
Definition: qxk.hpp:74
QP::QActive *volatile curr
currently executing thread
Definition: qxk.hpp:67
QXK_Attr QXK_attr_
global attributes of the QXK kernel
Definition: qxk.cpp:54
QP::QActive * QXK_current(void) noexcept
return the currently executing active-object/thread
Definition: qxk.cpp:549
std::uint8_t volatile intNest
ISR nesting level.
Definition: qxk.hpp:72
attributes of the QXK kernel
Definition: qxk.hpp:66
Priority Set of up to 32 elements *‍/.
Definition: qpset.hpp:68