QP/C  7.4.0-rc.3
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.2.0 <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 : 2025-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)%0x2710U))
59#error qpc version 7.3.0 or higher required
60#endif
61//$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
62//$define${QF::QActive::ctor} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
63
64//${QF::QActive::ctor} .......................................................
65//! @protected @memberof QActive
66void QActive_ctor(QActive * const me,
67 QStateHandler const initial)
68{
69 // clear the whole QActive object, so that the framework can start
70 // correctly even if the startup code fails to clear the uninitialized
71 // data (as is required by the C Standard).
72 QF_bzero_(me, sizeof(*me));
73
74 // NOTE: QActive inherits the abstract QAsm class, but it calls the
75 // constructor of the QHsm subclass. This is because QActive inherits
76 // the behavior from the QHsm subclass.
77 QHsm_ctor((QHsm *)(me), initial);
78
79 // NOTE: this vtable is identical as QHsm, but is provided
80 // for the QActive subclass to provide a UNIQUE vptr to distinguish
81 // subclasses of QActive (e.g., in the debugger).
82 static struct QAsmVtable const vtable = { // QActive virtual table
83 &QHsm_init_,
84 &QHsm_dispatch_,
85 &QHsm_isIn_
86 #ifdef Q_SPY
87 ,&QHsm_getStateHandler_
88 #endif
89 };
90 me->super.vptr = &vtable; // hook vptr to QActive vtable
91}
92//$enddef${QF::QActive::ctor} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
93
94//$define${QF::QActive::register_} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
95
96//${QF::QActive::register_} ..................................................
97//! @private @memberof QActive
98void QActive_register_(QActive * const me) {
101 QF_MEM_SYS();
102
103 if (me->pthre == 0U) { // preemption-threshold not defined?
104 me->pthre = me->prio; // apply the default
105 }
106
107 #ifndef Q_UNSAFE
108
109 Q_REQUIRE_INCRIT(100, (0U < me->prio) && (me->prio <= QF_MAX_ACTIVE)
110 && (QActive_registry_[me->prio] == (QActive *)0)
111 && (me->prio <= me->pthre));
112
113 uint8_t prev_thre = me->pthre;
114 uint8_t next_thre = me->pthre;
115
116 uint_fast8_t p;
117 for (p = (uint_fast8_t)me->prio - 1U; p > 0U; --p) {
118 if (QActive_registry_[p] != (QActive *)0) {
119 prev_thre = QActive_registry_[p]->pthre;
120 break;
121 }
122 }
123 for (p = (uint_fast8_t)me->prio + 1U; p <= QF_MAX_ACTIVE; ++p) {
124 if (QActive_registry_[p] != (QActive *)0) {
125 next_thre = QActive_registry_[p]->pthre;
126 break;
127 }
128 }
129
130 Q_ASSERT_INCRIT(190, (prev_thre <= me->pthre)
131 && (me->pthre <= next_thre));
132
133 me->prio_dis = (uint8_t)(~me->prio);
134 me->pthre_dis = (uint8_t)(~me->pthre);
135
136 #endif // Q_UNSAFE
137
138 // register the AO at the QF-prio.
139 QActive_registry_[me->prio] = me;
140
141 QF_MEM_APP();
142 QF_CRIT_EXIT();
143}
144//$enddef${QF::QActive::register_} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
145
146//$define${QF::QActive::unregister_} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
147
148//${QF::QActive::unregister_} ................................................
149//! @private @memberof QActive
150void QActive_unregister_(QActive * const me) {
151 uint_fast8_t const p = (uint_fast8_t)me->prio;
152
155 QF_MEM_SYS();
156
157 Q_REQUIRE_INCRIT(200, (0U < p) && (p <= QF_MAX_ACTIVE)
158 && (QActive_registry_[p] == me));
159 QActive_registry_[p] = (QActive *)0; // free-up the prio. level
160 me->super.state.fun = Q_STATE_CAST(0); // invalidate the state
161
162 QF_MEM_APP();
163 QF_CRIT_EXIT();
164}
165//$enddef${QF::QActive::unregister_} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#define QF_MEM_APP()
Definition qp.h:1288
#define Q_STATE_CAST(handler_)
Perform cast to QStateHandler.
Definition qp.h:530
QState(* QStateHandler)(void *const me, QEvt const *const e)
Pointer to a state-handler function.
Definition qp.h:229
#define QF_MEM_SYS()
Definition qp.h:1283
#define QF_MAX_ACTIVE
Maximum # Active Objects in the system (1..64)
Definition qp_config.h:118
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:804
uint8_t pthre_dis
Definition qp.h:836
uint8_t prio_dis
Definition qp.h:831
QAsm super
Definition qp.h:806
uint8_t prio
QF-priority [1..QF_MAX_ACTIVE] of this AO.
Definition qp.h:809
uint8_t pthre
Preemption-threshold [1..QF_MAX_ACTIVE] of this AO.
Definition qp.h:812
struct QAsmVtable const * vptr
Virtual pointer inherited by all QAsm subclasses (see also Object Orientation)
Definition qp.h:284
union QAsmAttr state
Current state (pointer to the current state-handler function)
Definition qp.h:289
Virtual table for the QAsm class.
Definition qp.h:301
Hierarchical State Machine class (QHsm-style state machine implementation strategy)
Definition qp.h:316
QStateHandler fun
Definition qp.h:268