QP-nano  6.9.0
Real-Time Embedded Framework
qkn.h File Reference

Public QK-nano interface. More...

Go to the source code of this file.

Data Structures

struct  QK_PrivAttr
 

Macros

#define QK_SCHEDULE_()
 

Typedefs

typedef uint_fast16_t QSchedStatus
 

Functions

uint_fast8_t QK_sched_ (void)
 
void QK_activate_ (void)
 
void QK_onContextSw (uint_fast8_t prev, uint_fast8_t next)
 
void QK_onIdle (void)
 
QSchedStatus QK_schedLock (uint_fast8_t ceiling)
 
void QK_schedUnlock (QSchedStatus stat)
 

Variables

QK_PrivAttr QK_attr_
 

Data Structure Documentation

◆ QK_PrivAttr

struct QK_PrivAttr

attributes of the QK kernel

Definition at line 45 of file qkn.h.

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

Macro Definition Documentation

◆ QK_SCHEDULE_

#define QK_SCHEDULE_ ( )
Value:
do { \
if (QK_sched_() != 0U) { \
QK_activate_(); \
} \
} while(false)
uint_fast8_t QK_sched_(void)
Definition: qkn.c:247

Definition at line 66 of file qkn.h.

Typedef Documentation

◆ QSchedStatus

QK-nano Scheduler locking

The scheduler lock status

Definition at line 126 of file qkn.h.

Function Documentation

◆ QK_sched_()

uint_fast8_t QK_sched_ ( void  )

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

Description
The QK-nano 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 247 of file qkn.c.

◆ QK_activate_()

void QK_activate_ ( void  )

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

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 291 of file qkn.c.

◆ QK_onContextSw()

void QK_onContextSw ( uint_fast8_t  prev,
uint_fast8_t  next 
)

QK-nano context switch callback (customized in BSPs for QK-nano)

Description
This callback function provides a mechanism to perform additional custom operations when QK switches context from one thread to another.
Parameters
[in]prevpriority of the previous thread (active object) (prev==0 means that prev was the QK idle loop)
[in]nextpriority of 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.
#ifdef QK_ON_CONTEXT_SW
/* NOTE: the context-switch callback is called with interrupts DISABLED */
(void)prev;
if (next != (uint_fast8_t)0) {
//_impure_ptr = &reentrant[next];
}
}
#endif /* QK_ON_CONTEXT_SW */
unsigned int uint_fast8_t
Definition: 16bit/stdint.h:36
void QK_onContextSw(uint_fast8_t prev, uint_fast8_t next)

◆ QK_onIdle()

void QK_onIdle ( void  )

QK idle callback (customized in BSPs for QK)

QK_onIdle() is called continuously by the QK-nano 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. This is in contrast to the callback QF_onIdle(), which is used by the non-preemptive QF-nano scheduler.

◆ QK_schedLock()

QSchedStatus QK_schedLock ( uint_fast8_t  ceiling)

QK Scheduler lock

Description
This function locks the QK scheduler to the specified ceiling.
Parameters
[in]ceilingpriority ceiling to which the QK scheduler needs to be locked
Returns
The 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
QK_schedUnlock()
Usage
The following example shows how to lock and unlock the QK scheduler:
uint32_t BSP_random(void) { /* a very cheap pseudo-random-number generator */
uint32_t rnd;
QSchedStatus lockStat; /* <=== QK-nano scheduler lock status */
lockStat = QK_schedLock(N_PHILO); /* <=== lock scheduler up to N_PHILO prio */
/* "Super-Duper" Linear Congruential Generator (LCG)
* LCG(2^32, 3*7*11*13*23, 0, seed)
*/
rnd = l_rnd * (3U*7U*11U*13U*23U);
l_rnd = rnd; /* set for the next time */
QK_schedUnlock(lockStat); /* <=== unlock the scheduler */
return (rnd >> 8);
}
unsigned long int uint32_t
Definition: 16bit/stdint.h:31
uint_fast16_t QSchedStatus
Definition: qkn.h:126
QSchedStatus QK_schedLock(uint_fast8_t ceiling)
Definition: qkn.c:161
void QK_schedUnlock(QSchedStatus stat)
Definition: qkn.c:200

Definition at line 161 of file qkn.c.

◆ QK_schedUnlock()

void QK_schedUnlock ( QSchedStatus  stat)

QK Scheduler unlock

Description
This function unlocks the QK scheduler to the previous status.
Parameters
[in]statprevious QK Scheduler lock status returned from QK_schedLock()
Note
QK_schedUnlock() must always follow the corresponding QK_schedLock().
See also
QK_schedLock()
Usage
The following example shows how to lock and unlock the QK scheduler:
uint32_t BSP_random(void) { /* a very cheap pseudo-random-number generator */
uint32_t rnd;
QSchedStatus lockStat; /* <=== QK-nano scheduler lock status */
lockStat = QK_schedLock(N_PHILO); /* <=== lock scheduler up to N_PHILO prio */
/* "Super-Duper" Linear Congruential Generator (LCG)
* LCG(2^32, 3*7*11*13*23, 0, seed)
*/
rnd = l_rnd * (3U*7U*11U*13U*23U);
l_rnd = rnd; /* set for the next time */
QK_schedUnlock(lockStat); /* <=== unlock the scheduler */
return (rnd >> 8);
}
Precondition
The current lock priority must be greater than the previous

Definition at line 200 of file qkn.c.

Variable Documentation

◆ QK_attr_

QK_PrivAttr QK_attr_
extern

global attributes of the QK kernel

Definition at line 52 of file qkn.c.