@@ -28,10 +28,13 @@ This structure of the code is recommended for applications with only one active
2828 <code >: QActive(Q_STATE_CAST(& Blinky::initial)),
2929 m_timeEvt(this, TIMEOUT_SIG, 0U)</code >
3030 </operation >
31- <statechart properties =" 0x00 " >
31+ <statechart properties =" 0x02 " >
3232 <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 >
3538 <initial_glyph conn =" 2,2,5,1,20,8,-4" >
3639 <action box =" 0,-2,32,6" />
3740 </initial_glyph >
@@ -89,6 +92,14 @@ public:
8992
9093using namespace QP;
9194
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+
92103//----------------------------------------------------------------------------
93104// BSP functions
94105
@@ -97,6 +108,18 @@ void BSP::init(void) {
97108 // initialize the hardware used in this sketch...
98109 // NOTE: interrupts are configured and started later in QF::onStartup()
99110 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
100123}
101124//............................................................................
102125void BSP::ledOff(void) {
@@ -127,7 +150,7 @@ void BSP::ledOn(void) {
127150// interrupts.................................................................
128151void TIMER_HANDLER(void) {
129152 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
131154}
132155//............................................................................
133156void QF::onStartup(void) {
@@ -155,6 +178,7 @@ void QF::onStartup(void) {
155178 NVIC_EnableIRQ(TIMER_IRQn);
156179 // ...
157180}
181+
158182//............................................................................
159183void QV::onIdle(void) { // called with interrupts DISABLED
160184#ifdef NDEBUG
@@ -164,6 +188,29 @@ void QV::onIdle(void) { // called with interrupts DISABLED
164188 QV_CPU_SLEEP(); // atomically go to sleep and enable interrupts
165189#else
166190 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+
167214#endif
168215}
169216//............................................................................
@@ -180,6 +227,55 @@ extern "C" Q_NORETURN Q_onAssert(char const * const module, int locati
180227 }
181228}
182229
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+ }
183279</text >
184280 </file >
185281 <file name =" blinky.hpp" >
0 commit comments