QP/C++  7.0.1
Real-Time Embedded Framework
qk.hpp File Reference

QK/C++ platform-independent public interface. More...

#include "qequeue.hpp"
#include "qmpool.hpp"
#include "qpset.hpp"

Go to the source code of this file.

Data Structures

struct  QK_Attr
 attributes of the QK kernel (in C for easy access in assembly) More...
 
class  QK
 QK services. More...
 

Namespaces

namespace  QP
 namespace associated with the QP/C++ framework
 

Macros

#define QF_EQUEUE_TYPE   QEQueue
 
#define QF_THREAD_TYPE   void*
 
#define QK_ISR_CONTEXT_()   (QK_attr_.intNest != 0U)
 Internal port-specific macro that reports the execution context. More...
 
#define QF_SCHED_STAT_   QSchedStatus lockStat_;
 Internal macro to represent the scheduler lock status. More...
 
#define QF_SCHED_LOCK_(prio_)
 Internal macro for selective scheduler locking. More...
 
#define QF_SCHED_UNLOCK_()
 Internal macro for selective scheduler unlocking. More...
 
#define QACTIVE_EQUEUE_WAIT_(me_)    Q_ASSERT_ID(110, (me_)->m_eQueue.m_frontEvt != nullptr)
 
#define QACTIVE_EQUEUE_SIGNAL_(me_)
 
#define QF_EPOOL_TYPE_   QMPool
 
#define QF_EPOOL_INIT_(p_, poolSto_, poolSize_, evtSize_)    (p_).init((poolSto_), (poolSize_), (evtSize_))
 
#define QF_EPOOL_EVENT_SIZE_(p_)   ((p_).m_blockSize)
 
#define QF_EPOOL_GET_(p_, e_, m_, qs_id_)    ((e_) = static_cast<QEvt *>((p_).get((m_), (qs_id_))))
 
#define QF_EPOOL_PUT_(p_, e_, qs_id_)   ((p_).put((e_), (qs_id_)))
 

Typedefs

using QSchedStatus = std::uint_fast16_t
 The scheduler lock status. More...
 

Functions

std::uint_fast8_t QK_sched_ (void) noexcept
 QK scheduler finds the highest-priority thread ready to run. More...
 
void QK_activate_ (void) noexcept
 QK activator activates the next active object. The activated AO preempts. More...
 
void QK_onContextSw (QP::QActive *prev, QP::QActive *next)
 QK context switch callback (customized in BSPs for QK) More...
 

Variables

QK_Attr QK_attr_
 global attributes of the QK kernel More...
 

Detailed Description

Date
Last updated on: 2021-12-23
Version
Last updated for: Version 7.0.0, 2022-04-30

Definition in file qk.hpp.


Data Structure Documentation

◆ QK_Attr

struct QK_Attr

Definition at line 59 of file qk.hpp.

Data Fields
uint8_t volatile actPrio prio of the active AO
uint8_t volatile nextPrio prio of the next AO to execute
uint8_t volatile lockPrio lock prio (0 == no-lock)
uint8_t volatile lockHolder prio of the lock holder
uint8_t volatile intNest ISR nesting level.
QPSet readySet QK ready-set of AOs and "naked" threads.

Macro Definition Documentation

◆ QF_EQUEUE_TYPE

#define QF_EQUEUE_TYPE   QEQueue

Definition at line 43 of file qk.hpp.

◆ QF_THREAD_TYPE

#define QF_THREAD_TYPE   void*

Definition at line 48 of file qk.hpp.

◆ QK_ISR_CONTEXT_

#define QK_ISR_CONTEXT_ ( )    (QK_attr_.intNest != 0U)
Returns
true if the code executes in the ISR context and false otherwise

Definition at line 163 of file qk.hpp.

◆ QF_SCHED_STAT_

#define QF_SCHED_STAT_   QSchedStatus lockStat_;

Definition at line 170 of file qk.hpp.

◆ QF_SCHED_LOCK_

#define QF_SCHED_LOCK_ (   prio_)
Value:
do { \
if (QK_ISR_CONTEXT_()) { \
lockStat_ = 0xFFU; \
} else { \
lockStat_ = QK::schedLock((prio_)); \
} \
} while (false)
#define QK_ISR_CONTEXT_()
Internal port-specific macro that reports the execution context.
Definition: qk.hpp:163

Definition at line 173 of file qk.hpp.

◆ QF_SCHED_UNLOCK_

#define QF_SCHED_UNLOCK_ ( )
Value:
do { \
if (lockStat_ != 0xFFU) { \
QK::schedUnlock(lockStat_); \
} \
} while (false)

Definition at line 182 of file qk.hpp.

