QP/C 6.9.0
qk.h
Go to the documentation of this file.
1 
41 #ifndef QK_H
42 #define QK_H
43 
44 #include "qequeue.h" /* QK kernel uses the native QP event queue */
45 #include "qmpool.h" /* QK kernel uses the native QP memory pool */
46 #include "qpset.h" /* QK kernel uses the native QP priority set */
47 
48 /****************************************************************************/
49 /* QF configuration for QK -- data members of the QActive class... */
50 
51 /* QK event-queue used for AOs */
52 #define QF_EQUEUE_TYPE QEQueue
53 
54 /* QK thread type used for AOs
55 * QK uses this member to store the private Thread-Local Storage pointer.
56 */
57 #define QF_THREAD_TYPE void*
58 
59 
60 /****************************************************************************/
62 typedef struct {
63  uint8_t volatile actPrio;
64  uint8_t volatile nextPrio;
65  uint8_t volatile lockPrio;
66  uint8_t volatile lockHolder;
67  uint8_t volatile intNest;
69 } QK_PrivAttr;
70 
72 extern QK_PrivAttr QK_attr_;
73 
74 /****************************************************************************/
75 #ifdef QK_ON_CONTEXT_SW
76 
77  struct QActive; /* forward declaration */
78 
99  void QK_onContextSw(struct QActive *prev, struct QActive *next);
100 
101 #endif /* QK_ON_CONTEXT_SW */
102 
116 void QK_onIdle(void);
117 
118 
119 /****************************************************************************/
121 uint_fast8_t QK_sched_(void);
122 
126 void QK_activate_(void);
127 
128 /****************************************************************************/
133 
136 
138 void QK_schedUnlock(QSchedStatus stat);
139 
140 /****************************************************************************/
141 /* interface used only inside QP implementation, but not in applications */
142 #ifdef QP_IMPL
143 
144  #ifndef QK_ISR_CONTEXT_
145 
150  #define QK_ISR_CONTEXT_() (QK_attr_.intNest != 0U)
151  #endif /* QK_ISR_CONTEXT_ */
152 
153  /* QK-specific scheduler locking */
157  #define QF_SCHED_STAT_ QSchedStatus lockStat_;
158 
160  #define QF_SCHED_LOCK_(prio_) do { \
161  if (QK_ISR_CONTEXT_()) { \
162  lockStat_ = 0xFFU; \
163  } else { \
164  lockStat_ = QK_schedLock((prio_)); \
165  } \
166  } while (false)
167 
169  #define QF_SCHED_UNLOCK_() do { \
170  if (lockStat_ != 0xFFU) { \
171  QK_schedUnlock(lockStat_); \
172  } \
173  } while (false)
174 
175  /* native event queue operations... */
176  #define QACTIVE_EQUEUE_WAIT_(me_) \
177  (Q_ASSERT_ID(110, (me_)->eQueue.frontEvt != (QEvt *)0))
178 
179  #define QACTIVE_EQUEUE_SIGNAL_(me_) do { \
180  QPSet_insert(&QK_attr_.readySet, (uint_fast8_t)(me_)->prio); \
181  if (!QK_ISR_CONTEXT_()) { \
182  if (QK_sched_() != 0U) { \
183  QK_activate_(); \
184  } \
185  } \
186  } while (false)
187 
188  /* native QF event pool operations */
189  #define QF_EPOOL_TYPE_ QMPool
190  #define QF_EPOOL_INIT_(p_, poolSto_, poolSize_, evtSize_) \
191  (QMPool_init(&(p_), (poolSto_), (poolSize_), (evtSize_)))
192  #define QF_EPOOL_EVENT_SIZE_(p_) ((uint_fast16_t)(p_).blockSize)
193  #define QF_EPOOL_GET_(p_, e_, m_) ((e_) = (QEvt *)QMPool_get(&(p_), (m_)))
194  #define QF_EPOOL_PUT_(p_, e_) (QMPool_put(&(p_), (e_)))
195 
196 #endif /* QP_IMPL */
197 
198 #endif /* QK_H */
199 
uint8_t
unsigned char uint8_t
exact-width 8-bit unsigned int
Definition: 16bit/stdint.h:29
qequeue.h
QP natvie, platform-independent, thread-safe event queue interface.
QK_onContextSw
void QK_onContextSw(struct QActive *prev, struct QActive *next)
QK context switch callback (customized in BSPs for QK)
QK_PrivAttr::lockHolder
uint8_t volatile lockHolder
prio of the AO holding the lock
Definition: qk.h:66
QK_attr_
QK_PrivAttr QK_attr_
global private attributes of the QK kernel
Definition: qk.c:59
QK_PrivAttr::readySet
QPSet readySet
QK ready-set of AOs.
Definition: qk.h:68
qmpool.h
QP native, platform-independent memory pool QMPool interface.
QActive
Active Object base class (based on QHsm implementation)
Definition: qf.h:116
QK_PrivAttr
private attributes of the QK kernel
Definition: qk.h:62
uint_fast8_t
unsigned int uint_fast8_t
fast at-least 8-bit unsigned int
Definition: 16bit/stdint.h:36
QK_PrivAttr::nextPrio
uint8_t volatile nextPrio
prio of the next AO to execute
Definition: qk.h:64
QSchedStatus
uint_fast16_t QSchedStatus
QK Scheduler locking.
Definition: qk.h:132
QK_PrivAttr::actPrio
uint8_t volatile actPrio
prio of the active AO
Definition: qk.h:63
QK_schedLock
QSchedStatus QK_schedLock(uint_fast8_t ceiling)
QK Scheduler lock.
Definition: qk.c:230
qpset.h
QP native, platform-independent priority sets of 32 or 64 elements.
QK_sched_
uint_fast8_t QK_sched_(void)
QK scheduler finds the highest-priority thread ready to run.
Definition: qk.c:328
QK_activate_
void QK_activate_(void)
QK activator activates the next active object.
Definition: qk.c:358
QK_schedUnlock
void QK_schedUnlock(QSchedStatus stat)
QK Scheduler unlock.
Definition: qk.c:280
QK_PrivAttr::intNest
uint8_t volatile intNest
ISR nesting level.
Definition: qk.h:67
QK_PrivAttr::lockPrio
uint8_t volatile lockPrio
lock prio (0 == no-lock)
Definition: qk.h:65
QK_onIdle
void QK_onIdle(void)
QK idle callback (customized in BSPs for QK)
QPSet
Priority Set of up to 32 elements.
Definition: qpset.h:68
uint_fast16_t
unsigned int uint_fast16_t
fast at-least 16-bit unsigned int
Definition: 16bit/stdint.h:38