QP/C++ 8.1.1
Real-Time Event Framework
Loading...
Searching...
No Matches
qf_act.cpp
Go to the documentation of this file.
1//============================================================================
2// QP/C++ Real-Time Event Framework (RTEF)
3//
4// Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
5//
6// Q u a n t u m L e a P s
7// ------------------------
8// Modern Embedded Software
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
11//
12// This software is dual-licensed under the terms of the open-source GNU
13// General Public License (GPL) or under the terms of one of the closed-
14// source Quantum Leaps commercial licenses.
15//
16// Redistributions in source code must retain this top-level comment block.
17// Plagiarizing this software to sidestep the license obligations is illegal.
18//
19// NOTE:
20// The GPL does NOT permit the incorporation of this code into proprietary
21// programs. Please contact Quantum Leaps for commercial licensing options,
22// which expressly supersede the GPL and are designed explicitly for
23// closed-source distribution.
24//
25// Quantum Leaps contact information:
26// <www.state-machine.com/licensing>
27// <info@state-machine.com>
28//============================================================================
29#define QP_IMPL // this is QP implementation
30#include "qp_port.hpp" // QP port
31#include "qp_pkg.hpp" // QP package-scope interface
32#include "qsafe.h" // QP Functional Safety (FuSa) Subsystem
33#ifdef Q_SPY // QS software tracing enabled?
34 #include "qs_port.hpp" // QS port
35 #include "qs_pkg.hpp" // QS facilities for pre-defined trace records
36#else
37 #include "qs_dummy.hpp" // disable the QS software tracing
38#endif // Q_SPY
39
40// unnamed namespace for local definitions with internal linkage
41namespace {
42Q_DEFINE_THIS_MODULE("qf_act")
43} // unnamed namespace
44
45//----------------------------------------------------------------------------
46namespace QP {
47
48// QP version string embedded in the binary image
49static constexpr char versionStr[24] = "QP/C++ " QP_VERSION_STR;
50
51//............................................................................
52char const *version() noexcept {
53 // public access to versionStr[] so that it won't be eliminated as unused
54 return &versionStr[0];
55}
56//............................................................................
57void QEvt_refCtr_inc_(QEvt const * const me) noexcept {
58 // NOTE: this function must be called *inside* a critical section
59
60 // the event reference count must not exceed the number of AOs
61 // in the system plus each AO possibly holding one event reference
62 Q_REQUIRE_INCRIT(200, me->refCtr_ < (QF_MAX_ACTIVE + QF_MAX_ACTIVE));
63
64 QEvt * const mut_me = const_cast<QEvt *>(me); // cast 'const' away
65 ++mut_me->refCtr_;
66}
67//............................................................................
68void QEvt_refCtr_dec_(QEvt const * const me) noexcept {
69 // NOTE: this function must be called inside a critical section
70 QEvt * const mut_me = const_cast<QEvt *>(me); // cast 'const' away
71 --mut_me->refCtr_;
72}
73
74//----------------------------------------------------------------------------
75QAsm::QAsm() noexcept // default QAsm ctor
76 : m_state(),
77 m_temp ()
78{}
79//............................................................................
80QState QAsm::top(void * const me, QEvt const * const e) noexcept {
81 Q_UNUSED_PAR(me);
82 Q_UNUSED_PAR(e);
83 return Q_RET_IGNORED; // the top state ignores all events
84}
85//............................................................................
86void QAsm::init(std::uint_fast8_t const qsId) {
87 // this init() overload delegates to the init() without margin parameter
88 this->init(nullptr, qsId);
89}
90
91} // namespace QP
QAsm() noexcept
Constructor of the QP::QAsm base class.
Definition qf_act.cpp:75
QAsmAttr m_temp
Temporary storage for target/act-table etc.
Definition qp.hpp:170
static constexpr QState Q_RET_IGNORED
Definition qp.hpp:181
virtual void init(void const *const e, std::uint_fast8_t const qsId)=0
Virtual function to take the top-most initial transition in the state machine.
QAsmAttr m_state
Current state (pointer to the current state-handler function).
Definition qp.hpp:169
static QState top(void *const me, QEvt const *const e) noexcept
Top state handler that ignores all events.
Definition qf_act.cpp:80
Event class.
Definition qp.hpp:101
std::uint32_t refCtr_
Event reference counter.
Definition qp.hpp:105
QP/C++ Framework namespace.
Definition qequeue.hpp:36
char const * version() noexcept
Definition qf_act.cpp:52
void QEvt_refCtr_inc_(QEvt const *const me) noexcept
Internal function to increment the refCtr of a const event.
Definition qf_act.cpp:57
static constexpr char versionStr[24]
Definition qf_act.cpp:49
std::uint_fast8_t QState
Type returned from state-handler functions.
Definition qp.hpp:134
void QEvt_refCtr_dec_(QEvt const *const me) noexcept
Internal function to decrement the refCtr of a const event.
Definition qf_act.cpp:68
#define Q_UNUSED_PAR(par_)
Helper macro to clearly mark unused parameters of functions.
Definition qp.hpp:89
#define QP_VERSION_STR
Version string complying with Software Versioning specification.
Definition qp.hpp:33
#define QF_MAX_ACTIVE
Maximum # Active Objects in the system (1..64).
Definition qp_config.hpp:98
QP Framework in C++ internal (package-scope) interface
Sample QP/C++ port.
QS (QP/Spy software tracing) internal (package-scope) interface.
Sample QS/C++ port.
QP Functional Safety (FuSa) Subsystem.
#define Q_REQUIRE_INCRIT(id_, expr_)
Assertion for checking a precondition (in critical section).
Definition qsafe.h:98