QP/C  7.0.0
Real-Time Embedded Framework
qf_act.c
Go to the documentation of this file.
1/*============================================================================
2* QP/C Real-Time Embedded Framework (RTEF)
3* Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
4*
5* SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
6*
7* This software is dual-licensed under the terms of the open source GNU
8* General Public License version 3 (or any later version), or alternatively,
9* under the terms of one of the closed source Quantum Leaps commercial
10* licenses.
11*
12* The terms of the open source GNU General Public License version 3
13* can be found at: <www.gnu.org/licenses/gpl-3.0>
14*
15* The terms of the closed source Quantum Leaps commercial licenses
16* can be found at: <www.state-machine.com/licensing>
17*
18* Redistributions in source code must retain this top-level comment block.
19* Plagiarizing this software to sidestep the license obligations is illegal.
20*
21* Contact information:
22* <www.state-machine.com>
23* <info@state-machine.com>
24============================================================================*/
32#define QP_IMPL /* this is QP implementation */
33#include "qf_port.h" /* QF port */
34#include "qf_pkg.h" /* QF package-scope interface */
35#include "qassert.h" /* QP embedded systems-friendly assertions */
36#ifdef Q_SPY /* QS software tracing enabled? */
37 #include "qs_port.h" /* QS port */
38 #include "qs_pkg.h" /* QS facilities for pre-defined trace records */
39#else
40 #include "qs_dummy.h" /* disable the QS software tracing */
41#endif /* Q_SPY */
42
44
45/*==========================================================================*/
46/* global objects */
48QActive *QF_active_[QF_MAX_ACTIVE + 1U]; /* to be used by QF ports only */
49
50/*==========================================================================*/
65void QF_add_(QActive * const a) {
66 uint_fast8_t const p = (uint_fast8_t)a->prio;
67
73 Q_REQUIRE_ID(100, (0U < p)
74 && (p <= QF_MAX_ACTIVE)
75 && (QF_active_[p] == (QActive *)0));
77 QF_CRIT_E_();
78 QF_active_[p] = a; /* register the active object at this priority */
79 QF_CRIT_X_();
80}
81
82/*==========================================================================*/
98void QF_remove_(QActive * const a) {
99 uint_fast8_t const p = (uint_fast8_t)a->prio;
100
105 Q_REQUIRE_ID(200, (0U < p) && (p <= QF_MAX_ACTIVE)
106 && (QF_active_[p] == a));
108 QF_CRIT_E_();
109 QF_active_[p] = (QActive *)0; /* free-up the priority level */
110 a->super.state.fun = Q_STATE_CAST(0); /* invalidate the state */
111 QF_CRIT_X_();
112}
113
114/*==========================================================================*/
129void QF_bzero(void * const start, uint_fast16_t len) {
130 uint8_t *ptr = (uint8_t *)start;
131 for (uint_fast16_t n = len; n > 0U; --n) {
132 *ptr = 0U;
133 ++ptr;
134 }
135}
136
137/*==========================================================================*/
138/* log-base-2 implementation */
139#ifndef QF_LOG2
140
142 uint_fast8_t QF_LOG2(QPSetBits x) {
143 static uint8_t const log2LUT[16] = {
144 0U, 1U, 2U, 2U, 3U, 3U, 3U, 3U,
145 4U, 4U, 4U, 4U, 4U, 4U, 4U, 4U
146 };
147 uint_fast8_t n = 0U;
148 QPSetBits t;
149
150#if (QF_MAX_ACTIVE > 16U)
151 t = (QPSetBits)(x >> 16U);
152 if (0U != t) {
153 n += 16U;
154 x = t;
155 }
156#endif
157#if (QF_MAX_ACTIVE > 8U)
158 t = (x >> 8U);
159 if (0U != t) {
160 n += 8U;
161 x = t;
162 }
163#endif
164 t = (x >> 4U);
165 if (0U != t) {
166 n += 4U;
167 x = t;
168 }
169 return n + log2LUT[x];
170 }
171
172#endif /* QF_LOG2 */
Customizable and memory-efficient assertions for embedded systems.
#define Q_DEFINE_THIS_MODULE(name_)
Definition: qassert.h:102
#define Q_REQUIRE_ID(id_, test_)
Definition: qassert.h:252
#define Q_STATE_CAST(handler_)
Definition: qep.h:196
Internal (package scope) QF/C interface.
#define QF_CRIT_STAT_
Definition: qf_pkg.h:54
#define QF_CRIT_X_()
Definition: qf_pkg.h:78
#define QF_CRIT_E_()
Definition: qf_pkg.h:66
uint8_t QPSetBits
Definition: qpset.h:43
Internal (package scope) QS/C interface.
#define QF_MAX_ACTIVE
Definition: qf.h:107
QHsm super
Definition: qf.h:108
uint8_t prio
Definition: qf.h:152
void QF_bzero(void *const start, uint_fast16_t len)
Definition: qf_act.c:129
void QF_remove_(QActive *const a)
Definition: qf_act.c:98
void QF_add_(QActive *const a)
Definition: qf_act.c:65
QActive * QF_active_[QF_MAX_ACTIVE+1U]
Definition: qf_act.c:48
#define QF_LOG2(n_)
Definition: qf_act.c:142
union QHsmAttr state
Definition: qep.h:255
QStateHandler fun
Definition: qep.h:220