QP/C++ 6.9.3
qxk.hpp File Reference

QXK/C++ preemptive extended (blocking) kernel, platform-independent public interface. More...

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

Go to the source code of this file.

Data Structures

struct  QXK_Attr
 attributes of the QXK kernel More...
 
class  QXK
 QXK services. More...
 

Namespaces

 QP
 namespace associated with the QP/C++ framework
 

Macros

#define QF_EQUEUE_TYPE   QEQueue
 
#define QF_OS_OBJECT_TYPE   void*
 
#define QF_THREAD_TYPE   void*
 
#define QXK_TLS(type_)   (static_cast<type_>(QXK_current()->m_thread))
 Access Thread-Local Storage (TLS) and cast it on the given type_. More...
 
#define QXK_ISR_CONTEXT_()    (QXK_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_)))
 

Functions

std::uint_fast8_t QXK_sched_ (void) noexcept
 QXK scheduler finds the highest-priority thread ready to run. More...
 
void QXK_activate_ (void)
 QXK activator activates the next active object. The activated AO preempts. More...
 
QP::QActiveQXK_current (void) noexcept
 return the currently executing active-object/thread More...
 
void QXK_onContextSw (QP::QActive *prev, QP::QActive *next)
 QXK context switch callback (customized in BSPs for QXK) More...
 

Variables

QXK_Attr QXK_attr_
 global attributes of the QXK kernel More...
 

Detailed Description

QXK/C++ preemptive extended (blocking) kernel, platform-independent public interface.

Definition in file qxk.hpp.


Data Structure Documentation

◆ QXK_Attr

struct QXK_Attr

attributes of the QXK kernel

Definition at line 74 of file qxk.hpp.

Collaboration diagram for QXK_Attr:
Collaboration graph
Data Fields
QActive *volatile curr currently executing thread
QActive *volatile next next thread to execute
uint8_t volatile actPrio prio of the active basic thread
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.
QActive * idleThread pointer to the idle thread
QPSet readySet ready-set of all threads

Macro Definition Documentation

◆ QF_EQUEUE_TYPE

#define QF_EQUEUE_TYPE   QEQueue

Definition at line 51 of file qxk.hpp.

◆ QF_OS_OBJECT_TYPE

#define QF_OS_OBJECT_TYPE   void*

Definition at line 56 of file qxk.hpp.

◆ QF_THREAD_TYPE

#define QF_THREAD_TYPE   void*

Definition at line 59 of file qxk.hpp.

◆ QXK_TLS

#define QXK_TLS (   type_)    (static_cast<type_>(QXK_current()->m_thread))

Access Thread-Local Storage (TLS) and cast it on the given type_.

Definition at line 62 of file qxk.hpp.

◆ QXK_ISR_CONTEXT_

#define QXK_ISR_CONTEXT_ ( )     (QXK_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 178 of file qxk.hpp.

◆ QF_SCHED_STAT_

#define QF_SCHED_STAT_   QSchedStatus lockStat_;

Internal macro to represent the scheduler lock status.

Definition at line 186 of file qxk.hpp.

◆ QF_SCHED_LOCK_

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

Internal macro for selective scheduler locking.

Definition at line 189 of file qxk.hpp.

◆ QF_SCHED_UNLOCK_

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

Internal macro for selective scheduler unlocking.

Definition at line 198 of file qxk.hpp.

◆ QACTIVE_EQUEUE_WAIT_

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

Definition at line 205 of file qxk.hpp.

◆ QACTIVE_EQUEUE_SIGNAL_

#define QACTIVE_EQUEUE_SIGNAL_ (   me_)
Value:
do { \
QXK_attr_.readySet.insert( \
static_cast<std::uint_fast8_t>((me_)->m_dynPrio)); \
if (!QXK_ISR_CONTEXT_()) { \
if (QXK_sched_() != 0U) { \
QXK_activate_(); \
} \
} \
} while (false)
unsigned int uint_fast8_t
fast at-least 8-bit unsigned int
Definition: 16bit/stdint.h:36
std::uint_fast8_t QXK_sched_(void) noexcept
QXK scheduler finds the highest-priority thread ready to run.
Definition: qxk.cpp:346

Definition at line 208 of file qxk.hpp.

◆ QF_EPOOL_TYPE_

#define QF_EPOOL_TYPE_   QMPool

Definition at line 219 of file qxk.hpp.

◆ QF_EPOOL_INIT_

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

Definition at line 220 of file qxk.hpp.

◆ QF_EPOOL_EVENT_SIZE_

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

Definition at line 222 of file qxk.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 223 of file qxk.hpp.

◆ QF_EPOOL_PUT_

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

Definition at line 225 of file qxk.hpp.

Function Documentation

◆ QXK_sched_()

std::uint_fast8_t QXK_sched_ ( void  )
noexcept

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

Description
The QXK scheduler finds the priority of the highest-priority thread that is ready to run.
Returns
the 1-based priority of the the active object to run next, or zero if no eligible active object is found.
Attention
QXK_sched_() must be always called with interrupts disabled and returns with interrupts disabled.

Definition at line 346 of file qxk.cpp.

◆ QXK_activate_()

void QXK_activate_ ( void  )

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

Attention
QXK_activate_() must be always called with interrupts disabled and returns with interrupts disabled.
Note
The activate function might enable interrupts internally, but it always returns with interrupts disabled.
Precondition
QXK_attr_.next must be valid

Definition at line 423 of file qxk.cpp.

◆ QXK_current()

QP::QActive* QXK_current ( void  )
noexcept

return the currently executing active-object/thread

Precondition
the QXK kernel must be running
Postcondition
the current thread must be valid

Definition at line 555 of file qxk.cpp.

◆ QXK_onContextSw()

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

QXK context switch callback (customized in BSPs for QXK)

Description
This callback function provides a mechanism to perform additional custom operations when QXK switches context from one thread to another.
Parameters
[in]prevpointer to the previous thread (active object) (prev==0 means that prev was the QXK idle thread)
[in]nextpointer to the next thread (active object) (next==0) means that next is the QXK idle thread)
Attention
QXK_onContextSw() is invoked with interrupts disabled and must also return with interrupts disabled.
Note
This callback is enabled by defining the macro QXK_ON_CONTEXT_SW.
extern "C" { // use the "C" calling convention
#ifdef QXK_ON_CONTEXT_SW
// NOTE: the context-switch callback is called with interrupts DISABLED
void QXK_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 // QXK_ON_CONTEXT_SW
} // extern "C"
#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
void QXK_onContextSw(QP::QActive *prev, QP::QActive *next)
QXK context switch callback (customized in BSPs for QXK)

Variable Documentation

◆ QXK_attr_

QXK_Attr QXK_attr_
extern

global attributes of the QXK kernel

Definition at line 60 of file qxk.cpp.