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