QP/C 8.1.2
Real-Time Event Framework
Loading...
Searching...
No Matches
qk.h
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_H_
30#define QK_H_
31
32//============================================================================
33
34typedef uint_fast8_t QSchedStatus;
35
36//----------------------------------------------------------------------------
37//! @class QK
38typedef struct {
39 QPSet readySet; //!< @private @memberof QK
40 uint8_t actPrio; //!< @private @memberof QK
41 uint8_t nextPrio; //!< @private @memberof QK
42 uint8_t actThre; //!< @private @memberof QK
43 uint8_t lockCeil; //!< @private @memberof QK
44 uint8_t intNest; //!< @private @memberof QK
45} QK;
46
47//! @static @private @memberof QK
48uint_fast8_t QK_sched_(void);
49
50//! @static @private @memberof QK
51uint_fast8_t QK_sched_act_(
52 QActive const * const act,
53 uint_fast8_t const pthre_in);
54
55//! @static @private @memberof QK
56void QK_activate_(void);
57
58//! @static @public @memberof QK
59QSchedStatus QK_schedLock(uint8_t const ceiling);
60
61//! @static @public @memberof QK
62void QK_schedUnlock(QSchedStatus const prevCeil);
63
64//! @static @public @memberof QK
65void QK_onIdle(void);
66
67//! @static @private @memberof QK
68extern QK QK_priv_;
69
70//============================================================================
71// interface used only for internal implementation, but not in applications
72
73#ifdef QP_IMPL
74//! @cond INTERNAL
75
76// scheduler locking for QK...
77#define QF_SCHED_STAT_ QSchedStatus lockStat_;
78#define QF_SCHED_LOCK_(ceil_) do { \
79 if (QK_ISR_CONTEXT_()) { \
80 lockStat_ = 0xFFU; \
81 } else { \
82 lockStat_ = QK_schedLock((ceil_)); \
83 } \
84} while (false)
85
86#define QF_SCHED_UNLOCK_() do { \
87 if (lockStat_ != 0xFFU) { \
88 QK_schedUnlock(lockStat_); \
89 } \
90} while (false)
91
92// QActive event queue customization for QK...
93#define QACTIVE_EQUEUE_WAIT_(me_) ((void)0)
94#define QACTIVE_EQUEUE_SIGNAL_(me_) do { \
95 QPSet_insert(&QK_priv_.readySet, (uint_fast8_t)(me_)->prio); \
96 if (!QK_ISR_CONTEXT_()) { \
97 if (QK_sched_() != 0U) { \
98 QK_activate_(); \
99 } \
100 } \
101} while (false)
102
103// QMPool operations
104#define QF_EPOOL_TYPE_ QMPool
105#define QF_EPOOL_INIT_(p_, poolSto_, poolSize_, evtSize_) \
106 (QMPool_init(&(p_), (poolSto_), (poolSize_), (evtSize_)))
107#define QF_EPOOL_EVENT_SIZE_(p_) ((uint16_t)(p_).blockSize)
108#define QF_EPOOL_GET_(p_, e_, m_, qsId_) \
109 ((e_) = (QEvt *)QMPool_get(&(p_), (m_), (qsId_)))
110#define QF_EPOOL_PUT_(p_, e_, qsId_) (QMPool_put(&(p_), (e_), (qsId_)))
111#define QF_EPOOL_USE_(ePool_) (QMPool_getUse(ePool_))
112#define QF_EPOOL_FREE_(ePool_) ((ePool_)->nFree)
113#define QF_EPOOL_MIN_(ePool_) ((ePool_)->nMin)
114
115//! @endcond
116#endif // QP_IMPL
117
118#endif // QK_H_
uint_fast8_t QSchedStatus
The scheduler lock status for QK_schedLock() and QK_schedUnlock().
Definition qk.h:34
Active object class (based on the QHsm implementation strategy).
Definition qp.h:447
QK preemptive non-blocking kernel (QK namespace emulated as a "class" in C.
Definition qk.h:38
uint8_t actPrio
Priority of the currently active AO.
Definition qk.h:40
uint8_t nextPrio
Next AO priority scheduled by QK.
Definition qk.h:41
QPSet readySet
Set of active-objects/threads that are ready to run in the QK kernel.
Definition qk.h:39
uint8_t intNest
Up-down counter indicating current interrupt nesting (used in some QK ports).
Definition qk.h:44
void QK_onIdle(void)
QK idle callback (customized in BSPs for QK).
QK QK_priv_
Definition qk.h:68
uint8_t actThre
Preemption threshold of the currently active AO.
Definition qk.h:42
uint8_t lockCeil
Scheduler lock-ceiling (0 if scheduler unlocked).
Definition qk.h:43
Set of Active Objects of up to QF_MAX_ACTIVE elements.
Definition qp.h:407