QP/C++  8.0.0
Real-Time Embedded Framework
Loading...
Searching...
No Matches
qp.hpp
Go to the documentation of this file.
1//$file${include::qp.hpp} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
2//
3// Model: qpcpp.qm
4// File: ${include::qp.hpp}
5//
6// This code has been generated by QM 7.0.0 <www.state-machine.com/qm>.
7// DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
8//
9// Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
10//
11// Q u a n t u m L e a P s
12// ------------------------
13// Modern Embedded Software
14//
15// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
16//
17// The QP/C++ software is dual-licensed under the terms of the open-source
18// GNU General Public License (GPL) or under the terms of one of the closed-
19// source Quantum Leaps commercial licenses.
20//
21// Redistributions in source code must retain this top-level comment block.
22// Plagiarizing this software to sidestep the license obligations is illegal.
23//
24// NOTE:
25// The GPL does NOT permit the incorporation of this code into proprietary
26// programs. Please contact Quantum Leaps for commercial licensing options,
27// which expressly supersede the GPL and are designed explicitly for
28// closed-source distribution.
29//
30// Quantum Leaps contact information:
31// <www.state-machine.com/licensing>
32// <info@state-machine.com>
33//
34//$endhead${include::qp.hpp} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
35#ifndef QP_HPP_
36#define QP_HPP_
37
38//============================================================================
39#define QP_VERSION_STR "8.0.0"
40#define QP_VERSION 800U
41#define QP_RELEASE 0x7055936FU
42
43//============================================================================
44//! @cond INTERNAL
45
46#ifndef Q_SIGNAL_SIZE
47#define Q_SIGNAL_SIZE 2U
48#endif
49
50#ifndef QF_MAX_ACTIVE
51#define QF_MAX_ACTIVE 32U
52#endif
53
54#if (QF_MAX_ACTIVE > 64U)
55#error QF_MAX_ACTIVE exceeds the maximum of 64U;
56#endif
57
58#ifndef QF_MAX_TICK_RATE
59#define QF_MAX_TICK_RATE 1U
60#endif
61
62#if (QF_MAX_TICK_RATE > 15U)
63#error QF_MAX_TICK_RATE exceeds the maximum of 15U;
64#endif
65
66#ifndef QF_MAX_EPOOL
67#define QF_MAX_EPOOL 3U
68#endif
69
70#if (QF_MAX_EPOOL > 15U)
71#error QF_MAX_EPOOL exceeds the maximum of 15U;
72#endif
73
74#ifndef QF_TIMEEVT_CTR_SIZE
75#define QF_TIMEEVT_CTR_SIZE 4U
76#endif
77
78#if (QF_TIMEEVT_CTR_SIZE > 4U)
79#error QF_TIMEEVT_CTR_SIZE defined incorrectly, expected 1U, 2U, or 4U;
80#endif
81
82#ifndef QF_EVENT_SIZ_SIZE
83#define QF_EVENT_SIZ_SIZE 2U
84#endif
85
86#if (QF_EVENT_SIZ_SIZE > 4U)
87#error QF_EVENT_SIZ_SIZE defined incorrectly, expected 1U, 2U, or 4U;
88#endif
89
90//! @endcond
91//============================================================================
92
93//$declare${glob-types} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
94
95//${glob-types::int_t} .......................................................
96using int_t = int;
97
98//${glob-types::enum_t} ......................................................
99using enum_t = int;
100
101//${glob-types::float32_t} ...................................................
102using float32_t = float;
103
104//${glob-types::float64_t} ...................................................
105using float64_t = double;
106//$enddecl${glob-types} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
107
108//$declare${QEP} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
109namespace QP {
110
111//${QEP::versionStr[]} .......................................................
112//! the current QP version number string in ROM, based on #QP_VERSION_STR
113constexpr char const versionStr[] {QP_VERSION_STR};
114
115//${QEP::QSignal} ............................................................
116#if (Q_SIGNAL_SIZE == 1U)
117using QSignal = std::uint8_t;
118#endif // (Q_SIGNAL_SIZE == 1U)
119
120//${QEP::QSignal} ............................................................
121#if (Q_SIGNAL_SIZE == 2U)
122using QSignal = std::uint16_t;
123#endif // (Q_SIGNAL_SIZE == 2U)
124
125//${QEP::QSignal} ............................................................
126#if (Q_SIGNAL_SIZE == 4U)
127using QSignal = std::uint32_t;
128#endif // (Q_SIGNAL_SIZE == 4U)
129
130//${QEP::QEvt} ...............................................................
131class QEvt {
132public:
134 std::uint8_t evtTag_;
135 std::uint8_t volatile refCtr_;
136
137public:
138 enum DynEvt: std::uint8_t { DYNAMIC };
139
140public:
141 explicit constexpr QEvt(QSignal const s) noexcept
142 : sig(s),
143 evtTag_(0x01U),
144 refCtr_(0x0EU)
145 {}
146 QEvt() = delete;
147 void init() noexcept {
148 // no event parameters to initialize
149 }
150 void init(DynEvt const dummy) noexcept {
151 static_cast<void>(dummy);
152 // no event parameters to initialize
153 }
154 bool verify_() const noexcept {
155 std::uint8_t rc = refCtr_;
156 return (rc <= 2U*QF_MAX_ACTIVE)
157 && (((evtTag_ ^ rc) & 0x0FU) == 0x0FU);
158 }
159 std::uint_fast8_t getPoolNum_() const noexcept {
160 return static_cast<std::uint8_t>(evtTag_ >> 4U);
161 }
162}; // class QEvt
163
164//${QEP::QState} .............................................................
165using QState = std::uint_fast8_t;
166
167//${QEP::QStateHandler} ......................................................
168using QStateHandler = QState (*)(void * const me, QEvt const * const e);
169
170//${QEP::QActionHandler} .....................................................
171using QActionHandler = QState (*)(void * const me);
172
173//${QEP::QXThread} ...........................................................
174// forward declaration
175class QXThread;
176
177//${QEP::QXThreadHandler} ....................................................
178using QXThreadHandler = void (*)(QXThread * const me);
179
180//${QEP::QMState} ............................................................
188
189//${QEP::QMTranActTable} .....................................................
193};
194
195//${QEP::QAsmAttr} ...........................................................
196union QAsmAttr {
200 QMState const *obj;
202#ifndef Q_UNSAFE
203 std::uintptr_t uint;
204#endif
205 constexpr QAsmAttr() : fun(nullptr) {}
206};
207
208//${QEP::Q_USER_SIG} .........................................................
209constexpr enum_t Q_USER_SIG {4};
210
211//${QEP::QAsm} ...............................................................
212class QAsm {
213protected:
216
217public:
218
219 //! All possible return values from state-handlers
220 //! @note
221 //! The order is important for algorithmic correctness.
223 // unhandled and need to "bubble up"
224 Q_RET_SUPER, //!< event passed to superstate to handle
225 Q_RET_UNHANDLED, //!< event unhandled due to a guard
226
227 // handled and do not need to "bubble up"
228 Q_RET_HANDLED, //!< event handled (internal transition)
229 Q_RET_IGNORED, //!< event silently ignored (bubbled up to top)
230
231 // entry/exit
232 Q_RET_ENTRY, //!< state entry action executed
233 Q_RET_EXIT, //!< state exit action executed
234
235 // no side effects
236 Q_RET_NULL, //!< return value without any effect
237
238 // transitions need to execute transition-action table in QP::QMsm
239 Q_RET_TRAN, //!< regular transition
240 Q_RET_TRAN_INIT, //!< initial transition in a state
241
242 // transitions that additionally clobber QHsm.m_state
243 Q_RET_TRAN_HIST, //!< transition to history of a given state
244 };
245
246 //! Reserved signals by the QP-framework.
248 Q_EMPTY_SIG, //!< signal to execute the default case
249 Q_ENTRY_SIG, //!< signal for entry actions
250 Q_EXIT_SIG, //!< signal for exit actions
251 Q_INIT_SIG //!< signal for nested initial transitions
252 };
253
254protected:
255 explicit QAsm() noexcept
256 : m_state(),
257 m_temp ()
258 {}
259
260public:
261
262#ifdef Q_XTOR
263 virtual ~QAsm() noexcept {
264 // empty
265 }
266#endif // def Q_XTOR
267 virtual void init(
268 void const * const e,
269 std::uint_fast8_t const qsId) = 0;
270 virtual void init(std::uint_fast8_t const qsId) {
271 this->init(nullptr, qsId);
272 }
273 virtual void dispatch(
274 QEvt const * const e,
275 std::uint_fast8_t const qsId) = 0;
276 virtual bool isIn(QStateHandler const state) noexcept {
277 static_cast<void>(state);
278 return false;
279 }
280 QStateHandler state() const noexcept {
281 return m_state.fun;
282 }
283 QMState const * stateObj() const noexcept {
284 return m_state.obj;
285 }
286
287#ifdef Q_SPY
288 virtual QStateHandler getStateHandler() noexcept {
289 return m_state.fun;
290 }
291#endif // def Q_SPY
292 static QState top(
293 void * const me,
294 QEvt const * const e) noexcept
295 {
296 static_cast<void>(me);
297 static_cast<void>(e);
298 return Q_RET_IGNORED; // the top state ignores all events
299 }
300
301protected:
302 QState tran(QStateHandler const target) noexcept {
303 m_temp.fun = target;
304 return Q_RET_TRAN;
305 }
306 QState tran_hist(QStateHandler const hist) noexcept {
307 m_temp.fun = hist;
308 return Q_RET_TRAN_HIST;
309 }
310 QState super(QStateHandler const superstate) noexcept {
311 m_temp.fun = superstate;
312 return Q_RET_SUPER;
313 }
314 QState qm_tran(void const * const tatbl) noexcept {
315 m_temp.tatbl = static_cast<QP::QMTranActTable const *>(tatbl);
316 return Q_RET_TRAN;
317 }
318 QState qm_tran_init(void const * const tatbl) noexcept {
319 m_temp.tatbl = static_cast<QP::QMTranActTable const *>(tatbl);
320 return Q_RET_TRAN_INIT;
321 }
323 QMState const * const hist,
324 void const * const tatbl) noexcept
325 {
326 m_state.obj = hist;
327 m_temp.tatbl = static_cast<QP::QMTranActTable const *>(tatbl);
328 return Q_RET_TRAN_HIST;
329 }
330
331#ifdef Q_SPY
332 QState qm_entry(QMState const * const s) noexcept {
333 m_temp.obj = s;
334 return Q_RET_ENTRY;
335 }
336#endif // def Q_SPY
337
338#ifndef Q_SPY
339 QState qm_entry(QMState const * const s) noexcept {
340 static_cast<void>(s); // unused parameter
341 return Q_RET_ENTRY;
342 }
343#endif // ndef Q_SPY
344
345#ifdef Q_SPY
346 QState qm_exit(QMState const * const s) noexcept {
347 m_temp.obj = s;
348 return Q_RET_EXIT;
349 }
350#endif // def Q_SPY
351
352#ifndef Q_SPY
353 QState qm_exit(QMState const * const s) noexcept {
354 static_cast<void>(s); // unused parameter
355 return Q_RET_EXIT;
356 }
357#endif // ndef Q_SPY
358}; // class QAsm
359
360//${QEP::QHsm} ...............................................................
361class QHsm : public QP::QAsm {
362protected:
363 explicit QHsm(QStateHandler const initial) noexcept;
364
365public:
366 void init(
367 void const * const e,
368 std::uint_fast8_t const qsId) override;
369 void init(std::uint_fast8_t const qsId) override {
370 this->init(nullptr, qsId);
371 }
372 void dispatch(
373 QEvt const * const e,
374 std::uint_fast8_t const qsId) override;
375 bool isIn(QStateHandler const state) noexcept override;
376 QStateHandler childState(QStateHandler const parent) noexcept;
377
378#ifdef Q_SPY
379 QStateHandler getStateHandler() noexcept override {
380 return m_state.fun;
381 }
382#endif // def Q_SPY
383
384private:
385 std::int_fast8_t hsm_tran(
386 QStateHandler * const path,
387 std::uint_fast8_t const qsId);
388}; // class QHsm
389
390//${QEP::QMsm} ...............................................................
391class QMsm : public QP::QAsm {
392protected:
393 explicit QMsm(QStateHandler const initial) noexcept;
394
395public:
396 void init(
397 void const * const e,
398 std::uint_fast8_t const qsId) override;
399 void init(std::uint_fast8_t const qsId) override {
400 this->init(nullptr, qsId);
401 }
402 void dispatch(
403 QEvt const * const e,
404 std::uint_fast8_t const qsId) override;
405
406#ifdef Q_SPY
407 QStateHandler getStateHandler() noexcept override {
408 return m_state.obj->stateHandler;
409 }
410#endif // def Q_SPY
411 bool isIn(QStateHandler const state) noexcept override;
412 QMState const * childStateObj(QMState const * const parent) const noexcept;
413
414private:
416 QMTranActTable const * const tatbl,
417 std::uint_fast8_t const qsId);
419 QMState const * const cs,
420 QMState const * const ts,
421 std::uint_fast8_t const qsId);
423 QMState const * const hist,
424 std::uint_fast8_t const qsId);
425
426public:
427 QMState const * topQMState() const noexcept;
428}; // class QMsm
429
430} // namespace QP
431//$enddecl${QEP} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
432
433//$declare${QEP-macros} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
434
435//${QEP-macros::Q_STATE_DECL} ................................................
436#define Q_STATE_DECL(state_) \
437 QP::QState state_ ## _h(QP::QEvt const * const e); \
438 static QP::QState state_(void * const me, QP::QEvt const * const e)
439
440//${QEP-macros::Q_STATE_DEF} .................................................
441#define Q_STATE_DEF(subclass_, state_) \
442 QP::QState subclass_::state_(void * const me, QP::QEvt const * const e) { \
443 return static_cast<subclass_ *>(me)->state_ ## _h(e); } \
444 QP::QState subclass_::state_ ## _h(QP::QEvt const * const e)
445
446//${QEP-macros::Q_HANDLED} ...................................................
447#define Q_HANDLED() (Q_RET_HANDLED)
448
449//${QEP-macros::Q_UNHANDLED} .................................................
450#define Q_UNHANDLED() (Q_RET_UNHANDLED)
451
452//${QEP-macros::Q_EVT_CAST} ..................................................
453#define Q_EVT_CAST(subclass_) (static_cast<subclass_ const *>(e))
454
455//${QEP-macros::Q_STATE_CAST} ................................................
456#define Q_STATE_CAST(handler_) \
457 (reinterpret_cast<QP::QStateHandler>(handler_))
458
459//${QEP-macros::QM_STATE_DECL} ...............................................
460#define QM_STATE_DECL(state_) \
461 QP::QState state_ ## _h(QP::QEvt const * const e); \
462 static QP::QState state_(void * const me, QP::QEvt const * const e); \
463 static QP::QMState const state_ ## _s
464
465//${QEP-macros::QM_ACTION_DECL} ..............................................
466#define QM_ACTION_DECL(action_) \
467 QP::QState action_ ## _h(); \
468 static QP::QState action_(void * const me)
469
470//${QEP-macros::QM_STATE_DEF} ................................................
471#define QM_STATE_DEF(subclass_, state_) \
472 QP::QState subclass_::state_(void * const me, QP::QEvt const * const e) {\
473 return static_cast<subclass_ *>(me)->state_ ## _h(e); } \
474 QP::QState subclass_::state_ ## _h(QP::QEvt const * const e)
475
476//${QEP-macros::QM_ACTION_DEF} ...............................................
477#define QM_ACTION_DEF(subclass_, action_) \
478 QP::QState subclass_::action_(void * const me) { \
479 return static_cast<subclass_ *>(me)->action_ ## _h(); } \
480 QP::QState subclass_::action_ ## _h()
481
482//${QEP-macros::QM_HANDLED} ..................................................
483#define QM_HANDLED() (Q_RET_HANDLED)
484
485//${QEP-macros::QM_UNHANDLED} ................................................
486#define QM_UNHANDLED() (Q_RET_HANDLED)
487
488//${QEP-macros::QM_SUPER} ....................................................
489#define QM_SUPER() (Q_RET_SUPER)
490
491//${QEP-macros::QM_STATE_NULL} ...............................................
492#define QM_STATE_NULL (nullptr)
493
494//${QEP-macros::Q_ACTION_NULL} ...............................................
495#define Q_ACTION_NULL (nullptr)
496
497//${QEP-macros::Q_UNUSED_PAR} ................................................
498#define Q_UNUSED_PAR(par_) (static_cast<void>(par_))
499
500//${QEP-macros::Q_DIM} .......................................................
501#define Q_DIM(array_) (sizeof(array_) / sizeof((array_)[0U]))
502
503//${QEP-macros::Q_UINT2PTR_CAST} .............................................
504#define Q_UINT2PTR_CAST(type_, uint_) (reinterpret_cast<type_ *>(uint_))
505
506//${QEP-macros::INIT} ........................................................
507#ifdef Q_SPY
508#define INIT(qsId_) init((qsId_))
509#endif // def Q_SPY
510
511//${QEP-macros::INIT} ........................................................
512#ifndef Q_SPY
513#define INIT(dummy) init(0U)
514#endif // ndef Q_SPY
515
516//${QEP-macros::DISPATCH} ....................................................
517#ifdef Q_SPY
518#define DISPATCH(e_, qsId_) dispatch((e_), (qsId_))
519#endif // def Q_SPY
520
521//${QEP-macros::DISPATCH} ....................................................
522#ifndef Q_SPY
523#define DISPATCH(e_, dummy) dispatch((e_), 0U)
524#endif // ndef Q_SPY
525//$enddecl${QEP-macros} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
526
527//$declare${QF::types} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
528namespace QP {
529
530//${QF::types::QPrioSpec} ....................................................
531using QPrioSpec = std::uint16_t;
532
533//${QF::types::QEvtPtr} ......................................................
534using QEvtPtr = QEvt const *;
535
536//${QF::types::QTimeEvtCtr} ..................................................
537#if (QF_TIMEEVT_CTR_SIZE == 1U)
538using QTimeEvtCtr = std::uint8_t;
539#endif // (QF_TIMEEVT_CTR_SIZE == 1U)
540
541//${QF::types::QTimeEvtCtr} ..................................................
542#if (QF_TIMEEVT_CTR_SIZE == 2U)
543using QTimeEvtCtr = std::uint16_t;
544#endif // (QF_TIMEEVT_CTR_SIZE == 2U)
545
546//${QF::types::QTimeEvtCtr} ..................................................
547#if (QF_TIMEEVT_CTR_SIZE == 4U)
548using QTimeEvtCtr = std::uint32_t;
549#endif // (QF_TIMEEVT_CTR_SIZE == 4U)
550
551//${QF::types::QPSetBits} ....................................................
552#if (QF_MAX_ACTIVE <= 8U)
553using QPSetBits = std::uint8_t;
554#endif // (QF_MAX_ACTIVE <= 8U)
555
556//${QF::types::QPSetBits} ....................................................
557#if (8U < QF_MAX_ACTIVE) && (QF_MAX_ACTIVE <= 16U)
558using QPSetBits = std::uint16_t;
559#endif // (8U < QF_MAX_ACTIVE) && (QF_MAX_ACTIVE <= 16U)
560
561//${QF::types::QPSetBits} ....................................................
562#if (16 < QF_MAX_ACTIVE)
563using QPSetBits = std::uint32_t;
564#endif // (16 < QF_MAX_ACTIVE)
565
566//${QF::types::QF_LOG2} ......................................................
567#ifndef QF_LOG2
568std::uint_fast8_t QF_LOG2(QP::QPSetBits x) noexcept;
569#endif // ndef QF_LOG2
570
571//${QF::types::QPSet} ........................................................
572class QPSet {
573private:
574 QPSetBits m_bits[((QF_MAX_ACTIVE + (8U*sizeof(QPSetBits))) - 1U)/(8U*sizeof(QPSetBits))];
575
576public:
577 void setEmpty() noexcept {
578 m_bits[0] = 0U;
579 #if (QF_MAX_ACTIVE > 32)
580 m_bits[1] = 0U;
581 #endif
582 }
583 bool isEmpty() const noexcept {
584 #if (QF_MAX_ACTIVE <= 32U)
585 return (m_bits[0] == 0U);
586 #else
587 return (m_bits[0] == 0U) ? (m_bits[1] == 0U) : false;
588 #endif
589 }
590 bool notEmpty() const noexcept {
591 #if (QF_MAX_ACTIVE <= 32U)
592 return (m_bits[0] != 0U);
593 #else
594 return (m_bits[0] != 0U) ? true : (m_bits[1] != 0U);
595 #endif
596 }
597 bool hasElement(std::uint_fast8_t const n) const noexcept {
598 #if (QF_MAX_ACTIVE <= 32U)
599 return (m_bits[0] & (static_cast<QPSetBits>(1U) << (n - 1U))) != 0U;
600 #else
601 return (n <= 32U)
602 ? ((m_bits[0] & (static_cast<QPSetBits>(1U) << (n - 1U))) != 0U)
603 : ((m_bits[1] & (static_cast<QPSetBits>(1U) << (n - 33U))) != 0U);
604 #endif
605 }
606 void insert(std::uint_fast8_t const n) noexcept {
607 #if (QF_MAX_ACTIVE <= 32U)
608 m_bits[0] = (m_bits[0] | (static_cast<QPSetBits>(1U) << (n - 1U)));
609 #else
610 if (n <= 32U) {
611 m_bits[0] = (m_bits[0] | (static_cast<QPSetBits>(1U) << (n - 1U)));
612 }
613 else {
614 m_bits[1] = (m_bits[1] | (static_cast<QPSetBits>(1U) << (n - 33U)));
615 }
616 #endif
617 }
618 void remove(std::uint_fast8_t const n) noexcept {
619 #if (QF_MAX_ACTIVE <= 32U)
620 m_bits[0] = (m_bits[0] & static_cast<QPSetBits>(~(1U << (n - 1U))));
621 #else
622 if (n <= 32U) {
623 (m_bits[0] = (m_bits[0] & ~(static_cast<QPSetBits>(1U) << (n - 1U))));
624 }
625 else {
626 (m_bits[1] = (m_bits[1] & ~(static_cast<QPSetBits>(1U) << (n - 33U))));
627 }
628 #endif
629 }
630 std::uint_fast8_t findMax() const noexcept {
631 #if (QF_MAX_ACTIVE <= 32U)
632 return QF_LOG2(m_bits[0]);
633 #else
634 return (m_bits[1] != 0U)
635 ? (QF_LOG2(m_bits[1]) + 32U)
636 : (QF_LOG2(m_bits[0]));
637 #endif
638 }
639
640#ifndef Q_UNSAFE
641 void update_(QPSet * const dis) const noexcept {
642 dis->m_bits[0] = ~m_bits[0];
643 #if (QF_MAX_ACTIVE > 32U)
644 dis->m_bits[1] = ~m_bits[1];
645 #endif
646 }
647#endif // ndef Q_UNSAFE
648
649#ifndef Q_UNSAFE
650 bool verify_(QPSet const * const dis) const noexcept {
651 #if (QF_MAX_ACTIVE <= 32U)
652 return m_bits[0] == static_cast<QPSetBits>(~dis->m_bits[0]);
653 #else
654 return (m_bits[0] == static_cast<QPSetBits>(~dis->m_bits[0]))
655 && (m_bits[1] == static_cast<QPSetBits>(~dis->m_bits[1]));
656 #endif
657 }
658#endif // ndef Q_UNSAFE
659}; // class QPSet
660
661//${QF::types::QSubscrList} ..................................................
663private:
665
666#ifndef Q_UNSAFE
668#endif // ndef Q_UNSAFE
669
670 // friends...
671 friend class QActive;
672}; // class QSubscrList
673
674//${QF::types::QPtrDis} ......................................................
675class QPtrDis {
676private:
677 std::uintptr_t m_ptr_dis;
678
679 // friends...
680 friend class QTimeEvt;
681
682 // friends...
683 friend class QXThread;
684
685public:
686 QPtrDis(void const * const ptr = nullptr) noexcept;
687}; // class QPtrDis
688
689//${QF::types::QEQueue} ......................................................
690class QEQueue;
691
692} // namespace QP
693//$enddecl${QF::types} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
694
695//$declare${QF::QActive} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
696namespace QP {
697
698//${QF::QActive} .............................................................
699class QActive : public QP::QAsm {
700protected:
701 std::uint8_t m_prio;
702 std::uint8_t m_pthre;
703
704#ifdef QACTIVE_THREAD_TYPE
706#endif // def QACTIVE_THREAD_TYPE
707
708#ifdef QACTIVE_OS_OBJ_TYPE
710#endif // def QACTIVE_OS_OBJ_TYPE
711
712#ifdef QACTIVE_EQUEUE_TYPE
714#endif // def QACTIVE_EQUEUE_TYPE
715
716public:
717
718#ifndef Q_UNSAFE
719 std::uint8_t m_prio_dis;
720#endif // ndef Q_UNSAFE
721
722#ifndef Q_UNSAFE
723 std::uint8_t m_pthre_dis;
724#endif // ndef Q_UNSAFE
725 static QActive * registry_[QF_MAX_ACTIVE + 1U];
728
729 // friends...
730 friend class QTimeEvt;
731 friend class QTicker;
732 friend class QXThread;
733 friend class QXMutex;
734 friend class QXSemaphore;
735 friend class QActiveDummy;
736 friend class GuiQActive;
737 friend class GuiQMActive;
738 friend void schedLock();
739
740protected:
741 explicit QActive(QStateHandler const initial) noexcept
742 : QAsm(),
743 m_prio(0U),
744 m_pthre(0U)
745 {
746 m_state.fun = Q_STATE_CAST(&top);
747 m_temp.fun = initial;
748
749 #ifndef Q_UNSAFE
750 m_prio_dis = static_cast<std::uint8_t>(~m_prio);
751 m_pthre_dis = static_cast<std::uint8_t>(~m_pthre);
752 #endif
753 }
754
755public:
756 void init(
757 void const * const e,
758 std::uint_fast8_t const qsId) override
759 {
760 reinterpret_cast<QHsm *>(this)->QHsm::init(e, qsId);
761 }
762 void init(std::uint_fast8_t const qsId) override {
763 this->init(nullptr, qsId);
764 }
766 QEvt const * const e,
767 std::uint_fast8_t const qsId) override
768 {
769 reinterpret_cast<QHsm *>(this)->QHsm::dispatch(e, qsId);
770 }
771 bool isIn(QStateHandler const state) noexcept override {
772 return reinterpret_cast<QHsm *>(this)->QHsm::isIn(state);
773 }
774 QStateHandler childState(QStateHandler const parent) noexcept {
775 return reinterpret_cast<QHsm *>(this)->QHsm::childState(parent);
776 }
778 std::uint32_t attr1,
779 void const * attr2 = nullptr);
780 void start(
781 QPrioSpec const prioSpec,
782 QEvtPtr * const qSto,
783 std::uint_fast16_t const qLen,
784 void * const stkSto,
785 std::uint_fast16_t const stkSize,
786 void const * const par);
787 void start(
788 QPrioSpec const prioSpec,
789 QEvtPtr * const qSto,
790 std::uint_fast16_t const qLen,
791 void * const stkSto,
792 std::uint_fast16_t const stkSize)
793 {
794 this->start(prioSpec, qSto, qLen, stkSto, stkSize, nullptr);
795 }
796
797#ifdef QACTIVE_CAN_STOP
798 void stop();
799#endif // def QACTIVE_CAN_STOP
800 void register_() noexcept;
801 void unregister_() noexcept;
802 bool post_(
803 QEvt const * const e,
804 std::uint_fast16_t const margin,
805 void const * const sender) noexcept;
806 void postLIFO(QEvt const * const e) noexcept;
807 QEvt const * get_() noexcept;
808 static std::uint_fast16_t getQueueMin(std::uint_fast8_t const prio) noexcept;
809 static void psInit(
810 QSubscrList * const subscrSto,
811 enum_t const maxSignal) noexcept;
812 static void publish_(
813 QEvt const * const e,
814 void const * const sender,
815 std::uint_fast8_t const qsId) noexcept;
816 void subscribe(enum_t const sig) const noexcept;
817 void unsubscribe(enum_t const sig) const noexcept;
818 void unsubscribeAll() const noexcept;
819 bool defer(
820 QEQueue * const eq,
821 QEvt const * const e) const noexcept;
822 bool recall(QEQueue * const eq) noexcept;
823 std::uint_fast16_t flushDeferred(
824 QEQueue * const eq,
825 std::uint_fast16_t const num = 0xFFFFU) const noexcept;
826 std::uint_fast8_t getPrio() const noexcept {
827 return static_cast<std::uint_fast8_t>(m_prio);
828 }
829 void setPrio(QPrioSpec const prio) noexcept {
830 m_prio = static_cast<std::uint8_t>(prio & 0xFFU);
831 m_pthre = static_cast<std::uint8_t>(prio >> 8U);
832 }
833 std::uint_fast8_t getPThre() const noexcept {
834 return static_cast<std::uint_fast8_t>(m_pthre);
835 }
836
837#ifdef QACTIVE_EQUEUE_TYPE
838 QACTIVE_EQUEUE_TYPE const & getEQueue() const noexcept {
839 return m_eQueue;
840 }
841#endif // def QACTIVE_EQUEUE_TYPE
842
843#ifdef QACTIVE_OS_OBJ_TYPE
844 QACTIVE_OS_OBJ_TYPE const & getOsObject() const noexcept {
845 return m_osObject;
846 }
847#endif // def QACTIVE_OS_OBJ_TYPE
848
849#ifdef QACTIVE_THREAD_TYPE
850 QACTIVE_THREAD_TYPE const & getThread() const noexcept {
851 return m_thread;
852 }
853#endif // def QACTIVE_THREAD_TYPE
854
855#ifdef QACTIVE_THREAD_TYPE
856 void setThread(QACTIVE_THREAD_TYPE const & thr) {
857 m_thread = thr;
858 }
859#endif // def QACTIVE_THREAD_TYPE
860 static void evtLoop_(QActive * act);
861
862#ifdef QF_ISR_API
863 virtual bool postFromISR(
864 QEvt const * const e,
865 std::uint_fast16_t const margin,
866 void * par,
867 void const * const sender) noexcept;
868#endif // def QF_ISR_API
869
870#ifdef QF_ISR_API
871 static void publishFromISR(
872 QEvt const * e,
873 void * par,
874 void const * sender) noexcept;
875#endif // def QF_ISR_API
876}; // class QActive
877
878} // namespace QP
879//$enddecl${QF::QActive} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
880
881//$declare${QF::QMActive} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
882namespace QP {
883
884//${QF::QMActive} ............................................................
885class QMActive : public QP::QActive {
886protected:
887 QMActive(QStateHandler const initial) noexcept;
888
889public:
890 void init(
891 void const * const e,
892 std::uint_fast8_t const qsId) override
893 {
894 reinterpret_cast<QMsm *>(this)->QMsm::init(e, qsId);
895 }
896 void init(std::uint_fast8_t const qsId) override {
897 this->init(nullptr, qsId);
898 }
900 QEvt const * const e,
901 std::uint_fast8_t const qsId) override
902 {
903 reinterpret_cast<QMsm *>(this)->QMsm::dispatch(e, qsId);
904 }
905 bool isIn(QStateHandler const state) noexcept override {
906 return reinterpret_cast<QMsm *>(this)->QMsm::isIn(state);
907 }
908
909#ifdef Q_SPY
910 QStateHandler getStateHandler() noexcept override {
911 return reinterpret_cast<QMsm *>(this)->QMsm::getStateHandler();
912 }
913#endif // def Q_SPY
914 QMState const * childStateObj(QMState const * const parent) const noexcept {
915 return reinterpret_cast<QMsm const *>(this)
916 ->QMsm::childStateObj(parent);
917 }
918}; // class QMActive
919
920} // namespace QP
921//$enddecl${QF::QMActive} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
922
923//$declare${QF::QTimeEvt} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
924namespace QP {
925
926//${QF::QTimeEvt} ............................................................
927class QTimeEvt : public QP::QEvt {
928private:
929 QTimeEvt * volatile m_next;
930
931#ifndef Q_UNSAFE
932 std::uintptr_t m_next_dis;
933#endif // ndef Q_UNSAFE
934 void * m_act;
936
937#ifndef Q_UNSAFE
939#endif // ndef Q_UNSAFE
941 std::uint8_t m_tickRate;
942 std::uint8_t m_flags;
943
944public:
945 static QTimeEvt timeEvtHead_[QF_MAX_TICK_RATE];
946
947#ifndef Q_UNSAFE
948 static QPtrDis timeEvtHead_dis_[QF_MAX_TICK_RATE];
949#endif // ndef Q_UNSAFE
950
951private:
952 friend class QXThread;
953
954public:
955 QTimeEvt(
956 QActive * const act,
957 QSignal const sig,
958 std::uint_fast8_t const tickRate = 0U) noexcept;
959 void armX(
960 std::uint32_t const nTicks,
961 std::uint32_t const interval = 0U) noexcept;
962 bool disarm() noexcept;
963 bool rearm(std::uint32_t const nTicks) noexcept;
964 bool wasDisarmed() noexcept;
965 void const * getAct() const noexcept {
966 return m_act;
967 }
968 QTimeEvtCtr getCtr() const noexcept {
969 return m_ctr;
970 }
971 QTimeEvtCtr getInterval() const noexcept {
972 return m_interval;
973 }
974 std::uint8_t getTickRate() const noexcept {
975 return m_tickRate;
976 }
977 static void tick(
978 std::uint_fast8_t const tickRate,
979 void const * const sender) noexcept;
980
981#ifdef Q_UTEST
982 static void tick1_(
983 std::uint_fast8_t const tickRate,
984 void const * const sender);
985#endif // def Q_UTEST
986
987#ifdef QF_ISR_API
988 static void tickFromISR(
989 std::uint_fast8_t const tickRate,
990 void * par,
991 void const * sender) noexcept;
992#endif // def QF_ISR_API
993 static bool noActive(std::uint_fast8_t const tickRate) noexcept;
994 QActive * toActive() noexcept {
995 return static_cast<QActive *>(m_act);
996 }
997 QTimeEvt * toTimeEvt() noexcept {
998 return static_cast<QTimeEvt *>(m_act);
999 }
1000
1001private:
1002 QTimeEvt() noexcept;
1003 QTimeEvt(QTimeEvt const & other) = delete;
1004 QTimeEvt & operator=(QTimeEvt const & other) = delete;
1005}; // class QTimeEvt
1006
1007} // namespace QP
1008//$enddecl${QF::QTimeEvt} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1009
1010//$declare${QF::QTicker} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
1011namespace QP {
1012
1013//${QF::QTicker} .............................................................
1014class QTicker : public QP::QActive {
1015public:
1016 explicit QTicker(std::uint_fast8_t const tickRate) noexcept;
1017 void init(
1018 void const * const e,
1019 std::uint_fast8_t const qsId) override;
1020 void init(std::uint_fast8_t const qsId) override {
1021 this->init(nullptr, qsId);
1022 }
1023 void dispatch(
1024 QEvt const * const e,
1025 std::uint_fast8_t const qsId) override;
1026 void trig_(void const * const sender) noexcept;
1027}; // class QTicker
1028
1029} // namespace QP
1030//$enddecl${QF::QTicker} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1031
1032//$declare${QF::QF-base} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
1033namespace QP {
1034namespace QF {
1035
1036//${QF::QF-base::init} .......................................................
1037void init();
1038
1039//${QF::QF-base::stop} .......................................................
1040void stop();
1041
1042//${QF::QF-base::run} ........................................................
1043int_t run();
1044
1045//${QF::QF-base::onStartup} ..................................................
1047
1048//${QF::QF-base::onCleanup} ..................................................
1050
1051//${QF::QF-base::psInit} .....................................................
1052//! @deprecated
1053inline void psInit(
1054 QSubscrList * const subscrSto,
1055 enum_t const maxSignal) noexcept
1056{
1057 QActive::psInit(subscrSto, maxSignal);
1058}
1059
1060//${QF::QF-base::publish_} ...................................................
1061//! @deprecated
1062inline void publish_(
1063 QEvt const * const e,
1064 void const * const sender,
1065 std::uint_fast8_t const qsId) noexcept
1066{
1067 QActive::publish_(e, sender, qsId);
1068}
1069
1070//${QF::QF-base::tick} .......................................................
1071//! @deprecated
1072inline void tick(
1073 std::uint_fast8_t const tickRate,
1074 void const * const sender) noexcept
1075{
1076 QTimeEvt::tick(tickRate, sender);
1077}
1078
1079//${QF::QF-base::getQueueMin} ................................................
1080//! @deprecated
1081inline std::uint_fast16_t getQueueMin(std::uint_fast8_t const prio) noexcept {
1082 return QActive::getQueueMin(prio);
1083}
1084
1085//${QF::QF-base::NO_MARGIN} ..................................................
1086constexpr std::uint_fast16_t NO_MARGIN {0xFFFFU};
1087
1088} // namespace QF
1089} // namespace QP
1090//$enddecl${QF::QF-base} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1091
1092//$declare${QF::QF-dyn} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
1093namespace QP {
1094namespace QF {
1095
1096//${QF::QF-dyn::poolInit} ....................................................
1097void poolInit(
1098 void * const poolSto,
1099 std::uint_fast32_t const poolSize,
1100 std::uint_fast16_t const evtSize) noexcept;
1101
1102//${QF::QF-dyn::poolGetMaxBlockSize} .........................................
1103std::uint_fast16_t poolGetMaxBlockSize() noexcept;
1104
1105//${QF::QF-dyn::getPoolMin} ..................................................
1106std::uint_fast16_t getPoolMin(std::uint_fast8_t const poolNum) noexcept;
1107
1108//${QF::QF-dyn::newX_} .......................................................
1109QEvt * newX_(
1110 std::uint_fast16_t const evtSize,
1111 std::uint_fast16_t const margin,
1112 enum_t const sig) noexcept;
1113
1114//${QF::QF-dyn::gc} ..........................................................
1115void gc(QEvt const * const e) noexcept;
1116
1117//${QF::QF-dyn::newRef_} .....................................................
1118QEvt const * newRef_(
1119 QEvt const * const e,
1120 QEvt const * const evtRef) noexcept;
1121
1122//${QF::QF-dyn::deleteRef_} ..................................................
1123void deleteRef_(QEvt const * const evtRef) noexcept;
1124
1125//${QF::QF-dyn::q_new} .......................................................
1126#ifndef QEVT_PAR_INIT
1127template<class evtT_>
1128inline evtT_ * q_new(enum_t const sig) {
1129 return static_cast<evtT_*>(
1130 QP::QF::newX_(sizeof(evtT_), QP::QF::NO_MARGIN, sig));
1131}
1132#endif // ndef QEVT_PAR_INIT
1133
1134//${QF::QF-dyn::q_new} .......................................................
1135#ifdef QEVT_PAR_INIT
1136template<class evtT_, typename... Args>
1137inline evtT_ * q_new(
1138 enum_t const sig,
1139 Args... args)
1140{
1141 evtT_ *e = static_cast<evtT_*>(
1142 QP::QF::newX_(sizeof(evtT_), QP::QF::NO_MARGIN, sig));
1143 e->init(args...); // e cannot be nullptr
1144 return e;
1145}
1146#endif // def QEVT_PAR_INIT
1147
1148//${QF::QF-dyn::q_new_x} .....................................................
1149#ifndef QEVT_PAR_INIT
1150template<class evtT_>
1151inline evtT_ * q_new_x(
1152 std::uint_fast16_t const margin,
1153 enum_t const sig)
1154{
1155 return static_cast<evtT_*>(QP::QF::newX_(sizeof(evtT_), margin, sig));
1156}
1157#endif // ndef QEVT_PAR_INIT
1158
1159//${QF::QF-dyn::q_new_x} .....................................................
1160#ifdef QEVT_PAR_INIT
1161template<class evtT_, typename... Args>
1162inline evtT_ * q_new_x(
1163 std::uint_fast16_t const margin,
1164 enum_t const sig,
1165 Args... args)
1166{
1167 evtT_ *e = static_cast<evtT_*>(QP::QF::newX_(sizeof(evtT_), margin, sig));
1168 if (e != nullptr) {
1169 e->init(args...);
1170 }
1171 return e;
1172}
1173#endif // def QEVT_PAR_INIT
1174
1175//${QF::QF-dyn::q_new_ref} ...................................................
1176template<class evtT_>
1177inline void q_new_ref(
1178 QP::QEvt const * const e,
1179 evtT_ const *& evtRef)
1180{
1181 evtRef = static_cast<evtT_ const *>(QP::QF::newRef_(e, evtRef));
1182}
1183
1184//${QF::QF-dyn::q_delete_ref} ................................................
1185template<class evtT_>
1186inline void q_delete_ref(evtT_ const *& evtRef) {
1187 QP::QF::deleteRef_(evtRef);
1188 evtRef = nullptr;
1189}
1190
1191//${QF::QF-dyn::newXfromISR_} ................................................
1192#ifdef QF_ISR_API
1194 std::uint_fast16_t const evtSize,
1195 std::uint_fast16_t const margin,
1196 enum_t const sig) noexcept;
1197#endif // def QF_ISR_API
1198
1199//${QF::QF-dyn::gcFromISR} ...................................................
1200#ifdef QF_ISR_API
1201void gcFromISR(QEvt const * e) noexcept;
1202#endif // def QF_ISR_API
1203
1204} // namespace QF
1205} // namespace QP
1206//$enddecl${QF::QF-dyn} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1207
1208extern "C" {
1209//$declare${QF-extern-C} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
1210
1211//${QF-extern-C::QF_onContextSw} .............................................
1212#ifdef QF_ON_CONTEXT_SW
1214 QP::QActive * prev,
1215 QP::QActive * next);
1216#endif // def QF_ON_CONTEXT_SW
1217//$enddecl${QF-extern-C} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1218} // extern "C"
1219
1220//$declare${QF-macros} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
1221
1222//${QF-macros::Q_PRIO} .......................................................
1223#define Q_PRIO(prio_, pthre_) \
1224 (static_cast<QP::QPrioSpec>((prio_) | (pthre_) << 8U))
1225
1226//${QF-macros::Q_NEW} ........................................................
1227#ifndef QEVT_PAR_INIT
1228#define Q_NEW(evtT_, sig_) (QP::QF::q_new<evtT_>((sig_)))
1229#endif // ndef QEVT_PAR_INIT
1230
1231//${QF-macros::Q_NEW} ........................................................
1232#ifdef QEVT_PAR_INIT
1233#define Q_NEW(evtT_, sig_, ...) (QP::QF::q_new<evtT_>((sig_), __VA_ARGS__))
1234#endif // def QEVT_PAR_INIT
1235
1236//${QF-macros::Q_NEW_X} ......................................................
1237#ifndef QEVT_PAR_INIT
1238#define Q_NEW_X(evtT_, margin_, sig_) (QP::QF::q_new_x<evtT_>((margin_), (sig_)))
1239#endif // ndef QEVT_PAR_INIT
1240
1241//${QF-macros::Q_NEW_X} ......................................................
1242#ifdef QEVT_PAR_INIT
1243#define Q_NEW_X(evtT_, margin_, sig_, ...) (QP::QF::q_new_x<evtT_>((margin_), (sig_), __VA_ARGS__))
1244#endif // def QEVT_PAR_INIT
1245
1246//${QF-macros::Q_NEW_REF} ....................................................
1247#define Q_NEW_REF(evtRef_, evtT_) (QP::QF::q_new_ref<evtT_>(e, (evtRef_)))
1248
1249//${QF-macros::Q_DELETE_REF} .................................................
1250#define Q_DELETE_REF(evtRef_) do { \
1251 QP::QF::deleteRef_((evtRef_)); \
1252 (evtRef_) = nullptr; \
1253} while (false)
1254
1255//${QF-macros::PUBLISH} ......................................................
1256#ifdef Q_SPY
1257#define PUBLISH(e_, sender_) \
1258 publish_((e_), (sender_), (sender_)->getPrio())
1259#endif // def Q_SPY
1260
1261//${QF-macros::PUBLISH} ......................................................
1262#ifndef Q_SPY
1263#define PUBLISH(e_, dummy) publish_((e_), nullptr, 0U)
1264#endif // ndef Q_SPY
1265
1266//${QF-macros::POST} .........................................................
1267#ifdef Q_SPY
1268#define POST(e_, sender_) post_((e_), QP::QF::NO_MARGIN, (sender_))
1269#endif // def Q_SPY
1270
1271//${QF-macros::POST} .........................................................
1272#ifndef Q_SPY
1273#define POST(e_, dummy) post_((e_), QP::QF::NO_MARGIN, nullptr)
1274#endif // ndef Q_SPY
1275
1276//${QF-macros::POST_X} .......................................................
1277#ifdef Q_SPY
1278#define POST_X(e_, margin_, sender_) \
1279 post_((e_), (margin_), (sender_))
1280#endif // def Q_SPY
1281
1282//${QF-macros::POST_X} .......................................................
1283#ifndef Q_SPY
1284#define POST_X(e_, margin_, dummy) post_((e_), (margin_), nullptr)
1285#endif // ndef Q_SPY
1286
1287//${QF-macros::TICK_X} .......................................................
1288#ifdef Q_SPY
1289#define TICK_X(tickRate_, sender_) tick((tickRate_), (sender_))
1290#endif // def Q_SPY
1291
1292//${QF-macros::TICK_X} .......................................................
1293#ifndef Q_SPY
1294#define TICK_X(tickRate_, dummy) tick((tickRate_), nullptr)
1295#endif // ndef Q_SPY
1296
1297//${QF-macros::TICK} .........................................................
1298#define TICK(sender_) TICK_X(0U, (sender_))
1299
1300//${QF-macros::TRIG} .........................................................
1301#ifdef Q_SPY
1302#define TRIG(sender_) trig_((sender_))
1303#endif // def Q_SPY
1304
1305//${QF-macros::TRIG} .........................................................
1306#ifndef Q_SPY
1307#define TRIG(sender_) trig_(nullptr)
1308#endif // ndef Q_SPY
1309
1310//${QF-macros::QF_CRIT_EXIT_NOP} .............................................
1311#ifndef QF_CRIT_EXIT_NOP
1312#define QF_CRIT_EXIT_NOP() (static_cast<void>(0))
1313#endif // ndef QF_CRIT_EXIT_NOP
1314
1315//${QF-macros::QF_MEM_SYS} ...................................................
1316#ifndef QF_MEM_SYS
1317#define QF_MEM_SYS() (static_cast<void>(0))
1318#endif // ndef QF_MEM_SYS
1319
1320//${QF-macros::QF_MEM_APP} ...................................................
1321#ifndef QF_MEM_APP
1322#define QF_MEM_APP() (static_cast<void>(0))
1323#endif // ndef QF_MEM_APP
1324//$enddecl${QF-macros} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1325
1326#endif // QP_HPP_
Dummy Active Object for testing.
Active object class (based on the QHsm implementation strategy)
Definition qp.hpp:699
QACTIVE_OS_OBJ_TYPE const & getOsObject() const noexcept
Definition qp.hpp:844
virtual bool postFromISR(QEvt const *const e, std::uint_fast16_t const margin, void *par, void const *const sender) noexcept
QACTIVE_THREAD_TYPE m_thread
Definition qp.hpp:705
void init(void const *const e, std::uint_fast8_t const qsId) override
Virtual function to take the top-most initial transition in the state machine.
Definition qp.hpp:756
void setThread(QACTIVE_THREAD_TYPE const &thr)
Definition qp.hpp:856
std::uint8_t m_pthre_dis
Definition qp.hpp:723
static QSubscrList * subscrList_
Definition qp.hpp:726
std::uint_fast8_t getPThre() const noexcept
Definition qp.hpp:833
QACTIVE_THREAD_TYPE const & getThread() const noexcept
Definition qp.hpp:850
static void publishFromISR(QEvt const *e, void *par, void const *sender) noexcept
static void evtLoop_(QActive *act)
void setAttr(std::uint32_t attr1, void const *attr2=nullptr)
void dispatch(QEvt const *const e, std::uint_fast8_t const qsId) override
Virtual function to dispatch an event to the state machine.
Definition qp.hpp:765
static enum_t maxPubSignal_
Definition qp.hpp:727
bool isIn(QStateHandler const state) noexcept override
Virtual function to check whether the state machine is in a given state.
Definition qp.hpp:771
void init(std::uint_fast8_t const qsId) override
Virtual function to take the top-most initial transition in the state machine (overloaded).
Definition qp.hpp:762
void setPrio(QPrioSpec const prio) noexcept
Definition qp.hpp:829
QActive(QStateHandler const initial) noexcept
Definition qp.hpp:741
QACTIVE_EQUEUE_TYPE m_eQueue
Definition qp.hpp:713
friend void schedLock()
QStateHandler childState(QStateHandler const parent) noexcept
Definition qp.hpp:774
std::uint8_t m_pthre
Definition qp.hpp:702
QACTIVE_EQUEUE_TYPE const & getEQueue() const noexcept
Definition qp.hpp:838
std::uint8_t m_prio_dis
Definition qp.hpp:719
QACTIVE_OS_OBJ_TYPE m_osObject
Definition qp.hpp:709
std::uint8_t m_prio
Definition qp.hpp:701
void start(QPrioSpec const prioSpec, QEvtPtr *const qSto, std::uint_fast16_t const qLen, void *const stkSto, std::uint_fast16_t const stkSize)
Definition qp.hpp:787
Abstract State Machine class (state machine interface)
Definition qp.hpp:212
virtual void init(std::uint_fast8_t const qsId)
Virtual function to take the top-most initial transition in the state machine (overloaded).
Definition qp.hpp:270
QState qm_entry(QMState const *const s) noexcept
Internal helper function to execute state entry actions in QP::QMsm.
Definition qp.hpp:332
QAsm() noexcept
Constructor of the QP::QAsm base class.
Definition qp.hpp:255
QState qm_tran_hist(QMState const *const hist, void const *const tatbl) noexcept
Internal helper function to take a state transition to history in QP::QMsm.
Definition qp.hpp:322
QStateHandler state() const noexcept
Definition qp.hpp:280
virtual bool isIn(QStateHandler const state) noexcept
Virtual function to check whether the state machine is in a given state.
Definition qp.hpp:276
QState qm_tran(void const *const tatbl) noexcept
Internal helper function to take a state transition in QP::QMsm.
Definition qp.hpp:314
QStateRet
Definition qp.hpp:222
@ Q_RET_HANDLED
event handled (internal transition)
Definition qp.hpp:228
@ Q_RET_ENTRY
state entry action executed
Definition qp.hpp:232
@ Q_RET_IGNORED
event silently ignored (bubbled up to top)
Definition qp.hpp:229
@ Q_RET_UNHANDLED
event unhandled due to a guard
Definition qp.hpp:225
@ Q_RET_TRAN
regular transition
Definition qp.hpp:239
@ Q_RET_TRAN_HIST
transition to history of a given state
Definition qp.hpp:243
@ Q_RET_NULL
return value without any effect
Definition qp.hpp:236
@ Q_RET_TRAN_INIT
initial transition in a state
Definition qp.hpp:240
@ Q_RET_EXIT
state exit action executed
Definition qp.hpp:233
@ Q_RET_SUPER
event passed to superstate to handle
Definition qp.hpp:224
QState qm_exit(QMState const *const s) noexcept
Internal helper function to execute state exit actions in QP::QMsm.
Definition qp.hpp:346
QState tran_hist(QStateHandler const hist) noexcept
Internal helper function to take a state transition to history in sublclasses of QP::QAsm.
Definition qp.hpp:306
QState super(QStateHandler const superstate) noexcept
Internal helper function to indicate superstate of a given state in sublclasses of QP::QAsm.
Definition qp.hpp:310
QState qm_tran_init(void const *const tatbl) noexcept
Definition qp.hpp:318
QAsmAttr m_temp
Temporary storage for target/act-table etc.
Definition qp.hpp:215
static QState top(void *const me, QEvt const *const e) noexcept
Top state handler that ignores all events.
Definition qp.hpp:292
virtual QStateHandler getStateHandler() noexcept
Virtual method for getting the state handler.
Definition qp.hpp:288
QMState const * stateObj() const noexcept
Definition qp.hpp:283
virtual void init(void const *const e, std::uint_fast8_t const qsId)=0
Virtual function to take the top-most initial transition in the state machine.
QState tran(QStateHandler const target) noexcept
Internal helper function to take a state transition in sublclasses of QP::QAsm.
Definition qp.hpp:302
virtual ~QAsm() noexcept
Virtual destructor of the QP::QAsm abstract base class.
Definition qp.hpp:263
QAsmAttr m_state
Current state (pointer to the current state-handler function)
Definition qp.hpp:214
ReservedSig
Reserved signals by the QP-framework.
Definition qp.hpp:247
@ Q_EXIT_SIG
signal for exit actions
Definition qp.hpp:250
@ Q_INIT_SIG
signal for nested initial transitions
Definition qp.hpp:251
@ Q_ENTRY_SIG
signal for entry actions
Definition qp.hpp:249
@ Q_EMPTY_SIG
signal to execute the default case
Definition qp.hpp:248
virtual void dispatch(QEvt const *const e, std::uint_fast8_t const qsId)=0
Virtual function to dispatch an event to the state machine.
Native QP event queue.
Definition qequeue.hpp:60
Event class.
Definition qp.hpp:131
QSignal sig
Signal of the event (see Event Signal)
Definition qp.hpp:133
@ DYNAMIC
Definition qp.hpp:138
std::uint8_t volatile refCtr_
Event reference counter.)
Definition qp.hpp:135
bool verify_() const noexcept
Internal function to verify the internal integrity of the event instance (QP FuSa Subsystem)
Definition qp.hpp:154
std::uint8_t evtTag_
Event "tag" contains pool-ID plus the Duplicate Inverted Storage of the QEvt::refCtr_.
Definition qp.hpp:134
constexpr QEvt(QSignal const s) noexcept
Definition qp.hpp:141
void init(DynEvt const dummy) noexcept
Definition qp.hpp:150
std::uint_fast8_t getPoolNum_() const noexcept
Internal function to get the event pool-number of the given event.
Definition qp.hpp:159
void init() noexcept
Definition qp.hpp:147
QEvt()=delete
Hierarchical State Machine class (QHsm-style state machine implementation strategy)
Definition qp.hpp:361
std::int_fast8_t hsm_tran(QStateHandler *const path, std::uint_fast8_t const qsId)
Definition qep_hsm.cpp:525
QStateHandler getStateHandler() noexcept override
Definition qp.hpp:379
void init(std::uint_fast8_t const qsId) override
Virtual function to take the top-most initial transition in the state machine (overloaded).
Definition qp.hpp:369
QStateHandler childState(QStateHandler const parent) noexcept
Definition qep_hsm.cpp:486
void dispatch(QEvt const *const e, std::uint_fast8_t const qsId) override
Virtual function to dispatch an event to the state machine.
Definition qep_hsm.cpp:245
void init(void const *const e, std::uint_fast8_t const qsId) override
Virtual function to take the top-most initial transition in the state machine.
Definition qep_hsm.cpp:123
QHsm(QStateHandler const initial) noexcept
Definition qep_hsm.cpp:115
bool isIn(QStateHandler const state) noexcept override
Definition qep_hsm.cpp:450
Active object class (based on QMsm implementation strategy)
Definition qp.hpp:885
bool isIn(QStateHandler const state) noexcept override
Virtual function to check whether the state machine is in a given state.
Definition qp.hpp:905
QMActive(QStateHandler const initial) noexcept
Constructor of QP::QMActive class.
Definition qf_qmact.cpp:63
QStateHandler getStateHandler() noexcept override
Virtual method for getting the state handler.
Definition qp.hpp:910
void dispatch(QEvt const *const e, std::uint_fast8_t const qsId) override
Virtual function to dispatch an event to the state machine.
Definition qp.hpp:899
void init(void const *const e, std::uint_fast8_t const qsId) override
Virtual function to take the top-most initial transition in the state machine.
Definition qp.hpp:890
QMState const * childStateObj(QMState const *const parent) const noexcept
Definition qp.hpp:914
void init(std::uint_fast8_t const qsId) override
Virtual function to take the top-most initial transition in the state machine (overloaded).
Definition qp.hpp:896
Hierarchical State Machine class (QMsm-style state machine implementation strategy)
Definition qp.hpp:391
QState execTatbl_(QMTranActTable const *const tatbl, std::uint_fast8_t const qsId)
Definition qep_msm.cpp:403
void init(std::uint_fast8_t const qsId) override
Virtual function to take the top-most initial transition in the state machine (overloaded).
Definition qp.hpp:399
void dispatch(QEvt const *const e, std::uint_fast8_t const qsId) override
Virtual function to dispatch an event to the state machine.
Definition qep_msm.cpp:158
void exitToTranSource_(QMState const *const cs, QMState const *const ts, std::uint_fast8_t const qsId)
Definition qep_msm.cpp:466
QState enterHistory_(QMState const *const hist, std::uint_fast8_t const qsId)
Definition qep_msm.cpp:504
void init(void const *const e, std::uint_fast8_t const qsId) override
Virtual function to take the top-most initial transition in the state machine.
Definition qep_msm.cpp:97
bool isIn(QStateHandler const state) noexcept override
Definition qep_msm.cpp:328
QMsm(QStateHandler const initial) noexcept
Definition qep_msm.cpp:89
QMState const * topQMState() const noexcept
Definition qep_msm.cpp:567
QStateHandler getStateHandler() noexcept override
Definition qp.hpp:407
QMState const * childStateObj(QMState const *const parent) const noexcept
Definition qep_msm.cpp:352
Set of Active Objects of up to QF_MAX_ACTIVE elements.
Definition qp.hpp:572
std::uint_fast8_t findMax() const noexcept
Definition qp.hpp:630
void remove(std::uint_fast8_t const n) noexcept
Definition qp.hpp:618
bool verify_(QPSet const *const dis) const noexcept
Definition qp.hpp:650
bool notEmpty() const noexcept
Definition qp.hpp:590
bool hasElement(std::uint_fast8_t const n) const noexcept
Definition qp.hpp:597
QPSetBits m_bits[((QF_MAX_ACTIVE+(8U *sizeof(QPSetBits))) - 1U)/(8U *sizeof(QPSetBits))]
Definition qp.hpp:574
void update_(QPSet *const dis) const noexcept
Definition qp.hpp:641
void setEmpty() noexcept
Definition qp.hpp:577
bool isEmpty() const noexcept
Definition qp.hpp:583
void insert(std::uint_fast8_t const n) noexcept
Definition qp.hpp:606
std::uintptr_t m_ptr_dis
Definition qp.hpp:677
QPtrDis(void const *const ptr=nullptr) noexcept
Definition qf_act.cpp:131
Subscriber List (for publish-subscribe)
Definition qp.hpp:662
QPSet m_set
Definition qp.hpp:664
QPSet m_set_dis
Definition qp.hpp:667
"Ticker" Active Object class
Definition qp.hpp:1014
void init(std::uint_fast8_t const qsId) override
Virtual function to take the top-most initial transition in the state machine (overloaded).
Definition qp.hpp:1020
Time Event class.
Definition qp.hpp:927
QTimeEvt * toTimeEvt() noexcept
Definition qp.hpp:997
std::uint8_t m_flags
Definition qp.hpp:942
std::uintptr_t m_next_dis
Definition qp.hpp:932
static void tick1_(std::uint_fast8_t const tickRate, void const *const sender)
QTimeEvtCtr getInterval() const noexcept
Definition qp.hpp:971
static void tickFromISR(std::uint_fast8_t const tickRate, void *par, void const *sender) noexcept
void * m_act
Active object that receives the time events.
Definition qp.hpp:934
QTimeEvt *volatile m_next
Link to the next time event in the list.
Definition qp.hpp:929
QActive * toActive() noexcept
Definition qp.hpp:994
std::uint8_t m_tickRate
Definition qp.hpp:941
QTimeEvtCtr getCtr() const noexcept
Definition qp.hpp:968
std::uint8_t getTickRate() const noexcept
Definition qp.hpp:974
QTimeEvtCtr volatile m_ctr
Down-counter of the time event.
Definition qp.hpp:935
QTimeEvtCtr m_interval
Interval for periodic time event (zero for one-shot time event)
Definition qp.hpp:940
QTimeEvtCtr m_ctr_dis
Definition qp.hpp:938
Blocking Mutex of the QXK preemptive kernel.
Counting Semaphore of the QXK preemptive kernel.
eXtended (blocking) thread of the QXK preemptive kernel
QF Active Object Framework namespace.
void deleteRef_(QEvt const *const evtRef) noexcept
Definition qf_dyn.cpp:307
void onCleanup()
void psInit(QSubscrList *const subscrSto, enum_t const maxSignal) noexcept
Definition qp.hpp:1053
QEvt const * newRef_(QEvt const *const e, QEvt const *const evtRef) noexcept
Definition qf_dyn.cpp:270
evtT_ * q_new(enum_t const sig, Args... args)
Definition qp.hpp:1137
void tick(std::uint_fast8_t const tickRate, void const *const sender) noexcept
Definition qp.hpp:1072
std::uint_fast16_t poolGetMaxBlockSize() noexcept
Definition qf_dyn.cpp:103
evtT_ * q_new_x(std::uint_fast16_t const margin, enum_t const sig, Args... args)
Definition qp.hpp:1162
void gcFromISR(QEvt const *e) noexcept
void poolInit(void *const poolSto, std::uint_fast32_t const poolSize, std::uint_fast16_t const evtSize) noexcept
Definition qf_dyn.cpp:64
constexpr std::uint_fast16_t NO_MARGIN
Definition qp.hpp:1086
void init()
Definition qv.cpp:131
void q_new_ref(QP::QEvt const *const e, evtT_ const *&evtRef)
Definition qp.hpp:1177
std::uint_fast16_t getQueueMin(std::uint_fast8_t const prio) noexcept
Definition qp.hpp:1081
QEvt * newXfromISR_(std::uint_fast16_t const evtSize, std::uint_fast16_t const margin, enum_t const sig) noexcept
void q_delete_ref(evtT_ const *&evtRef)
Definition qp.hpp:1186
QEvt * newX_(std::uint_fast16_t const evtSize, std::uint_fast16_t const margin, enum_t const sig) noexcept
Definition qf_dyn.cpp:134
int_t run()
Definition qv.cpp:153
void stop()
Definition qv.cpp:147
void publish_(QEvt const *const e, void const *const sender, std::uint_fast8_t const qsId) noexcept
Definition qp.hpp:1062
void onStartup()
QP/C++ framework.
Definition qequeue.hpp:42
constexpr enum_t Q_USER_SIG
Definition qp.hpp:209
std::uint32_t QTimeEvtCtr
Data type to store the block-size defined based on the macro QF_TIMEEVT_CTR_SIZE.
Definition qp.hpp:548
QState(*)(void *const me) QActionHandler
Pointer to an action-handler function.
Definition qp.hpp:171
QEvt const * QEvtPtr
Pointer to const event instances passed around in QP Framework.
Definition qp.hpp:534
std::uint_fast8_t QF_LOG2(QP::QPSetBits x) noexcept
Definition qf_act.cpp:91
std::uint_fast8_t QState
Type returned from state-handler functions.
Definition qp.hpp:165
QState(*)(void *const me, QEvt const *const e) QStateHandler
Pointer to a state-handler function.
Definition qp.hpp:168
constexpr char const versionStr[]
the current QP version number string in ROM, based on QP_VERSION_STR
Definition qp.hpp:113
std::uint32_t QPSetBits
Definition qp.hpp:563
std::uint16_t QSignal
The signal of event QP::QEvt.
Definition qp.hpp:122
void(*)(QXThread *const me) QXThreadHandler
Pointer to an extended-thread handler function.
Definition qp.hpp:178
std::uint16_t QPrioSpec
Priority specification for Active Objects in QP.
Definition qp.hpp:531
int enum_t
Definition qp.hpp:99
int int_t
Alias for assertion-ID numbers in QP assertions and return from QP::QF::run()
Definition qp.hpp:96
float float32_t
Alias for IEEE 754 32-bit floating point number.
Definition qp.hpp:102
#define QP_VERSION_STR
Version string complying with Semantic Versioning
Definition qp.hpp:39
double float64_t
Alias for IEEE 754 64-bit floating point number.
Definition qp.hpp:105
#define Q_STATE_CAST(handler_)
Definition qp.hpp:456
void QF_onContextSw(QP::QActive *prev, QP::QActive *next)
#define QF_MAX_TICK_RATE
Maximum # clock tick rates in the system (0..15)
#define QF_MAX_ACTIVE
Maximum # Active Objects in the system (1..64)
#define QACTIVE_OS_OBJ_TYPE
QP::QActive "OS-object" type used in various QP/C++ ports.
Definition qp_port.hpp:29
#define QACTIVE_EQUEUE_TYPE
QP::QActive event queue type used in various QP/C++ ports.
Definition qp_port.hpp:26
#define QACTIVE_THREAD_TYPE
QP::QActive "thread" type used in various QP/C++ ports.
Definition qp_port.hpp:32
State object for the QP::QMsm class (QM State Machine)
Definition qp.hpp:181
QActionHandler const entryAction
Definition qp.hpp:184
QStateHandler const stateHandler
Definition qp.hpp:183
QActionHandler const exitAction
Definition qp.hpp:185
QMState const * superstate
Definition qp.hpp:182
QActionHandler const initAction
Definition qp.hpp:186
Transition-Action Table for the QP::QMsm State Machine.
Definition qp.hpp:190
QMState const * target
Definition qp.hpp:191
QActionHandler const act[1]
Definition qp.hpp:192
Attribute of for the QP::QAsm class (Abstract State Machine)
Definition qp.hpp:196
std::uintptr_t uint
Definition qp.hpp:203
QMState const * obj
Definition qp.hpp:200
QStateHandler fun
Definition qp.hpp:197
QMTranActTable const * tatbl
Definition qp.hpp:201
constexpr QAsmAttr()
Definition qp.hpp:205
QXThreadHandler thr
Definition qp.hpp:199
QActionHandler act
Definition qp.hpp:198