QP/C  7.2.2
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} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
2/*
3* Model: qpc.qm
4* File: ${src::qf::qf_qact.c}
5*
6* This code has been generated by QM 5.2.5 <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) : qpc
13* Support ends : 2023-12-31
14* License scope:
15*
16* Copyright (C) 2005 Quantum Leaps, LLC <state-machine.com>.
17*
18* SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
19*
20* This software is dual-licensed under the terms of the open source GNU
21* General Public License version 3 (or any later version), or alternatively,
22* under the terms of one of the closed source Quantum Leaps commercial
23* licenses.
24*
25* The terms of the open source GNU General Public License version 3
26* can be found at: <www.gnu.org/licenses/gpl-3.0>
27*
28* The terms of the closed source Quantum Leaps commercial licenses
29* can be found at: <www.state-machine.com/licensing>
30*
31* Redistributions in source code must retain this top-level comment block.
32* Plagiarizing this software to sidestep the license obligations is illegal.
33*
34* Contact information:
35* <www.state-machine.com/licensing>
36* <info@state-machine.com>
37*/
38/*$endhead${src::qf::qf_qact.c} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
39/*! @file
40* @brief QActive_ctor() definition
41*
42* @details
43* This file must remain separate from the rest to avoid pulling in the
44* "virtual" functions QHsm::QHsm_init_() and QHsm::QHsm_dispatch_() in
45* case they are not used by the application.
46*
47* @sa qf_qmact.c
48*/
49#define QP_IMPL /* this is QP implementation */
50#include "qf_port.h" /* QF port */
51#include "qf_pkg.h" /* QF package-scope interface */
52#include "qassert.h" /* QP embedded systems-friendly assertions */
53
54Q_DEFINE_THIS_MODULE("qf_qact")
55
56//============================================================================
57/*$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
58/* Check for the minimum required QP version */
59#if (QP_VERSION < 700U) || (QP_VERSION != ((QP_RELEASE^4294967295U) % 0x3E8U))
60#error qpc version 7.0.0 or higher required
61#endif
62/*$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
63
64/*$define${QF::QActive::registry_[QF_MAX_ACTIVE + 1U]} vvvvvvvvvvvvvvvvvvvvv*/
65QActive * QActive_registry_[QF_MAX_ACTIVE + 1U];
66/*$enddef${QF::QActive::registry_[QF_MAX_ACTIVE + 1U]} ^^^^^^^^^^^^^^^^^^^^^*/
67/*$define${QF::QF-pkg::readySet_} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
68
69/*${QF::QF-pkg::readySet_} .................................................*/
70QPSet QF_readySet_;
71/*$enddef${QF::QF-pkg::readySet_} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
72/*$define${QF::QF-base::intLock_} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
73
74/*${QF::QF-base::intLock_} .................................................*/
75uint_fast8_t volatile QF_intLock_;
76/*$enddef${QF::QF-base::intLock_} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
77/*$define${QF::QF-base::intNest_} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
78
79/*${QF::QF-base::intNest_} .................................................*/
80uint_fast8_t volatile QF_intNest_;
81/*$enddef${QF::QF-base::intNest_} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
82/*$define${QF::QF-pkg::readySet_rmc_} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
83
84/*${QF::QF-pkg::readySet_rmc_} .............................................*/
85#ifndef QP_NSSM
86QPSet QF_readySet_rmc_;
87#endif /* ndef QP_NSSM */
88/*$enddef${QF::QF-pkg::readySet_rmc_} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
89
90//============================================================================
91/*$define${QF::QF-pkg::bzero} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
92
93/*${QF::QF-pkg::bzero} .....................................................*/
94/*! @static @public @memberof QF */
95void QF_bzero(
96 void * const start,
97 uint_fast16_t const len)
98{
99 uint8_t *ptr = (uint8_t *)start;
100 for (uint_fast16_t n = len; n > 0U; --n) {
101 *ptr = 0U;
102 ++ptr;
103 }
104}
105/*$enddef${QF::QF-pkg::bzero} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
106
107//============================================================================
108/*$define${QF::QActive::ctor} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
109
110/*${QF::QActive::ctor} .....................................................*/
111/*! @protected @memberof QActive */
112void QActive_ctor(QActive * const me,
113 QStateHandler const initial)
114{
115 static QActiveVtable const vtable = { /* QActive virtual table */
116 { &QHsm_init_,
117 &QHsm_dispatch_
118 #ifdef Q_SPY
119 ,&QHsm_getStateHandler_
120 #endif
121 },
123 &QActive_post_,
124 &QActive_postLIFO_
125 };
126 /* clear the whole QActive object, so that the framework can start
127 * correctly even if the startup code fails to clear the uninitialized
128 * data (as is required by the C Standard).
129 */
130 QF_bzero(me, sizeof(*me));
131
132 QHsm_ctor(&me->super, initial); /* explicitly call superclass' ctor */
133 me->super.vptr = &vtable.super; /* hook the vptr to QActive vtable */
134}
135/*$enddef${QF::QActive::ctor} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
136/*$define${QF::QActive::register_} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
137
138/*${QF::QActive::register_} ................................................*/
139/*! @protected @memberof QActive */
140void QActive_register_(QActive * const me) {
141 if (me->pthre == 0U) { /* preemption-threshold not defined? */
142 me->pthre = me->prio; /* apply the default */
143 }
144
145 #ifndef QP_NSSM
146
147 Q_REQUIRE_ID(100, (0U < me->prio) && (me->prio <= QF_MAX_ACTIVE)
148 && (QActive_registry_[me->prio] == (QActive *)0)
149 && (me->prio <= me->pthre));
150
151 uint8_t prev_thre = me->pthre;
152 uint8_t next_thre = me->pthre;
153 uint_fast8_t p;
154
155 for (p = (uint_fast8_t)me->prio - 1U; p > 0U; --p) {
156 if (QActive_registry_[p] != (QActive *)0) {
157 prev_thre = QActive_registry_[p]->pthre;
158 break;
159 }
160 }
161 for (p = (uint_fast8_t)me->prio + 1U; p <= QF_MAX_ACTIVE; ++p) {
162 if (QActive_registry_[p] != (QActive *)0) {
163 next_thre = QActive_registry_[p]->pthre;
164 break;
165 }
166 }
167
168 Q_ENSURE_ID(190, (prev_thre <= me->pthre) && (me->pthre <= next_thre));
169
170 #endif /* QP_NSSM */
171
173 QF_CRIT_E_();
174 /* register the AO at the "QF-priority" */
175 QActive_registry_[me->prio] = me;
176 QF_CRIT_X_();
177}
178/*$enddef${QF::QActive::register_} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
179/*$define${QF::QActive::unregister_} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
180
181/*${QF::QActive::unregister_} ..............................................*/
182/*! @protected @memberof QActive */
183void QActive_unregister_(QActive * const me) {
184 uint_fast8_t const p = (uint_fast8_t)me->prio;
185
186 Q_REQUIRE_ID(200, (0U < p) && (p <= QF_MAX_ACTIVE)
187 && (QActive_registry_[p] == me));
189 QF_CRIT_E_();
190 QActive_registry_[p] = (QActive *)0; /* free-up the priority level */
191 me->super.state.fun = Q_STATE_CAST(0); /* invalidate the state */
192 QF_CRIT_X_();
193}
194/*$enddef${QF::QActive::unregister_} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
195
196//============================================================================
197/*$define${QF-types::QF_LOG2} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
198
199/*${QF-types::QF_LOG2} .....................................................*/
200#ifndef QF_LOG2
201uint_fast8_t QF_LOG2(QPSetBits x) {
202 static uint8_t const log2LUT[16] = {
203 0U, 1U, 2U, 2U, 3U, 3U, 3U, 3U,
204 4U, 4U, 4U, 4U, 4U, 4U, 4U, 4U
205 };
206 uint_fast8_t n = 0U;
207 QPSetBits t;
208
209 #if (QF_MAX_ACTIVE > 16U)
210 t = (QPSetBits)(x >> 16U);
211 if (t != 0U) {
212 n += 16U;
213 x = t;
214 }
215 #endif
216 #if (QF_MAX_ACTIVE > 8U)
217 t = (x >> 8U);
218 if (t != 0U) {
219 n += 8U;
220 x = t;
221 }
222 #endif
223 t = (x >> 4U);
224 if (t != 0U) {
225 n += 4U;
226 x = t;
227 }
228 return n + log2LUT[x];
229}
230#endif /* ndef QF_LOG2 */
231/*$enddef${QF-types::QF_LOG2} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
Customizable and memory-efficient Design by Contract (DbC) for embedded systems.
#define Q_ENSURE_ID(id_, expr_)
Definition: qassert.h:266
#define Q_REQUIRE_ID(id_, expr_)
Definition: qassert.h:240
#define Q_STATE_CAST(handler_)
Definition: qep.h:1089
QState(* QStateHandler)(void *const me, QEvt const *const e)
Definition: qep.h:256
uint32_t QPSetBits
Definition: qf.h:132
Internal (package scope) QF/C interface.
#define QF_CRIT_STAT_
Definition: qf_pkg.h:113
#define QF_CRIT_X_()
Definition: qf_pkg.h:143
#define QF_CRIT_E_()
Definition: qf_pkg.h:128
QF/C sample port with all configurable options.
#define QF_MAX_ACTIVE
Definition: qf_port.h:71
#define QF_LOG2(n_)
Definition: qf_port.h:250
void QActive_start_(QActive *const me, QPrioSpec const prioSpec, QEvt const **const qSto, uint_fast16_t const qLen, void *const stkSto, uint_fast16_t const stkSize, void const *const par)
Definition: qutest.c:213
Active object class (based on the QHsm implementation strategy)
Definition: qf.h:426
QHsm super
Definition: qf.h:428
uint8_t prio
Definition: qf.h:480
uint8_t pthre
Definition: qf.h:486
Virtual table for the QActive class.
Definition: qf.h:992
struct QHsmVtable super
Definition: qf.h:993
struct QHsmVtable const * vptr
Definition: qep.h:373
union QHsmAttr state
Definition: qep.h:380
Priority Set of up to QF_MAX_ACTIVE elements.
Definition: qf.h:234
QStateHandler fun
Definition: qep.h:312