17.01.2015 Views

QDK PIC24/dsPIC-XC16 - Quantum Leaps

QDK PIC24/dsPIC-XC16 - Quantum Leaps

QDK PIC24/dsPIC-XC16 - Quantum Leaps

SHOW MORE
SHOW LESS

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

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

100U<br />

void BSP_init(void);<br />

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

void BSP_displayPaused(uint8_t paused);<br />

. . .<br />

6.3 BSP initialization<br />

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

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

element is configuring the FRC (Fast RC Oscillator) clock by setting the flash word 2. Of course, the clock<br />

configuration can be different in your projects, but it must be consistent with the settings for various<br />

peripherals, such as timers, UARTs, etc.<br />

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

_CONFIG2(FNOSC_FRC); /* set flash configuration for the device */<br />

. . .<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 = 0x0000U; /* Use Internal Osc (Fcy), 16 bit mode, prescaler = 1 */<br />

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

PR2 = (uint16_t)(BSP_TMR2_PERIOD – 1.0 + 0.5); /* Timer2 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 />

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!