QP/C  7.3.4
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 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) : qpc
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${src::qf::qf_qact.c} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
43#define QP_IMPL // this is QP implementation
44#include "qp_port.h" // QP port
45#include "qp_pkg.h" // QP package-scope interface
46#include "qsafe.h" // QP Functional Safety (FuSa) Subsystem
47#ifdef Q_SPY // QS software tracing enabled?
48 #include "qs_port.h" // QS port
49 #include "qs_pkg.h" // QS facilities for pre-defined trace records
50#else
51 #include "qs_dummy.h" // disable the QS software tracing
52#endif // Q_SPY
53
54Q_DEFINE_THIS_MODULE("qf_qact")
55
56//$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
57// Check for the minimum required QP version
58#if (QP_VERSION < 730U) || (QP_VERSION != ((QP_RELEASE^4294967295U) % 0x3E8U))
59#error qpc version 7.3.0 or higher required
60#endif
61//$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
62
63//$define${QF::QActive::ctor} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
64
65//${QF::QActive::ctor} .......................................................
66//! @protected @memberof QActive
67void QActive_ctor(QActive * const me,
68 QStateHandler const initial)
69{
70 // clear the whole QActive object, so that the framework can start
71 // correctly even if the startup code fails to clear the uninitialized
72 // data (as is required by the C Standard).
73 QF_bzero_(me, sizeof(*me));
74
75 // NOTE: QActive inherits the abstract QAsm class, but it calls the
76 // constructor of the QHsm subclass. This is because QActive inherits
77 // the behavior from the QHsm subclass.
78 QHsm_ctor((QHsm *)(me), initial);
79
80 // NOTE: this vtable is identical as QHsm, but is provided
81 // for the QActive subclass to provide a UNIQUE vptr to distinguish
82 // subclasses of QActive (e.g., in the debugger).
83 static struct QAsmVtable const vtable = { // QActive virtual table
84 &QHsm_init_,
85 &QHsm_dispatch_,
86 &QHsm_isIn_
87 #ifdef Q_SPY
88 ,&QHsm_getStateHandler_
89 #endif
90 };
91 me->super.vptr = &vtable; // hook vptr to QActive vtable
92}
93//$enddef${QF::QActive::ctor} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
94
95//$define${QF::QActive::register_} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
96
97//${QF::QActive::register_} ..................................................
98//! @private @memberof QActive
99void QActive_register_(QActive * const me) {
102 QF_MEM_SYS();
103
104 if (me->pthre == 0U) { // preemption-threshold not defined?
105 me->pthre = me->prio; // apply the default
106 }
107
108 #ifndef Q_UNSAFE
109
110 Q_REQUIRE_INCRIT(100, (0U < me->prio) && (me->prio <= QF_MAX_ACTIVE)
111 && (QActive_registry_[me->prio] == (QActive *)0)
112 && (me->prio <= me->pthre));
113
114 uint8_t prev_thre = me->pthre;
115 uint8_t next_thre = me->pthre;
116
117 uint_fast8_t p;
118 for (p = (uint_fast8_t)me->prio - 1U; p > 0U; --p) {
119 if (QActive_registry_[p] != (QActive *)0) {
120 prev_thre = QActive_registry_[p]->pthre;
121 break;
122 }
123 }
124 for (p = (uint_fast8_t)me->prio + 1U; p <= QF_MAX_ACTIVE; ++p) {
125 if (QActive_registry_[p] != (QActive *)0) {
126 next_thre = QActive_registry_[p]->pthre;
127 break;
128 }
129 }
130
131 Q_ASSERT_INCRIT(190, (prev_thre <= me->pthre)
132 && (me->pthre <= next_thre));
133
134 me->prio_dis = (uint8_t)(~me->prio);
135 me->pthre_dis = (uint8_t)(~me->pthre);
136
137 #endif // Q_UNSAFE
138
139 // register the AO at the QF-prio.
140 QActive_registry_[me->prio] = me;
141
142 QF_MEM_APP();
143 QF_CRIT_EXIT();
144}
145//$enddef${QF::QActive::register_} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
146
147//$define${QF::QActive::unregister_} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
148
149//${QF::QActive::unregister_} ................................................
150//! @private @memberof QActive
151void QActive_unregister_(QActive * const me) {
152 uint_fast8_t const p = (uint_fast8_t)me->prio;
153
156 QF_MEM_SYS();
157
158 Q_REQUIRE_INCRIT(200, (0U < p) && (p <= QF_MAX_ACTIVE)
159 && (QActive_registry_[p] == me));
160 QActive_registry_[p] = (QActive *)0; // free-up the prio. level
161 me->super.state.fun = Q_STATE_CAST(0); // invalidate the state
162
163 QF_MEM_APP();
164 QF_CRIT_EXIT();
165}
166//$enddef${QF::QActive::unregister_} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
QActive * QActive_registry_[QF_MAX_ACTIVE+1U]
Definition qf_act.c:64
#define QF_MEM_APP()
Definition qp.h:1284
QState(* QStateHandler)(void *const me, QEvt const *const e)
Definition qp.h:226
#define Q_STATE_CAST(handler_)
Definition qp.h:526
#define QF_MEM_SYS()
Definition qp.h:1279
#define QF_MAX_ACTIVE
Definition qp_config.h:112
Internal (package scope) QP/C interface.
Sample QP/C port.
QS/C package-scope interface.
Sample QS/C port.
QP Functional Safety (FuSa) Subsystem.
#define QF_CRIT_ENTRY()
Definition qsafe.h:58
#define Q_ASSERT_INCRIT(id_, expr_)
Definition qsafe.h:72
#define QF_CRIT_EXIT()
Definition qsafe.h:62
#define Q_REQUIRE_INCRIT(id_, expr_)
Definition qsafe.h:136
#define QF_CRIT_STAT
Definition qsafe.h:54
Active object class (based on the QHsm implementation strategy)
Definition qp.h:800
uint8_t prio
Definition qp.h:805
uint8_t pthre
Definition qp.h:808
uint8_t pthre_dis
Definition qp.h:832
uint8_t prio_dis
Definition qp.h:827
QAsm super
Definition qp.h:802
struct QAsmVtable const * vptr
Definition qp.h:281
union QAsmAttr state
Definition qp.h:286
Virtual table for the QAsm class.
Definition qp.h:298
Hierarchical State Machine class (QHsm-style state machine implementation strategy)
Definition qp.h:313
QStateHandler fun
Definition qp.h:265