QP/C++ 6.9.3
qk.hpp File Reference

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

#include "qequeue.hpp"
#include "qmpool.hpp"
#include "qpset.hpp"
Include dependency graph for qk.hpp:
This graph shows which files directly or indirectly include this file:

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

 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_).getBlockSize())
 
#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

QK/C++ platform-independent public interface.

Definition in file qk.hpp.


Data Structure Documentation

◆ QK_Attr

struct QK_Attr

attributes of the QK kernel (in C for easy access in assembly)

Definition at line 67 of file qk.hpp.

Collaboration diagram for QK_Attr:
Collaboration graph
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 51 of file qk.hpp.

◆ QF_THREAD_TYPE

#define QF_THREAD_TYPE   void*

Definition at line 56 of file qk.hpp.

◆ QK_ISR_CONTEXT_

#define QK_ISR_CONTEXT_ ( )    (QK_attr_.intNest != 0U)

Internal port-specific macro that reports the execution context.

Returns
true if the code executes in the ISR context and false otherwise

Definition at line 173 of file qk.hpp.

◆ QF_SCHED_STAT_

#define QF_SCHED_STAT_   QSchedStatus lockStat_;

Internal macro to represent the scheduler lock status.

Definition at line 180 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:173

Internal macro for selective scheduler locking.

Definition at line 183 of file qk.hpp.

◆ QF_SCHED_UNLOCK_

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

Internal macro for selective scheduler unlocking.

Definition at line 192 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 199 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)
unsigned int uint_fast8_t
fast at-least 8-bit unsigned int
Definition: 16bit/stdint.h:36
std::uint_fast8_t QK_sched_(void) noexcept
QK scheduler finds the highest-priority thread ready to run.
Definition: qk.cpp:329

Definition at line 202 of file qk.hpp.

◆ QF_EPOOL_TYPE_

#define QF_EPOOL_TYPE_   QMPool

Definition at line 213 of file qk.hpp.

◆ QF_EPOOL_INIT_

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

Definition at line 214 of file qk.hpp.

◆ QF_EPOOL_EVENT_SIZE_

#define QF_EPOOL_EVENT_SIZE_ (   p_)    ((p_).getBlockSize())

Definition at line 216 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 217 of file qk.hpp.

◆ QF_EPOOL_PUT_

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

Definition at line 219 of file qk.hpp.

Function Documentation

◆ QK_sched_()

std::uint_fast8_t QK_sched_ ( void  )
noexcept

QK scheduler finds the highest-priority thread ready to run.

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 329 of file qk.cpp.

◆ QK_activate_()

void QK_activate_ ( void  )
noexcept

QK activator activates the next active object. The activated AO preempts.

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 356 of file qk.cpp.

◆ QK_onContextSw()

void QK_onContextSw ( QP::QActive prev,
QP::QActive next 
)

QK context switch callback (customized in BSPs for QK)

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:897
#define QS_END_NOCRIT()
End a QS user record without exiting critical section.
Definition: qs.hpp:734
#define QS_BEGIN_NOCRIT(rec_, qs_id_)
Begin a QS user record without entering critical section.
Definition: qs.hpp:728

Variable Documentation

◆ QK_attr_

QK_Attr QK_attr_
extern

global attributes of the QK kernel

Definition at line 60 of file qk.cpp.