Reference Manual For QP/C 8.1.6
Loading...
Searching...
No Matches
QK Class Reference

QK preemptive non-blocking kernel (QK namespace emulated as a "class" in C). More...

Static Public Member Functions

QSchedStatus QK_schedLock (uint8_t const ceiling)
 QK selective scheduler lock.
void QK_schedUnlock (QSchedStatus const prevCeil)
 QK selective scheduler unlock.
void QK_onIdle (void)
 QK idle callback (customized in BSPs for QK).

Static Private Member Functions

uint_fast8_t QK_sched_ (void)
 QK scheduler finds the highest-priority AO ready to run.
uint_fast8_t QK_sched_act_ (QActive const *const act, uint_fast8_t const pthre_in)
 QK internal helper function to determine whether activation is needed.
void QK_activate_ (void)
 QK activator activates the next active object. The activated AO preempts the currently executing AOs.

Private Attributes

QPSet readySet
 Set of active-objects/threads that are ready to run in the QK kernel.
uint8_t actPrio
 Priority of the currently active AO.
uint8_t nextPrio
 Next AO priority scheduled by QK.
uint8_t actThre
 Preemption threshold of the currently active AO.
uint8_t lockCeil
 Scheduler lock-ceiling (0 if scheduler unlocked).
uint8_t intNest
 Up-down counter indicating current interrupt nesting (used in some QK ports) .
QK QK_priv_

Detailed Description

QK preemptive non-blocking kernel (QK namespace emulated as a "class" in C).

Details

The QK kernel is emulated in C as a "class" with only static members. Its private attributes (such as QK::readySet, QK::actPrio, QK::nextPrio, QK::actThre, QK::lockCeil, and QK::intNest, as well as their Duplicate Inverse Storage in SafeQP) are kept in the single instance QK_priv_ of the QK structure.

See also

Backward Traceability

  • [SDS_QP_QK] Design view: QK preemptive non-blocking kernel.
  • [SRS_QP_REQ_700] QP/C Framework shall provide preemptive non-blocking QK kernel as one of the built-in kernels.

Forward Traceability

  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation

Definition at line 38 of file qk.h.

Member Function Documentation

◆ QK_sched_()

uint_fast8_t QK_sched_ ( void )
staticprivate

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

Details

The QK scheduler finds out the priority of the highest-priority AO that (1) has events to process and (2) has priority that is higher than the system ceiling, which is the larger of the preemption threshold of the running AO and the scheduler-lock ceiling (see [SDS_QP_QK]).

Return values
priorityThe QF-priority of the next active object to activate,
0if no activation of AO is needed.
Attention
QK_sched_() must be always called with interrupts disabled and returns with interrupts disabled.

Backward Traceability

  • [SRS_QP_REQ_701] QK kernel shall activate a ready Active Object only if its priority is higher than the system ceiling.
  • [SRS_QP_REQ_702] QK kernel shall activate an Active Object as soon as it meets the activation condition.
  • [SDS_QP_OS_SCHED] Design view: Ready set, scheduling, and scheduler lock.

Forward Traceability

  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation

Definition at line 113 of file qk.c.

◆ QK_sched_act_()

uint_fast8_t QK_sched_act_ ( QActive const *const act,
uint_fast8_t const pthre_in )
staticprivate

QK internal helper function to determine whether activation is needed.

Details

Parameters
[in]actcurrently executing Active Object
[in]pthre_incurrent priority threshold
Return values
priorityThe priority of Active Object to activate
0if no activation needed
Attention
QK_act_() must be always called with interrupts disabled and returns with interrupts disabled.

Forward Traceability

  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation

Definition at line 141 of file qk.c.

◆ QK_activate_()

void QK_activate_ ( void )
staticprivate

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

Details

QK_activate_() activates, one after another, the ready-to-run AOs with priorities higher than both the preemption threshold of the preempted context and the scheduler-lock ceiling (see [SDS_QP_QK]).

Attention
QK_activate_() must be always called with interrupts disabled and returns with interrupts disabled.

Backward Traceability

  • [SRS_QP_REQ_701] QK kernel shall activate a ready Active Object only if its priority is higher than the system ceiling.
  • [SRS_QP_REQ_702] QK kernel shall activate an Active Object as soon as it meets the activation condition.
  • [SRS_QP_REQ_703] QK kernel shall resume a preempted Active Object only after all Active Objects that preempted it have completed their RTC steps.
  • [SRS_QP_REQ_730] QK kernel shall support preemption-threshold scheduling (PTS).
  • [SDS_QP_OS_SCHED] Design view: Ready set, scheduling, and scheduler lock.
  • [SDS_QP_OS_CTXSW] Design view: Context switch.

