qpcpp/src/qf_pkg.hpp

170 lines
6.7 KiB
C++
Raw Normal View History

//! @file
//! @brief Internal (package scope) QF/C++ interface.
//! @cond
//============================================================================
//! Last updated for version 6.9.1
//! Last updated on 2020-09-17
//!
//! Q u a n t u m L e a P s
//! ------------------------
//! Modern Embedded Software
//!
//! Copyright (C) 2005-2020 Quantum Leaps. All rights reserved.
//!
//! This program is open source software: you can redistribute it and/or
//! modify it under the terms of the GNU General Public License as published
//! by the Free Software Foundation, either version 3 of the License, or
//! (at your option) any later version.
//!
//! Alternatively, this program may be distributed and modified under the
//! terms of Quantum Leaps commercial licenses, which expressly supersede
//! the GNU General Public License and are specifically designed for
//! licensees interested in retaining the proprietary status of their code.
//!
//! This program is distributed in the hope that it will be useful,
//! but WITHOUT ANY WARRANTY; without even the implied warranty of
//! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//! GNU General Public License for more details.
//!
//! You should have received a copy of the GNU General Public License
//! along with this program. If not, see <www.gnu.org/licenses>.
//!
//! Contact information:
//! <www.state-machine.com/licensing>
//! <info@state-machine.com>
//============================================================================
//! @endcond
2017-05-27 10:39:57 -04:00
2019-10-27 12:26:31 -04:00
#ifndef QF_PKG_HPP
#define QF_PKG_HPP
2017-05-27 10:39:57 -04:00
//! helper macro to cast const away from an event pointer @p e_
#define QF_EVT_CONST_CAST_(e_) const_cast<QEvt *>(e_)
// QF-specific critical section...
#ifndef QF_CRIT_STAT_TYPE
//! This is an internal macro for defining the critical section
//! status type.
//! @description
//! The purpose of this macro is to enable writing the same code for the
//! case when critical section status type is defined and when it is not.
//! If the macro #QF_CRIT_STAT_TYPE is defined, this internal macro
//! provides the definition of the critical section status variable.
//! Otherwise this macro is empty.
//! @sa #QF_CRIT_STAT_TYPE
2017-05-27 10:39:57 -04:00
#define QF_CRIT_STAT_
//! This is an internal macro for entering a critical section.
//! @description
//! The purpose of this macro is to enable writing the same code for the
//! case when critical section status type is defined and when it is not.
//! If the macro #QF_CRIT_STAT_TYPE is defined, this internal macro
//! invokes QF_CRIT_ENTRY() passing the key variable as the parameter.
//! Otherwise QF_CRIT_ENTRY() is invoked with a dummy parameter.
//! @sa QF_CRIT_ENTRY()
2020-10-01 12:50:17 -04:00
#define QF_CRIT_E_() QF_CRIT_ENTRY(dummy)
2017-05-27 10:39:57 -04:00
//! This is an internal macro for exiting a critical section.
//! @description
//! The purpose of this macro is to enable writing the same code for the
//! case when critical section status type is defined and when it is not.
//! If the macro #QF_CRIT_STAT_TYPE is defined, this internal macro
//! invokes QF_CRIT_EXIT() passing the key variable as the parameter.
//! Otherwise QF_CRIT_EXIT() is invoked with a dummy parameter.
//! @sa QF_CRIT_EXIT()
//!
2020-10-01 12:50:17 -04:00
#define QF_CRIT_X_() QF_CRIT_EXIT(dummy)
2017-05-27 10:39:57 -04:00
2020-07-18 17:58:58 -04:00
#elif (!defined QF_CRIT_STAT_)
2017-05-27 10:39:57 -04:00
#define QF_CRIT_STAT_ QF_CRIT_STAT_TYPE critStat_;
2020-10-01 12:50:17 -04:00
#define QF_CRIT_E_() QF_CRIT_ENTRY(critStat_)
#define QF_CRIT_X_() QF_CRIT_EXIT(critStat_)
2017-05-27 10:39:57 -04:00
#endif // QF_CRIT_STAT_TYPE
2018-06-16 17:21:53 -04:00
// Assertions inside the crticial section ------------------------------------
#ifdef Q_NASSERT // Q_NASSERT defined--assertion checking disabled
#define Q_ASSERT_CRIT_(id_, test_) ((void)0)
#define Q_REQUIRE_CRIT_(id_, test_) ((void)0)
#define Q_ERROR_CRIT_(id_) ((void)0)
#else // Q_NASSERT not defined--assertion checking enabled
#define Q_ASSERT_CRIT_(id_, test_) do {\
if ((test_)) {} else { \
2020-10-01 12:50:17 -04:00
QF_CRIT_X_(); \
2018-06-16 17:21:53 -04:00
Q_onAssert(&Q_this_module_[0], static_cast<int_t>(id_)); \
} \
} while (false)
#define Q_REQUIRE_CRIT_(id_, test_) Q_ASSERT_CRIT_((id_), (test_))
#define Q_ERROR_CRIT_(id_) do { \
2020-10-01 12:50:17 -04:00
QF_CRIT_X_(); \
2018-06-16 17:21:53 -04:00
Q_onAssert(&Q_this_module_[0], static_cast<int_t>(id_)); \
} while (false)
#endif // Q_NASSERT
2017-05-27 10:39:57 -04:00
namespace QP {
// package-scope objects -----------------------------------------------------
extern QF_EPOOL_TYPE_ QF_pool_[QF_MAX_EPOOL]; //!< allocate event pools
2020-03-17 21:33:58 -04:00
extern std::uint_fast8_t QF_maxPool_; //!< # of initialized event pools
extern QSubscrList *QF_subscrList_; //!< the subscriber list array
extern enum_t QF_maxPubSignal_; //!< the maximum published signal
2017-05-27 10:39:57 -04:00
//............................................................................
//! Structure representing a free block in the Native QF Memory Pool
//! @sa QP::QMPool
2017-05-27 10:39:57 -04:00
struct QFreeBlock {
QFreeBlock * volatile m_next; //!< link to the next free block
};
2018-11-22 11:34:13 -05:00
//............................................................................
// The following flags and bitmasks are for the fields of the @c refCtr_
// attribute of the QP::QTimeEvt class (inherited from QEvt). This attribute
// is NOT used for reference counting in time events, because the @c poolId_
// attribute is zero ("static events").
//
constexpr std::uint_fast8_t TE_IS_LINKED = 1U << 7U; // flag
constexpr std::uint_fast8_t TE_WAS_DISARMED = 1U << 6U; // flag
constexpr std::uint_fast8_t TE_TICK_RATE = 0x0FU; // bitmask
2018-11-22 11:34:13 -05:00
//============================================================================
2017-05-27 10:39:57 -04:00
// internal helper inline functions
2018-03-22 09:33:35 -04:00
//! return the Pool-ID of an event @p e
2020-03-17 21:33:58 -04:00
inline std::uint8_t QF_EVT_POOL_ID_ (QEvt const * const e) noexcept {
2018-03-22 09:33:35 -04:00
return e->poolId_;
}
//! return the Reference Conter of an event @p e
2020-03-17 21:33:58 -04:00
inline std::uint8_t QF_EVT_REF_CTR_ (QEvt const * const e) noexcept {
2018-03-22 09:33:35 -04:00
return e->refCtr_;
}
2017-05-27 10:39:57 -04:00
//! increment the refCtr_ of an event @p e
2020-03-17 21:33:58 -04:00
inline void QF_EVT_REF_CTR_INC_(QEvt const * const e) noexcept {
2017-05-27 10:39:57 -04:00
++(QF_EVT_CONST_CAST_(e))->refCtr_;
}
//! decrement the refCtr_ of an event @p e
2020-03-17 21:33:58 -04:00
inline void QF_EVT_REF_CTR_DEC_(QEvt const * const e) noexcept {
2017-05-27 10:39:57 -04:00
--(QF_EVT_CONST_CAST_(e))->refCtr_;
}
2019-12-31 15:56:23 -05:00
} // namespace QP
2017-05-27 10:39:57 -04:00
//! macro to test that a pointer @p x_ is in range between @p min_ and @p max_
//! @description
//! This macro is specifically and exclusively used for checking the range
//! of a block pointer returned to the pool. Such a check must rely on the
//! pointer arithmetic not compliant with the [AUTOSAR Rule M5-0-18].
//! Defining a specific macro for this purpose allows to selectively
//! disable the warnings for this particular case.
2017-05-27 10:39:57 -04:00
#define QF_PTR_RANGE_(x_, min_, max_) (((min_) <= (x_)) && ((x_) <= (max_)))
2019-10-27 12:26:31 -04:00
#endif // QF_PKG_HPP