QP/C  8.0.2
Real-Time Embedded Framework
Loading...
Searching...
No Matches
qp.h
Go to the documentation of this file.
1//============================================================================
2// QP/C Real-Time Embedded Framework (RTEF)
3// Version 8.0.2
4//
5// Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
6//
7// Q u a n t u m L e a P s
8// ------------------------
9// Modern Embedded Software
10//
11// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
12//
13// This software is dual-licensed under the terms of the open-source GNU
14// General Public License (GPL) or under the terms of one of the closed-
15// source Quantum Leaps commercial licenses.
16//
17// Redistributions in source code must retain this top-level comment block.
18// Plagiarizing this software to sidestep the license obligations is illegal.
19//
20// NOTE:
21// The GPL does NOT permit the incorporation of this code into proprietary
22// programs. Please contact Quantum Leaps for commercial licensing options,
23// which expressly supersede the GPL and are designed explicitly for
24// closed-source distribution.
25//
26// Quantum Leaps contact information:
27// <www.state-machine.com/licensing>
28// <info@state-machine.com>
29//============================================================================
30#ifndef QP_H_
31#define QP_H_
32
33//============================================================================
34#define QP_VERSION_STR "8.0.2"
35#define QP_VERSION 802U
36// <VER>=802 <DATE>=250120
37#define QP_RELEASE 0x6AEAB45DU
38
39//============================================================================
40// default configuration settings
41//! @cond INTERNAL
42
43#ifndef Q_SIGNAL_SIZE
44#define Q_SIGNAL_SIZE 2U
45#endif
46
47#ifndef QF_MAX_ACTIVE
48#define QF_MAX_ACTIVE 32U
49#endif
50
51#if (QF_MAX_ACTIVE > 64U)
52#error QF_MAX_ACTIVE exceeds the maximum of 64U;
53#endif
54
55#ifndef QF_MAX_TICK_RATE
56#define QF_MAX_TICK_RATE 1U
57#endif
58
59#if (QF_MAX_TICK_RATE > 15U)
60#error QF_MAX_TICK_RATE exceeds the maximum of 15U;
61#endif
62
63#ifndef QF_MAX_EPOOL
64#define QF_MAX_EPOOL 3U
65#endif
66
67#if (QF_MAX_EPOOL > 15U)
68#error QF_MAX_EPOOL exceeds the maximum of 15U;
69#endif
70
71#ifndef QF_TIMEEVT_CTR_SIZE
72#define QF_TIMEEVT_CTR_SIZE 4U
73#endif
74
75#if (QF_TIMEEVT_CTR_SIZE > 4U)
76#error QF_TIMEEVT_CTR_SIZE defined incorrectly, expected 1U, 2U, or 4U;
77#endif
78
79#ifndef QF_EVENT_SIZ_SIZE
80#define QF_EVENT_SIZ_SIZE 2U
81#endif
82
83#if (QF_EVENT_SIZ_SIZE > 4U)
84#error QF_EVENT_SIZ_SIZE defined incorrectly, expected 1U, 2U, or 4U;
85#endif
86
87//! @endcond
88
89//============================================================================
90// global types/utilities
91
92typedef int int_t;
93typedef int enum_t;
94typedef float float32_t;
95typedef double float64_t;
96
97#define Q_UNUSED_PAR(par_) ((void)(par_))
98#define Q_DIM(array_) (sizeof(array_) / sizeof((array_)[0U]))
99#define Q_UINT2PTR_CAST(type_, uint_) ((type_ *)(uint_))
100
101//============================================================================
102extern char const QP_versionStr[24];
103
104// QSignal type
105#if (Q_SIGNAL_SIZE == 1U)
106 typedef uint8_t QSignal;
107#elif (Q_SIGNAL_SIZE == 2U)
108 typedef uint16_t QSignal;
109#elif (Q_SIGNAL_SIZE == 4U)
110 typedef uint32_t QSignal;
111#endif
112
113//============================================================================
114//! @class QEvt
115typedef struct QEvt {
116 QSignal sig; //!< @public @memberof QEvt
117 uint8_t poolNum_; //!< @private @memberof QEvt
118 uint8_t volatile refCtr_; //!< @private @memberof QEvt
119} QEvt;
120
121#define QEVT_INITIALIZER(sig_) { (QSignal)(sig_), 0x00U, 0xE0U }
122//! @public @memberof QEvt
123static inline void QEvt_ctor(QEvt * const me,
124 enum_t const sig)
125{
126 me->sig = (QSignal)sig;
127 me->poolNum_ = 0x00U;
128 me->refCtr_ = 0xE0U;
129}
130
131//! @public @memberof QEvt
132static inline QEvt * QEvt_init(QEvt * const me,
133 uint8_t const dummy)
134{
135 Q_UNUSED_PAR(dummy);
136 return me;
137}
138
139typedef QEvt const * QEvtPtr;
140
141#define QEVT_DYNAMIC ((uint8_t)0)
142#define Q_EVT_CAST(class_) ((class_ const *)(e))
143
144//============================================================================
145// QEP (hierarchical event processor) types
146
147typedef uint_fast8_t QState;
148typedef QState (*QStateHandler)(void * const me, QEvt const * const e);
149typedef QState (*QActionHandler)(void * const me);
150
151struct QXThread; // forward declarsation
152typedef void (* QXThreadHandler )(struct QXThread * const me);
153
154typedef struct QMState {
155 struct QMState const *superstate; //!< @private @memberof QMState
156 QStateHandler const stateHandler; //!< @private @memberof QMState
157 QActionHandler const entryAction; //!< @private @memberof QMState
158 QActionHandler const exitAction; //!< @private @memberof QMState
159 QActionHandler const initAction; //!< @private @memberof QMState
160} QMState;
161
162typedef struct QMTranActTable {
163 QMState const *target; //!< @private @memberof QMTranActTable
164 QActionHandler const act[1]; //!< @private @memberof QMTranActTable
166
167union QAsmAttr {
168 QStateHandler fun; //!< @private @memberof QAsmAttr
169 QActionHandler act; //!< @private @memberof QAsmAttr
170 QXThreadHandler thr; //!< @private @memberof QAsmAttr
171 QMTranActTable const *tatbl; //!< @private @memberof QAsmAttr
172 struct QMState const *obj; //!< @private @memberof QAsmAttr
173};
174
175#define Q_STATE_CAST(handler_) ((QStateHandler)(handler_))
176#define Q_ACTION_CAST(action_) ((QActionHandler)(action_))
177#define Q_ACTION_NULL ((QActionHandler)0)
178
179//============================================================================
180//! @class QAsm
181typedef struct {
182 struct QAsmVtable const * vptr; //!< @protected @memberof QAsm
183 union QAsmAttr state; //!< @protected @memberof QAsm
184 union QAsmAttr temp; //!< @protected @memberof QAsm
185} QAsm;
186
187// All possible values returned from state/action handlers
188// NOTE: The ordering is important for algorithmic correctness.
189#define Q_RET_SUPER ((QState)0U)
190#define Q_RET_UNHANDLED ((QState)1U)
191
192// handled and do not need to "bubble up"
193#define Q_RET_HANDLED ((QState)2U)
194#define Q_RET_IGNORED ((QState)3U)
195
196// entry/exit
197#define Q_RET_ENTRY ((QState)4U)
198#define Q_RET_EXIT ((QState)5U)
199
200// no side effects
201#define Q_RET_NULL ((QState)6U)
202
203// transitions need to execute transition-action table in ::QMsm
204#define Q_RET_TRAN ((QState)7U)
205#define Q_RET_TRAN_INIT ((QState)8U)
206
207// transitions that additionally clobber me->state
208#define Q_RET_TRAN_HIST ((QState)9U)
209
210// Reserved signals by the QP-framework.
211#define Q_EMPTY_SIG ((QSignal)0U)
212#define Q_ENTRY_SIG ((QSignal)1U)
213#define Q_EXIT_SIG ((QSignal)2U)
214#define Q_INIT_SIG ((QSignal)3U)
215#define Q_USER_SIG ((enum_t)4)
216
217//! @protected @memberof QAsm
218static inline void QAsm_ctor(QAsm * const me) {
219 me->vptr = (struct QAsmVtable *)0;
220 me->state.fun = (QStateHandler)0;
221 me->temp.fun = (QStateHandler)0;
222}
223
225 void (*init)(QAsm * const me, void const * const e,
226 uint_fast8_t const qsId);
227 void (*dispatch)(QAsm * const me, QEvt const * const e,
228 uint_fast8_t const qsId);
229 bool (*isIn)(QAsm * const me, QStateHandler const s);
230#ifdef Q_SPY
232#endif // Q_SPY
233};
234
235#ifdef Q_SPY
236 #define QASM_INIT(me_, par_, qsId_) \
237 (*((QAsm *)(me_))->vptr->init)((QAsm *)(me_), (par_), (qsId_))
238 #define QASM_DISPATCH(me_, e_, qsId_) \
239 (*((QAsm *)(me_))->vptr->dispatch)((QAsm *)(me_), (e_), (qsId_))
240 #define QASM_IS_IN(me_, state_) \
241 (*((QAsm *)(me_))->vptr->isIn)((QAsm *)(me_), (state_))
242#else
243 #define QASM_INIT(me_, par_, dummy) \
244 (*((QAsm *)(me_))->vptr->init)((QAsm *)(me_), (par_), 0U)
245 #define QASM_DISPATCH(me_, e_, dummy) \
246 (*((QAsm *)(me_))->vptr->dispatch)((QAsm *)(me_), (e_), 0U)
247#endif // ndef Q_SPY
248
249#define Q_ASM_UPCAST(ptr_) ((QAsm *)(ptr_))
250
251//============================================================================
252//! @class QHsm
253//! @extends QAsm
254typedef struct {
255 QAsm super; //!< @protected @memberof QHsm
256} QHsm;
257
258//! @protected @memberof QHsm
259void QHsm_ctor(QHsm * const me,
260 QStateHandler const initial);
261
262//! @private @memberof QHsm
263void QHsm_init_(
264 QAsm * const me,
265 void const * const e,
266 uint_fast8_t const qsId);
267
268//! @private @memberof QHsm
269void QHsm_dispatch_(
270 QAsm * const me,
271 QEvt const * const e,
272 uint_fast8_t const qsId);
273
274//! @private @memberof QHsm
275bool QHsm_isIn_(
276 QAsm * const me,
277 QStateHandler const state);
278
279#ifdef Q_SPY
280//! @private @memberof QHsm
281QStateHandler QHsm_getStateHandler_(QAsm * const me);
282#endif // def Q_SPY
283
284//! @protected @memberof QHsm
285QState QHsm_top(QHsm const * const me,
286 QEvt const * const e);
287
288//! @public @memberof QHsm
289static inline QStateHandler QHsm_state(QHsm const * const me) {
290 return me->super.state.fun;
291}
292
293//! @public @memberof QHsm
294QStateHandler QHsm_childState(QHsm * const me,
295 QStateHandler const parent);
296
297#define Q_HSM_UPCAST(ptr_) ((QHsm *)(ptr_))
298
299#define Q_TRAN(target_) \
300 ((Q_ASM_UPCAST(me))->temp.fun = Q_STATE_CAST(target_), \
301 (QState)Q_RET_TRAN)
302#define Q_TRAN_HIST(hist_) \
303 ((Q_ASM_UPCAST(me))->temp.fun = (hist_), \
304 (QState)Q_RET_TRAN_HIST)
305#define Q_SUPER(super_) \
306 ((Q_ASM_UPCAST(me))->temp.fun = Q_STATE_CAST(super_), \
307 (QState)Q_RET_SUPER)
308#define Q_HANDLED() ((QState)Q_RET_HANDLED)
309#define Q_UNHANDLED() ((QState)Q_RET_UNHANDLED)
310
311//============================================================================
312//! @class QMsm
313//! @extends QAsm
314typedef struct {
315 QAsm super; //!< @protected @memberof QMsm
316} QMsm;
317
318//! @protected @memberof QMsm
319void QMsm_ctor(QMsm * const me,
320 QStateHandler const initial);
321
322//! @private @memberof QMsm
323void QMsm_init_(
324 QAsm * const me,
325 void const * const e,
326 uint_fast8_t const qsId);
327
328//! @private @memberof QMsm
329void QMsm_dispatch_(
330 QAsm * const me,
331 QEvt const * const e,
332 uint_fast8_t const qsId);
333
334//! @private @memberof QMsm
335bool QMsm_isIn_(
336 QAsm * const me,
337 QStateHandler const state);
338
339#ifdef Q_SPY
340//! @public @memberof QMsm
341QStateHandler QMsm_getStateHandler_(QAsm * const me);
342#endif // def Q_SPY
343
344//! @public @memberof QMsm
345static inline QMState const * QMsm_stateObj(QMsm const * const me) {
346 return me->super.state.obj;
347}
348
349//! @public @memberof QMsm
350QMState const * QMsm_childStateObj(QMsm const * const me,
351 QMState const * const parent);
352//============================================================================
353// QEP-macros
354
355#define Q_MSM_UPCAST(ptr_) ((QMsm *)(ptr_))
356#ifdef Q_SPY
357 #define QM_ENTRY(state_) \
358 ((Q_ASM_UPCAST(me))->temp.obj = (state_), (QState)Q_RET_ENTRY)
359 #define QM_EXIT(state_) \
360 ((Q_ASM_UPCAST(me))->temp.obj = (state_), (QState)Q_RET_EXIT)
361#else
362 #define QM_ENTRY(dummy) ((QState)Q_RET_ENTRY)
363 #define QM_EXIT(dummy) ((QState)Q_RET_EXIT)
364#endif // ndef Q_SPY
365
366#define QM_TRAN(tatbl_) ((Q_ASM_UPCAST(me))->temp.tatbl \
367 = (struct QMTranActTable const *)(tatbl_), (QState)Q_RET_TRAN)
368
369#define QM_TRAN_INIT(tatbl_) ((Q_ASM_UPCAST(me))->temp.tatbl \
370 = (struct QMTranActTable const *)(tatbl_), (QState)Q_RET_TRAN_INIT)
371
372#define QM_TRAN_HIST(history_, tatbl_) \
373 ((((Q_ASM_UPCAST(me))->state.obj = (history_)), \
374 ((Q_ASM_UPCAST(me))->temp.tatbl = \
375 (struct QMTranActTable const *)(tatbl_))), (QState)Q_RET_TRAN_HIST)
376
377#define QM_HANDLED() ((QState)Q_RET_HANDLED)
378#define QM_UNHANDLED() ((QState)Q_RET_UNHANDLED)
379#define QM_SUPER() ((QState)Q_RET_SUPER)
380#define QM_STATE_NULL ((QMState *)0)
381
382//============================================================================
383// QF (active object framework) types
384
385typedef uint16_t QPrioSpec;
386
387#if (QF_TIMEEVT_CTR_SIZE == 1U)
388 typedef uint8_t QTimeEvtCtr;
389#elif (QF_TIMEEVT_CTR_SIZE == 2U)
390 typedef uint16_t QTimeEvtCtr;
391#elif (QF_TIMEEVT_CTR_SIZE == 4U)
392 typedef uint32_t QTimeEvtCtr;
393#endif // (QF_TIMEEVT_CTR_SIZE == 4U)
394
395#if (QF_MAX_ACTIVE <= 8U)
396 typedef uint8_t QPSetBits;
397#elif (8U < QF_MAX_ACTIVE) && (QF_MAX_ACTIVE <= 16U)
398 typedef uint16_t QPSetBits;
399#elif (16U < QF_MAX_ACTIVE)
400 typedef uint32_t QPSetBits;
401#endif // (16U < QF_MAX_ACTIVE)
402
403#ifndef QF_LOG2
404 uint_fast8_t QF_LOG2(QPSetBits const bitmask);
405#endif // ndef QF_LOG2
406
407//============================================================================
408//! @class QPSet
409typedef struct {
410 //! @private @memberof QPSet
411 QPSetBits bits[((QF_MAX_ACTIVE + (8U*sizeof(QPSetBits))) - 1U)
412 / (8U*sizeof(QPSetBits))];
413} QPSet;
414
415//! @public @memberof QPSet
416static inline void QPSet_setEmpty(QPSet * const me) {
417 me->bits[0] = 0U;
418#if (QF_MAX_ACTIVE > 32)
419 me->bits[1] = 0U;
420#endif
421}
422
423//! @public @memberof QPSet
424static inline bool QPSet_isEmpty(QPSet const * const me) {
425#if (QF_MAX_ACTIVE <= 32U)
426 return (me->bits[0] == 0U);
427#else
428 return (me->bits[0] == 0U) ? (me->bits[1] == 0U) : false;
429#endif
430}
431
432//! @public @memberof QPSet
433static inline bool QPSet_notEmpty(QPSet const * const me) {
434#if (QF_MAX_ACTIVE <= 32U)
435 return (me->bits[0] != 0U);
436#else
437 return (me->bits[0] != 0U) ? true : (me->bits[1] != 0U);
438#endif
439}
440
441//! @public @memberof QPSet
442static inline bool QPSet_hasElement(QPSet const * const me,
443 uint_fast8_t const n)
444{
445#if (QF_MAX_ACTIVE <= 32U)
446 return (me->bits[0] & ((QPSetBits)1U << (n - 1U))) != 0U;
447#else
448 return (n <= 32U)
449 ? ((me->bits[0] & ((QPSetBits)1U << (n - 1U))) != 0U)
450 : ((me->bits[1] & ((QPSetBits)1U << (n - 33U))) != 0U);
451#endif
452}
453
454//! @public @memberof QPSet
455static inline void QPSet_insert(QPSet * const me,
456 uint_fast8_t const n)
457{
458#if (QF_MAX_ACTIVE <= 32U)
459 me->bits[0] = (me->bits[0] | ((QPSetBits)1U << (n - 1U)));
460#else
461 if (n <= 32U) {
462 me->bits[0] = (me->bits[0] | ((QPSetBits)1U << (n - 1U)));
463 }
464 else {
465 me->bits[1] = (me->bits[1] | ((QPSetBits)1U << (n - 33U)));
466 }
467#endif
468}
469
470//! @public @memberof QPSet
471static inline void QPSet_remove(QPSet * const me,
472 uint_fast8_t const n)
473{
474#if (QF_MAX_ACTIVE <= 32U)
475 me->bits[0] = (me->bits[0] & (QPSetBits)(~((QPSetBits)1U << (n - 1U))));
476#else
477 if (n <= 32U) {
478 (me->bits[0] = (me->bits[0] & ~((QPSetBits)1U << (n - 1U))));
479 }
480 else {
481 (me->bits[1] = (me->bits[1] & ~((QPSetBits)1U << (n - 33U))));
482 }
483#endif
484}
485
486//! @public @memberof QPSet
487static inline uint_fast8_t QPSet_findMax(QPSet const * const me) {
488#if (QF_MAX_ACTIVE <= 32U)
489 return QF_LOG2(me->bits[0]);
490#else
491 return (me->bits[1] != 0U)
492 ? (QF_LOG2(me->bits[1]) + 32U)
493 : (QF_LOG2(me->bits[0]));
494#endif
495}
496
497//! @struct QSubscrList
498typedef struct {
499 QPSet set; //!< @private @memberof QSubscrList
501
502struct QEQueue; // forward declaration
503
504//============================================================================
505//! @class QActive
506//! @extends QAsm
507typedef struct QActive {
508 QAsm super; //!< @protected @memberof QActive
509 uint8_t prio; //!< @protected @memberof QActive
510 uint8_t pthre; //!< @protected @memberof QActive
511
512#ifdef QACTIVE_THREAD_TYPE
513 QACTIVE_THREAD_TYPE thread; //!< @protected @memberof QActive
514#endif // def QACTIVE_THREAD_TYPE
515
516#ifdef QACTIVE_OS_OBJ_TYPE
517 QACTIVE_OS_OBJ_TYPE osObject; //!< @protected @memberof QActive
518#endif // def QACTIVE_OS_OBJ_TYPE
519
520#ifdef QACTIVE_EQUEUE_TYPE
521 QACTIVE_EQUEUE_TYPE eQueue; //!< @protected @memberof QActive
522#endif // def QACTIVE_EQUEUE_TYPE
523} QActive;
524
525//! @static @private @memberof QActive
527
528//! @static @private @memberof QActive
530
531//! @static @private @memberof QActive
533
534//! @protected @memberof QActive
535void QActive_ctor(QActive * const me,
536 QStateHandler const initial);
537
538//! @public @memberof QActive
539void QActive_setAttr(QActive * const me,
540 uint32_t attr1,
541 void const * attr2);
542
543//! @public @memberof QActive
544void QActive_start(QActive * const me,
545 QPrioSpec const prioSpec,
546 QEvtPtr * const qSto,
547 uint_fast16_t const qLen,
548 void * const stkSto,
549 uint_fast16_t const stkSize,
550 void const * const par);
551
552#ifdef QACTIVE_CAN_STOP
553//! @protected @memberof QActive
554void QActive_stop(QActive * const me);
555#endif // def QACTIVE_CAN_STOP
556
557//! @private @memberof QActive
558void QActive_register_(QActive * const me);
559
560//! @private @memberof QActive
561void QActive_unregister_(QActive * const me);
562
563//! @private @memberof QActive
564bool QActive_post_(QActive * const me,
565 QEvt const * const e,
566 uint_fast16_t const margin,
567 void const * const sender);
568
569//! @private @memberof QActive
570void QActive_postLIFO_(QActive * const me,
571 QEvt const * const e);
572
573//! @private @memberof QActive
574QEvt const * QActive_get_(QActive * const me);
575
576//! @static @public @memberof QActive
578 QSubscrList * const subscrSto,
579 enum_t const maxSignal);
580
581//! @static @private @memberof QActive
583 QEvt const * const e,
584 void const * const sender,
585 uint_fast8_t const qsId);
586
587//! @protected @memberof QActive
588void QActive_subscribe(QActive const * const me,
589 enum_t const sig);
590
591//! @protected @memberof QActive
592void QActive_unsubscribe(QActive const * const me,
593 enum_t const sig);
594
595//! @protected @memberof QActive
596void QActive_unsubscribeAll(QActive const * const me);
597
598//! @protected @memberof QActive
599bool QActive_defer(QActive const * const me,
600 struct QEQueue * const eq,
601 QEvt const * const e);
602
603//! @protected @memberof QActive
604bool QActive_recall(QActive * const me,
605 struct QEQueue * const eq);
606
607//! @protected @memberof QActive
608uint_fast16_t QActive_flushDeferred(QActive const * const me,
609 struct QEQueue * const eq,
610 uint_fast16_t const num);
611
612//! @private @memberof QActive
613void QActive_evtLoop_(QActive * const me);
614
615//============================================================================
616//! @class QMActive
617//! @extends QActive
618typedef struct {
619 QActive super; //!< @protected @memberof QMActive
620} QMActive;
621
622//! @protected @memberof QMActive
623void QMActive_ctor(QMActive * const me,
624 QStateHandler const initial);
625
626//============================================================================
627//! @class QTimeEvt
628//! @extends QEvt
629typedef struct QTimeEvt {
630 QEvt super; //!< @protected @memberof QTimeEvt
631
632 struct QTimeEvt * volatile next; //!< @private @memberof QTimeEvt
633 void * act; //!< @private @memberof QTimeEvt
634 QTimeEvtCtr volatile ctr; //!< @private @memberof QTimeEvt
635 QTimeEvtCtr interval; //!< @private @memberof QTimeEvt
636 uint8_t tickRate; //!< @private @memberof QTimeEvt
637 uint8_t flags; //!< @private @memberof QTimeEvt
638} QTimeEvt;
639
640//! @public @memberof QTimeEvt
641void QTimeEvt_ctorX(QTimeEvt * const me,
642 QActive * const act,
643 enum_t const sig,
644 uint_fast8_t const tickRate);
645
646//! @public @memberof QTimeEvt
647void QTimeEvt_armX(QTimeEvt * const me,
648 uint32_t const nTicks,
649 uint32_t const interval);
650
651//! @public @memberof QTimeEvt
652bool QTimeEvt_disarm(QTimeEvt * const me);
653
654//! @public @memberof QTimeEvt
655bool QTimeEvt_rearm(QTimeEvt * const me,
656 uint32_t const nTicks);
657
658//! @public @memberof QTimeEvt
659bool QTimeEvt_wasDisarmed(QTimeEvt * const me);
660
661//! @public @memberof QTimeEvt
662QTimeEvtCtr QTimeEvt_currCtr(QTimeEvt const * const me);
663
664//! @static @private @memberof QTimeEvt
665void QTimeEvt_init(void);
666
667//! @static @private @memberof QTimeEvt
668void QTimeEvt_tick_(
669 uint_fast8_t const tickRate,
670 void const * const sender);
671
672//! @private @memberof QTimeEvt
674 QTimeEvt * const prev_link,
675 QActive const * const act,
676 uint_fast8_t const tickRate);
677
678#ifdef Q_UTEST
679 //! @static @private @memberof QTimeEvt
681 uint_fast8_t const tickRate,
682 void const * const sender);
683#endif // def Q_UTEST
684
685//! @static @public @memberof QTimeEvt
686bool QTimeEvt_noActive(uint_fast8_t const tickRate);
687
688//! @static @private @memberof QTimeEvt
690
691//============================================================================
692//! @class QTicker
693//! @extends QActive
694typedef struct {
695 QActive super; //!< @protected @memberof QTicker
696} QTicker;
697
698//! @public @memberof QTicker
699void QTicker_ctor(QTicker * const me,
700 uint_fast8_t const tickRate);
701
702//! @private @memberof QTicker
703void QTicker_init_(
704 QAsm * const me,
705 void const * const par,
706 uint_fast8_t const qsId);
707
708//! @private @memberof QTicker
709void QTicker_dispatch_(
710 QAsm * const me,
711 QEvt const * const e,
712 uint_fast8_t const qsId);
713
714//! @private @memberof QTicker
715void QTicker_trig_(
716 QActive * const me,
717 void const * const sender);
718
719//============================================================================
720// QF base facilities
721
722//! @static @public @memberof QF
723void QF_init(void);
724
725//! @static @public @memberof QF
726void QF_stop(void);
727
728//! @static @public @memberof QF
729int_t QF_run(void);
730
731//! @static @public @memberof QF
732uint_fast16_t QF_getQueueMin(uint_fast8_t const prio);
733
734//! @static @public @memberof QF
735void QF_onStartup(void);
736
737//! @static @public @memberof QF
738void QF_onCleanup(void);
739
740#ifdef QF_ON_CONTEXT_SW
741 //! @static @public @memberof QF
743 QActive * prev,
744 QActive * next);
745#endif // def QF_ON_CONTEXT_SW
746
747#define Q_PRIO(prio_, pthre_) ((QPrioSpec)((prio_) | ((pthre_) << 8U)))
748#define QF_NO_MARGIN ((uint_fast16_t)0xFFFFU)
749
750//============================================================================
751// QF dynamic memory facilities
752
753//! @static @public @memberof QF
755 void * const poolSto,
756 uint_fast32_t const poolSize,
757 uint_fast16_t const evtSize);
758
759//! @static @public @memberof QF
760uint_fast16_t QF_poolGetMaxBlockSize(void);
761
762//! @static @public @memberof QF
763uint_fast16_t QF_getPoolMin(uint_fast8_t const poolNum);
764
765//! @static @private @memberof QF
766QEvt * QF_newX_(
767 uint_fast16_t const evtSize,
768 uint_fast16_t const margin,
769 enum_t const sig);
770
771//! @static @public @memberof QF
772void QF_gc(QEvt const * const e);
773
774//! @static @private @memberof QF
775QEvt const * QF_newRef_(
776 QEvt const * const e,
777 void const * const evtRef);
778
779//! @static @private @memberof QF
780void QF_deleteRef_(void const * const evtRef);
781
782//! @static @public @memberof QF
783void QF_gcFromISR(QEvt const * const e);
784
785#ifdef QEVT_PAR_INIT
786 #define Q_NEW(evtT_, sig_, ...) \
787 (evtT_##_init((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
788 QF_NO_MARGIN, (sig_)), __VA_ARGS__))
789 #define Q_NEW_X(evtT_, margin_, sig_, ...) \
790 (evtT_##_init((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
791 (margin_), (sig_)), __VA_ARGS__))
792#else
793 #define Q_NEW(evtT_, sig_) \
794 ((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
795 QF_NO_MARGIN, (enum_t)(sig_)))
796 #define Q_NEW_X(evtT_, margin_, sig_) \
797 ((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
798 (margin_), (enum_t)(sig_)))
799#endif // QEVT_PAR_INIT
800
801#define Q_NEW_REF(evtRef_, evtT_) \
802 ((evtRef_) = (evtT_ const *)QF_newRef_(e, (evtRef_)))
803#define Q_DELETE_REF(evtRef_) do { \
804 QF_deleteRef_((evtRef_)); \
805 (evtRef_) = (void *)0; \
806} while (false)
807
808#ifdef Q_SPY
809 #define QACTIVE_POST(me_, e_, sender_) \
810 ((void)QActive_post_((me_), (e_), QF_NO_MARGIN, (sender_)))
811 #define QACTIVE_POST_X(me_, e_, margin_, sender_) \
812 (QActive_post_((me_), (e_), (margin_), (sender_)))
813 #define QACTIVE_PUBLISH(e_, sender_) \
814 (QActive_publish_((e_), (void const *)(sender_), (sender_)->prio))
815 #define QTIMEEVT_TICK_X(tickRate_, sender_) (QTimeEvt_tick_((tickRate_), (sender_)))
816 #define QTICKER_TRIG(ticker_, sender_) (QTicker_trig_((ticker_), (sender_)))
817#else
818 #define QACTIVE_POST(me_, e_, dummy) \
819 ((void)QActive_post_((me_), (e_), QF_NO_MARGIN, (void *)0))
820 #define QACTIVE_POST_X(me_, e_, margin_, dummy) \
821 (QActive_post_((me_), (e_), (margin_), (void *)0))
822 #define QACTIVE_PUBLISH(e_, dummy) (QActive_publish_((e_), (void *)0, 0U))
823 #define QTIMEEVT_TICK_X(tickRate_, dummy) (QTimeEvt_tick_((tickRate_), (void *)0))
824 #define QTICKER_TRIG(ticker_, sender_) (QTicker_trig_((ticker_), (void *)0))
825#endif // ndef Q_SPY
826
827#define QACTIVE_POST_LIFO(me_, e_) (QActive_postLIFO_((me_), (e_)))
828#define QTIMEEVT_TICK(sender_) QTIMEEVT_TICK_X(0U, (sender_))
829
830#ifndef QF_CRIT_EXIT_NOP
831 #define QF_CRIT_EXIT_NOP() ((void)0)
832#endif // ndef QF_CRIT_EXIT_NOP
833
834//============================================================================
835// memory protection facilities
836
837#ifdef QF_MEM_ISOLATE
838 #error Memory isolation not supported in this QP edition, need SafeQP
839#endif // def QF_MEM_ISOLATE
840
841#endif // QP_H_
void QF_onStartup(void)
void QF_poolInit(void *const poolSto, uint_fast32_t const poolSize, uint_fast16_t const evtSize)
void QF_onCleanup(void)
void QF_gc(QEvt const *const e)
Definition qf_dyn.c:183
uint_fast16_t QF_poolGetMaxBlockSize(void)
Definition qf_dyn.c:82
uint_fast16_t QF_getPoolMin(uint_fast8_t const poolNum)
Definition qf_dyn.c:94
void QF_onContextSw(QActive *prev, QActive *next)
QEvt * QF_newX_(uint_fast16_t const evtSize, uint_fast16_t const margin, enum_t const sig)
Definition qf_dyn.c:110
void QF_gcFromISR(QEvt const *const e)
void QF_deleteRef_(void const *const evtRef)
Definition qf_dyn.c:274
QEvt const * QF_newRef_(QEvt const *const e, void const *const evtRef)
Definition qf_dyn.c:238
eXtended (blocking) thread of the QXK preemptive kernel
#define Q_UNUSED_PAR(par_)
Helper macro to clearly mark unused parameters of functions.
Definition qp.h:97
float float32_t
Alias for IEEE 754 32-bit floating point number.
Definition qp.h:94
void(* QXThreadHandler)(struct QXThread *const me)
Pointer to an extended-thread handler function.
Definition qp.h:152
uint32_t QPSetBits
Bitmask for the internal representation of QPSet elements.
Definition qp.h:400
QState(* QStateHandler)(void *const me, QEvt const *const e)
Pointer to a state-handler function.
Definition qp.h:148
QEvt const * QEvtPtr
Pointer to const event instances passed around in QP Framework.
Definition qp.h:139
uint32_t QTimeEvtCtr
Data type to store the block-size defined based on the macro QF_TIMEEVT_CTR_SIZE.
Definition qp.h:392
uint_fast8_t QF_LOG2(QPSetBits const bitmask)
Log-base-2 calculation when hardware acceleration is NOT provided (QF_LOG2 not defined)
Definition qf_act.c:66
int int_t
Alias for assertion-ID numbers in QP assertions and return from QF_run()
Definition qp.h:92
double float64_t
Alias for IEEE 754 64-bit floating point number.
Definition qp.h:95
int enum_t
Definition qp.h:93
uint_fast8_t QState
Type returned from state-handler functions.
Definition qp.h:147
char const QP_versionStr[24]
Definition qf_act.c:44
QState(* QActionHandler)(void *const me)
Pointer to an action-handler function.
Definition qp.h:149
uint16_t QSignal
The signal of event QEvt.
Definition qp.h:108
uint16_t QPrioSpec
Priority specification for Active Objects in QP.
Definition qp.h:385
#define QF_MAX_TICK_RATE
Maximum # clock tick rates in the system (0..15)
Definition qp_config.h:143
#define QF_MAX_ACTIVE
Maximum # Active Objects in the system (1..64)
Definition qp_config.h:123
#define QACTIVE_OS_OBJ_TYPE
QActive "OS-object" type used in various QP/C ports.
Definition qp_port.h:30
#define QACTIVE_EQUEUE_TYPE
QActive event queue type used in various QP/C ports.
Definition qp_port.h:27
#define QACTIVE_THREAD_TYPE
QActive "thread" type used in various QP/C ports.
Definition qp_port.h:33
Active object class (based on the QHsm implementation strategy)
Definition qp.h:507
QSubscrList * QActive_subscrList_
Static (one per-class) pointer to all subscriber AOs for a given event signal.
Definition qp.h:529
void QActive_unsubscribe(QActive const *const me, enum_t const sig)
Definition qf_ps.c:183
QAsm super
Definition qp.h:508
void QActive_unregister_(QActive *const me)
Definition qf_qact.c:123
QACTIVE_THREAD_TYPE thread
Port-dependent representation of the thread of the active object.
Definition qp.h:513
bool QActive_post_(QActive *const me, QEvt const *const e, uint_fast16_t const margin, void const *const sender)
QEvt const * QActive_get_(QActive *const me)
Definition qf_actq.c:210
void QActive_postLIFO_(QActive *const me, QEvt const *const e)
Definition qf_actq.c:132
void QActive_ctor(QActive *const me, QStateHandler const initial)
bool QActive_defer(QActive const *const me, struct QEQueue *const eq, QEvt const *const e)
void QActive_setAttr(QActive *const me, uint32_t attr1, void const *attr2)
enum_t QActive_maxPubSignal_
Static (one per-class) maximum published signal (the size of the subscrList_ array)
Definition qp.h:532
QACTIVE_OS_OBJ_TYPE osObject
Port-dependent per-thread object.
Definition qp.h:517
bool QActive_recall(QActive *const me, struct QEQueue *const eq)
Definition qf_defer.c:67
QACTIVE_EQUEUE_TYPE eQueue
Port-dependent event-queue type (often QEQueue)
Definition qp.h:521
void QActive_publish_(QEvt const *const e, void const *const sender, uint_fast8_t const qsId)
Definition qf_ps.c:63
void QActive_stop(QActive *const me)
void QActive_register_(QActive *const me)
Definition qf_qact.c:74
QActive * QActive_registry_[QF_MAX_ACTIVE+1U]
Static (one per-class) array of registered active objects.
Definition qp.h:526
uint8_t prio
QF-priority [1..QF_MAX_ACTIVE] of this AO.
Definition qp.h:509
void QActive_subscribe(QActive const *const me, enum_t const sig)
Definition qf_ps.c:156
void QActive_start(QActive *const me, QPrioSpec const prioSpec, QEvtPtr *const qSto, uint_fast16_t const qLen, void *const stkSto, uint_fast16_t const stkSize, void const *const par)
Definition qv.c:214
uint_fast16_t QActive_flushDeferred(QActive const *const me, struct QEQueue *const eq, uint_fast16_t const num)
Definition qf_defer.c:120
void QActive_unsubscribeAll(QActive const *const me)
Definition qf_ps.c:210
void QActive_psInit(QSubscrList *const subscrSto, enum_t const maxSignal)
uint8_t pthre
Preemption-threshold [1..QF_MAX_ACTIVE] of this AO.
Definition qp.h:510
void QActive_evtLoop_(QActive *const me)
Abstract State Machine class (state machine interface)
Definition qp.h:181
struct QAsmVtable const * vptr
Virtual pointer inherited by all QAsm subclasses (see also Object Orientation)
Definition qp.h:182
union QAsmAttr state
Current state (pointer to the current state-handler function)
Definition qp.h:183
union QAsmAttr temp
Temporary storage for target/act-table etc.
Definition qp.h:184
static void QAsm_ctor(QAsm *const me)
Definition qp.h:218
Virtual table for the QAsm class.
Definition qp.h:224
void(* init)(QAsm *const me, void const *const e, uint_fast8_t const qsId)
Virtual function to take the top-most initial transition in the state machine.
Definition qp.h:225
bool(* isIn)(QAsm *const me, QStateHandler const s)
Virtual function to check whether the state machine is in a given state.
Definition qp.h:229
QStateHandler(* getStateHandler)(QAsm *const me)
Virtual function to get the current state handler of the state machine.
Definition qp.h:231
void(* dispatch)(QAsm *const me, QEvt const *const e, uint_fast8_t const qsId)
Virtual function to dispatch an event to the state machine.
Definition qp.h:227
Native QF Event Queue.
Definition qequeue.h:49
Event class.
Definition qp.h:115
QSignal sig
Signal of the event (see Event Signal)
Definition qp.h:116
static QEvt * QEvt_init(QEvt *const me, uint8_t const dummy)
Definition qp.h:132
uint8_t volatile refCtr_
Event reference counter.
Definition qp.h:118
static void QEvt_ctor(QEvt *const me, enum_t const sig)
Definition qp.h:123
uint8_t poolNum_
Definition qp.h:117
Hierarchical State Machine class (QHsm-style state machine implementation strategy)
Definition qp.h:254
QAsm super
Definition qp.h:255
static QStateHandler QHsm_state(QHsm const *const me)
Definition qp.h:289
Active object class (based on QMsm implementation strategy)
Definition qp.h:618
QActive super
Definition qp.h:619
State object for the QMsm class (QM State Machine)
Definition qp.h:154
struct QMState const * superstate
Definition qp.h:155
QActionHandler const entryAction
Definition qp.h:157
QActionHandler const initAction
Definition qp.h:159
QActionHandler const exitAction
Definition qp.h:158
QStateHandler const stateHandler
Definition qp.h:156
Transition-Action Table for the QMsm State Machine.
Definition qp.h:162
QActionHandler const act[1]
Definition qp.h:164
QMState const * target
Definition qp.h:163
Hierarchical State Machine class (QMsm-style state machine implementation strategy)
Definition qp.h:314
QAsm super
Definition qp.h:315
static QMState const * QMsm_stateObj(QMsm const *const me)
Definition qp.h:345
Set of Active Objects of up to QF_MAX_ACTIVE elements.
Definition qp.h:409
static uint_fast8_t QPSet_findMax(QPSet const *const me)
Definition qp.h:487
static bool QPSet_notEmpty(QPSet const *const me)
Definition qp.h:433
static bool QPSet_hasElement(QPSet const *const me, uint_fast8_t const n)
Definition qp.h:442
static void QPSet_setEmpty(QPSet *const me)
Definition qp.h:416
static void QPSet_insert(QPSet *const me, uint_fast8_t const n)
Definition qp.h:455
QPSetBits bits[((QF_MAX_ACTIVE+(8U *sizeof(QPSetBits))) - 1U)/(8U *sizeof(QPSetBits))]
Bitmask with a bit for each element.
Definition qp.h:412
static void QPSet_remove(QPSet *const me, uint_fast8_t const n)
Definition qp.h:471
static bool QPSet_isEmpty(QPSet const *const me)
Definition qp.h:424
Subscriber List (for publish-subscribe)
Definition qp.h:498
QPSet set
The set of AOs that subscribed to a given event signal.
Definition qp.h:499
"Ticker" Active Object class
Definition qp.h:694
QActive super
Definition qp.h:695
Time Event class.
Definition qp.h:629
void QTimeEvt_ctorX(QTimeEvt *const me, QActive *const act, enum_t const sig, uint_fast8_t const tickRate)
struct QTimeEvt *volatile next
Link to the next time event in the list.
Definition qp.h:632
QTimeEvtCtr volatile ctr
Down-counter of the time event.
Definition qp.h:634
bool QTimeEvt_noActive(uint_fast8_t const tickRate)
Definition qf_time.c:377
void QTimeEvt_tick1_(uint_fast8_t const tickRate, void const *const sender)
void QTimeEvt_armX(QTimeEvt *const me, uint32_t const nTicks, uint32_t const interval)
Definition qf_time.c:73
void QTimeEvt_tick_(uint_fast8_t const tickRate, void const *const sender)
Definition qf_time.c:287
QTimeEvt * QTimeEvt_expire_(QTimeEvt *const me, QTimeEvt *const prev_link, QActive const *const act, uint_fast8_t const tickRate)
Definition qf_time.c:398
QTimeEvtCtr interval
Interval for periodic time event (zero for one-shot time event)
Definition qp.h:635
QTimeEvtCtr QTimeEvt_currCtr(QTimeEvt const *const me)
Definition qf_time.c:264
QTimeEvt QTimeEvt_timeEvtHead_[QF_MAX_TICK_RATE]
Array of heads of linked lists of time events (one for every clock tick rate)
Definition qp.h:689
bool QTimeEvt_rearm(QTimeEvt *const me, uint32_t const nTicks)
Definition qf_time.c:181
void QTimeEvt_init(void)
Definition qf_time.c:275
bool QTimeEvt_wasDisarmed(QTimeEvt *const me)
Definition qf_time.c:250
bool QTimeEvt_disarm(QTimeEvt *const me)
Definition qf_time.c:137
uint8_t flags
Definition qp.h:637
QEvt super
Definition qp.h:630
void * act
Active object that receives the time events.
Definition qp.h:633
uint8_t tickRate
Definition qp.h:636
Attribute of for the QAsm class (Abstract State Machine)
Definition qp.h:167
QMTranActTable const * tatbl
Definition qp.h:171
QXThreadHandler thr
Definition qp.h:170
QStateHandler fun
Definition qp.h:168
struct QMState const * obj
Definition qp.h:172
QActionHandler act
Definition qp.h:169