Forward Traceability

  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation

Definition at line 178 of file qk.c.

◆ QK_schedLock()

QSchedStatus QK_schedLock ( uint8_t const ceiling)
static

QK selective scheduler lock.

Details

This function locks the QK scheduler to the specified ceiling: Active Objects with priorities equal to or lower than the ceiling are not activated until the scheduler is unlocked. The lock request only raises the current lock ceiling; a request with a ceiling equal to or lower than the current lock ceiling leaves it unchanged and returns the status 0xFF, for which the unlock has no effect.

Parameters
[in]ceilingpreemption ceiling to which the QK scheduler needs to be locked
Return values
lock-statusThe previous QK Scheduler lock status, which is to be used to unlock the scheduler by restoring its previous lock status in QK_schedUnlock().
Note
QK_schedLock() must be always followed by the corresponding QK_schedUnlock().

See also

Usage

The following example shows how to lock and unlock the QK scheduler:

uint32_t BSP_random(void) {
uint32_t rnd;
QSchedStatus lockStat = QK_schedLock(N_PHILO); // <== N_PHILO ceiling
. . . // access/manipulate the shared random seed resource
QK_schedUnlock(lockStat); // <=== unlock
return rnd;
}
uint_fast8_t QSchedStatus
The scheduler lock status returned by the scheduler-lock operations of the preemptive built-in kernel...
Definition qk.h:34
QSchedStatus QK_schedLock(uint8_t const ceiling)
QK selective scheduler lock.
Definition qk.c:52
void QK_schedUnlock(QSchedStatus const prevCeil)
QK selective scheduler unlock.
Definition qk.c:80

Backward Traceability

  • [SRS_QP_REQ_720] QK kernel shall provide API to selectively lock scheduling Active Objects with priorities up to the specified scheduler-lock ceiling priority.
  • [SDS_QP_OS_SCHED] Design view: Ready set, scheduling, and scheduler lock.

Forward Traceability

  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation

Definition at line 52 of file qk.c.

◆ QK_schedUnlock()

void QK_schedUnlock ( QSchedStatus const prevCeil)
static

QK selective scheduler unlock.

Details

This function unlocks the QK scheduler to the previous status.

Parameters
[in]prevCeilprevious QK Scheduler lock ceiling returned from QK_schedLock()
Note
QK_schedUnlock() must always follow the corresponding QK_schedLock().

See also

Usage

The following example shows how to lock and unlock the QK scheduler:

uint32_t BSP_random(void) {
uint32_t rnd;
QSchedStatus lockStat = QK_schedLock(N_PHILO); // <== N_PHILO ceiling
. . . // access/manipulate the shared random seed resource
QK_schedUnlock(lockStat); // <=== unlock
return rnd;
}

Backward Traceability

  • [SRS_QP_REQ_721] QK kernel shall provide API to unlock scheduling Active Objects.
  • [SDS_QP_OS_SCHED] Design view: Ready set, scheduling, and scheduler lock.

Forward Traceability

  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation

Definition at line 80 of file qk.c.

◆ QK_onIdle()

void QK_onIdle ( void )
static

QK idle callback (customized in BSPs for QK).

Details

QK_onIdle() is called continuously by the QK idle loop. This callback gives the application an opportunity to enter a power-saving CPU mode, or perform some other idle processing.

Note
QK_onIdle() is invoked with interrupts enabled and must also return with interrupts enabled.

Backward Traceability

Forward Traceability

  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation

Member Data Documentation

◆ readySet

QPSet readySet
private

Set of active-objects/threads that are ready to run in the QK kernel.

Forward Traceability

  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation

Definition at line 39 of file qk.h.

◆ actPrio

uint8_t actPrio
private

Priority of the currently active AO.

Forward Traceability

  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation

Definition at line 40 of file qk.h.

◆ nextPrio

uint8_t nextPrio
private

Next AO priority scheduled by QK.

Forward Traceability

  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation

Definition at line 41 of file qk.h.

◆ actThre

uint8_t actThre
private

Preemption threshold of the currently active AO.

Forward Traceability

  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation

Definition at line 42 of file qk.h.

◆ lockCeil

uint8_t lockCeil
private

Scheduler lock-ceiling (0 if scheduler unlocked).

Forward Traceability

  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation

Definition at line 43 of file qk.h.

◆ intNest

uint8_t intNest
private

Up-down counter indicating current interrupt nesting (used in some QK ports) .

Definition at line 44 of file qk.h.

◆ QK_priv_

QK QK_priv_
private

Definition at line 68 of file qk.h.