QP/C  7.3.4
Real-Time Embedded Framework
Loading...
Searching...
No Matches
qxk.h
Go to the documentation of this file.
1//$file${include::qxk.h} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
2//
3// Model: qpc.qm
4// File: ${include::qxk.h}
5//
6// This code has been generated by QM 6.1.1 <www.state-machine.com/qm>.
7// DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
8//
9// This code is covered by the following QP license:
10// License # : LicenseRef-QL-dual
11// Issued to : Any user of the QP/C real-time embedded framework
12// Framework(s) : qpc
13// Support ends : 2024-12-31
14// License scope:
15//
16// Copyright (C) 2005 Quantum Leaps, LLC <state-machine.com>.
17//
18// Q u a n t u m L e a P s
19// ------------------------
20// Modern Embedded Software
21//
22// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
23//
24// This software is dual-licensed under the terms of the open source GNU
25// General Public License version 3 (or any later version), or alternatively,
26// under the terms of one of the closed source Quantum Leaps commercial
27// licenses.
28//
29// The terms of the open source GNU General Public License version 3
30// can be found at: <www.gnu.org/licenses/gpl-3.0>
31//
32// The terms of the closed source Quantum Leaps commercial licenses
33// can be found at: <www.state-machine.com/licensing>
34//
35// Redistributions in source code must retain this top-level comment block.
36// Plagiarizing this software to sidestep the license obligations is illegal.
37//
38// Contact information:
39// <www.state-machine.com/licensing>
40// <info@state-machine.com>
41//
42//$endhead${include::qxk.h} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
43#ifndef QXK_H_
44#define QXK_H_
45
46//$declare${QXK::QXK} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
47
48//${QXK::QXK} ................................................................
49//! @class QXK
50typedef struct QXK {
51 //! @cond INTERNAL
52 uint8_t dummy;
53 //! @endcond
54} QXK;
55//$enddecl${QXK::QXK} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56
57//$declare${QXK::QSchedStatus} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
58
59//${QXK::QSchedStatus} .......................................................
60typedef uint_fast16_t QSchedStatus;
61//$enddecl${QXK::QSchedStatus} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
62
63//$declare${QXK::QXTHREAD_NO_TIMEOUT} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
64
65//${QXK::QXTHREAD_NO_TIMEOUT} ................................................
66#define QXTHREAD_NO_TIMEOUT ((QTimeEvtCtr)0)
67//$enddecl${QXK::QXTHREAD_NO_TIMEOUT} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
68
69//$declare${QXK::QXK-base} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
70
71//${QXK::QXK-base::Attr} .....................................................
72//! @class QXK_Attr
73typedef struct {
74// private:
75
76 //! @memberof QXK_Attr
77 struct QActive * volatile curr;
78
79 //! @memberof QXK_Attr
80 struct QActive * volatile next;
81
82 //! @memberof QXK_Attr
83 struct QActive * volatile prev;
84
85 //! @memberof QXK_Attr
86 uint_fast8_t volatile actPrio;
87
88 //! @memberof QXK_Attr
89 uint_fast8_t volatile lockCeil;
90
91 //! @memberof QXK_Attr
92 uint_fast8_t volatile lockHolder;
93
94 //! @memberof QXK_Attr
96
97#ifndef Q_UNSAFE
98 //! @memberof QXK_Attr
100#endif // ndef Q_UNSAFE
101} QXK_Attr;
102
103//${QXK::QXK-base::priv_} ....................................................
104//! @static @private @memberof QXK
106
107//${QXK::QXK-base::onIdle} ...................................................
108//! @static @public @memberof QXK
109void QXK_onIdle(void);
110
111//${QXK::QXK-base::schedLock} ................................................
112//! @static @public @memberof QXK
113QSchedStatus QXK_schedLock(uint_fast8_t const ceiling);
114
115//${QXK::QXK-base::schedUnlock} ..............................................
116//! @static @public @memberof QXK
117void QXK_schedUnlock(QSchedStatus const stat);
118
119//${QXK::QXK-base::current} ..................................................
120//! @static @public @memberof QXK
121QActive * QXK_current(void);
122
123//${QXK::QXK-base::sched_} ...................................................
124//! @static @private @memberof QXK
125uint_fast8_t QXK_sched_(void);
126
127//${QXK::QXK-base::activate_} ................................................
128//! @static @private @memberof QXK
129void QXK_activate_(void);
130
131//${QXK::QXK-base::contextSw_} ...............................................
132//! @static @public @memberof QXK
133void QXK_contextSw_(QActive * const next);
134
135//${QXK::QXK-base::threadExit_} ..............................................
136//! @static @private @memberof QXK
137void QXK_threadExit_(void);
138//$enddecl${QXK::QXK-base} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
139
140//$declare${QXK::QXThread} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
141
142//${QXK::QXThread} ...........................................................
143//! @class QXThread
144//! @extends QActive
145typedef struct QXThread {
146// protected:
148
149// private:
150
151 //! @private @memberof QXThread
153} QXThread;
154
155//! @static @private @memberof QXThread
156//! dummy static member to force QM to generate 'struct QXThread'
158
159// public:
160
161//! @public @memberof QXThread
162void QXThread_ctor(QXThread * const me,
163 QXThreadHandler const handler,
164 uint_fast8_t const tickRate);
165
166//! @public @memberof QXThread
167bool QXThread_delay(QTimeEvtCtr const nTicks);
168
169//! @public @memberof QXThread
170bool QXThread_delayCancel(QXThread * const me);
171
172//! @static @public @memberof QXThread
173QEvt const * QXThread_queueGet(QTimeEvtCtr const nTicks);
174
175// private:
176
177//! @private @memberof QXThread
178void QXThread_block_(QXThread const * const me);
179
180//! @private @memberof QXThread
181void QXThread_unblock_(QXThread const * const me);
182
183//! @private @memberof QXThread
184void QXThread_timeout_(QActive * const act);
185
186//! @private @memberof QXThread
187void QXThread_teArm_(QXThread * const me,
188 enum_t const sig,
189 QTimeEvtCtr const nTicks);
190
191//! @private @memberof QXThread
192bool QXThread_teDisarm_(QXThread * const me);
193
194// public:
195
196//! @private @memberof QXThread
198 QActive * const me,
199 QXThreadHandler const handler,
200 void * const stkSto,
201 uint_fast16_t const stkSize);
202//$enddecl${QXK::QXThread} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
203
204//$declare${QXK::QXSemaphore} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
205
206//${QXK::QXSemaphore} ........................................................
207//! @class QXSemaphore
208typedef struct {
209// private:
210
211 //! @private @memberof QXSemaphore
213
214 //! @private @memberof QXSemaphore
215 uint8_t volatile count;
216
217 //! @private @memberof QXSemaphore
218 uint8_t max_count;
220
221// public:
222
223//! @public @memberof QXSemaphore
225 uint_fast8_t const count,
226 uint_fast8_t const max_count);
227
228//! @public @memberof QXSemaphore
229bool QXSemaphore_wait(QXSemaphore * const me,
230 QTimeEvtCtr const nTicks);
231
232//! @public @memberof QXSemaphore
233bool QXSemaphore_tryWait(QXSemaphore * const me);
234
235//! @public @memberof QXSemaphore
236bool QXSemaphore_signal(QXSemaphore * const me);
237//$enddecl${QXK::QXSemaphore} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
238
239//$declare${QXK::QXMutex} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
240
241//${QXK::QXMutex} ............................................................
242//! @class QXMutex
243typedef struct {
244// private:
245
246 //! @private @memberof QXMutex
248
249 //! @private @memberof QXMutex
251} QXMutex;
252
253// public:
254
255//! @public @memberof QXMutex
256void QXMutex_init(QXMutex * const me,
257 QPrioSpec const prioSpec);
258
259//! @public @memberof QXMutex
260bool QXMutex_lock(QXMutex * const me,
261 QTimeEvtCtr const nTicks);
262
263//! @public @memberof QXMutex
264bool QXMutex_tryLock(QXMutex * const me);
265
266//! @public @memberof QXMutex
267void QXMutex_unlock(QXMutex * const me);
268//$enddecl${QXK::QXMutex} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
269
270//$declare${QXK-macros} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
271
272//${QXK-macros::QXTHREAD_START} ..............................................
273#define QXTHREAD_START(me_, prioSpec_, qSto_, qLen_, stkSto_, stkSize_, par_) QACTIVE_START((me_), (prioSpec_), (qSto_), (qLen_), \
274 (stkSto_), (stkSize_), (par_))
275
276//${QXK-macros::QXTHREAD_POST_X} .............................................
277#define QXTHREAD_POST_X(me_, e_, margin_, sender_) \
278 QACTIVE_POST_X(&(me_)->super, (e_), (margin_), (sender_))
279//$enddecl${QXK-macros} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
280
281//============================================================================
282// interface used only for internal implementation, but not in applications
283#ifdef QP_IMPL
284
285//$declare${QXK-impl} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
286
287//${QXK-impl::QF_SCHED_STAT_} ................................................
288#define QF_SCHED_STAT_ QSchedStatus lockStat_;
289
290//${QXK-impl::QF_SCHED_LOCK_} ................................................
291#define QF_SCHED_LOCK_(ceil_) do { \
292 if (QXK_ISR_CONTEXT_()) { \
293 lockStat_ = 0xFFU; \
294 } else { \
295 lockStat_ = QXK_schedLock((ceil_)); \
296 } \
297} while (false)
298
299//${QXK-impl::QF_SCHED_UNLOCK_} ..............................................
300#define QF_SCHED_UNLOCK_() do { \
301 if (lockStat_ != 0xFFU) { \
302 QXK_schedUnlock(lockStat_); \
303 } \
304} while (false)
305
306//${QXK-impl::QACTIVE_EQUEUE_WAIT_} ..........................................
307#define QACTIVE_EQUEUE_WAIT_(me_) \
308 Q_ASSERT_INCRIT(310, (me_)->eQueue.frontEvt != (QEvt *)0)
309
310//${QXK-impl::QACTIVE_EQUEUE_SIGNAL_} ........................................
311#ifndef Q_UNSAFE
312#define QACTIVE_EQUEUE_SIGNAL_(me_) do { \
313 QPSet_insert(&QXK_priv_.readySet, (uint_fast8_t)(me_)->prio); \
314 QPSet_update_(&QXK_priv_.readySet, &QXK_priv_.readySet_dis); \
315 if (!QXK_ISR_CONTEXT_()) { \
316 if (QXK_sched_() != 0U) { \
317 QXK_activate_(); \
318 } \
319 } \
320} while (false)
321#endif // ndef Q_UNSAFE
322
323//${QXK-impl::QACTIVE_EQUEUE_SIGNAL_} ........................................
324#ifdef Q_UNSAFE
325#define QACTIVE_EQUEUE_SIGNAL_(me_) do { \
326 QPSet_insert(&QXK_priv_.readySet, (uint_fast8_t)(me_)->prio); \
327 if (!QXK_ISR_CONTEXT_()) { \
328 if (QXK_sched_() != 0U) { \
329 QXK_activate_(); \
330 } \
331 } \
332} while (false)
333#endif // def Q_UNSAFE
334
335//${QXK-impl::QXTHREAD_EQUEUE_SIGNAL_} .......................................
336#ifndef Q_UNSAFE
337#define QXTHREAD_EQUEUE_SIGNAL_(me_) do { \
338 if (me->super.temp.obj == QXK_PTR_CAST_(QMState*, &me->eQueue)) { \
339 (void)QXThread_teDisarm_(QXTHREAD_CAST_(me)); \
340 QPSet_insert(&QXK_priv_.readySet, (uint_fast8_t)me->prio); \
341 QPSet_update_(&QXK_priv_.readySet, &QXK_priv_.readySet_dis); \
342 if (!QXK_ISR_CONTEXT_()) { \
343 (void)QXK_sched_(); \
344 } \
345 } \
346} while (false)
347#endif // ndef Q_UNSAFE
348
349//${QXK-impl::QXTHREAD_EQUEUE_SIGNAL_} .......................................
350#ifdef Q_UNSAFE
351#define QXTHREAD_EQUEUE_SIGNAL_(me_) do { \
352 if (me->super.temp.obj == QXK_PTR_CAST_(QMState*, &me->eQueue)) { \
353 (void)QXThread_teDisarm_(QXTHREAD_CAST_(me)); \
354 QPSet_insert(&QXK_priv_.readySet, (uint_fast8_t)me->prio); \
355 if (!QXK_ISR_CONTEXT_()) { \
356 (void)QXK_sched_(); \
357 } \
358 } \
359} while (false)
360#endif // def Q_UNSAFE
361
362//${QXK-impl::QXK_PTR_CAST_} .................................................
363#define QXK_PTR_CAST_(type_, ptr_) ((type_)(ptr_))
364
365//${QXK-impl::QXTHREAD_CAST_} ................................................
366#define QXTHREAD_CAST_(ptr_) ((QXThread *)(ptr_))
367//$enddecl${QXK-impl} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
368
369//$declare${QF_EPOOL-impl} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
370
371//${QF_EPOOL-impl::QF_EPOOL_TYPE_} ...........................................
372#define QF_EPOOL_TYPE_ QMPool
373
374//${QF_EPOOL-impl::QF_EPOOL_INIT_} ...........................................
375#define QF_EPOOL_INIT_(p_, poolSto_, poolSize_, evtSize_) \
376 (QMPool_init(&(p_), (poolSto_), (poolSize_), (evtSize_)))
377
378//${QF_EPOOL-impl::QF_EPOOL_EVENT_SIZE_} .....................................
379#define QF_EPOOL_EVENT_SIZE_(p_) ((uint_fast16_t)(p_).blockSize)
380
381//${QF_EPOOL-impl::QF_EPOOL_GET_} ............................................
382#define QF_EPOOL_GET_(p_, e_, m_, qsId_) \
383 ((e_) = (QEvt *)QMPool_get(&(p_), (m_), (qsId_)))
384
385//${QF_EPOOL-impl::QF_EPOOL_PUT_} ............................................
386#define QF_EPOOL_PUT_(p_, e_, qsId_) \
387 (QMPool_put(&(p_), (e_), (qsId_)))
388//$enddecl${QF_EPOOL-impl} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
389
394
395#endif // QP_IMPL
396
397#endif // QXK_H_
uint32_t QTimeEvtCtr
Definition qp.h:633
int enum_t
Definition qp.h:109
uint16_t QPrioSpec
Definition qp.h:619
void(* QXThreadHandler)(struct QXThread *const me)
Definition qp.h:236
uint_fast16_t QSchedStatus
Definition qxk.h:60
QXK_TimeoutSigs
Definition qxk.h:390
@ QXK_TIMEOUT_SIG
Definition qxk.h:392
@ QXK_DELAY_SIG
Definition qxk.h:391
Active object class (based on the QHsm implementation strategy)
Definition qp.h:800
Event class.
Definition qp.h:147
Set of Active Objects of up to QF_MAX_ACTIVE elements.
Definition qp.h:658
Time Event class.
Definition qp.h:969
Private attributes of the QXK kernel.
Definition qxk.h:73
QPSet readySet_dis
Definition qxk.h:99
struct QActive *volatile curr
Definition qxk.h:77
uint_fast8_t volatile lockHolder
Definition qxk.h:92
QPSet readySet
Definition qxk.h:95
uint_fast8_t volatile lockCeil
Definition qxk.h:89
struct QActive *volatile next
Definition qxk.h:80
struct QActive *volatile prev
Definition qxk.h:83
uint_fast8_t volatile actPrio
Definition qxk.h:86
QXK dual-mode kernel (QXK namespace emulated as a "class" in C)
Definition qxk.h:50
void QXK_onIdle(void)
QXK_Attr QXK_priv_
Definition qxk.h:105
QSchedStatus QXK_schedLock(uint_fast8_t const ceiling)
Blocking Mutex of the QXK preemptive kernel.
Definition qxk.h:243
void QXMutex_init(QXMutex *const me, QPrioSpec const prioSpec)
QActive ao
Definition qxk.h:247
QPSet waitSet
Definition qxk.h:250
Counting Semaphore of the QXK preemptive kernel.
Definition qxk.h:208
uint8_t max_count
Definition qxk.h:218
QPSet waitSet
Definition qxk.h:212
uint8_t volatile count
Definition qxk.h:215
void QXSemaphore_init(QXSemaphore *const me, uint_fast8_t const count, uint_fast8_t const max_count)
eXtended (blocking) thread of the QXK preemptive kernel
Definition qxk.h:145
QActive super
Definition qxk.h:147
void QXThread_stackInit_(QActive *const me, QXThreadHandler const handler, void *const stkSto, uint_fast16_t const stkSize)
void QXThread_ctor(QXThread *const me, QXThreadHandler const handler, uint_fast8_t const tickRate)
QXThread const * QXThread_dummy
Definition qxk.h:157
QTimeEvt timeEvt
Definition qxk.h:152