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