QP/C  8.0.3
Real-Time Event Framework
Loading...
Searching...
No Matches
qequeue.h
Go to the documentation of this file.
1//============================================================================
2// QP/C Real-Time Event Framework (RTEF)
3//
4// Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
5//
6// Q u a n t u m L e a P s
7// ------------------------
8// Modern Embedded Software
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
11//
12// This software is dual-licensed under the terms of the open-source GNU
13// General Public License (GPL) or under the terms of one of the closed-
14// source Quantum Leaps commercial licenses.
15//
16// Redistributions in source code must retain this top-level comment block.
17// Plagiarizing this software to sidestep the license obligations is illegal.
18//
19// NOTE:
20// The GPL does NOT permit the incorporation of this code into proprietary
21// programs. Please contact Quantum Leaps for commercial licensing options,
22// which expressly supersede the GPL and are designed explicitly for
23// closed-source distribution.
24//
25// Quantum Leaps contact information:
26// <www.state-machine.com/licensing>
27// <info@state-machine.com>
28//============================================================================
29#ifndef QEQUEUE_H_
30#define QEQUEUE_H_
31
32#ifndef QF_EQUEUE_CTR_SIZE
33 #define QF_EQUEUE_CTR_SIZE 1U
34#endif
35
36#if (QF_EQUEUE_CTR_SIZE == 1U)
37 typedef uint8_t QEQueueCtr;
38#elif (QF_EQUEUE_CTR_SIZE == 2U)
39 typedef uint16_t QEQueueCtr;
40#else
41 #error QF_EQUEUE_CTR_SIZE defined incorrectly, expected 1U or 2U
42#endif
43
44struct QEvt; // forward declaration
45
46//============================================================================
47//! @class QEQueue
48typedef struct QEQueue {
49 struct QEvt const * volatile frontEvt; //!< @private @memberof QEQueue
50 struct QEvt const * * ring; //!< @private @memberof QEQueue
51 QEQueueCtr end; //!< @private @memberof QEQueue
52 QEQueueCtr volatile head; //!< @private @memberof QEQueue
53 QEQueueCtr volatile tail; //!< @private @memberof QEQueue
54 QEQueueCtr volatile nFree; //!< @private @memberof QEQueue
55 QEQueueCtr nMin; //!< @private @memberof QEQueue
56} QEQueue;
57
58//! @public @memberof QEQueue
59void QEQueue_init(QEQueue * const me,
60 struct QEvt const * * const qSto,
61 uint_fast16_t const qLen);
62
63//! @public @memberof QEQueue
64bool QEQueue_post(QEQueue * const me,
65 struct QEvt const * const e,
66 uint_fast16_t const margin,
67 uint_fast8_t const qsId);
68
69//! @public @memberof QEQueue
70void QEQueue_postLIFO(QEQueue * const me,
71 struct QEvt const * const e,
72 uint_fast8_t const qsId);
73
74//! @public @memberof QEQueue
75struct QEvt const * QEQueue_get(QEQueue * const me,
76 uint_fast8_t const qsId);
77
78//! @public @memberof QEQueue
79static inline QEQueueCtr QEQueue_getNFree(QEQueue const * const me) {
80 return me->nFree;
81}
82
83//! @public @memberof QEQueue
84static inline QEQueueCtr QEQueue_getNMin(QEQueue const * const me) {
85 return me->nMin;
86}
87
88//! @public @memberof QEQueue
89static inline bool QEQueue_isEmpty(QEQueue const * const me) {
90 return me->frontEvt == (struct QEvt *)0;
91}
92
93#endif // QEQUEUE_H_
uint16_t QEQueueCtr
Definition qequeue.h:39
Native QF Event Queue.
Definition qequeue.h:48
QEQueueCtr volatile tail
Offset of where next event will be extracted from the buffer.
Definition qequeue.h:53
static bool QEQueue_isEmpty(QEQueue const *const me)
Find out if the queue is empty.
Definition qequeue.h:89
QEQueueCtr volatile head
Offset to where next event will be inserted into the buffer.
Definition qequeue.h:52
QEQueueCtr end
Offset of the end of the ring buffer from the start of the buffer.
Definition qequeue.h:51
static QEQueueCtr QEQueue_getNFree(QEQueue const *const me)
Obtain the number of free entries still available in the queue.
Definition qequeue.h:79
struct QEvt const * QEQueue_get(QEQueue *const me, uint_fast8_t const qsId)
Obtain an event from the "raw" thread-safe queue.
Definition qf_qeq.c:209
QEQueueCtr nMin
Minimum number of free events ever in the ring buffer.
Definition qequeue.h:55
QEQueueCtr volatile nFree
Number of free events in the ring buffer.
Definition qequeue.h:54
struct QEvt const ** ring
Pointer to the start of the ring buffer.
Definition qequeue.h:50
void QEQueue_init(QEQueue *const me, struct QEvt const **const qSto, uint_fast16_t const qLen)
Initialize the native QF event queue.
void QEQueue_postLIFO(QEQueue *const me, struct QEvt const *const e, uint_fast8_t const qsId)
Post an event to the "raw" thread-safe event queue (LIFO)
Definition qf_qeq.c:152
struct QEvt const *volatile frontEvt
Pointer to event at the front of the queue.
Definition qequeue.h:49
bool QEQueue_post(QEQueue *const me, struct QEvt const *const e, uint_fast16_t const margin, uint_fast8_t const qsId)
Post an event to the "raw" thread-safe event queue (FIFO)
Definition qf_qeq.c:70
static QEQueueCtr QEQueue_getNMin(QEQueue const *const me)
Obtain the minimum number of free entries ever in the queue (a.k.a. "low-watermark")
Definition qequeue.h:84
Event class.
Definition qp.h:112