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

QK-nano preemptive kernel implementation. More...

#include "qpn_conf.h"
#include "qfn_port.h"
#include "qassert.h"

Go to the source code of this file.

Functions

static void initialize (void)
 
int_t QF_run (void)
 
QSchedStatus QK_schedLock (uint_fast8_t ceiling)
 
void QK_schedUnlock (QSchedStatus stat)
 
uint_fast8_t QK_sched_ (void)
 
void QK_activate_ (void)
 

Variables

QK_PrivAttr QK_attr_
 

Function Documentation

◆ initialize()

static void initialize ( void  )
static
Description
Helper function to set the priorities of all the statically allocated active objects in the system followed by executing the top-most initial transtions in all active objects.
Note
The system initialization is specifically encapsulated in a function to reduce stack use, because the temporary stack variables needed for the initialization go out of scope for the rest of system execution.
Precondition
the number of active objects must be initialized by calling: QF_init(Q_DIM(QF_active));

Definition at line 69 of file qkn.c.

◆ QF_run()

int_t QF_run ( void  )
Description
QF_run() is typically called from your startup code after you initialize the QF and start at least one active object with QActive_start(). This implementation of QF_run() is for the preemptive QK-nano kernel.
Returns
In QK-nano QF_run() does not return.

Definition at line 121 of file qkn.c.

◆ QK_schedLock()

QSchedStatus QK_schedLock ( uint_fast8_t  ceiling)
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);
}
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)
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.

◆ QK_sched_()

uint_fast8_t QK_sched_ ( void  )
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  )
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.

Variable Documentation

◆ QK_attr_

QK_PrivAttr QK_attr_

global attributes of the QK kernel

Definition at line 52 of file qkn.c.