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