QP/C  8.0.0
Real-Time Embedded Framework
Loading...
Searching...
No Matches
qf_qact.c
Go to the documentation of this file.
1//$file${src::qf::qf_qact.c} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
2//
3// Model: qpc.qm
4// File: ${src::qf::qf_qact.c}
5//
6// This code has been generated by QM 7.0.0 <www.state-machine.com/qm>.
7// DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
8//
9// Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
10//
11// Q u a n t u m L e a P s
12// ------------------------
13// Modern Embedded Software
14//
15// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
16//
17// The QP/C software is dual-licensed under the terms of the open-source GNU
18// General Public License (GPL) or under the terms of one of the closed-
19// source Quantum Leaps commercial licenses.
20//
21// Redistributions in source code must retain this top-level comment block.
22// Plagiarizing this software to sidestep the license obligations is illegal.
23//
24// NOTE:
25// The GPL does NOT permit the incorporation of this code into proprietary
26// programs. Please contact Quantum Leaps for commercial licensing options,
27// which expressly supersede the GPL and are designed explicitly for
28// closed-source distribution.
29//
30// Quantum Leaps contact information:
31// <www.state-machine.com/licensing>
32// <info@state-machine.com>
33//
34//$endhead${src::qf::qf_qact.c} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
35#define QP_IMPL // this is QP implementation
36#include "qp_port.h" // QP port
37#include "qp_pkg.h" // QP package-scope interface
38#include "qsafe.h" // QP Functional Safety (FuSa) Subsystem
39#ifdef Q_SPY // QS software tracing enabled?
40 #include "qs_port.h" // QS port
41 #include "qs_pkg.h" // QS facilities for pre-defined trace records
42#else
43 #include "qs_dummy.h" // disable the QS software tracing
44#endif // Q_SPY
45
46Q_DEFINE_THIS_MODULE("qf_qact")
47
48//$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
49// Check for the minimum required QP version
50#if (QP_VERSION < 730U) || (QP_VERSION != ((QP_RELEASE^4294967295U)%0x2710U))
51#error qpc version 7.3.0 or higher required
52#endif
53//$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54//$define${QF::QActive::ctor} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
55
56//${QF::QActive::ctor} .......................................................
57//! @protected @memberof QActive
58void QActive_ctor(QActive * const me,
59 QStateHandler const initial)
60{
61 // clear the whole QActive object, so that the framework can start
62 // correctly even if the startup code fails to clear the uninitialized
63 // data (as is required by the C Standard).
64 QF_bzero_(me, sizeof(*me));
65
66 // NOTE: QActive inherits the abstract QAsm class, but it calls the
67 // constructor of the QHsm subclass. This is because QActive inherits
68 // the behavior from the QHsm subclass.
69 QHsm_ctor((QHsm *)(me), initial);
70
71 // NOTE: this vtable is identical as QHsm, but is provided
72 // for the QActive subclass to provide a UNIQUE vptr to distinguish
73 // subclasses of QActive (e.g., in the debugger).
74 static struct QAsmVtable const vtable = { // QActive virtual table
75 &QHsm_init_,
76 &QHsm_dispatch_,
77 &QHsm_isIn_
78 #ifdef Q_SPY
79 ,&QHsm_getStateHandler_
80 #endif
81 };
82 me->super.vptr = &vtable; // hook vptr to QActive vtable
83}
84//$enddef${QF::QActive::ctor} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
85
86//$define${QF::QActive::register_} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
87
88//${QF::QActive::register_} ..................................................
89//! @private @memberof QActive
90void QActive_register_(QActive * const me) {
93 QF_MEM_SYS();
94
95 if (me->pthre == 0U) { // preemption-threshold not defined?
96 me->pthre = me->prio; // apply the default
97 }
98
99 #ifndef Q_UNSAFE
100
101 Q_REQUIRE_INCRIT(100, (0U < me->prio) && (me->prio <= QF_MAX_ACTIVE)
102 && (QActive_registry_[me->prio] == (QActive *)0)
103 && (me->prio <= me->pthre));
104
105 uint8_t prev_thre = me->pthre;
106 uint8_t next_thre = me->pthre;
107
108 uint_fast8_t p;
109 for (p = (uint_fast8_t)me->prio - 1U; p > 0U; --p) {
110 if (QActive_registry_[p] != (QActive *)0) {
111 prev_thre = QActive_registry_[p]->pthre;
112 break;
113 }
114 }
115 for (p = (uint_fast8_t)me->prio + 1U; p <= QF_MAX_ACTIVE; ++p) {
116 if (QActive_registry_[p] != (QActive *)0) {
117 next_thre = QActive_registry_[p]->pthre;
118 break;
119 }
120 }
121
122 Q_ASSERT_INCRIT(190, (prev_thre <= me->pthre)
123 && (me->pthre <= next_thre));
124
125 me->prio_dis = (uint8_t)(~me->prio);
126 me->pthre_dis = (uint8_t)(~me->pthre);
127
128 #endif // Q_UNSAFE
129
130 // register the AO at the QF-prio.
131 QActive_registry_[me->prio] = me;
132
133 QF_MEM_APP();
134 QF_CRIT_EXIT();
135}
136//$enddef${QF::QActive::register_} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
137
138//$define${QF::QActive::unregister_} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
139
140//${QF::QActive::unregister_} ................................................
141//! @private @memberof QActive
142void QActive_unregister_(QActive * const me) {
143 uint_fast8_t const p = (uint_fast8_t)me->prio;
144
147 QF_MEM_SYS();
148
149 Q_REQUIRE_INCRIT(200, (0U < p) && (p <= QF_MAX_ACTIVE)
150 && (QActive_registry_[p] == me));
151 QActive_registry_[p] = (QActive *)0; // free-up the prio. level
152 me->super.state.fun = Q_STATE_CAST(0); // invalidate the state
153
154 QF_MEM_APP();
155 QF_CRIT_EXIT();
156}
157//$enddef${QF::QActive::unregister_} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#define QF_MEM_APP()
Definition qp.h:1280
#define Q_STATE_CAST(handler_)
Perform cast to QStateHandler.
Definition qp.h:519
QState(* QStateHandler)(void *const me, QEvt const *const e)
Pointer to a state-handler function.
Definition qp.h:215
#define QF_MEM_SYS()
Definition qp.h:1275
#define QF_MAX_ACTIVE
Maximum # Active Objects in the system (1..64)
Definition qp_config.h:123
Internal (package scope) QP/C interface.
Sample QP/C port.
Sample QS/C port.
QP Functional Safety (FuSa) Subsystem.
#define QF_CRIT_ENTRY()
Definition qsafe.h:50
#define Q_ASSERT_INCRIT(id_, expr_)
Definition qsafe.h:64
#define QF_CRIT_EXIT()
Definition qsafe.h:54
#define Q_REQUIRE_INCRIT(id_, expr_)
Definition qsafe.h:128
#define QF_CRIT_STAT
Definition qsafe.h:46
Active object class (based on the QHsm implementation strategy)
Definition qp.h:779
uint8_t pthre_dis
Definition qp.h:811
uint8_t prio_dis
Definition qp.h:806
QAsm super
Definition qp.h:781
uint8_t prio
QF-priority [1..QF_MAX_ACTIVE] of this AO.
Definition qp.h:784
uint8_t pthre
Preemption-threshold [1..QF_MAX_ACTIVE] of this AO.
Definition qp.h:787
struct QAsmVtable const * vptr
Virtual pointer inherited by all QAsm subclasses (see also Object Orientation)
Definition qp.h:260
union QAsmAttr state
Current state (pointer to the current state-handler function)
Definition qp.h:265
Virtual table for the QAsm class.
Definition qp.h:277
Hierarchical State Machine class (QHsm-style state machine implementation strategy)
Definition qp.h:292
QStateHandler fun
Definition qp.h:244