03.11.2014 Views

QDK-nano PIC24/dsPIC-C30 - Quantum Leaps

QDK-nano PIC24/dsPIC-C30 - Quantum Leaps

QDK-nano PIC24/dsPIC-C30 - Quantum Leaps

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>QDK</strong>-<strong>nano</strong><br />

<strong>PIC24</strong>/<strong>dsPIC</strong>-<strong>C30</strong><br />

www.state-machine.com/pic<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 9: QK_onIdle() callback for <strong>PIC24</strong>/<strong>dsPIC</strong>.<br />

QF_INT_LOCK();<br />

LED_ON (IDLE_LED); /* blink the IDLE LED, see NOTE01 */<br />

LED_OFF(IDLE_LED);<br />

QF_INT_UNLOCK();<br />

#ifdef 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-<strong>nano</strong> 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 />

_INT0IF = 0;<br />

QActive_postISR(&AO_Ped, PEDS_WAITING_SIG, 0);<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 7 shows how to trigger the INT0 interrupt from the MPLAB debugger. From the debugger you need<br />

to first open the “File Registers” window (menu View | File Registers) as shown in Figure 7. You scroll to<br />

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 />

The general testing strategy is to break into the application at an interesting place for preemption, set<br />

breakpoints to verify which path through the code is taken, and trigger the INT0 interrupt, as described<br />

above. Next, you need to free-run the code (don’t use single stepping) so that the <strong>PIC24</strong>/<strong>dsPIC</strong> CPU can<br />

perform prioritization. You observe the order in which the breakpoints are hit. This procedure will become<br />

clearer after a few examples.<br />

Copyright © <strong>Quantum</strong> <strong>Leaps</strong>, LLC. All Rights Reserved.<br />

21 of 29

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!