30.12.2014 Views

QDK PIC24/dsPIC-C30 - Quantum Leaps

QDK PIC24/dsPIC-C30 - Quantum Leaps

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

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

www.state-machine.com/pic<br />

6.2 The BSP header file bsp.h<br />

The BSP header file for the DPP application defines the desired ticking rate. This constant is useful for<br />

defining timeouts, which are always specified in units of clock ticks:<br />

#define BSP_TICKS_PER_SEC 100<br />

void BSP_init(void);<br />

void BSP_displyPhilStat(uint8_t n, char const *stat);<br />

void BSP_busyDelay(void); /* to artificially extend RTC processing */<br />

6.3 BSP initialization<br />

The following BSP_init() function for the Explorer 16 board configures the DSP and peripherals as,<br />

shown in Listing 11. This file has been designed to be easily modifiable for other applications.<br />

Listing 11: The BSP_init() implementation in the bsp.c for the DPP example.<br />

void BSP_init(void) {<br />

RCONbits.SWDTEN = 0; /* disable Watchdog */<br />

TRISA = 0x00; /* set LED pins as outputs */<br />

PORTA = 0x00; /* set LEDs drive state low */<br />

}<br />

if (QS_INIT((void *)0) == 0) { /* initialize the QS software tracing */<br />

Q_ERROR();<br />

}<br />

6.4 Starting Interrupts in QF_onStartup()<br />

QP invokes the QF_onStartup() callback just before starting the background loop. The<br />

QF_onStartup() function must configure and start interrupts. At the minimum, QF_onStartup() must<br />

start the system clock tick interrupt. The following QF_onStartup() function enables the CPU Timer 0.<br />

void QF_onStartup(void) { /* entered with interrupts locked */<br />

T2CON = 0; /* Use Internal Osc (Fcy), 16 bit mode, prescaler = 1 */<br />

TMR2 = 0; /* Start counting from 0 and clear the prescaler count */<br />

PR2 = BSP_TMR2_PERIOD - 1; /* set the timer period */<br />

_T2IP = TIMER2_ISR_PRIO; /* set Timer 2 interrupt priority */<br />

_T2IF = 0; /* clear the interrupt for Timer 2 */<br />

_T2IE = 1; /* enable interrupt for Timer 2 */<br />

T2CONbits.TON = 1; /* start Timer 2 */<br />

}<br />

6.5 Assertion Handling Policy in Q_onAssert()<br />

As described in Chapter 6 of [PSiCC2], all QP components use internally assertions to detect errors in the<br />

way application is using the QP services. You need to define how the application reacts in case of<br />

assertion failure by providing the callback function Q_onAssert(). Typically, you would put the system in<br />

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

28 of 35

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

Saved successfully!

Ooh no, something went wrong!