QP/C++ 8.1.2
Real-Time Event Framework
Loading...
Searching...
No Matches
qk.hpp
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#ifndef QK_HPP_
30#define QK_HPP_
31
32//============================================================================
33namespace QP {
34
35using QSchedStatus = std::uint8_t;
36
37//----------------------------------------------------------------------------
38class QK {
39public:
41 std::uint8_t actPrio;
42 std::uint8_t nextPrio;
43 std::uint8_t actThre;
44 std::uint8_t lockCeil;
45 std::uint8_t intNest;
46
47
48 static QSchedStatus schedLock(std::uint8_t const ceiling) noexcept;
49 static void schedUnlock(QSchedStatus const prevCeil) noexcept;
50 static void onIdle();
51
52 static std::uint_fast8_t sched_() noexcept;
53 static std::uint_fast8_t sched_act_(
54 QActive const* const act,
55 std::uint_fast8_t const pthre_in) noexcept;
56 static void activate_();
57
58 static QK priv_;
59
60}; // class QK
61
62} // namespace QP
63
64//============================================================================
65// interface used only for internal implementation, but not in applications
66
67#ifdef QP_IMPL
68//! @cond INTERNAL
69
70// scheduler locking for QK...
71#define QF_SCHED_STAT_ QSchedStatus lockStat_;
72#define QF_SCHED_LOCK_(ceil_) do { \
73 if (QK_ISR_CONTEXT_()) { \
74 lockStat_ = 0xFFU; \
75 } else { \
76 lockStat_ = QK::schedLock((ceil_)); \
77 } \
78} while (false)
79
80#define QF_SCHED_UNLOCK_() do { \
81 if (lockStat_ != 0xFFU) { \
82 QK::schedUnlock(lockStat_); \
83 } \
84} while (false)
85
86// QActive event queue customization for QK...
87#define QACTIVE_EQUEUE_WAIT_(me_) (static_cast<void>(0))
88#define QACTIVE_EQUEUE_SIGNAL_(me_) do { \
89 QK::priv_.readySet.insert( \
90 static_cast<std::uint_fast8_t>((me_)->m_prio)); \
91 if (!QK_ISR_CONTEXT_()) { \
92 if (QK::sched_() != 0U) { \
93 QK::activate_(); \
94 } \
95 } \
96} while (false)
97
98// QMPool operations
99#define QF_EPOOL_TYPE_ QMPool
100#define QF_EPOOL_INIT_(p_, poolSto_, poolSize_, evtSize_) \
101 (p_).init((poolSto_), (poolSize_), (evtSize_))
102#define QF_EPOOL_EVENT_SIZE_(p_) ((p_).getBlockSize())
103#define QF_EPOOL_GET_(p_, e_, m_, qsId_) \
104 ((e_) = static_cast<QEvt *>((p_).get((m_), (qsId_))))
105#define QF_EPOOL_PUT_(p_, e_, qsId_) ((p_).put((e_), (qsId_)))
106#define QF_EPOOL_USE_(ePool_) ((ePool_)->getUse())
107#define QF_EPOOL_FREE_(ePool_) ((ePool_)->getFree())
108#define QF_EPOOL_MIN_(ePool_) ((ePool_)->getMin())
109
110//! @endcond
111#endif // QP_IMPL
112
113#endif // QK_HPP_
Active object class (based on the QP::QHsm implementation strategy).
Definition qp.hpp:492
QK preemptive non-blocking kernel.
Definition qk.hpp:38
static QK priv_
Definition qk.hpp:58
std::uint8_t intNest
Up-down counter indicating current interrupt nesting (used in some QK ports).
Definition qk.hpp:45
static std::uint_fast8_t sched_act_(QActive const *const act, std::uint_fast8_t const pthre_in) noexcept
QK internal helper function to determine whether activation is needed.
Definition qk.cpp:142
static void schedUnlock(QSchedStatus const prevCeil) noexcept
QK selective scheduler unlock.
Definition qk.cpp:83
QP::QPSet readySet
Set of active-objects/threads that are ready to run in the QK kernel.
Definition qk.hpp:40
std::uint8_t lockCeil
Scheduler lock-ceiling (0 if scheduler unlocked).
Definition qk.hpp:44
static std::uint_fast8_t sched_() noexcept
QK scheduler finds the highest-priority AO ready to run.
Definition qk.cpp:115
std::uint8_t actPrio
Priority of the currently active AO.
Definition qk.hpp:41
static QSchedStatus schedLock(std::uint8_t const ceiling) noexcept
QK selective scheduler lock.
Definition qk.cpp:56
std::uint8_t nextPrio
Next AO priority scheduled by QK.
Definition qk.hpp:42
static void activate_()
QK activator activates the next active object. The activated AO preempts the currently executing AOs.
Definition qk.cpp:177
static void onIdle()
QK idle callback (customized in BSPs for QK).
std::uint8_t actThre
Preemption threshold of the currently active AO.
Definition qk.hpp:43
Set of Active Objects of up to QF_MAX_ACTIVE elements.
Definition qp.hpp:447
QP/C++ Framework namespace.
Definition qequeue.hpp:36
std::uint8_t QSchedStatus
The scheduler lock status for QK::schedLock() and QK::schedUnlock().
Definition qk.hpp:35