QDK PIC24/dsPIC-C30 - Quantum Leaps
QDK PIC24/dsPIC-C30 - Quantum Leaps
QDK PIC24/dsPIC-C30 - 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>C30</strong><br />
www.state-machine.com/pic<br />
The following Listing 10 shows an example implementation of QK_onIdle() for the <strong>PIC24</strong>/<strong>dsPIC</strong>. Please<br />
note that the ilde-LED is turned on and off in a critical section (so that the intensity of the LED does not<br />
include any preemptions by interrupts and tasks). The transition to the Idle mode happens in a very<br />
straightforward way, because transition to idle mode is always safe under a preemptive priority-based<br />
kernel, such as QK.<br />
void QK_onIdle(void) {<br />
Listing 10: QK_onIdle() callback for <strong>PIC24</strong>/<strong>dsPIC</strong>.<br />
QF_INT_DISABLE();<br />
LED_ON (IDLE_LED); /* blink the IDLE LED, see NOTE01 */<br />
LED_OFF(IDLE_LED);<br />
QF_INT_ENABLE();<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 QEvent const eat_evt = { EAT_SIG, 0 };<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 />
Copyright © <strong>Quantum</strong> <strong>Leaps</strong>, LLC. All Rights Reserved.<br />
23 of 35