◆ QACTIVE_EQUEUE_WAIT_

#define QACTIVE_EQUEUE_WAIT_ (   me_)     Q_ASSERT_ID(110, (me_)->m_eQueue.m_frontEvt != nullptr)

Definition at line 189 of file qk.hpp.

◆ QACTIVE_EQUEUE_SIGNAL_

#define QACTIVE_EQUEUE_SIGNAL_ (   me_)
Value:
do { \
QK_attr_.readySet.insert( \
static_cast<std::uint_fast8_t>((me_)->m_prio)); \
if (!QK_ISR_CONTEXT_()) { \
if (QK_sched_() != 0U) { \
QK_activate_(); \
} \
} \
} while (false)
std::uint_fast8_t QK_sched_(void) noexcept
QK scheduler finds the highest-priority thread ready to run.
Definition: qk.cpp:321

Definition at line 192 of file qk.hpp.

◆ QF_EPOOL_TYPE_

#define QF_EPOOL_TYPE_   QMPool

Definition at line 203 of file qk.hpp.

◆ QF_EPOOL_INIT_

#define QF_EPOOL_INIT_ (   p_,
  poolSto_,
  poolSize_,
  evtSize_ 
)     (p_).init((poolSto_), (poolSize_), (evtSize_))

Definition at line 204 of file qk.hpp.

◆ QF_EPOOL_EVENT_SIZE_

#define QF_EPOOL_EVENT_SIZE_ (   p_)    ((p_).m_blockSize)

Definition at line 206 of file qk.hpp.

◆ QF_EPOOL_GET_

#define QF_EPOOL_GET_ (   p_,
  e_,
  m_,
  qs_id_ 
)     ((e_) = static_cast<QEvt *>((p_).get((m_), (qs_id_))))

Definition at line 207 of file qk.hpp.

◆ QF_EPOOL_PUT_

#define QF_EPOOL_PUT_ (   p_,
  e_,
  qs_id_ 
)    ((p_).put((e_), (qs_id_)))

Definition at line 209 of file qk.hpp.

Function Documentation

◆ QK_sched_()

std::uint_fast8_t QK_sched_ ( void  )
noexcept
Description
The QK scheduler finds out the priority of the highest-priority AO that (1) has events to process and (2) has priority that is above the current priority.
Returns
the 1-based priority of the the active object, or zero if no eligible active object is ready to run.
Attention
QK_sched_() must be always called with interrupts disabled and returns with interrupts disabled.

Definition at line 321 of file qk.cpp.

◆ QK_activate_()

void QK_activate_ ( void  )
noexcept
Description
QK_activate_() activates ready-to run AOs that are above the initial active priority (QK_attr_.actPrio).
Note
The activator might enable interrupts internally, but always returns with interrupts disabled.

Definition at line 348 of file qk.cpp.

◆ QK_onContextSw()

void QK_onContextSw ( QP::QActive prev,
QP::QActive next 
)
Description
This callback function provides a mechanism to perform additional custom operations when QK switches context from one thread to another.
Parameters
[in]prevpointer to the previous thread (active object) (prev==0 means that prev was the QK idle loop)
[in]nextpointer to the next thread (active object) (next==0) means that next is the QK idle loop)
Attention
QK_onContextSw() is invoked with interrupts disabled and must also return with interrupts disabled.
Note
This callback is enabled by defining the macro #QK_ON_CONTEXT_SW.
extern "C" { // use the "C" calling convention
#ifdef QK_ON_CONTEXT_SW
// NOTE: the context-switch callback is called with interrupts DISABLED
void QK_onContextSw(QActive *prev, QActive *next) {
(void)prev;
if (next != (QActive *)0) { // next is not the QK idle loop?
_impure_ptr = next->thread; // switch to next TLS
}
// If you use QS software tracing, use the _NOCRIT() begin/end
QS_BEGIN_NOCRIT(ON_CONTEXT_SW, 0U)
QS_OBJ(prev);
QS_OBJ(next);
}
#endif // QK_ON_CONTEXT_SW
} // extern "C"
void QK_onContextSw(QP::QActive *prev, QP::QActive *next)
QK context switch callback (customized in BSPs for QK)
#define QS_OBJ(obj_)
Output formatted object pointer to the QS record.
Definition: qs.hpp:859
#define QS_END_NOCRIT()
End a QS user record without exiting critical section.
Definition: qs.hpp:696
#define QS_BEGIN_NOCRIT(rec_, qs_id_)
Begin a QS user record without entering critical section.
Definition: qs.hpp:690

Variable Documentation

◆ QK_attr_

QK_Attr QK_attr_
extern

Definition at line 52 of file qk.cpp.