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

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

7 The QS Software Tracing Instrumentation<br />

QS is a software tracing facility built into all QP components and also available to the Application code.<br />

QS allows you to gain unprecedented visibility into your application by selectively logging al-most all<br />

interesting events occurring within state machines, the framework, the kernel, and your application code.<br />

QS software tracing is minimally intrusive, offers precise time-stamping, sophisticated runtime filtering of<br />

events, and good data compression (see Chapter 11 in PSiCC2 [PSiCC2]).<br />

This <strong>QDK</strong> demonstrates how to use the QS software tracing instrumentation to generate real-time trace of<br />

a running QP application. QS can be configured to send the trace data out of the serial port of the target<br />

device. On the Explorer 16 board, QS uses the built-in UART2 to send the trace data to the host. The QS<br />

platform-dependent implementation is located in the file bsp.c and looks as follows:<br />

(1) #ifdef Q_SPY<br />

Listing 12: QS implementation to send data with UART2 of <strong>PIC24</strong>/<strong>dsPIC</strong> MCU<br />

(2) static uint32_t l_tickTime; /* timestamp at tick */<br />

(3) enum AppRecords { /* application-specific trace records */<br />

PHILO_STAT = QS_USER<br />

};<br />

#define QS_BUF_SIZE<br />

#define BAUD_RATE<br />

1024U<br />

38400U<br />

(4) uint8_t QS_onStartup(void const *arg) {<br />

(5) static uint8_t qsBuf[QS_BUF_SIZE]; /* buffer for <strong>Quantum</strong> Spy */<br />

(6) QS_initBuf(qsBuf, sizeof(qsBuf)); /* initialize the QS trace buffer */<br />

/* initialize the UART2 for transmitting the QS trace data */<br />

(7) TRISFbits.TRISF5 = 0; /* set UART2 TX pin as output */<br />

U2MODE = 0x0008; /* enable high baud rate */<br />

U2STA = 0x0000; /* use default settings of 8N1 */<br />

U2BRG = ((BSP_FCY_HZ / 4 / BAUD_RATE) - 1); /* baud rate generator */<br />

U2MODEbits.UARTEN = 1;<br />

U2STAbits.UTXEN = 1;<br />

(8) QS_FILTER_ON(QS_ALL_RECORDS);<br />

/* setup the QS filters... */<br />

// QS_FILTER_OFF(QS_QEP_STATE_EMPTY);<br />

// QS_FILTER_OFF(QS_QEP_STATE_ENTRY);<br />

// QS_FILTER_OFF(QS_QEP_STATE_EXIT);<br />

// QS_FILTER_OFF(QS_QEP_STATE_INIT);<br />

// QS_FILTER_OFF(QS_QEP_INIT_TRAN);<br />

// QS_FILTER_OFF(QS_QEP_INTERN_TRAN);<br />

// QS_FILTER_OFF(QS_QEP_TRAN);<br />

// QS_FILTER_OFF(QS_QEP_dummyD);<br />

QS_FILTER_OFF(QS_QF_ACTIVE_ADD);<br />

. . .<br />

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

30 of 35

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

Saved successfully!

Ooh no, something went wrong!