QP/C++ 6.9.3
qxk.hpp
Go to the documentation of this file.
1 
40 #ifndef QXK_HPP
41 #define QXK_HPP
42 
43 #include "qequeue.hpp" // QXK kernel uses the native QF event queue
44 #include "qmpool.hpp" // QXK kernel uses the native QF memory pool
45 #include "qpset.hpp" // QXK kernel uses the native QF priority set
46 
47 //****************************************************************************
48 // QF configuration for QXK -- data members of the QActive class...
49 
50 // QXK event-queue used for AOs
51 #define QF_EQUEUE_TYPE QEQueue
52 
53 // QXK OS-object used to store the private stack poiner for extended threads.
54 // (The private stack pointer is NULL for basic-threads).
55 //
56 #define QF_OS_OBJECT_TYPE void*
57 
58 // QXK thread type used to store the private Thread-Local Storage pointer.
59 #define QF_THREAD_TYPE void*
60 
62 #define QXK_TLS(type_) (static_cast<type_>(QXK_current()->m_thread))
63 
64 
65 //****************************************************************************
66 namespace QP {
67  class QActive; // forward declaration
68 } // namespace QP
69 
70 //****************************************************************************
71 extern "C" {
72 
74 struct QXK_Attr {
75  QP::QActive * volatile curr;
76  QP::QActive * volatile next;
77  std::uint8_t volatile actPrio;
80  std::uint8_t volatile intNest;
83 };
84 
86 extern QXK_Attr QXK_attr_;
87 
89 std::uint_fast8_t QXK_sched_(void) noexcept;
90 
92 // the currently executing AOs.
93 //
94 void QXK_activate_(void);
95 
97 QP::QActive *QXK_current(void) noexcept;
98 
99 #ifdef QXK_ON_CONTEXT_SW
100 
122 
123 #endif // QXK_ON_CONTEXT_SW
124 
125 } // extern "C"
126 
127 //****************************************************************************
128 namespace QP {
129 
132 
133 //****************************************************************************
144 class QXK {
145 public:
147  static QSchedStatus schedLock(std::uint_fast8_t const ceiling) noexcept;
148 
150  static void schedUnlock(QSchedStatus const stat) noexcept;
151 
162  static void onIdle(void);
163 };
164 
165 } // namespace QP
166 
167 
168 //****************************************************************************
169 // interface used only inside QF, but not in applications
170 
171 #ifdef QP_IMPL
172 
173  #ifndef QXK_ISR_CONTEXT_
175  // (ISR vs. thread).
178  #define QXK_ISR_CONTEXT_() \
179  (QXK_attr_.intNest != 0U)
180  #endif // QXK_ISR_CONTEXT_
181 
182  // QXK-specific scheduler locking
184  // that needs to be preserved to allow nesting of locks.
185  //
186  #define QF_SCHED_STAT_ QSchedStatus lockStat_;
187 
189  #define QF_SCHED_LOCK_(prio_) do { \
190  if (QXK_ISR_CONTEXT_()) { \
191  lockStat_ = 0xFFU; \
192  } else { \
193  lockStat_ = QXK::schedLock((prio_)); \
194  } \
195  } while (false)
196 
198  #define QF_SCHED_UNLOCK_() do { \
199  if (lockStat_ != 0xFFU) { \
200  QXK::schedUnlock(lockStat_); \
201  } \
202  } while (false)
203 
204  // QXK-specific native event queue operations...
205  #define QACTIVE_EQUEUE_WAIT_(me_) \
206  Q_ASSERT_ID(110, (me_)->m_eQueue.m_frontEvt != nullptr)
207 
208  #define QACTIVE_EQUEUE_SIGNAL_(me_) do { \
209  QXK_attr_.readySet.insert( \
210  static_cast<std::uint_fast8_t>((me_)->m_dynPrio)); \
211  if (!QXK_ISR_CONTEXT_()) { \
212  if (QXK_sched_() != 0U) { \
213  QXK_activate_(); \
214  } \
215  } \
216  } while (false)
217 
218  // QXK-specific native QF event pool operations...
219  #define QF_EPOOL_TYPE_ QMPool
220  #define QF_EPOOL_INIT_(p_, poolSto_, poolSize_, evtSize_) \
221  (p_).init((poolSto_), (poolSize_), (evtSize_))
222  #define QF_EPOOL_EVENT_SIZE_(p_) ((p_).getBlockSize())
223  #define QF_EPOOL_GET_(p_, e_, m_, qs_id_) \
224  ((e_) = static_cast<QEvt *>((p_).get((m_), (qs_id_))))
225  #define QF_EPOOL_PUT_(p_, e_, qs_id_) ((p_).put((e_), (qs_id_)))
226 
227 #endif // QP_IMPL
228 
229 #endif // QXK_HPP
230 
unsigned int uint_fast16_t
fast at-least 16-bit unsigned int
Definition: 16bit/stdint.h:38
unsigned char uint8_t
exact-width 8-bit unsigned int
Definition: 16bit/stdint.h:29
unsigned int uint_fast8_t
fast at-least 8-bit unsigned int
Definition: 16bit/stdint.h:36
QActive active object (based on QP::QHsm implementation)
Definition: qf.hpp:144
QXK services.
Definition: qxk.hpp:144
static QSchedStatus schedLock(std::uint_fast8_t const ceiling) noexcept
QXK selective scheduler lock.
Definition: qxk.cpp:238
static void schedUnlock(QSchedStatus const stat) noexcept
QXK selective scheduler unlock.
Definition: qxk.cpp:293
static void onIdle(void)
QXK idle callback (customized in BSPs for QXK)
namespace associated with the QP/C++ framework
Definition: struct.dox:1
std::uint_fast16_t QSchedStatus
The scheduler lock status.
Definition: qk.hpp:119
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:78
std::uint8_t volatile lockHolder
prio of the lock holder
Definition: qxk.hpp:79
QP::QActive * QXK_current(void) noexcept
return the currently executing active-object/thread
Definition: qxk.cpp:555
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:81
void QXK_activate_(void)
QXK activator activates the next active object. The activated AO preempts.
Definition: qxk.cpp:423
std::uint_fast8_t QXK_sched_(void) noexcept
QXK scheduler finds the highest-priority thread ready to run.
Definition: qxk.cpp:346
QP::QActive *volatile next
next thread to execute
Definition: qxk.hpp:76
std::uint8_t volatile actPrio
prio of the active basic thread
Definition: qxk.hpp:77
QP::QPSet readySet
ready-set of all threads
Definition: qxk.hpp:82
QP::QActive *volatile curr
currently executing thread
Definition: qxk.hpp:75
QXK_Attr QXK_attr_
global attributes of the QXK kernel
Definition: qxk.cpp:60
std::uint8_t volatile intNest
ISR nesting level.
Definition: qxk.hpp:80
attributes of the QXK kernel
Definition: qxk.hpp:74
Priority Set of up to 32 elements *‍/.
Definition: qpset.hpp:76