@@ -28,10 +28,13 @@ This structure of the code is recommended for applications with only one active
28
28
<code >: QActive(Q_STATE_CAST(& Blinky::initial)),
29
29
m_timeEvt(this, TIMEOUT_SIG, 0U)</code >
30
30
</operation >
31
- <statechart properties =" 0x00 " >
31
+ <statechart properties =" 0x02 " >
32
32
<initial target =" ../1" >
33
- <action >m_timeEvt.armX(BSP::TICKS_PER_SEC/2, BSP::TICKS_PER_SEC/2);
34
- (void)e; // unused parameter</action >
33
+ <action >(void)e; // unused parameter
34
+ m_timeEvt.armX(BSP::TICKS_PER_SEC/2, BSP::TICKS_PER_SEC/2);
35
+
36
+ QS_OBJ_DICTIONARY(& Blinky::instance);
37
+ QS_SIG_DICTIONARY(TIMEOUT_SIG, nullptr);</action >
35
38
<initial_glyph conn =" 2,2,5,1,20,8,-4" >
36
39
<action box =" 0,-2,32,6" />
37
40
</initial_glyph >
@@ -89,6 +92,14 @@ public:
89
92
90
93
using namespace QP;
91
94
95
+ //----------------------------------------------------------------------------
96
+ // QS facilities
97
+
98
+ // un-comment if QS instrumentation needed
99
+ //#define QS_ON
100
+
101
+ static QP::QSpyId const l_TIMER_ID = { 0U }; // QSpy source ID
102
+
92
103
//----------------------------------------------------------------------------
93
104
// BSP functions
94
105
@@ -97,6 +108,18 @@ void BSP::init(void) {
97
108
// initialize the hardware used in this sketch...
98
109
// NOTE: interrupts are configured and started later in QF::onStartup()
99
110
pinMode(LED_BUILTIN, OUTPUT);
111
+
112
+ #ifdef QS_ON
113
+ QS_INIT(nullptr);
114
+
115
+ // output QS dictionaries...
116
+ QS_OBJ_DICTIONARY(& l_TIMER_ID);
117
+
118
+ // setup the QS filters...
119
+ QS_GLB_FILTER(QP::QS_SM_RECORDS); // state machine records
120
+ QS_GLB_FILTER(QP::QS_AO_RECORDS); // active object records
121
+ QS_GLB_FILTER(QP::QS_UA_RECORDS); // all user records
122
+ #endif
100
123
}
101
124
//............................................................................
102
125
void BSP::ledOff(void) {
@@ -127,7 +150,7 @@ void BSP::ledOn(void) {
127
150
// interrupts.................................................................
128
151
void TIMER_HANDLER(void) {
129
152
TC_GetStatus(TIMER, TIMER_CHANNEL); // clear the interrupt source
130
- QF::TICK_X(0, (void *)0 ); // process time events for tick rate 0
153
+ QF::TICK_X(0U, & l_TIMER_ID ); // process time events for tick rate 0
131
154
}
132
155
//............................................................................
133
156
void QF::onStartup(void) {
@@ -155,6 +178,7 @@ void QF::onStartup(void) {
155
178
NVIC_EnableIRQ(TIMER_IRQn);
156
179
// ...
157
180
}
181
+
158
182
//............................................................................
159
183
void QV::onIdle(void) { // called with interrupts DISABLED
160
184
#ifdef NDEBUG
@@ -164,6 +188,29 @@ void QV::onIdle(void) { // called with interrupts DISABLED
164
188
QV_CPU_SLEEP(); // atomically go to sleep and enable interrupts
165
189
#else
166
190
QF_INT_ENABLE(); // simply re-enable interrupts
191
+
192
+ #ifdef QS_ON
193
+
194
+ // transmit QS outgoing data (QS-TX)
195
+ uint16_t len = Serial.availableForWrite();
196
+ if (len > 0U) { // any space available in the output buffer?
197
+ uint8_t const *buf = QS::getBlock(& len);
198
+ if (buf) {
199
+ Serial.write(buf, len); // asynchronous and non-blocking
200
+ }
201
+ }
202
+
203
+ // receive QS incoming data (QS-RX)
204
+ len = Serial.available();
205
+ if (len > 0U) {
206
+ do {
207
+ QP::QS::rxPut(Serial.read());
208
+ } while (--len > 0U);
209
+ QS::rxParse();
210
+ }
211
+
212
+ #endif // QS_ON
213
+
167
214
#endif
168
215
}
169
216
//............................................................................
@@ -180,6 +227,55 @@ extern "C" Q_NORETURN Q_onAssert(char const * const module, int locati
180
227
}
181
228
}
182
229
230
+ //----------------------------------------------------------------------------
231
+ // QS callbacks...
232
+ #ifdef QS_ON
233
+
234
+ //............................................................................
235
+ bool QP::QS::onStartup(void const * arg) {
236
+ static uint8_t qsTxBuf[1024]; // buffer for QS transmit channel (QS-TX)
237
+ static uint8_t qsRxBuf[128]; // buffer for QS receive channel (QS-RX)
238
+ initBuf (qsTxBuf, sizeof(qsTxBuf));
239
+ rxInitBuf(qsRxBuf, sizeof(qsRxBuf));
240
+ Serial.begin(115200); // run serial port at 115200 baud rate
241
+ return true; // return success
242
+ }
243
+ //............................................................................
244
+ void QP::QS::onCommand(uint8_t cmdId, uint32_t param1,
245
+ uint32_t param2, uint32_t param3)
246
+ {
247
+ (void)cmdId;
248
+ (void)param1;
249
+ (void)param2;
250
+ (void)param3;
251
+ }
252
+
253
+ #endif // QS_ON
254
+
255
+ //............................................................................
256
+ void QP::QS::onCleanup(void) {
257
+ }
258
+ //............................................................................
259
+ QP::QSTimeCtr QP::QS::onGetTime(void) {
260
+ return millis();
261
+ }
262
+ //............................................................................
263
+ void QP::QS::onFlush(void) {
264
+ #ifdef QS_ON
265
+ uint16_t len = 0xFFFFU; // big number to get as many bytes as available
266
+ uint8_t const *buf = QS::getBlock(& len); // get continguous block of data
267
+ while (buf != nullptr) { // data available?
268
+ Serial.write(buf, len); // might poll until all bytes fit
269
+ len = 0xFFFFU; // big number to get as many bytes as available
270
+ buf = QS::getBlock(& len); // try to get more data
271
+ }
272
+ Serial.flush(); // wait for the transmission of outgoing data to complete
273
+ #endif // QS_ON
274
+ }
275
+ //............................................................................
276
+ void QP::QS::onReset(void) {
277
+ NVIC_SystemReset();
278
+ }
183
279
</text >
184
280
</file >
185
281
<file name =" blinky.hpp" >
0 commit comments