QDK PIC24/dsPIC-XC16 - Quantum Leaps
QDK PIC24/dsPIC-XC16 - Quantum Leaps
QDK PIC24/dsPIC-XC16 - Quantum Leaps
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>QDK</strong><br />
<strong>PIC24</strong>/<strong>dsPIC</strong>-<strong>XC16</strong><br />
www.state-machine.com/pic<br />
void QK_onIdle(void) {<br />
Listing 10: QK_onIdle() callback for <strong>PIC24</strong>/<strong>dsPIC</strong>.<br />
#ifdef Q_SPY<br />
while (U2STAbits.UTXBF == 0U) { /* TX Buffer not full */<br />
uint16_t b;<br />
QF_INT_DISABLE();<br />
b = QS_getByte();<br />
QF_INT_ENABLE();<br />
if (b == QS_EOD) { /* End-Of-Data reached */<br />
break; /* break out of the loop */<br />
}<br />
U2TXREG = (uint8_t)b; /* stick the byte to TXREG for transmission */<br />
}<br />
#elif defined NDEBUG<br />
Idle(); /* transition to Idle mode */<br />
#endif<br />
}<br />
4.4 Testing QK Preemption Scenarios<br />
The technique described in this section will allow you to use the MPLAB debugger to trigger an interrupt<br />
at any machine instruction and observe the preemptions it causes. The interrupt used for the testing<br />
purposes is the GPIOA interrupt (INTID == 0). The ISR for this interrupt is shown below:<br />
The DPP example application for the preemptive QK kernel includes special ISR (INT0 ISR) for<br />
convenient testing of various preemption scenarios, defined as follows:<br />
#define INT0_ISR_PRIO 6<br />
QK_ISR(auto_psv) _INT0Interrupt() {<br />
static QEvt const eat_evt = { EAT_SIG, 0U, 0U };<br />
_INT0IF = 0;<br />
QACTIVE_POST(AO_Table, &eat_evt, &l_INT0Interrupt);<br />
QK_ISR_EXIT(); /* inform QK about exiting the ISR */<br />
}<br />
The INT0 ISR, is assigned priority 6, which is higher than the priority of the system clock tick ISR.<br />
Figure 10 shows how to trigger the INT0 interrupt from the MPLABX debugger. From the debugger you<br />
need to first open the “File Registers” window (menu View | File Registers) as shown in Figure 10. You<br />
scroll to the IFS0 register at address 0x0084. To trigger the INT0 interrupt you need to write 1 to the leastsignificant<br />
bit (bit #0) of the IFS0 register.<br />
Copyright © <strong>Quantum</strong> <strong>Leaps</strong>, LLC. All Rights Reserved.<br />
23 of 35