QDK-nano PIC24/dsPIC-C30 - Quantum Leaps
QDK-nano PIC24/dsPIC-C30 - Quantum Leaps
QDK-nano PIC24/dsPIC-C30 - Quantum Leaps
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 />
QP-<strong>nano</strong> will use uint16_t. If you don’t define this macro in qpn_port.h, the default of 0 (no<br />
parameter) will be assumed.<br />
(3) The macro QF_TIMEEVT_CTR_SIZE defines the size (in bytes) of the time event down-counter. The<br />
allowed values are 0 (no time events), 1, 2, or 4 bytes. Here the value of QF_TIMEEVT_CTR_SIZE is<br />
set to 2, so that QP-<strong>nano</strong> will use uint16_t. If you don’t define this macro in qpn_port.h, the<br />
default of 0 (no time events) will be assumed.<br />
(4) You must define the QF_MAX_ACTIVE macro as the exact number of active objects used in the<br />
application. The provided value must be between 1 and 8 and must be consistent with the definition<br />
of the QF_active[] array in main.c.<br />
(5) The interrupt locking macro resolves to the single instruction DISI #0x3FFF, which disables<br />
interrupts for 16383 instruction cycles. The number of cycles is much longer than any actual critical<br />
section in QP-<strong>nano</strong>.<br />
NOTE: The DISI instruction only disables interrupts with priority levels 1-6. Priority level 7 interrupts<br />
and all trap events still have the ability to interrupt the CPU when the DISI instruction is active. This<br />
means that from the perspective of QP, the level 7 interrupts are treated as non-maskable interrupts<br />
(NMIs). Such non-maskable interrupts cannot call any QP services. In particular, they cannot post<br />
events (see also Section 5).<br />
(6) The DISI #0 instruction is then used to unconditionally unlock the interrupts at the end of the critical<br />
section.<br />
(7) The interrupt nesting is allowed, as it is the default for <strong>PIC24</strong>/<strong>dsPIC</strong>.<br />
(8) The C99-standard exact-width integer types are defined explicitly, because the MPLAB <strong>C30</strong><br />
compiler does not provide the standard header file.<br />
(9) The qpn_port.h must include the QEP-<strong>nano</strong> event processor interface qepn.h.<br />
(10) The qpn_port.h must include the QF-<strong>nano</strong> real-time framework interface qfn.h.<br />
3.2 ISRs in the Non-Preemptive “Vanilla” Configuration<br />
The MPLAB <strong>C30</strong> compiler supports writing interrupts in C. In the non-preemptive “vanilla” port, the ISRs<br />
are identical as in the simplest of all “superloop” (main+ISRs), and there is nothing QP-<strong>nano</strong>-specific in<br />
the structure of the ISRs. The only QP-specific requirement is that you provide a periodic system clock<br />
tick ISR and you invoke QF_tick() in it. The ISRs are located in the bsp.c file found in the application<br />
directory.<br />
NOTE: The non-preemptive “vanilla” kernel allows interrupts nesting, as the interrupt preemptions<br />
are handled entirely by the <strong>PIC24</strong>/<strong>dsPIC</strong> hardware.<br />
Listing 3: The system tick interrupt calling QF_tick() function to manage armed time events.<br />
(1) void __attribute__((__interrupt__,<br />
(2) auto_psv))<br />
(3) _T2Interrupt(void)<br />
{<br />
(4) _T2IF = 0; /* clear Timer 2 interrupt flag */<br />
Copyright © <strong>Quantum</strong> <strong>Leaps</strong>, LLC. All Rights Reserved.<br />
11 of 29