QP/C 6.9.1
qxk.h
Go to the documentation of this file.
1 
41 #ifndef QXK_H
42 #define QXK_H
43 
44 #include "qequeue.h" /* QXK kernel uses the native QP event queue */
45 #include "qmpool.h" /* QXK kernel uses the native QP memory pool */
46 #include "qpset.h" /* QXK kernel uses the native QP priority set */
47 
48 /****************************************************************************/
49 /* QF configuration for QXK -- data members of the QActive class... */
50 
51 /* QXK event-queue used for AOs */
52 #define QF_EQUEUE_TYPE QEQueue
53 
54 /* QXK OS-object used to store the private stack poiner for extended threads.
55 * (The private stack pointer is NULL for basic-threads).
56 */
57 #define QF_OS_OBJECT_TYPE void*
58 
59 /* QXK thread type used to store the private Thread-Local Storage pointer. */
60 #define QF_THREAD_TYPE void*
61 
63 #define QXK_TLS(type_) ((type_)QXK_current()->thread)
64 
65 /****************************************************************************/
66 struct QActive; /* forward declaration */
67 
68 /****************************************************************************/
70 typedef struct {
71  struct QActive * volatile curr;
72  struct QActive * volatile next;
73  uint8_t volatile actPrio;
74  uint8_t volatile lockPrio;
75  uint8_t volatile lockHolder;
76  uint8_t volatile intNest;
77  struct QActive * idleThread;
79 } QXK_PrivAttr;
80 
82 extern QXK_PrivAttr QXK_attr_;
83 
84 /****************************************************************************/
85 #ifdef QXK_ON_CONTEXT_SW
86 
107  void QXK_onContextSw(struct QActive *prev, struct QActive *next);
108 
109 #endif /* QXK_ON_CONTEXT_SW */
110 
122 void QXK_onIdle(void);
123 
124 /****************************************************************************/
127 
131 void QXK_activate_(void);
132 
133 /****************************************************************************/
135 struct QActive *QXK_current(void);
136 
137 /****************************************************************************/
142 
145 
147 void QXK_schedUnlock(QSchedStatus stat);
148 
149 /****************************************************************************/
150 /* interface used only inside QP implementation, but not in applications */
151 #ifdef QP_IMPL
152 
153  #ifndef QXK_ISR_CONTEXT_
154 
159  #define QXK_ISR_CONTEXT_() (QXK_attr_.intNest != 0U)
160  #endif /* QXK_ISR_CONTEXT_ */
161 
162  /* QF-specific scheduler locking */
166  #define QF_SCHED_STAT_ QSchedStatus lockStat_;
167 
169  #define QF_SCHED_LOCK_(prio_) do { \
170  if (QXK_ISR_CONTEXT_()) { \
171  lockStat_ = 0xFFU; \
172  } else { \
173  lockStat_ = QXK_schedLock((prio_)); \
174  } \
175  } while (false)
176 
178  #define QF_SCHED_UNLOCK_() do { \
179  if (lockStat_ != 0xFFU) { \
180  QXK_schedUnlock(lockStat_); \
181  } \
182  } while (false)
183 
184  #define QACTIVE_EQUEUE_WAIT_(me_) \
185  (Q_ASSERT_ID(110, (me_)->eQueue.frontEvt != (QEvt *)0))
186 
187  #define QACTIVE_EQUEUE_SIGNAL_(me_) do { \
188  QPSet_insert(&QXK_attr_.readySet, (uint_fast8_t)(me_)->dynPrio); \
189  if (!QXK_ISR_CONTEXT_()) { \
190  if (QXK_sched_() != 0U) { \
191  QXK_activate_(); \
192  } \
193  } \
194  } while (false)
195 
196  /* native QF event pool operations */
197  #define QF_EPOOL_TYPE_ QMPool
198  #define QF_EPOOL_INIT_(p_, poolSto_, poolSize_, evtSize_) \
199  (QMPool_init(&(p_), (poolSto_), (poolSize_), (evtSize_)))
200  #define QF_EPOOL_EVENT_SIZE_(p_) ((uint_fast16_t)(p_).blockSize)
201  #define QF_EPOOL_GET_(p_, e_, m_, qs_id_) \
202  ((e_) = (QEvt *)QMPool_get(&(p_), (m_), (qs_id_)))
203  #define QF_EPOOL_PUT_(p_, e_, qs_id_) \
204  (QMPool_put(&(p_), (e_), (qs_id_)))
205 
206 #endif /* QP_IMPL */
207 
208 #endif /* QXK_H */
uint8_t
unsigned char uint8_t
exact-width 8-bit unsigned int
Definition: 16bit/stdint.h:29
QXK_schedLock
QSchedStatus QXK_schedLock(uint_fast8_t ceiling)
QXK Scheduler lock.
Definition: qxk.c:249
qequeue.h
QP natvie, platform-independent, thread-safe event queue interface.
QXK_onContextSw
void QXK_onContextSw(struct QActive *prev, struct QActive *next)
QXK context switch callback (customized in BSPs for QXK)
QXK_PrivAttr::curr
struct QActive *volatile curr
current thread pointer (NULL=basic)
Definition: qxk.h:71
QXK_onIdle
void QXK_onIdle(void)
QXK idle callback (customized in BSPs for QXK)
QXK_PrivAttr
attributes of the QXK kernel
Definition: qxk.h:70
QXK_activate_
void QXK_activate_(void)
QXK activator activates the next active object.
Definition: qxk.c:431
qmpool.h
QP native, platform-independent memory pool QMPool interface.
QActive
Active Object base class (based on QHsm implementation)
Definition: qf.h:116
QXK_sched_
uint_fast8_t QXK_sched_(void)
QXK scheduler finds the highest-priority thread ready to run.
Definition: qxk.c:353
uint_fast8_t
unsigned int uint_fast8_t
fast at-least 8-bit unsigned int
Definition: 16bit/stdint.h:36
QXK_attr_
QXK_PrivAttr QXK_attr_
global attributes of the QXK kernel
Definition: qxk.c:59
QSchedStatus
uint_fast16_t QSchedStatus
QK Scheduler locking.
Definition: qk.h:132
QXK_PrivAttr::idleThread
struct QActive * idleThread
pointer to the idle thread
Definition: qxk.h:77
QXK_PrivAttr::actPrio
uint8_t volatile actPrio
prio of the active AO
Definition: qxk.h:73
QXK_PrivAttr::lockPrio
uint8_t volatile lockPrio
lock prio (0 == no-lock)
Definition: qxk.h:74
qpset.h
QP native, platform-independent priority sets of 32 or 64 elements.
QXK_PrivAttr::lockHolder
uint8_t volatile lockHolder
prio of the lock holder
Definition: qxk.h:75
QXK_PrivAttr::readySet
QPSet readySet
ready-set of all threads
Definition: qxk.h:78
QXK_PrivAttr::next
struct QActive *volatile next
next thread pointer to execute
Definition: qxk.h:72
QXK_schedUnlock
void QXK_schedUnlock(QSchedStatus stat)
QXK Scheduler unlock.
Definition: qxk.c:305
QXK_PrivAttr::intNest
uint8_t volatile intNest
ISR nesting level.
Definition: qxk.h:76
QPSet
Priority Set of up to 32 elements.
Definition: qpset.h:68
QSchedStatus
uint_fast16_t QSchedStatus
QXK Scheduler locking.
Definition: qxk.h:141
QXK_current
struct QActive * QXK_current(void)
return the currently executing active-object/thread
Definition: qxk.c:565
uint_fast16_t
unsigned int uint_fast16_t
fast at-least 16-bit unsigned int
Definition: 16bit/stdint.h:38