QP-nano  6.9.0
Real-Time Embedded Framework
qvn.c
Go to the documentation of this file.
1
40#include "qpn_conf.h" /* QP-nano configuration file (from the application) */
41#include "qfn_port.h" /* QF-nano port from the port directory */
42#include "qassert.h" /* embedded systems-friendly assertions */
43
45
46/* protection against including this source file in a wrong project */
47#ifndef QVN_H
48 #error "Source file included in a project NOT based on the QV-nano kernel"
49#endif /* QVN_H */
50
51/****************************************************************************/
65 uint_fast8_t p;
66 QActive *a;
67
68#ifdef QF_MAX_ACTIVE /* deprecated constant provided? */
69#if (QF_MAX_ACTIVE < 1) || (8 < QF_MAX_ACTIVE)
70 #error "QF_MAX_ACTIVE not defined or out of range. Valid range is 1..8"
71#endif
72 QF_maxActive_ = (uint_fast8_t)QF_MAX_ACTIVE;
73#else
77 Q_REQUIRE_ID(100, (1U <= QF_maxActive_)
78 && (QF_maxActive_ <= 8U));
79#endif
80
81 /* set priorities all registered active objects... */
82 for (p = 1U; p <= QF_maxActive_; ++p) {
83 a = QF_ROM_ACTIVE_GET_(p);
84
85 /* QF_active[p] must be initialized */
86 Q_ASSERT_ID(810, a != (QActive *)0);
87
88 a->prio = (uint8_t)p; /* set the priority of the active object */
89 }
90
91 /* trigger initial transitions in all registered active objects... */
92 for (p = 1U; p <= QF_maxActive_; ++p) {
93 a = QF_ROM_ACTIVE_GET_(p);
94 QHSM_INIT(&a->super); /* take the initial transition in the SM */
95 }
96
97 QF_onStartup(); /* invoke startup callback */
98
99 /* the event loop of the cooperative QV-nano kernel... */
100 QF_INT_DISABLE();
101 for (;;) {
102 if (QF_readySet_ != 0U) {
103 QActiveCB const Q_ROM *acb;
104
105#ifdef QF_LOG2
106 p = QF_LOG2(QF_readySet_);
107#else
108 /* hi nibble non-zero? */
109 if ((QF_readySet_ & 0xF0U) != 0U) {
110 p = (uint_fast8_t)Q_ROM_BYTE(QF_log2Lkup[QF_readySet_ >> 4])
111 + 4U;
112 }
113 else { /* hi nibble of QF_readySet_ is zero */
114 p = (uint_fast8_t)Q_ROM_BYTE(QF_log2Lkup[QF_readySet_]);
115 }
116#endif /* QF_LOG2 */
117
118 acb = &QF_active[p];
119 a = QF_ROM_ACTIVE_GET_(p);
120
121 /* some unsuded events must be available */
122 Q_ASSERT_ID(820, a->nUsed > 0U);
123
124 --a->nUsed;
125 Q_SIG(a) = QF_ROM_QUEUE_AT_(acb, a->tail).sig;
126#if (Q_PARAM_SIZE != 0U)
127 Q_PAR(a) = QF_ROM_QUEUE_AT_(acb, a->tail).par;
128#endif
129 if (a->tail == 0U) { /* wrap around? */
130 a->tail = Q_ROM_BYTE(acb->qlen);
131 }
132 --a->tail;
133 QF_INT_ENABLE();
134
135 QHSM_DISPATCH(&a->super); /* dispatch to the HSM (RTC step) */
136
137 QF_INT_DISABLE();
138 /* empty queue? */
139 if (a->nUsed == 0U) {
140 /* clear the bit corresponding to 'p' */
141 QF_readySet_ &= (uint_fast8_t)~(1U << (p - 1U));
142 }
143 }
144 else {
145 /* QV_onIdle() must be called with interrupts DISABLED because
146 * the determination of the idle condition (no events in the
147 * queues) can change at any time by an interrupt posting events
148 * to a queue. QV_onIdle() MUST enable interrupts internally,
149 * perhaps at the same time as putting the CPU into a power-saving
150 * mode.
151 */
152 QV_onIdle();
153
154 QF_INT_DISABLE();
155 }
156 }
157#ifdef __GNUC__ /* GNU compiler? */
158 return 0;
159#endif
160}
161
Customizable and memory-efficient assertions for embedded systems.
#define Q_DEFINE_THIS_MODULE(name_)
Definition: qassert.h:125
#define Q_ROM
Definition: qassert.h:90
#define Q_ASSERT_ID(id_, test_)
Definition: qassert.h:160
int int_t
Definition: qassert.h:86
#define Q_REQUIRE_ID(id_, test_)
Definition: qassert.h:284
#define Q_PAR(me_)
Definition: qepn.h:150
#define QHSM_DISPATCH(me_)
Definition: qepn.h:224
#define Q_SIG(me_)
Definition: qepn.h:143
#define Q_ROM_BYTE(rom_var_)
Some compilers for Harvard-architecture MCUs, such as gcc for AVR, do not generate correct code for a...
Definition: qepn.h:454
#define QHSM_INIT(me_)
Definition: qepn.h:210
void QF_onStartup(void)
QActiveCB const Q_ROM QF_active[]
active object control blocks
uint_fast8_t volatile QF_readySet_
Definition: qfn.c:65
uint_fast8_t QF_maxActive_
Definition: qfn.c:53
#define QF_ROM_QUEUE_AT_(ao_, i_)
Definition: qfn.h:442
#define QF_ROM_ACTIVE_GET_(p_)
Definition: qfn.h:448
uint8_t const Q_ROM QF_log2Lkup[16]
Definition: qfn.c:89
Definition: qfn.h:397
int_t QF_run(void)
Definition: qvn.c:64
void QV_onIdle(void)
Definition: qfn.h:122
uint8_t volatile nUsed
Definition: qfn.h:142
QHsm super
derives from the QHsm base class
Definition: qfn.h:123
uint8_t prio
Definition: qfn.h:131
uint8_t volatile tail
Definition: qfn.h:137