QP/C  7.3.0
Real-Time Embedded Framework
No Matches
QXSemaphore Class Reference

Counting Semaphore of the QXK preemptive kernel. More...

#include "qxk.h"

Public Member Functions

void QXSemaphore_init (QXSemaphore *const me, uint_fast8_t const count, uint_fast8_t const max_count)
bool QXSemaphore_wait (QXSemaphore *const me, QTimeEvtCtr const nTicks)
bool QXSemaphore_tryWait (QXSemaphore *const me)
bool QXSemaphore_signal (QXSemaphore *const me)

Private Attributes

QPSet waitSet
uint8_t volatile count
uint8_t max_count

Detailed Description

Counting Semaphore of the QXK preemptive kernel.

QXSemaphore is a blocking mechanism intended primarily for signaling extended threads. The semaphore is initialized with the maximum count (see QXSemaphore_init()), which allows you to create a binary semaphore (when the maximum count is 1) and counting semaphore when the maximum count is > 1.

The following example illustrates how to instantiate and use the semaphore in your application.
QXSemaphore BTN_sema; // semaphore to signal a button press//
int main() {
. . .
// initialize the BTN_sema semaphore as binary, signaling semaphore//
QXSemaphore_init(&BTN_sema, // pointer to semaphore to initialize//
0U, // initial semaphore count (singaling semaphore)//
1U); // maximum semaphore count (binary semaphore)//
. . .
void main_threadXYZ(QXThread * const me) {
while (1) {
. . .
QXSemaphore_wait(&BTN_sema, // <--- pointer to semaphore to wait on//
QXTHREAD_NO_TIMEOUT); // timeout for waiting//
. . .
void GPIO_Handler(void) {
. . .
QXSemaphore_signal(&BTN_sema); // <--- pointer to semaphore to signal//
. . .
Definition qxk.h:66
Counting Semaphore of the QXK preemptive kernel.
Definition qxk.h:208
bool QXSemaphore_signal(QXSemaphore *const me)
Definition qxk_sema.c:224
bool QXSemaphore_wait(QXSemaphore *const me, QTimeEvtCtr const nTicks)
Definition qxk_sema.c:95
void QXSemaphore_init(QXSemaphore *const me, uint_fast8_t const count, uint_fast8_t const max_count)
eXtended (blocking) thread of the QXK preemptive kernel
Definition qxk.h:145

Definition at line 208 of file qxk.h.

Member Function Documentation

◆ QXSemaphore_init()

void QXSemaphore_init ( QXSemaphore *const  me,
uint_fast8_t const  count,
uint_fast8_t const  max_count 

◆ QXSemaphore_wait()

bool QXSemaphore_wait ( QXSemaphore *const  me,
QTimeEvtCtr const  nTicks 

Definition at line 95 of file qxk_sema.c.

◆ QXSemaphore_tryWait()

bool QXSemaphore_tryWait ( QXSemaphore *const  me)

Definition at line 182 of file qxk_sema.c.

◆ QXSemaphore_signal()

bool QXSemaphore_signal ( QXSemaphore *const  me)

Definition at line 224 of file qxk_sema.c.

Member Data Documentation

◆ waitSet


Set of extended threads waiting on this semaphore

Definition at line 212 of file qxk.h.

◆ count


Semaphore up-down counter

Definition at line 215 of file qxk.h.

◆ max_count


Maximum value of the semaphore counter (e.g., 1 for binary semaphore)

Definition at line 218 of file qxk.h.

The documentation for this class was generated from the following files: