QP/C++  8.0.4
Real-Time Event Framework
Loading...
Searching...
No Matches
qp.hpp
Go to the documentation of this file.
1//============================================================================
2// QP/C++ Real-Time Event Framework (RTEF)
3//
4// Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
5//
6// Q u a n t u m L e a P s
7// ------------------------
8// Modern Embedded Software
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
11//
12// This software is dual-licensed under the terms of the open-source GNU
13// General Public License (GPL) or under the terms of one of the closed-
14// source Quantum Leaps commercial licenses.
15//
16// Redistributions in source code must retain this top-level comment block.
17// Plagiarizing this software to sidestep the license obligations is illegal.
18//
19// NOTE:
20// The GPL does NOT permit the incorporation of this code into proprietary
21// programs. Please contact Quantum Leaps for commercial licensing options,
22// which expressly supersede the GPL and are designed explicitly for
23// closed-source distribution.
24//
25// Quantum Leaps contact information:
26// <www.state-machine.com/licensing>
27// <info@state-machine.com>
28//============================================================================
29#ifndef QP_HPP_
30#define QP_HPP_
31
32//============================================================================
33#define QP_VERSION_STR "8.0.4"
34#define QP_VERSION 804U
35// <VER>=804 <DATE>=250611
36#define QP_RELEASE 0x6A9FC8ABU
37
38//============================================================================
39// default configuration settings
40//! @cond INTERNAL
41
42#ifndef Q_SIGNAL_SIZE
43#define Q_SIGNAL_SIZE 2U
44#endif
45
46#ifndef QF_MAX_ACTIVE
47#define QF_MAX_ACTIVE 32U
48#endif
49
50#if (QF_MAX_ACTIVE > 64U)
51#error QF_MAX_ACTIVE exceeds the maximum of 64U;
52#endif
53
54#ifndef QF_MAX_TICK_RATE
55#define QF_MAX_TICK_RATE 1U
56#endif
57
58#if (QF_MAX_TICK_RATE > 15U)
59#error QF_MAX_TICK_RATE exceeds the maximum of 15U;
60#endif
61
62#ifndef QF_MAX_EPOOL
63#define QF_MAX_EPOOL 3U
64#endif
65
66#if (QF_MAX_EPOOL > 15U)
67#error QF_MAX_EPOOL exceeds the maximum of 15U;
68#endif
69
70#ifndef QF_TIMEEVT_CTR_SIZE
71#define QF_TIMEEVT_CTR_SIZE 4U
72#endif
73
74#if (QF_TIMEEVT_CTR_SIZE > 4U)
75#error QF_TIMEEVT_CTR_SIZE defined incorrectly, expected 1U, 2U, or 4U;
76#endif
77
78#ifndef QF_EVENT_SIZ_SIZE
79#define QF_EVENT_SIZ_SIZE 2U
80#endif
81
82#if (QF_EVENT_SIZ_SIZE > 4U)
83#error QF_EVENT_SIZ_SIZE defined incorrectly, expected 1U, 2U, or 4U;
84#endif
85
86//! @endcond
87
88//============================================================================
89// global types/utilities
90
91using int_t = int;
92using enum_t = int;
93
94#define Q_UNUSED_PAR(par_) (static_cast<void>(par_))
95#define Q_DIM(array_) (sizeof(array_) / sizeof((array_)[0U]))
96#define Q_UINT2PTR_CAST(type_, uint_) (reinterpret_cast<type_ *>(uint_))
97
98//============================================================================
99namespace QP {
100
101extern char const versionStr[24];
102
103// QSignal type
104#if (Q_SIGNAL_SIZE == 1U)
105 using QSignal = std::uint8_t;
106#elif (Q_SIGNAL_SIZE == 2U)
107 using QSignal = std::uint16_t;
108#elif (Q_SIGNAL_SIZE == 4U)
109 using QSignal = std::uint32_t;
110#endif
111
112//============================================================================
113
114class QEvt {
115public:
117 std::uint8_t poolNum_;
118 std::uint8_t volatile refCtr_;
119
120 enum DynEvt: std::uint8_t { DYNAMIC };
121
122 explicit constexpr QEvt(QSignal const s) noexcept
123 : sig(s)
124 ,poolNum_(0x00U)
125 ,refCtr_(0xE0U)
126 {}
127
128 QEvt() = delete;
129 void init() const noexcept {
130 // no event parameters to initialize
131 }
132 void init(DynEvt const dummy) const noexcept {
133 Q_UNUSED_PAR(dummy);
134 // no event parameters to initialize
135 }
136}; // class QEvt
137
138using QEvtPtr = QEvt const *;
139
140//============================================================================
141// QEP (hierarchical event processor) types
142
143using QState = std::uint_fast8_t;
144
145class QXThread; // forward declaration
146
147using QStateHandler = QState (*)(void * const me, QEvt const * const e);
148using QActionHandler = QState (*)(void * const me);
149using QXThreadHandler = void (*)(QXThread * const me);
150
158
162};
163
172
173constexpr enum_t Q_USER_SIG {4};
174
175//============================================================================
176class QAsm {
177public:
180
181 // All possible return values from state-handlers
182 // NOTE: The ordering is important for algorithmic correctness.
183 static constexpr QState Q_RET_SUPER {0U};
184 static constexpr QState Q_RET_UNHANDLED {1U};
185
186 // handled and do not need to "bubble up"
187 static constexpr QState Q_RET_HANDLED {2U};
188 static constexpr QState Q_RET_IGNORED {3U};
189
190 // entry/exit
191 static constexpr QState Q_RET_ENTRY {4U};
192 static constexpr QState Q_RET_EXIT {5U};
193
194 // no side effects
195 static constexpr QState Q_RET_NULL {6U};
196
197 // transitions need to execute transition-action table in QP::QMsm
198 static constexpr QState Q_RET_TRAN {7U};
199 static constexpr QState Q_RET_TRAN_INIT {8U};
200
201 // transitions that additionally clobber QHsm.m_state
202 static constexpr QState Q_RET_TRAN_HIST {9U};
203
204 // Reserved signals by the QP-framework
205 static constexpr QSignal Q_EMPTY_SIG {0U};
206 static constexpr QSignal Q_ENTRY_SIG {1U};
207 static constexpr QSignal Q_EXIT_SIG {2U};
208 static constexpr QSignal Q_INIT_SIG {3U};
209
210#ifdef Q_XTOR
211 virtual ~QAsm() noexcept {
212 // empty
213 }
214#endif // def Q_XTOR
215 virtual void init(
216 void const * const e,
217 std::uint_fast8_t const qsId) = 0;
218 virtual void init(std::uint_fast8_t const qsId) {
219 this->init(nullptr, qsId);
220 }
221 virtual void dispatch(
222 QEvt const * const e,
223 std::uint_fast8_t const qsId) = 0;
224 virtual bool isIn(QStateHandler const stateHndl) noexcept {
225 Q_UNUSED_PAR(stateHndl);
226 return false;
227 }
228 QStateHandler state() const noexcept {
229 return m_state.fun;
230 }
231 QMState const * stateObj() const noexcept {
232 return m_state.obj;
233 }
234
235#ifdef Q_SPY
236 virtual QStateHandler getStateHandler() noexcept {
237 return m_state.fun;
238 }
239#endif // def Q_SPY
240
241 static QState top(
242 void * const me,
243 QEvt const * const e) noexcept
244 {
245 static_cast<void>(me);
246 static_cast<void>(e);
247 return Q_RET_IGNORED; // the top state ignores all events
248 }
249
250protected:
251 explicit QAsm() noexcept
252 : m_state(),
253 m_temp ()
254 {}
255
256 QState tran(QStateHandler const target) noexcept {
257 m_temp.fun = target;
258 return Q_RET_TRAN;
259 }
260 QState tran_hist(QStateHandler const hist) noexcept {
261 m_temp.fun = hist;
262 return Q_RET_TRAN_HIST;
263 }
264 QState super(QStateHandler const superstate) noexcept {
265 m_temp.fun = superstate;
266 return Q_RET_SUPER;
267 }
268 QState qm_tran(void const * const tatbl) noexcept {
269 m_temp.tatbl = static_cast<QP::QMTranActTable const *>(tatbl);
270 return Q_RET_TRAN;
271 }
272 QState qm_tran_init(void const * const tatbl) noexcept {
273 m_temp.tatbl = static_cast<QP::QMTranActTable const *>(tatbl);
274 return Q_RET_TRAN_INIT;
275 }
277 QMState const * const hist,
278 void const * const tatbl) noexcept
279 {
280 m_state.obj = hist;
281 m_temp.tatbl = static_cast<QP::QMTranActTable const *>(tatbl);
282 return Q_RET_TRAN_HIST;
283 }
284
285#ifdef Q_SPY
286 QState qm_entry(QMState const * const s) noexcept {
287 m_temp.obj = s;
288 return Q_RET_ENTRY;
289 }
290#endif // def Q_SPY
291
292#ifndef Q_SPY
293 QState qm_entry(QMState const * const s) noexcept {
294 static_cast<void>(s); // unused parameter
295 return Q_RET_ENTRY;
296 }
297#endif // ndef Q_SPY
298
299#ifdef Q_SPY
300 QState qm_exit(QMState const * const s) noexcept {
301 m_temp.obj = s;
302 return Q_RET_EXIT;
303 }
304#else
305 QState qm_exit(QMState const * const s) noexcept {
306 static_cast<void>(s); // unused parameter
307 return Q_RET_EXIT;
308 }
309#endif // Q_SPY
310}; // class QAsm
311
312//============================================================================
313class QHsm : public QP::QAsm {
314protected:
315 explicit QHsm(QStateHandler const initial) noexcept;
316
317public:
318 void init(
319 void const * const e,
320 std::uint_fast8_t const qsId) override;
321 void init(std::uint_fast8_t const qsId) override {
322 this->init(nullptr, qsId);
323 }
324 void dispatch(
325 QEvt const * const e,
326 std::uint_fast8_t const qsId) override;
327 bool isIn(QStateHandler const stateHndl) noexcept override;
328 QStateHandler childState(QStateHandler const parentHndl) noexcept;
329
330#ifdef Q_SPY
331 QStateHandler getStateHandler() noexcept override {
332 return m_state.fun;
333 }
334#endif // def Q_SPY
335
336private:
337 std::int_fast8_t tran_simple_(
338 QStateHandler * const path,
339 std::uint_fast8_t const qsId);
340
341 std::int_fast8_t tran_complex_(
342 QStateHandler * const path,
343 std::uint_fast8_t const qsId);
344
346 QStateHandler * const path,
347 std::int_fast8_t const depth,
348 std::uint_fast8_t const qsId);
349
350 // friends...
351 friend class QS;
352}; // class QHsm
353
354//============================================================================
355class QMsm : public QP::QAsm {
356protected:
357 explicit QMsm(QStateHandler const initial) noexcept;
358
359public:
360 void init(
361 void const * const e,
362 std::uint_fast8_t const qsId) override;
363 void init(std::uint_fast8_t const qsId) override {
364 this->init(nullptr, qsId);
365 }
367 QEvt const * const e,
368 std::uint_fast8_t const qsId) override;
369
370#ifdef Q_SPY
371 QStateHandler getStateHandler() noexcept override {
372 return m_state.obj->stateHandler;
373 }
374#endif // def Q_SPY
375 QMState const * topQMState() const noexcept;
376 bool isIn(QStateHandler const stateHndl) noexcept override;
377 QMState const * childStateObj(QMState const * const parentHndl)
378 const noexcept;
379
380private:
382 QMTranActTable const * const tatbl,
383 std::uint_fast8_t const qsId);
385 QMState const * const curr_state,
386 QMState const * const tran_source,
387 std::uint_fast8_t const qsId);
389 QMState const * const hist,
390 std::uint_fast8_t const qsId);
391
392 // friends...
393 friend class QS;
394}; // class QMsm
395
396} // namespace QP
397
398//============================================================================
399// QEP-macros
400
401#define Q_STATE_DECL(state_) \
402 QP::QState state_ ## _h(QP::QEvt const * const e); \
403 static QP::QState state_(void * const me, QP::QEvt const * const e)
404
405#define Q_STATE_DEF(subclass_, state_) \
406 QP::QState subclass_::state_(void * const me, QP::QEvt const * const e) { \
407 return static_cast<subclass_ *>(me)->state_ ## _h(e); } \
408 QP::QState subclass_::state_ ## _h(QP::QEvt const * const e)
409
410#define Q_HANDLED() (Q_RET_HANDLED)
411#define Q_UNHANDLED() (Q_RET_UNHANDLED)
412
413#define Q_EVT_CAST(subclass_) (static_cast<subclass_ const *>(e))
414#define Q_STATE_CAST(handler_) (reinterpret_cast<QP::QStateHandler>(handler_))
415
416#define QM_STATE_DECL(state_) \
417 QP::QState state_ ## _h(QP::QEvt const * const e); \
418 static QP::QState state_(void * const me, QP::QEvt const * const e); \
419 static QP::QMState const state_ ## _s
420
421#define QM_ACTION_DECL(action_) \
422 QP::QState action_ ## _h(); \
423 static QP::QState action_(void * const me)
424
425#define QM_STATE_DEF(subclass_, state_) \
426 QP::QState subclass_::state_(void * const me, QP::QEvt const * const e) {\
427 return static_cast<subclass_ *>(me)->state_ ## _h(e); } \
428 QP::QState subclass_::state_ ## _h(QP::QEvt const * const e)
429
430#define QM_ACTION_DEF(subclass_, action_) \
431 QP::QState subclass_::action_(void * const me) { \
432 return static_cast<subclass_ *>(me)->action_ ## _h(); } \
433 QP::QState subclass_::action_ ## _h()
434
435#define QM_HANDLED() (Q_RET_HANDLED)
436#define QM_UNHANDLED() (Q_RET_HANDLED)
437#define QM_SUPER() (Q_RET_SUPER)
438#define QM_STATE_NULL (nullptr)
439#define Q_ACTION_NULL (nullptr)
440
441#ifdef Q_SPY
442 #define INIT(qsId_) init((qsId_))
443 #define DISPATCH(e_, qsId_) dispatch((e_), (qsId_))
444#else
445 #define INIT(dummy) init(0U)
446 #define DISPATCH(e_, dummy) dispatch((e_), 0U)
447#endif // ndef Q_SPY
448
449//============================================================================
450namespace QP {
451
452using QPrioSpec = std::uint16_t;
453
454#if (QF_TIMEEVT_CTR_SIZE == 1U)
455 using QTimeEvtCtr = std::uint8_t;
456#elif (QF_TIMEEVT_CTR_SIZE == 2U)
457 using QTimeEvtCtr = std::uint16_t;
458#elif (QF_TIMEEVT_CTR_SIZE == 4U)
459 using QTimeEvtCtr = std::uint32_t;
460#endif // (QF_TIMEEVT_CTR_SIZE == 4U)
461
462#if (QF_MAX_ACTIVE <= 8U)
463 using QPSetBits = std::uint8_t;
464#elif (8U < QF_MAX_ACTIVE) && (QF_MAX_ACTIVE <= 16U)
465 using QPSetBits = std::uint16_t;
466#elif (16 < QF_MAX_ACTIVE)
467 using QPSetBits = std::uint32_t;
468#endif // (16 < QF_MAX_ACTIVE)
469
470#ifndef QF_LOG2
471 std::uint_fast8_t QF_LOG2(QP::QPSetBits const bitmask) noexcept;
472#endif // ndef QF_LOG2
473
474//============================================================================
475class QPSet {
476private:
477 QPSetBits m_bits[((QF_MAX_ACTIVE + (8U * sizeof(QPSetBits))) - 1U)
478 / (8U * sizeof(QPSetBits))];
479public:
480 void setEmpty() noexcept {
481 m_bits[0] = 0U;
482#if (QF_MAX_ACTIVE > 32)
483 m_bits[1] = 0U;
484#endif
485 }
486 bool isEmpty() const noexcept {
487#if (QF_MAX_ACTIVE <= 32U)
488 return (m_bits[0] == 0U);
489#else
490 return (m_bits[0] == 0U) ? (m_bits[1] == 0U) : false;
491#endif
492 }
493 bool notEmpty() const noexcept {
494#if (QF_MAX_ACTIVE <= 32U)
495 return (m_bits[0] != 0U);
496#else
497 return (m_bits[0] != 0U) ? true : (m_bits[1] != 0U);
498#endif
499 }
500 bool hasElement(std::uint_fast8_t const n) const noexcept {
501#if (QF_MAX_ACTIVE <= 32U)
502 return (m_bits[0] & (static_cast<QPSetBits>(1U) << (n - 1U))) != 0U;
503#else
504 return (n <= 32U)
505 ? ((m_bits[0] & (static_cast<QPSetBits>(1U) << (n - 1U))) != 0U)
506 : ((m_bits[1] & (static_cast<QPSetBits>(1U) << (n - 33U))) != 0U);
507#endif
508 }
509 void insert(std::uint_fast8_t const n) noexcept {
510#if (QF_MAX_ACTIVE <= 32U)
511 m_bits[0] = (m_bits[0] | (static_cast<QPSetBits>(1U) << (n - 1U)));
512#else
513 if (n <= 32U) {
514 m_bits[0] = (m_bits[0] | (static_cast<QPSetBits>(1U) << (n - 1U)));
515 }
516 else {
517 m_bits[1] = (m_bits[1] | (static_cast<QPSetBits>(1U) << (n - 33U)));
518 }
519#endif
520 }
521 void remove(std::uint_fast8_t const n) noexcept {
522#if (QF_MAX_ACTIVE <= 32U)
523 m_bits[0] = (m_bits[0] & static_cast<QPSetBits>(~(1U << (n - 1U))));
524#else
525 if (n <= 32U) {
526 (m_bits[0] = (m_bits[0] & ~(static_cast<QPSetBits>(1U) << (n - 1U))));
527 }
528 else {
529 (m_bits[1] = (m_bits[1] & ~(static_cast<QPSetBits>(1U) << (n - 33U))));
530 }
531#endif
532 }
533 std::uint_fast8_t findMax() const noexcept {
534#if (QF_MAX_ACTIVE <= 32U)
535 return QF_LOG2(m_bits[0]);
536#else
537 return (m_bits[1] != 0U)
538 ? (QF_LOG2(m_bits[1]) + 32U)
539 : (QF_LOG2(m_bits[0]));
540#endif
541 }
542
543 // friends...
544 friend class QS;
545}; // class QPSet
546
547//============================================================================
549private:
551
552 // friends...
553 friend class QActive;
554 friend class QS;
555}; // class QSubscrList
556
557//============================================================================
558
559class QEQueue; // forward declaration
560class QActive; // forward declaration
561
562//----------------------------------------------------------------------------
563// declarations for friendship with the QActive class
564
565extern "C" {
566 std::uint_fast8_t QK_sched_() noexcept;
567 std::uint_fast8_t QK_sched_act_(
568 QP::QActive const * const act,
569 std::uint_fast8_t const pthre_in) noexcept;
570 void QK_activate_();
571
572 std::uint_fast8_t QXK_sched_() noexcept;
573 void QXK_contextSw_(QP::QActive * const next) noexcept;
574 void QXK_threadExit_() noexcept;
576} // extern "C"
577
578namespace QF {
579 void init();
580 void stop();
581 int_t run();
582
583 void onStartup();
584 void onCleanup();
585} // namespace QF
586
587namespace QXK {
588 QP::QActive *current() noexcept;
589} // namespace QXK
590
591//============================================================================
592class QActive : public QP::QAsm {
593private:
594 std::uint8_t m_prio;
595 std::uint8_t m_pthre;
596
597#ifdef QACTIVE_THREAD_TYPE
599#endif
600
601#ifdef QACTIVE_OS_OBJ_TYPE
603#endif
604
605#ifdef QACTIVE_EQUEUE_TYPE
607#endif
608
609protected:
610 explicit QActive(QStateHandler const initial) noexcept;
611
612public:
613 void init(
614 void const * const e,
615 std::uint_fast8_t const qsId) override
616 {
617 reinterpret_cast<QHsm *>(this)->QHsm::init(e, qsId);
618 }
619 void init(std::uint_fast8_t const qsId) override {
620 this->init(nullptr, qsId);
621 }
623 QEvt const * const e,
624 std::uint_fast8_t const qsId) override
625 {
626 reinterpret_cast<QHsm *>(this)->QHsm::dispatch(e, qsId);
627 }
628 bool isIn(QStateHandler const stateHndl) noexcept override {
629 return reinterpret_cast<QHsm *>(this)->QHsm::isIn(stateHndl);
630 }
631 QStateHandler childState(QStateHandler const parentHandler) noexcept {
632 return reinterpret_cast<QHsm *>(this)->QHsm::childState(parentHandler);
633 }
635 std::uint32_t attr1,
636 void const * attr2 = nullptr);
637 void start(
638 QPrioSpec const prioSpec,
639 QEvtPtr * const qSto,
640 std::uint_fast16_t const qLen,
641 void * const stkSto,
642 std::uint_fast16_t const stkSize,
643 void const * const par);
644 void start(
645 QPrioSpec const prioSpec,
646 QEvtPtr * const qSto,
647 std::uint_fast16_t const qLen,
648 void * const stkSto,
649 std::uint_fast16_t const stkSize)
650 {
651 this->start(prioSpec, qSto, qLen, stkSto, stkSize, nullptr);
652 }
653
654#ifdef QACTIVE_CAN_STOP
655 void stop();
656#endif // def QACTIVE_CAN_STOP
657 void register_() noexcept;
658 void unregister_() noexcept;
659 bool post_(
660 QEvt const * const e,
661 std::uint_fast16_t const margin,
662 void const * const sender) noexcept;
663 void postLIFO(QEvt const * const e) noexcept;
664 QEvt const * get_() noexcept;
665 static std::uint_fast16_t getQueueMin(
666 std::uint_fast8_t const prio) noexcept;
667 static void psInit(
668 QSubscrList * const subscrSto,
669 enum_t const maxSignal) noexcept;
670 static void publish_(
671 QEvt const * const e,
672 void const * const sender,
673 std::uint_fast8_t const qsId) noexcept;
674 void subscribe(enum_t const sig) const noexcept;
675 void unsubscribe(enum_t const sig) const noexcept;
676 void unsubscribeAll() const noexcept;
677 bool defer(
678 QEQueue * const eq,
679 QEvt const * const e) const noexcept;
680 bool recall(QEQueue * const eq) noexcept;
681 std::uint_fast16_t flushDeferred(
682 QEQueue * const eq,
683 std::uint_fast16_t const num = 0xFFFFU) const noexcept;
684 std::uint8_t getPrio() const noexcept {
685 return m_prio;
686 }
687 static void evtLoop_(QActive *act);
688 static QActive *fromRegistry(std::uint_fast8_t const prio);
689
690#ifdef QACTIVE_THREAD_TYPE
691 QACTIVE_THREAD_TYPE const & getThread() const noexcept {
692 return m_thread;
693 }
694 void setThread(QACTIVE_THREAD_TYPE const & thr) {
695 m_thread = thr;
696 }
697#endif // def QACTIVE_THREAD_TYPE
698
699#ifdef QACTIVE_OS_OBJ_TYPE
700 QACTIVE_OS_OBJ_TYPE const & getOsObject() const noexcept {
701 return m_osObject;
702 }
703#endif // def QACTIVE_OS_OBJ_TYPE
704
705#ifdef QF_ISR_API
706 virtual bool postFromISR(
707 QEvt const * const e,
708 std::uint_fast16_t const margin,
709 void * par,
710 void const * const sender) noexcept;
711
712 static void publishFromISR(
713 QEvt const * e,
714 void * par,
715 void const * sender) noexcept;
716#endif // QF_ISR_API
717
718private:
719 void postFIFO_(
720 QEvt const * const e,
721 void const * const sender);
722
724
727
728 // friends...
729 friend class QTimeEvt;
730 friend class QTicker;
731 friend class QXThread;
732 friend class QXMutex;
733 friend class QXSemaphore;
734 friend class QMActive;
735 friend class QActiveDummy;
736 friend class QS;
737
738 friend void QF::init();
739 friend void QF::stop();
740 friend int_t QF::run();
741 friend void QF::onStartup();
742 friend void QF::onCleanup();
743
744 friend std::uint_fast8_t QK_sched_() noexcept;
745 friend std::uint_fast8_t QK_sched_act_(
746 QP::QActive const * const act,
747 std::uint_fast8_t const pthre_in) noexcept;
748 friend void QK_activate_();
749
750 friend std::uint_fast8_t QXK_sched_() noexcept;
751 friend void QXK_contextSw_(QP::QActive * const next) noexcept;
752 friend void QXK_threadExit_() noexcept;
753 friend void QXK_activate_();
754 friend QP::QActive *QXK::current() noexcept;
755
756}; // class QActive
757
758//============================================================================
759class QMActive : public QP::QActive {
760protected:
761 explicit QMActive(QStateHandler const initial) noexcept;
762
763public:
764 void init(
765 void const * const e,
766 std::uint_fast8_t const qsId) override
767 {
768 reinterpret_cast<QMsm *>(this)->QMsm::init(e, qsId);
769 }
770 void init(std::uint_fast8_t const qsId) override {
771 this->init(nullptr, qsId);
772 }
774 QEvt const * const e,
775 std::uint_fast8_t const qsId) override
776 {
777 reinterpret_cast<QMsm *>(this)->QMsm::dispatch(e, qsId);
778 }
779 bool isIn(QStateHandler const stateHndl) noexcept override {
780 return reinterpret_cast<QMsm *>(this)->QMsm::isIn(stateHndl);
781 }
782
783#ifdef Q_SPY
784 QStateHandler getStateHandler() noexcept override {
785 return reinterpret_cast<QMsm *>(this)->QMsm::getStateHandler();
786 }
787#endif // def Q_SPY
788 QMState const * childStateObj(QMState const * const parent) const noexcept {
789 return reinterpret_cast<QMsm const *>(this)
790 ->QMsm::childStateObj(parent);
791 }
792}; // class QMActive
793
794//============================================================================
795class QTimeEvt : public QP::QEvt {
796private:
797 QTimeEvt * volatile m_next;
798 void * m_act;
801 std::uint8_t m_tickRate;
802 std::uint8_t m_flags;
803
804public:
806
807 QTimeEvt(
808 QActive * const act,
809 QSignal const sig,
810 std::uint_fast8_t const tickRate = 0U) noexcept;
811 void armX(
812 std::uint32_t const nTicks,
813 std::uint32_t const interval = 0U) noexcept;
814 bool disarm() noexcept;
815 bool rearm(std::uint32_t const nTicks) noexcept;
816 bool wasDisarmed() noexcept;
817 void const * getAct() const noexcept {
818 return m_act;
819 }
820 QTimeEvtCtr getCtr() const noexcept {
821 return m_ctr;
822 }
823 QTimeEvtCtr getInterval() const noexcept {
824 return m_interval;
825 }
826 std::uint8_t getTickRate() const noexcept {
827 return m_tickRate;
828 }
829 static void tick(
830 std::uint_fast8_t const tickRate,
831 void const * const sender) noexcept;
832
833#ifdef Q_UTEST
834 static void tick1_(
835 std::uint_fast8_t const tickRate,
836 void const * const sender);
837#endif // def Q_UTEST
838
839#ifdef QF_ISR_API
840 static void tickFromISR(
841 std::uint_fast8_t const tickRate,
842 void * par,
843 void const * sender) noexcept;
844#endif // def QF_ISR_API
845 static bool noActive(std::uint_fast8_t const tickRate) noexcept;
846 QActive * toActive() noexcept {
847 return static_cast<QActive *>(m_act);
848 }
849 QTimeEvt * toTimeEvt() noexcept {
850 return static_cast<QTimeEvt *>(m_act);
851 }
852
853private:
854 QTimeEvt() noexcept;
855 QTimeEvt(QTimeEvt const & other) = delete;
856 QTimeEvt & operator=(QTimeEvt const & other) = delete;
858 QTimeEvt * const prev_link,
859 QActive const * const act,
860 std::uint_fast8_t const tickRate) noexcept;
861
862 // fiends...
863 friend class QXThread;
864 friend class QS;
865}; // class QTimeEvt
866
867//============================================================================
868class QTicker : public QP::QActive {
869public:
870 explicit QTicker(std::uint_fast8_t const tickRate) noexcept;
871 void init(
872 void const * const e,
873 std::uint_fast8_t const qsId) override;
874 void init(std::uint_fast8_t const qsId) override {
875 this->init(nullptr, qsId);
876 }
877 void dispatch(
878 QEvt const * const e,
879 std::uint_fast8_t const qsId) override;
880 void trig_(void const * const sender) noexcept;
881}; // class QTicker
882
883//============================================================================
884namespace QF {
885
886//! @deprecated
887inline void psInit(
888 QSubscrList * const subscrSto,
889 enum_t const maxSignal) noexcept
890{
891 QActive::psInit(subscrSto, maxSignal);
892}
893
894//! @deprecated
895inline void publish_(
896 QEvt const * const e,
897 void const * const sender,
898 std::uint_fast8_t const qsId) noexcept
899{
900 QActive::publish_(e, sender, qsId);
901}
902
903//! @deprecated
904inline void tick(
905 std::uint_fast8_t const tickRate,
906 void const * const sender) noexcept
907{
908 QTimeEvt::tick(tickRate, sender);
909}
910
911//! @deprecated
912inline std::uint_fast16_t getQueueMin(std::uint_fast8_t const prio) noexcept {
913 return QActive::getQueueMin(prio);
914}
915
916constexpr std::uint_fast16_t NO_MARGIN {0xFFFFU};
917
918//============================================================================
919// QF dynamic memory facilities
920void poolInit(
921 void * const poolSto,
922 std::uint_fast32_t const poolSize,
923 std::uint_fast16_t const evtSize) noexcept;
924
925std::uint_fast16_t poolGetMaxBlockSize() noexcept;
926std::uint_fast16_t getPoolMin(std::uint_fast8_t const poolNum) noexcept;
927QEvt * newX_(
928 std::uint_fast16_t const evtSize,
929 std::uint_fast16_t const margin,
930 enum_t const sig) noexcept;
931void gc(QEvt const * const e) noexcept;
932QEvt const * newRef_(
933 QEvt const * const e,
934 QEvt const * const evtRef) noexcept;
935
936void deleteRef_(QEvt const * const evtRef) noexcept;
937
938#ifndef QEVT_PAR_INIT
939 template<class evtT_>
940 inline evtT_ * q_new(enum_t const sig) {
941 return static_cast<evtT_*>(
942 QP::QF::newX_(sizeof(evtT_), QP::QF::NO_MARGIN, sig));
943 }
944 template<class evtT_>
945 inline evtT_ * q_new_x(
946 std::uint_fast16_t const margin,
947 enum_t const sig)
948 {
949 return static_cast<evtT_*>(QP::QF::newX_(sizeof(evtT_), margin, sig));
950 }
951#else
952 template<class evtT_, typename... Args>
953 inline evtT_ * q_new(
954 enum_t const sig,
955 Args... args)
956 {
957 evtT_ *e = static_cast<evtT_*>(
958 QP::QF::newX_(sizeof(evtT_), QP::QF::NO_MARGIN, sig));
959 e->init(args...); // e cannot be nullptr
960 return e;
961 }
962 template<class evtT_, typename... Args>
963 inline evtT_ * q_new_x(
964 std::uint_fast16_t const margin,
965 enum_t const sig,
966 Args... args)
967 {
968 evtT_ *e = static_cast<evtT_*>(QP::QF::newX_(sizeof(evtT_), margin, sig));
969 if (e != nullptr) {
970 e->init(args...);
971 }
972 return e;
973 }
974#endif // def QEVT_PAR_INIT
975
976template<class evtT_>
977inline void q_new_ref(
978 QP::QEvt const * const e,
979 evtT_ const *& evtRef)
980{
981 evtRef = static_cast<evtT_ const *>(QP::QF::newRef_(e, evtRef));
982}
983
984template<class evtT_>
985inline void q_delete_ref(evtT_ const *& evtRef) {
986 QP::QF::deleteRef_(evtRef);
987 evtRef = nullptr;
988}
989
990#ifdef QF_ISR_API
992 std::uint_fast16_t const evtSize,
993 std::uint_fast16_t const margin,
994 enum_t const sig) noexcept;
995void gcFromISR(QEvt const * e) noexcept;
996#endif // def QF_ISR_API
997
998} // namespace QF
999} // namespace QP
1000
1001//============================================================================
1002extern "C" {
1003
1004//${QF-extern-C::QF_onContextSw} .............................................
1005#ifdef QF_ON_CONTEXT_SW
1007 QP::QActive * prev,
1008 QP::QActive * next);
1009#endif // def QF_ON_CONTEXT_SW
1010} // extern "C"
1011
1012//============================================================================
1013// QF base facilities
1014
1015#define Q_PRIO(prio_, pthre_) \
1016 (static_cast<QP::QPrioSpec>((prio_) | (pthre_) << 8U))
1017
1018#ifndef QEVT_PAR_INIT
1019 #define Q_NEW(evtT_, sig_) (QP::QF::q_new<evtT_>((sig_)))
1020 #define Q_NEW_X(evtT_, margin_, sig_) (QP::QF::q_new_x<evtT_>((margin_), (sig_)))
1021#else
1022 #define Q_NEW(evtT_, sig_, ...) (QP::QF::q_new<evtT_>((sig_), __VA_ARGS__))
1023 #define Q_NEW_X(evtT_, margin_, sig_, ...) (QP::QF::q_new_x<evtT_>((margin_), (sig_), __VA_ARGS__))
1024#endif // QEVT_PAR_INIT
1025
1026#define Q_NEW_REF(evtRef_, evtT_) (QP::QF::q_new_ref<evtT_>(e, (evtRef_)))
1027#define Q_DELETE_REF(evtRef_) do { \
1028 QP::QF::deleteRef_((evtRef_)); \
1029 (evtRef_) = nullptr; \
1030} while (false)
1031
1032#ifdef Q_SPY
1033 #define PUBLISH(e_, sender_) \
1034 publish_((e_), (sender_), (sender_)->getPrio())
1035 #define POST(e_, sender_) post_((e_), QP::QF::NO_MARGIN, (sender_))
1036 #define POST_X(e_, margin_, sender_) \
1037 post_((e_), (margin_), (sender_))
1038 #define TICK_X(tickRate_, sender_) tick((tickRate_), (sender_))
1039 #define TRIG(sender_) trig_((sender_))
1040#else
1041 #define PUBLISH(e_, dummy) publish_((e_), nullptr, 0U)
1042 #define POST(e_, dummy) post_((e_), QP::QF::NO_MARGIN, nullptr)
1043 #define POST_X(e_, margin_, dummy) post_((e_), (margin_), nullptr)
1044 #define TICK_X(tickRate_, dummy) tick((tickRate_), nullptr)
1045 #define TRIG(sender_) trig_(nullptr)
1046#endif // ndef Q_SPY
1047
1048#define TICK(sender_) TICK_X(0U, (sender_))
1049
1050#ifndef QF_CRIT_EXIT_NOP
1051 #define QF_CRIT_EXIT_NOP() (static_cast<void>(0))
1052#endif // ndef QF_CRIT_EXIT_NOP
1053
1054//============================================================================
1055// memory protection facilities
1056
1057#ifdef QF_MEM_ISOLATE
1058 #error Memory isolation not supported in this QP edition, need SafeQP
1059#endif // def QF_MEM_ISOLATE
1060
1061#endif // QP_HPP_
Active object class (based on the QHsm implementation strategy)
Definition qp.hpp:592
friend class QActiveDummy
Definition qp.hpp:735
QACTIVE_OS_OBJ_TYPE const & getOsObject() const noexcept
Definition qp.hpp:700
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:598
void unregister_() noexcept
Definition qf_qact.cpp:101
void start(QPrioSpec const prioSpec, QEvtPtr *const qSto, std::uint_fast16_t const qLen, void *const stkSto, std::uint_fast16_t const stkSize, void const *const par)
Definition qv.cpp:220
void subscribe(enum_t const sig) const noexcept
Definition qf_ps.cpp:162
friend class QTicker
Definition qp.hpp:730
friend class QXMutex
Definition qp.hpp:732
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:613
static QActive * registry_[QF_MAX_ACTIVE+1U]
Definition qp.hpp:723
bool defer(QEQueue *const eq, QEvt const *const e) const noexcept
Definition qf_defer.cpp:48
void setThread(QACTIVE_THREAD_TYPE const &thr)
Definition qp.hpp:694
friend class QS
Definition qp.hpp:736
static QSubscrList * subscrList_
Definition qp.hpp:725
void register_() noexcept
Definition qf_qact.cpp:59
QACTIVE_THREAD_TYPE const & getThread() const noexcept
Definition qp.hpp:691
friend void QXK_threadExit_() noexcept
void unsubscribe(enum_t const sig) const noexcept
Definition qf_ps.cpp:188
void postFIFO_(QEvt const *const e, void const *const sender)
Definition qf_actq.cpp:258
static void publishFromISR(QEvt const *e, void *par, void const *sender) noexcept
static void publish_(QEvt const *const e, void const *const sender, std::uint_fast8_t const qsId) noexcept
Definition qf_ps.cpp:68
static void evtLoop_(QActive *act)
void setAttr(std::uint32_t attr1, void const *attr2=nullptr)
static void psInit(QSubscrList *const subscrSto, enum_t const maxSignal) noexcept
Definition qf_ps.cpp:51
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:622
friend QP::QActive * QXK::current() noexcept
friend std::uint_fast8_t QXK_sched_() noexcept
bool post_(QEvt const *const e, std::uint_fast16_t const margin, void const *const sender) noexcept
Definition qf_actq.cpp:49
bool isIn(QStateHandler const stateHndl) noexcept override
Virtual function to check whether the state machine is in a given state.
Definition qp.hpp:628
friend std::uint_fast8_t QK_sched_act_(QP::QActive const *const act, std::uint_fast8_t const pthre_in) noexcept
Definition qk.cpp:145
static QActive * fromRegistry(std::uint_fast8_t const prio)
Definition qf_act.cpp:52
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:619
friend class QXSemaphore
Definition qp.hpp:733
QActive(QStateHandler const initial) noexcept
Definition qf_qact.cpp:49
std::uint8_t getPrio() const noexcept
Definition qp.hpp:684
QACTIVE_EQUEUE_TYPE m_eQueue
Definition qp.hpp:606
QEvt const * get_() noexcept
Definition qf_actq.cpp:198
friend void QXK_activate_()
QStateHandler childState(QStateHandler const parentHandler) noexcept
Definition qp.hpp:631
friend void QXK_contextSw_(QP::QActive *const next) noexcept
void postLIFO(QEvt const *const e) noexcept
Definition qf_actq.cpp:126
bool recall(QEQueue *const eq) noexcept
Definition qf_defer.cpp:80
friend class QTimeEvt
Definition qp.hpp:729
std::uint_fast16_t flushDeferred(QEQueue *const eq, std::uint_fast16_t const num=0xFFFFU) const noexcept
Definition qf_defer.cpp:132
std::uint8_t m_pthre
Definition qp.hpp:595
friend void QK_activate_()
Definition qk.cpp:180
QACTIVE_OS_OBJ_TYPE m_osObject
Definition qp.hpp:602
std::uint8_t m_prio
Definition qp.hpp:594
friend class QMActive
Definition qp.hpp:734
void unsubscribeAll() const noexcept
Definition qf_ps.cpp:214
static QSignal maxPubSignal_
Definition qp.hpp:726
static std::uint_fast16_t getQueueMin(std::uint_fast8_t const prio) noexcept
Definition qf_actq.cpp:313
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:644
friend class QXThread
Definition qp.hpp:731
Abstract State Machine class (state machine interface)
Definition qp.hpp:176
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:218
QState qm_entry(QMState const *const s) noexcept
Internal helper function to execute state entry actions in QP::QMsm.
Definition qp.hpp:286
QAsm() noexcept
Constructor of the QP::QAsm base class.
Definition qp.hpp:251
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:276
QStateHandler state() const noexcept
Definition qp.hpp:228
static constexpr QState Q_RET_UNHANDLED
Definition qp.hpp:184
QState qm_tran(void const *const tatbl) noexcept
Internal helper function to take a state transition in QP::QMsm.
Definition qp.hpp:268
static constexpr QState Q_RET_TRAN
Definition qp.hpp:198
static constexpr QState Q_RET_ENTRY
Definition qp.hpp:191
QState qm_exit(QMState const *const s) noexcept
Internal helper function to execute state exit actions in QP::QMsm.
Definition qp.hpp:300
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:260
QState super(QStateHandler const superstate) noexcept
Internal helper function to indicate superstate of a given state in sublclasses of QP::QAsm.
Definition qp.hpp:264
QState qm_tran_init(void const *const tatbl) noexcept
Definition qp.hpp:272
static constexpr QState Q_RET_NULL
Definition qp.hpp:195
QAsmAttr m_temp
Temporary storage for target/act-table etc.
Definition qp.hpp:179
static constexpr QState Q_RET_IGNORED
Definition qp.hpp:188
static constexpr QState Q_RET_SUPER
Definition qp.hpp:183
static QState top(void *const me, QEvt const *const e) noexcept
Top state handler that ignores all events.
Definition qp.hpp:241
static constexpr QState Q_RET_TRAN_INIT
Definition qp.hpp:199
static constexpr QState Q_RET_TRAN_HIST
Definition qp.hpp:202
virtual QStateHandler getStateHandler() noexcept
Virtual method for getting the state handler.
Definition qp.hpp:236
static constexpr QState Q_RET_EXIT
Definition qp.hpp:192
QMState const * stateObj() const noexcept
Definition qp.hpp:231
virtual bool isIn(QStateHandler const stateHndl) noexcept
Virtual function to check whether the state machine is in a given state.
Definition qp.hpp:224
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:256
virtual ~QAsm() noexcept
Virtual destructor of the QP::QAsm abstract base class.
Definition qp.hpp:211
static constexpr QSignal Q_INIT_SIG
Definition qp.hpp:208
QAsmAttr m_state
Current state (pointer to the current state-handler function)
Definition qp.hpp:178
virtual void dispatch(QEvt const *const e, std::uint_fast8_t const qsId)=0
Virtual function to dispatch an event to the state machine.
static constexpr QSignal Q_ENTRY_SIG
Definition qp.hpp:206
static constexpr QSignal Q_EXIT_SIG
Definition qp.hpp:207
static constexpr QSignal Q_EMPTY_SIG
Definition qp.hpp:205
static constexpr QState Q_RET_HANDLED
Definition qp.hpp:187
Native QP event queue.
Definition qequeue.hpp:53
Event class.
Definition qp.hpp:114
void init(DynEvt const dummy) const noexcept
Definition qp.hpp:132
QSignal sig
Signal of the event (see Event Signal)
Definition qp.hpp:116
@ DYNAMIC
Definition qp.hpp:120
std::uint8_t poolNum_
Event pool number of this event.
Definition qp.hpp:117
std::uint8_t volatile refCtr_
Event reference counter.
Definition qp.hpp:118
void init() const noexcept
Definition qp.hpp:129
constexpr QEvt(QSignal const s) noexcept
Event constexpr constructor applicable to immutable and mutable event instances.
Definition qp.hpp:122
QEvt()=delete
Hierarchical State Machine class (QHsm-style state machine implementation strategy)
Definition qp.hpp:313
QStateHandler getStateHandler() noexcept override
Definition qp.hpp:331
friend class QS
Definition qp.hpp:351
std::int_fast8_t tran_complex_(QStateHandler *const path, std::uint_fast8_t const qsId)
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:321
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:215
std::int_fast8_t tran_simple_(QStateHandler *const path, std::uint_fast8_t const qsId)
QStateHandler childState(QStateHandler const parentHndl) noexcept
Definition qep_hsm.cpp:533
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:155
QHsm(QStateHandler const initial) noexcept
Definition qep_hsm.cpp:147
void enter_target_(QStateHandler *const path, std::int_fast8_t const depth, std::uint_fast8_t const qsId)
bool isIn(QStateHandler const stateHndl) noexcept override
Definition qep_hsm.cpp:504
QMActive(QStateHandler const initial) noexcept
Constructor of QP::QMActive class.
Definition qf_qmact.cpp:48
bool isIn(QStateHandler const stateHndl) noexcept override
Virtual function to check whether the state machine is in a given state.
Definition qp.hpp:779
QStateHandler getStateHandler() noexcept override
Virtual method for getting the state handler.
Definition qp.hpp:784
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:773
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:764
QMState const * childStateObj(QMState const *const parent) const noexcept
Definition qp.hpp:788
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:770
Hierarchical State Machine class (QMsm-style state machine implementation strategy)
Definition qp.hpp:355
QMState const * childStateObj(QMState const *const parentHndl) const noexcept
void exitToTranSource_(QMState const *const curr_state, QMState const *const tran_source, std::uint_fast8_t const qsId)
friend class QS
Definition qp.hpp:393
QState execTatbl_(QMTranActTable const *const tatbl, std::uint_fast8_t const qsId)
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:363
void dispatch(QEvt const *const e, std::uint_fast8_t const qsId) override
Virtual function to dispatch an event to the state machine.
QState enterHistory_(QMState const *const hist, std::uint_fast8_t const qsId)
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.
bool isIn(QStateHandler const stateHndl) noexcept override
QMsm(QStateHandler const initial) noexcept
QMState const * topQMState() const noexcept
QStateHandler getStateHandler() noexcept override
Obtain the current active state from a MSM (read only)
Definition qp.hpp:371
Set of Active Objects of up to QF_MAX_ACTIVE elements.
Definition qp.hpp:475
std::uint_fast8_t findMax() const noexcept
Definition qp.hpp:533
friend class QS
Definition qp.hpp:544
void remove(std::uint_fast8_t const n) noexcept
Definition qp.hpp:521
bool notEmpty() const noexcept
Definition qp.hpp:493
bool hasElement(std::uint_fast8_t const n) const noexcept
Definition qp.hpp:500
QPSetBits m_bits[((QF_MAX_ACTIVE+(8U *sizeof(QPSetBits))) - 1U)/(8U *sizeof(QPSetBits))]
Definition qp.hpp:478
void setEmpty() noexcept
Definition qp.hpp:480
bool isEmpty() const noexcept
Definition qp.hpp:486
void insert(std::uint_fast8_t const n) noexcept
Definition qp.hpp:509
Subscriber List (for publish-subscribe)
Definition qp.hpp:548
QPSet m_set
Definition qp.hpp:550
friend class QActive
Definition qp.hpp:553
friend class QS
Definition qp.hpp:554
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 qf_actq.cpp:339
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:874
QTicker(std::uint_fast8_t const tickRate) noexcept
Definition qf_actq.cpp:331
Time Event class.
Definition qp.hpp:795
static void tick(std::uint_fast8_t const tickRate, void const *const sender) noexcept
Definition qf_time.cpp:254
QTimeEvt * toTimeEvt() noexcept
Definition qp.hpp:849
void const * getAct() const noexcept
Definition qp.hpp:817
friend class QS
Definition qp.hpp:864
static QTimeEvt timeEvtHead_[QF_MAX_TICK_RATE]
Definition qp.hpp:805
bool disarm() noexcept
Definition qf_time.cpp:133
std::uint8_t m_flags
Definition qp.hpp:802
QTimeEvt(QActive *const act, QSignal const sig, std::uint_fast8_t const tickRate=0U) noexcept
The "extended" constructor to initialize a Time Event.
Definition qf_time.cpp:50
static void tick1_(std::uint_fast8_t const tickRate, void const *const sender)
QTimeEvtCtr getInterval() const noexcept
Definition qp.hpp:823
static bool noActive(std::uint_fast8_t const tickRate) noexcept
Definition qf_time.cpp:341
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:798
QTimeEvt *volatile m_next
Link to the next time event in the list.
Definition qp.hpp:797
QActive * toActive() noexcept
Definition qp.hpp:846
std::uint8_t m_tickRate
Definition qp.hpp:801
void armX(std::uint32_t const nTicks, std::uint32_t const interval=0U) noexcept
Definition qf_time.cpp:72
QTimeEvtCtr getCtr() const noexcept
Definition qp.hpp:820
bool rearm(std::uint32_t const nTicks) noexcept
Definition qf_time.cpp:176
std::uint8_t getTickRate() const noexcept
Definition qp.hpp:826
QTimeEvtCtr volatile m_ctr
Down-counter of the time event.
Definition qp.hpp:799
QTimeEvt * expire_(QTimeEvt *const prev_link, QActive const *const act, std::uint_fast8_t const tickRate) noexcept
Definition qf_time.cpp:372
QTimeEvtCtr m_interval
Interval for periodic time event (zero for one-shot time event)
Definition qp.hpp:800
bool wasDisarmed() noexcept
Definition qf_time.cpp:241
friend class QXThread
Definition qp.hpp:863
eXtended (blocking) thread of the QXK preemptive kernel
Definition qxk.hpp:65
QF Active Object Framework namespace.
void deleteRef_(QEvt const *const evtRef) noexcept
Definition qf_dyn.cpp:282
void onCleanup()
void psInit(QSubscrList *const subscrSto, enum_t const maxSignal) noexcept
Definition qp.hpp:887
QEvt const * newRef_(QEvt const *const e, QEvt const *const evtRef) noexcept
Definition qf_dyn.cpp:248
evtT_ * q_new(enum_t const sig, Args... args)
Definition qp.hpp:953
void tick(std::uint_fast8_t const tickRate, void const *const sender) noexcept
Definition qp.hpp:904
evtT_ * q_new_x(std::uint_fast16_t const margin, enum_t const sig, Args... args)
Definition qp.hpp:963
void gcFromISR(QEvt const *e) noexcept
constexpr std::uint_fast16_t NO_MARGIN
Definition qp.hpp:916
void init()
Definition qv.cpp:97
void q_new_ref(QP::QEvt const *const e, evtT_ const *&evtRef)
Definition qp.hpp:977
std::uint_fast16_t getQueueMin(std::uint_fast8_t const prio) noexcept
Definition qp.hpp:912
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:985
QEvt * newX_(std::uint_fast16_t const evtSize, std::uint_fast16_t const margin, enum_t const sig) noexcept
Definition qf_dyn.cpp:119
int_t run()
Definition qv.cpp:114
void stop()
Definition qv.cpp:108
void publish_(QEvt const *const e, void const *const sender, std::uint_fast8_t const qsId) noexcept
Definition qp.hpp:895
void onStartup()
preemptive, dual-mode (non-blocking / blocking) kernel
Definition qp.hpp:587
QP::QActive * current() noexcept
QP/C++ framework.
Definition qequeue.hpp:36
void QXK_threadExit_() noexcept
constexpr enum_t Q_USER_SIG
Definition qp.hpp:173
std::uint32_t QTimeEvtCtr
Data type to store the block-size defined based on the macro QF_TIMEEVT_CTR_SIZE.
Definition qp.hpp:459
char const versionStr[24]
Definition qf_act.cpp:48
QState(*)(void *const me) QActionHandler
Pointer to an action-handler function.
Definition qp.hpp:148
std::uint_fast8_t QF_LOG2(QP::QPSetBits const bitmask) noexcept
Definition qf_act.cpp:76
QEvt const * QEvtPtr
Pointer to const event instances passed around in QP Framework.
Definition qp.hpp:138
void QK_activate_()
Definition qk.cpp:180
void QXK_contextSw_(QP::QActive *const next) noexcept
std::uint_fast8_t QState
Type returned from state-handler functions.
Definition qp.hpp:143
QState(*)(void *const me, QEvt const *const e) QStateHandler
Pointer to a state-handler function.
Definition qp.hpp:147
void QXK_activate_()
std::uint32_t QPSetBits
Definition qp.hpp:467
std::uint_fast8_t QK_sched_act_(QP::QActive const *const act, std::uint_fast8_t const pthre_in) noexcept
Definition qk.cpp:145
std::uint16_t QSignal
The signal of event QP::QEvt.
Definition qp.hpp:107
std::uint_fast8_t QK_sched_() noexcept
Definition qk.cpp:118
std::uint_fast8_t QXK_sched_() noexcept
void(*)(QXThread *const me) QXThreadHandler
Pointer to an extended-thread handler function.
Definition qp.hpp:149
std::uint16_t QPrioSpec
Priority specification for Active Objects in QP.
Definition qp.hpp:452
int enum_t
Definition qp.hpp:92
int int_t
Alias for assertion-ID numbers in QP assertions and return from QP::QF::run()
Definition qp.hpp:91
#define Q_UNUSED_PAR(par_)
Helper macro to clearly mark unused parameters of functions.
Definition qp.hpp:94
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:151
QActionHandler const entryAction
Definition qp.hpp:154
QStateHandler const stateHandler
Definition qp.hpp:153
QActionHandler const exitAction
Definition qp.hpp:155
QMState const * superstate
Definition qp.hpp:152
QActionHandler const initAction
Definition qp.hpp:156
Transition-Action Table for the QP::QMsm State Machine.
Definition qp.hpp:159
QMState const * target
Definition qp.hpp:160
QActionHandler const act[1]
Definition qp.hpp:161
Attribute of for the QP::QAsm class (Abstract State Machine)
Definition qp.hpp:164
std::uintptr_t uint
Definition qp.hpp:170
QMState const * obj
Definition qp.hpp:168
QStateHandler fun
Definition qp.hpp:165
QMTranActTable const * tatbl
Definition qp.hpp:169
QXThreadHandler thr
Definition qp.hpp:167
QActionHandler act
Definition qp.hpp:166