AN: Capstone Dive Computer Example - Quantum Leaps
AN: Capstone Dive Computer Example - Quantum Leaps
AN: Capstone Dive Computer Example - Quantum Leaps
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Application Note:<br />
<strong>Capstone</strong> <strong>Dive</strong> <strong>Computer</strong> <strong>Example</strong><br />
www.state-machine.com<br />
3 The <strong>Quantum</strong> Spy (QS) Instrumentation<br />
The <strong>Capstone</strong> examples (<strong>Example</strong>1a and <strong>Example</strong>2b) demonstrate how to use the <strong>Quantum</strong> Spy<br />
(QS) to generate real-time trace of a running QP application. Normally, the QS instrumentation is<br />
inactive and does not add any overhead to your application, but you can turn the instrumentation<br />
on by defining the Q_SPY macro and recompiling the code.<br />
<strong>Quantum</strong> Spy (QS) is a software tracing facility built into all QP components and also available to<br />
the Application code. QS allows you to gain unprecedented visibility into your application by selectively<br />
logging almost all interesting events occurring within state machines, the framework, the<br />
kernel, and your application code. QS software tracing is minimally intrusive, offers precise timestamping,<br />
sophisticated runtime filtering of events, and good data compression (see Chapter 11 in<br />
PSiCC2 [PSiCC2]).<br />
QS can be configured to send the real-time data out of the serial port of the target device. On the<br />
STR912F MCU, QS uses the built-in USART0 to send the trace data out (see Figure 3), so the QSPY<br />
host application can conveniently receive the trace data on the host PC. The complete implementation<br />
of the QS software-tracing output consists of several steps, which are all summarized in Listing<br />
5 (file bsp.c).<br />
(1) #ifdef Q_SPY<br />
(2) static uint32_t l_currTime32;<br />
(3) static uint16_t l_prevTime16;<br />
(4) enum AppRecords {<br />
PHILO_STAT = QS_USER<br />
/* application-specific trace records */<br />
};<br />
#endif<br />
/*--------------------------------------------------------------------------*/<br />
#ifdef Q_SPY<br />
(5) uint8_t QS_onStartup(void const *arg) {<br />
(6) static uint8_t qsBuf[BSP_QS_BUF_SIZE]; /* buffer for <strong>Quantum</strong> Spy */<br />
GPIO_InitTypeDef GPIO_InitStruct;<br />
UART_InitTypeDef UART_InitStruct;<br />
(7) QS_initBuf(qsBuf, sizeof(qsBuf));<br />
/* configure the UART0 for QSPY output ... */<br />
(8) SCU_APBPeriphClockConfig(__UART0, ENABLE); /* enable clock for UART0 */<br />
(9) SCU_APBPeriphClockConfig(__GPIO3, ENABLE); /* enable clock for GPIO3 */<br />
(10) SCU_APBPeriphReset(__UART0, DISABLE); /* remove UART0 from reset */<br />
(11) SCU_APBPeriphReset(__GPIO3, DISABLE); /* remove GPIO3 from reset */<br />
/* configure UART0_TX pin GPIO3.4 ... */<br />
(12) GPIO_DeInit(GPIO3);<br />
GPIO_InitStruct.GPIO_Pin<br />
= GPIO_Pin_4;<br />
GPIO_InitStruct.GPIO_Direction = GPIO_PinOutput;<br />
GPIO_InitStruct.GPIO_Type = GPIO_Type_PushPull;<br />
GPIO_InitStruct.GPIO_IPConnected = GPIO_IPConnected_Disable;<br />
GPIO_InitStruct.GPIO_Alternate = GPIO_OutputAlt3;<br />
GPIO_Init(GPIO3, &GPIO_InitStruct);<br />
/* configure UART0... */<br />
(13) UART_DeInit(UART0); /* force UART0 registers to reset values */<br />
UART_InitStruct.UART_WordLength = UART_WordLength_8D;<br />
UART_InitStruct.UART_StopBits<br />
UART_InitStruct.UART_Parity<br />
= UART_StopBits_1;<br />
= UART_Parity_No;<br />
UART_InitStruct.UART_BaudRate = BSP_QS_BAUD_RATE;<br />
Copyright © <strong>Quantum</strong> <strong>Leaps</strong>, LLC. All Rights Reserved.<br />
23 of 29