QP/C Real-Time Event Framework 8.1.5
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.5"
34#define QP_VERSION 815U
35// <VER>=815 <DATE>=260805
36#define QP_RELEASE 0x648C4D80U
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
133#ifndef QEQUEUE_H_
134// NOTE must be consistent with "qequeue.h"
135typedef struct {
136 QEvt const *e;
137} QEvtPtr;
138#endif // QEQUEUE_HPP_
139
140#define QEVT_DYNAMIC ((uint8_t)0)
141#define Q_EVT_CAST(class_) ((class_ const *)(e))
142
143//----------------------------------------------------------------------------
144// QEP (hierarchical event processor) types
145
146typedef uint_fast8_t QState;
147typedef QState (*QStateHandler)(void * const me, QEvt const * const e);
148typedef QState (*QActionHandler)(void * const me);
149
150struct QXThread; // forward declaration
151typedef void (* QXThreadHandler )(struct QXThread * const me);
152
153typedef struct QMState {
154 struct QMState const *superstate; //!< @private @memberof QMState
155 QStateHandler const stateHandler; //!< @private @memberof QMState
156 QActionHandler const entryAction; //!< @private @memberof QMState
157 QActionHandler const exitAction; //!< @private @memberof QMState
158 QActionHandler const initAction; //!< @private @memberof QMState
159} QMState;
160
161typedef struct QMTranActTable {
162 QMState const *target; //!< @private @memberof QMTranActTable
163 QActionHandler const act[1]; //!< @private @memberof QMTranActTable
165
166union QAsmAttr {
167 QStateHandler fun; //!< @private @memberof QAsmAttr
168 QActionHandler act; //!< @private @memberof QAsmAttr
169 QXThreadHandler thr; //!< @private @memberof QAsmAttr
170 QMTranActTable const *tatbl; //!< @private @memberof QAsmAttr
171 struct QMState const *obj; //!< @private @memberof QAsmAttr
172 uintptr_t uint; //!< @private @memberof QAsmAttr
173};
174
175#define Q_USER_SIG ((enum_t)4)
176
177#define Q_STATE_CAST(handler_) ((QStateHandler)(handler_))
178#define Q_ACTION_CAST(action_) ((QActionHandler)(action_))
179#define Q_ACTION_NULL ((QActionHandler)0)
180
181//----------------------------------------------------------------------------
182//! @class QAsm
183typedef struct {
184 struct QAsmVtable const * vptr; //!< @protected @memberof QAsm
185 union QAsmAttr state; //!< @protected @memberof QAsm
186 union QAsmAttr temp; //!< @protected @memberof QAsm
187} QAsm;
188
189// All possible values returned from state/action handlers...
190// NOTE: The numerical order is important for algorithmic correctness.
191#define Q_RET_SUPER ((QState)0U)
192#define Q_RET_UNHANDLED ((QState)1U)
193#define Q_RET_HANDLED ((QState)2U)
194#define Q_RET_TRAN ((QState)3U)
195#define Q_RET_TRAN_HIST ((QState)4U)
196
197// used in QHsm only...
198#define Q_RET_IGNORED ((QState)5U)
199
200// used in QMsm only...
201#define Q_RET_ENTRY ((QState)6U)
202#define Q_RET_EXIT ((QState)7U)
203#define Q_RET_TRAN_INIT ((QState)8U)
204
205// Reserved signals by the QP-framework (used in QHsm only)
206#define Q_EMPTY_SIG ((QSignal)0U)
207#define Q_ENTRY_SIG ((QSignal)1U)
208#define Q_EXIT_SIG ((QSignal)2U)
209#define Q_INIT_SIG ((QSignal)3U)
210
211// NOTE: QAsm_ctor() not declared because this is a purely abstract class
212
214 void (*init)(QAsm * const me, void const * const e,
215 uint_fast8_t const qsId);
216 void (*dispatch)(QAsm * const me, QEvt const * const e,
217 uint_fast8_t const qsId);
218 bool (*isIn)(QAsm * const me, QStateHandler const stateHndl);
219 QStateHandler (*getStateHandler)(QAsm const * const me);
220};
221
222#ifdef Q_SPY
223 #define QASM_INIT(me_, par_, qsId_) \
224 (*((QAsm *)(me_))->vptr->init)((QAsm *)(me_), (par_), (qsId_))
225 #define QASM_DISPATCH(me_, e_, qsId_) \
226 (*((QAsm *)(me_))->vptr->dispatch)((QAsm *)(me_), (e_), (qsId_))
227 #define QASM_IS_IN(me_, stateHndl_) \
228 (*((QAsm *)(me_))->vptr->isIn)((QAsm *)(me_), (stateHndl_))
229#else
230 #define QASM_INIT(me_, par_, dummy) \
231 (*((QAsm *)(me_))->vptr->init)((QAsm *)(me_), (par_), 0U)
232 #define QASM_DISPATCH(me_, e_, dummy) \
233 (*((QAsm *)(me_))->vptr->dispatch)((QAsm *)(me_), (e_), 0U)
234#endif // ndef Q_SPY
235
236#define QASM_GET_STATE_HANDLER(me_) \
237 (*((QAsm *)(me_))->vptr->getStateHandler)((QAsm *)(me_))
238
239#define Q_ASM_UPCAST(ptr_) ((QAsm *)(ptr_))
240
241//----------------------------------------------------------------------------
242//! @class QHsm
243//! @extends QAsm
244typedef struct {
245 QAsm super; //!< @protected @memberof QHsm
246} QHsm;
247
248//! @protected @memberof QHsm
249void QHsm_ctor(QHsm * const me,
250 QStateHandler const initial);
251
252//! @private @memberof QHsm
253void QHsm_init_(QAsm * const me,
254 void const * const e,
255 uint_fast8_t const qsId);
256
257//! @private @memberof QHsm
258void QHsm_dispatch_(QAsm * const me,
259 QEvt const * const e,
260 uint_fast8_t const qsId);
261
262//! @private @memberof QHsm
263bool QHsm_isIn_(
264 QAsm * const me,
265 QStateHandler const stateHndl);
266
267//! @private @memberof QHsm
268QStateHandler QHsm_getStateHandler_(QAsm const * const me);
269
270//! @protected @memberof QHsm
271QState QHsm_top(QHsm const * const me,
272 QEvt const * const e);
273
274//! @public @memberof QHsm
275QStateHandler QHsm_state(QHsm const * const me);
276
277//! @public @memberof QHsm
278QStateHandler QHsm_childState(QHsm * const me,
279 QStateHandler const parentHndl);
280
281//! @private @memberof QHsm
282size_t QHsm_tran_simple_(
283 QAsm * const me,
284 QStateHandler * const path,
285 uint_fast8_t const qsId);
286
287//! @private @memberof QHsm
288size_t QHsm_tran_complex_(
289 QAsm * const me,
290 QStateHandler * const path,
291 uint_fast8_t const qsId);
292
293//! @private @memberof QHsm
294void QHsm_enter_target_(
295 QAsm * const me,
296 QStateHandler * const path,
297 size_t const depth,
298 uint_fast8_t const qsId);
299
300#define Q_HSM_UPCAST(ptr_) ((QHsm *)(ptr_))
301
302#define Q_TRAN(target_) \
303 ((Q_ASM_UPCAST(me))->temp.fun = Q_STATE_CAST(target_), \
304 (QState)Q_RET_TRAN)
305#define Q_TRAN_HIST(hist_) \
306 ((Q_ASM_UPCAST(me))->temp.fun = (hist_), \
307 (QState)Q_RET_TRAN_HIST)
308#define Q_SUPER(super_) \
309 ((Q_ASM_UPCAST(me))->temp.fun = Q_STATE_CAST(super_), \
310 (QState)Q_RET_SUPER)
311#define Q_HANDLED() ((QState)Q_RET_HANDLED)
312#define Q_UNHANDLED() ((QState)Q_RET_UNHANDLED)
313
314//----------------------------------------------------------------------------
315//! @class QMsm
316//! @extends QAsm
317typedef struct {
318 QAsm super; //!< @protected @memberof QMsm
319} QMsm;
320
321//! @protected @memberof QMsm
322void QMsm_ctor(QMsm * const me,
323 QStateHandler const initial);
324
325//! @private @memberof QMsm
326void QMsm_init_(
327 QAsm * const me,
328 void const * const e,
329 uint_fast8_t const qsId);
330
331//! @private @memberof QMsm
332void QMsm_dispatch_(
333 QAsm * const me,
334 QEvt const * const e,
335 uint_fast8_t const qsId);
336
337//! @private @memberof QMsm
338bool QMsm_isIn_(
339 QAsm * const me,
340 QStateHandler const stateHndl);
341
342//! @private @memberof QMsm
343QStateHandler QMsm_getStateHandler_(QAsm const * const me);
344
345//! @public @memberof QMsm
346QMState const * QMsm_topQMState(void);
347
348//! @public @memberof QMsm
349QMState const * QMsm_stateObj(QMsm const * const me);
350
351//! @public @memberof QMsm
352QMState const * QMsm_childStateObj(QMsm const * const me,
353 QMState const * const parentHndl);
354
355//============================================================================
356// QEP-macros
357
358#define Q_MSM_UPCAST(ptr_) ((QMsm *)(ptr_))
359#ifdef Q_SPY
360 #define QM_ENTRY(state_) \
361 ((Q_ASM_UPCAST(me))->temp.obj = (state_), (QState)Q_RET_ENTRY)
362 #define QM_EXIT(state_) \
363 ((Q_ASM_UPCAST(me))->temp.obj = (state_), (QState)Q_RET_EXIT)
364#else
365 #define QM_ENTRY(dummy) ((QState)Q_RET_ENTRY)
366 #define QM_EXIT(dummy) ((QState)Q_RET_EXIT)
367#endif // ndef Q_SPY
368
369#define QM_TRAN(tatbl_) ((Q_ASM_UPCAST(me))->temp.tatbl \
370 = (struct QMTranActTable const *)(tatbl_), (QState)Q_RET_TRAN)
371
372#define QM_TRAN_INIT(tatbl_) ((Q_ASM_UPCAST(me))->temp.tatbl \
373 = (struct QMTranActTable const *)(tatbl_), (QState)Q_RET_TRAN_INIT)
374
375#define QM_TRAN_HIST(history_, tatbl_) \
376 ((((Q_ASM_UPCAST(me))->state.obj = (history_)), \
377 ((Q_ASM_UPCAST(me))->temp.tatbl = \
378 (struct QMTranActTable const *)(tatbl_))), (QState)Q_RET_TRAN_HIST)
379
380#define QM_HANDLED() ((QState)Q_RET_HANDLED)
381#define QM_UNHANDLED() ((QState)Q_RET_UNHANDLED)
382#define QM_SUPER() ((QState)Q_RET_SUPER)
383#define QM_STATE_NULL ((QMState *)0)
384
385//----------------------------------------------------------------------------
386// QF (active object framework) types
387
388typedef uint16_t QPrioSpec;
389
390#if (QF_TIMEEVT_CTR_SIZE == 1U)
391 typedef uint8_t QTimeEvtCtr;
392#elif (QF_TIMEEVT_CTR_SIZE == 2U)
393 typedef uint16_t QTimeEvtCtr;
394#elif (QF_TIMEEVT_CTR_SIZE == 4U)
395 typedef uint32_t QTimeEvtCtr;
396#endif // (QF_TIMEEVT_CTR_SIZE == 4U)
397
398#if (QF_MAX_ACTIVE <= 8U)
399 typedef uint8_t QPSetBits;
400#elif (8U < QF_MAX_ACTIVE) && (QF_MAX_ACTIVE <= 16U)
401 typedef uint16_t QPSetBits;
402#elif (16U < QF_MAX_ACTIVE)
403 typedef uint32_t QPSetBits;
404#endif // (16U < QF_MAX_ACTIVE)
405
406#ifndef QF_LOG2
407 uint_fast8_t QF_LOG2(QPSetBits const bitmask);
408#endif // ndef QF_LOG2
409
410//----------------------------------------------------------------------------
411//! @class QPSet
412typedef struct {
413 //! @private @memberof QPSet
415#if (QF_MAX_ACTIVE > 32U)
416 //! @private @memberof QPSet
418#endif
419} QPSet;
420
421//! @public @memberof QPSet
422void QPSet_setEmpty(QPSet * const me);
423
424//! @public @memberof QPSet
425bool QPSet_isEmpty(QPSet const * const me);
426
427//! @public @memberof QPSet
428bool QPSet_notEmpty(QPSet const * const me);
429
430//! @public @memberof QPSet
431bool QPSet_hasElement(QPSet const * const me, uint_fast8_t const n);
432
433//! @public @memberof QPSet
434void QPSet_insert(QPSet * const me, uint_fast8_t const n);
435
436//! @public @memberof QPSet
437void QPSet_remove(QPSet * const me, uint_fast8_t const n);
438
439//! @public @memberof QPSet
440uint_fast8_t QPSet_findMax(QPSet const * const me);
441
442//! @struct QSubscrList
443typedef struct {
444 QPSet set; //!< @private @memberof QSubscrList
446
447struct QEQueue; // forward declaration
448
449//----------------------------------------------------------------------------
450//! @class QActive
451//! @extends QAsm
452typedef struct QActive {
453 QAsm super; //!< @protected @memberof QActive
454 uint8_t prio; //!< @protected @memberof QActive
455 uint8_t pthre; //!< @protected @memberof QActive
456
457#ifdef QACTIVE_THREAD_TYPE
458 QACTIVE_THREAD_TYPE thread; //!< @protected @memberof QActive
459#endif
460
461#ifdef QACTIVE_OS_OBJ_TYPE
462 QACTIVE_OS_OBJ_TYPE osObject; //!< @protected @memberof QActive
463#endif
464
465#ifdef QACTIVE_EQUEUE_TYPE
466 QACTIVE_EQUEUE_TYPE eQueue; //!< @protected @memberof QActive
467#endif // def QACTIVE_EQUEUE_TYPE
468} QActive;
469
470//! @protected @memberof QActive
471void QActive_ctor(QActive * const me,
472 QStateHandler const initial);
473
474//! @public @memberof QActive
475void QActive_setAttr(QActive * const me,
476 uint32_t attr1,
477 void const * attr2);
478
479//! @public @memberof QActive
480void QActive_start(QActive * const me,
481 QPrioSpec const prioSpec,
482 QEvtPtr * const qSto,
483 uint_fast16_t const qLen,
484 void * const stkSto,
485 uint_fast16_t const stkSize,
486 void const * const par);
487
488#ifdef QACTIVE_CAN_STOP
489//! @protected @memberof QActive
490void QActive_stop(QActive * const me);
491#endif // def QACTIVE_CAN_STOP
492
493//! @private @memberof QActive
494void QActive_register_(QActive * const me);
495
496//! @private @memberof QActive
497void QActive_unregister_(QActive * const me);
498
499//! @private @memberof QActive
500bool QActive_post_(QActive * const me,
501 QEvt const * const e,
502 uint_fast16_t const margin,
503 void const * const sender);
504
505//! @private @memberof QActive
506void QActive_postLIFO_(QActive * const me,
507 QEvt const * const e);
508
509//! @private @memberof QActive
510QEvt const * QActive_get_(QActive * const me);
511
512//! @static @public @memberof QActive
513void QActive_psInit(
514 QSubscrList * const subscrSto,
515 enum_t const maxSignal);
516
517//! @static @private @memberof QActive
519 QEvt const * const e,
520 void const * const sender,
521 uint_fast8_t const qsId);
522
523//! @static @public @memberof QActive
524uint16_t QActive_getQueueUse(uint_fast8_t const prio);
525
526//! @static @public @memberof QActive
527uint16_t QActive_getQueueFree(uint_fast8_t const prio);
528
529//! @static @public @memberof QActive
530uint16_t QActive_getQueueMin(uint_fast8_t const prio);
531
532//! @protected @memberof QActive
533void QActive_subscribe(QActive const * const me,
534 enum_t const sig);
535
536//! @protected @memberof QActive
537void QActive_unsubscribe(QActive const * const me,
538 enum_t const sig);
539
540//! @protected @memberof QActive
541void QActive_unsubscribeAll(QActive const * const me);
542
543//! @protected @memberof QActive
544bool QActive_defer(QActive const * const me,
545 struct QEQueue * const eq,
546 QEvt const * const e);
547
548//! @protected @memberof QActive
549bool QActive_recall(QActive * const me,
550 struct QEQueue * const eq);
551
552//! @protected @memberof QActive
553uint16_t QActive_flushDeferred(QActive const * const me,
554 struct QEQueue * const eq,
555 uint_fast16_t const num);
556
557//! @private @memberof QActive
558void QActive_evtLoop_(QActive * const me);
559
560#define Q_ACTIVE_UPCAST(ptr_) ((QActive *)(ptr_))
561
562//----------------------------------------------------------------------------
563//! @class QMActive
564//! @extends QActive
565typedef struct {
566 QActive super; //!< @protected @memberof QMActive
567} QMActive;
568
569//! @protected @memberof QMActive
570void QMActive_ctor(QMActive * const me,
571 QStateHandler const initial);
572
573//----------------------------------------------------------------------------
574#if (QF_MAX_TICK_RATE > 0U)
575
576//! @class QTimeEvt
577//! @extends QEvt
578typedef struct QTimeEvt {
579 QEvt super; //!< @protected @memberof QTimeEvt
580
581 struct QTimeEvt *next; //!< @private @memberof QTimeEvt
582 void * act; //!< @private @memberof QTimeEvt
583 QTimeEvtCtr ctr; //!< @private @memberof QTimeEvt
584 QTimeEvtCtr interval; //!< @private @memberof QTimeEvt
585 uint8_t tickRate; //!< @private @memberof QTimeEvt
586 uint8_t flags; //!< @private @memberof QTimeEvt
587} QTimeEvt;
588
589//! @public @memberof QTimeEvt
590void QTimeEvt_ctorX(QTimeEvt * const me,
591 QActive * const act,
592 enum_t const sig,
593 uint_fast8_t const tickRate);
594
595//! @public @memberof QTimeEvt
596void QTimeEvt_armX(QTimeEvt * const me,
597 uint32_t const nTicks,
598 uint32_t const interval);
599
600//! @public @memberof QTimeEvt
601bool QTimeEvt_disarm(QTimeEvt * const me);
602
603//! @public @memberof QTimeEvt
604bool QTimeEvt_rearm(QTimeEvt * const me,
605 uint32_t const nTicks);
606
607//! @public @memberof QTimeEvt
608bool QTimeEvt_wasDisarmed(QTimeEvt * const me);
609
610//! @public @memberof QTimeEvt
611QTimeEvtCtr QTimeEvt_getCtr(QTimeEvt const * const me);
612
613//! @static @private @memberof QTimeEvt
614void QTimeEvt_init(void);
615
616//! @static @private @memberof QTimeEvt
617void QTimeEvt_tick_(
618 uint_fast8_t const tickRate,
619 void const * const sender);
620
621//! @private @memberof QTimeEvt
623 QTimeEvt * const prev_link,
624 QActive const * const act,
625 uint_fast8_t const tickRate);
626
627#ifdef Q_UTEST
628 //! @static @private @memberof QTimeEvt
629 void QTimeEvt_tick1_(
630 uint_fast8_t const tickRate,
631 void const * const sender);
632#endif // def Q_UTEST
633
634//! @static @public @memberof QTimeEvt
635bool QTimeEvt_noActive(uint_fast8_t const tickRate);
636
637//----------------------------------------------------------------------------
638//! @class QTicker
639//! @extends QActive
640typedef struct {
641 QActive super; //!< @protected @memberof QTicker
642} QTicker;
643
644//! @public @memberof QTicker
645void QTicker_ctor(QTicker * const me,
646 uint_fast8_t const tickRate);
647
648//! @private @memberof QTicker
649void QTicker_init_(QAsm * const me,
650 void const * const par,
651 uint_fast8_t const qsId);
652
653//! @private @memberof QTicker
654void QTicker_dispatch_(QAsm * const me,
655 QEvt const * const e,
656 uint_fast8_t const qsId);
657
658//! @private @memberof QTicker
659void QTicker_trig_(QTicker * const me,
660 void const * const sender);
661
662#endif // (QF_MAX_TICK_RATE > 0U)
663
664//----------------------------------------------------------------------------
665// QF base facilities
666
667//! @static @public @memberof QF
668void QF_init(void);
669
670//! @static @public @memberof QF
671void QF_stop(void);
672
673//! @static @public @memberof QF
674int_t QF_run(void);
675
676//! @static @public @memberof QF
677void QF_onStartup(void);
678
679//! @static @public @memberof QF
680void QF_onCleanup(void);
681
682#ifdef QF_ON_CONTEXT_SW
683 //! @static @public @memberof QF
685 QActive * prev,
686 QActive * next);
687#endif // def QF_ON_CONTEXT_SW
688
689static inline QPrioSpec Q_PRIO(uint8_t const prio, uint8_t const pthre) {
690 // combine the QF prio. preemption-threshold pthre in the upper byte
691 return (QPrioSpec)((uint32_t)prio | ((uint32_t)pthre << 8U));
692}
693
694#define QF_NO_MARGIN ((uint_fast16_t)0xFFFFU)
695
696//----------------------------------------------------------------------------
697// QF dynamic memory facilities
698
699//! @static @public @memberof QF
700void QF_poolInit(
701 void * const poolSto,
702 uint_fast32_t const poolSize,
703 uint_fast16_t const evtSize);
704
705//! @static @public @memberof QF
706uint16_t QF_poolGetMaxBlockSize(void);
707
708//! @static @public @memberof QF
709uint16_t QF_getPoolUse(uint_fast8_t const poolNum);
710
711//! @static @public @memberof QF
712uint16_t QF_getPoolFree(uint_fast8_t const poolNum);
713
714//! @static @public @memberof QF
715uint16_t QF_getPoolMin(uint_fast8_t const poolNum);
716
717//! @static @private @memberof QF
718QEvt * QF_newX_(
719 uint_fast16_t const evtSize,
720 uint_fast16_t const margin,
721 enum_t const sig);
722
723//! @static @public @memberof QF
724void QF_gc(QEvt const * const e);
725
726//! @static @private @memberof QF
727QEvt const * QF_newRef_(
728 QEvt const * const e,
729 void const * const evtRef);
730
731//! @static @private @memberof QF
732void QF_deleteRef_(void const * const evtRef);
733
734//! @static @public @memberof QF
735void QF_gcFromISR(QEvt const * const e);
736
737#ifdef QEVT_PAR_INIT
738 #define Q_NEW(evtT_, sig_, ...) \
739 (evtT_##_init((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
740 QF_NO_MARGIN, (sig_)), __VA_ARGS__))
741 #define Q_NEW_X(evtT_, margin_, sig_, ...) \
742 (evtT_##_init((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
743 (margin_), (sig_)), __VA_ARGS__))
744#else
745 #define Q_NEW(evtT_, sig_) \
746 ((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
747 QF_NO_MARGIN, (enum_t)(sig_)))
748 #define Q_NEW_X(evtT_, margin_, sig_) \
749 ((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
750 (margin_), (enum_t)(sig_)))
751#endif // QEVT_PAR_INIT
752
753#define Q_NEW_REF(evtRef_, evtT_) \
754 ((evtRef_) = (evtT_ const *)QF_newRef_(e, (evtRef_)))
755#define Q_DELETE_REF(evtRef_) do { \
756 QF_deleteRef_((evtRef_)); \
757 (evtRef_) = (void *)0; \
758} while (false)
759
760#ifdef Q_SPY
761 #define QACTIVE_POST(me_, e_, sender_) \
762 ((void)QActive_post_((me_), (e_), QF_NO_MARGIN, (sender_)))
763 #define QACTIVE_POST_X(me_, e_, margin_, sender_) \
764 (QActive_post_((me_), (e_), (margin_), (sender_)))
765 #define QACTIVE_PUBLISH(e_, sender_) \
766 (QActive_publish_((e_), (void const *)(sender_), (sender_)->prio))
767 #define QTIMEEVT_TICK_X(tickRate_, sender_) (QTimeEvt_tick_((tickRate_), (sender_)))
768 #define QTICKER_TRIG(ticker_, sender_) (QTicker_trig_((ticker_), (sender_)))
769#else
770 #define QACTIVE_POST(me_, e_, dummy) \
771 ((void)QActive_post_((me_), (e_), QF_NO_MARGIN, (void *)0))
772 #define QACTIVE_POST_X(me_, e_, margin_, dummy) \
773 (QActive_post_((me_), (e_), (margin_), (void *)0))
774 #define QACTIVE_PUBLISH(e_, dummy) (QActive_publish_((e_), (void *)0, 0U))
775 #define QTIMEEVT_TICK_X(tickRate_, dummy) (QTimeEvt_tick_((tickRate_), (void *)0))
776 #define QTICKER_TRIG(ticker_, sender_) (QTicker_trig_((ticker_), (void *)0))
777#endif // ndef Q_SPY
778
779#define QACTIVE_POST_LIFO(me_, e_) (QActive_postLIFO_((me_), (e_)))
780#define QTIMEEVT_TICK(sender_) QTIMEEVT_TICK_X(0U, (sender_))
781
782#ifndef QF_CRIT_EXIT_NOP
783 #define QF_CRIT_EXIT_NOP() ((void)0)
784#endif // ndef QF_CRIT_EXIT_NOP
785
786#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:151
uint32_t QPSetBits
Bitmask for the internal representation of QPSet elements.
Definition qp.h:403
QState(* QStateHandler)(void *const me, QEvt const *const e)
Pointer to a state-handler function.
Definition qp.h:147
uint32_t QTimeEvtCtr
Data type to store the block-size defined based on the macro QF_TIMEEVT_CTR_SIZE.
Definition qp.h:395
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:146
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:689
QState(* QActionHandler)(void *const me)
Pointer to an action-handler function.
Definition qp.h:148
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:388
#define QACTIVE_OS_OBJ_TYPE
Port-specific QActive "OS-object" type.
Definition qp_port.h:39
#define QACTIVE_EQUEUE_TYPE
Port-specific QActive event queue type.
Definition qp_port.h:32
#define QACTIVE_THREAD_TYPE
Port-specific QActive thread type.
Definition qp_port.h:46
#define QF_LOG2(bitmask_)
Port-specific integer log-base-2 of a 32-bit bitmask.
Definition qp_port.h:139
int_t QF_run(void)
Definition qutest.c:217
void QF_init(void)
Definition qutest.c:138
void QF_stop(void)
Definition qutest.c:145
Active object class (based on the QHsm implementation strategy).
Definition qp.h:452
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:230
QAsm super
Definition qp.h:453
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:458
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:194
uint16_t QActive_getQueueFree(uint_fast8_t const prio)
Definition qf_actq.c:349
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:122
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:462
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:466
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:80
void QActive_stop(QActive *const me)
Stops execution of an active object and removes it from the framework's supervision.
Definition qutest.c:263
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:454
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:196
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:167
uint16_t QActive_getQueueUse(uint_fast8_t const prio)
Definition qf_actq.c:315
void QActive_unsubscribeAll(QActive const *const me)
Unsubscribes from the delivery of all signals to the active object.
Definition qf_ps.c:264
void QActive_psInit(QSubscrList *const subscrSto, enum_t const maxSignal)
Initializes the publish-subscribe facility for the application.
Definition qf_ps.c:54
uint8_t pthre
Preemption-threshold [1..QF_MAX_ACTIVE] of this AO.
Definition qp.h:455
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:369
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:183
struct QAsmVtable const * vptr
Virtual pointer inherited by all QAsm subclasses (see also ARCH_QP_OOA).
Definition qp.h:184
union QAsmAttr state
Current state (pointer to the current state-handler function).
Definition qp.h:185
union QAsmAttr temp
Temporary storage for target/act-table etc..
Definition qp.h:186
Virtual table for the QAsm class.
Definition qp.h:213
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:214
QStateHandler(* getStateHandler)(QAsm const *const me)
Virtual function to get the current state handler of the state machine.
Definition qp.h:219
bool(* isIn)(QAsm *const me, QStateHandler const stateHndl)
Virtual function to check whether the state machine is in a given state.
Definition qp.h:218
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:216
Native QF Event Queue.
Definition qequeue.h:52
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
The data type to store in the event queue ring-buffer.
Definition qequeue.h:46
struct QEvt const * e
Definition qequeue.h:47
Hierarchical State Machine class (QHsm-style state machine implementation strategy).
Definition qp.h:244
QAsm super
Definition qp.h:245
Active object class (based on QMsm implementation strategy).
Definition qp.h:565
QActive super
Definition qp.h:566
State object for the QMsm class (QM State Machine).
Definition qp.h:153
struct QMState const * superstate
Definition qp.h:154
QActionHandler const entryAction
Definition qp.h:156
QActionHandler const initAction
Definition qp.h:158
QActionHandler const exitAction
Definition qp.h:157
QStateHandler const stateHandler
Definition qp.h:155
Transition-Action Table for the QMsm State Machine.
Definition qp.h:161
QActionHandler const act[1]
Definition qp.h:163
QMState const * target
Definition qp.h:162
Hierarchical State Machine class (QMsm-style state machine implementation strategy).
Definition qp.h:317
QAsm super
Definition qp.h:318
Set of Active Objects of up to QF_MAX_ACTIVE elements.
Definition qp.h:412
QPSetBits bits0
Bitmask for elements 1..32.
Definition qp.h:414
QPSetBits bits1
Bitmask for elements 33..64.
Definition qp.h:417
Subscriber List (for publish-subscribe).
Definition qp.h:443
QPSet set
The set of AOs that subscribed to a given event signal.
Definition qp.h:444
"Ticker" Active Object class
Definition qp.h:640
QActive super
Definition qp.h:641
Time Event class.
Definition qp.h:578
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:583
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 (the next upcoming) clock tick for QUTest.
Definition qutest.c:276
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:584
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:586
struct QTimeEvt * next
Link to the next time event in the list.
Definition qp.h:581
QEvt super
Definition qp.h:579
void * act
Active object that receives the time events.
Definition qp.h:582
uint8_t tickRate
Definition qp.h:585
eXtended (blocking) thread of the QXK preemptive kernel
Definition qxk.h:88
Attribute of for the QAsm class (Abstract State Machine).
Definition qp.h:166
uintptr_t uint
Definition qp.h:172
QMTranActTable const * tatbl
Definition qp.h:170
QXThreadHandler thr
Definition qp.h:169
QStateHandler fun
Definition qp.h:167
struct QMState const * obj
Definition qp.h:171
QActionHandler act
Definition qp.h:168