QP-nano  6.6.0
qkn.c File Reference

QK-nano preemptive kernel implementation. More...

#include "qpn_conf.h"
#include "qfn_port.h"
#include "qassert.h"
Include dependency graph for qkn.c:

Go to the source code of this file.

Functions

static void initialize (void)
 
int_t QF_run (void)
 Transfers control to QF-nano to run the application. More...
 
QSchedStatus QK_schedLock (uint_fast8_t ceiling)
 QK Scheduler lock. More...
 
void QK_schedUnlock (QSchedStatus stat)
 QK Scheduler unlock. More...
 
uint_fast8_t QK_sched_ (void)
 QK-nano scheduler finds the highest-priority thread ready to run. More...
 
void QK_activate_ (void)
 QK activator activates the next active object. More...
 

Variables

QK_Attr QK_attr_
 global attributes of the QK kernel More...
 

Detailed Description

QK-nano preemptive kernel implementation.

Definition in file qkn.c.

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  )

Transfers control to QF-nano to run the application.

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.
Precondition
the number of active objects must be initialized by calling: QF_init(Q_DIM(QF_active));

Definition at line 121 of file qkn.c.

◆ 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);
}

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.

◆ 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.

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

Variable Documentation

◆ QK_attr_

QK_Attr QK_attr_

global attributes of the QK kernel

Definition at line 52 of file qkn.c.

QK_schedUnlock
void QK_schedUnlock(QSchedStatus stat)
QK Scheduler unlock.
Definition: qkn.c:200
QK_schedLock
QSchedStatus QK_schedLock(uint_fast8_t ceiling)
QK Scheduler lock.
Definition: qkn.c:161
QSchedStatus
uint_fast16_t QSchedStatus
QK-nano Scheduler locking.
Definition: qkn.h:130
uint32_t
unsigned long uint32_t
exact-width 32-bit unsigned int
Definition: stdint.h:31