05.11.2014 Views

AN: Capstone Dive Computer Example - Quantum Leaps

AN: Capstone Dive Computer Example - Quantum Leaps

AN: Capstone Dive Computer Example - 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.

Application Note:<br />

<strong>Capstone</strong> <strong>Dive</strong> <strong>Computer</strong> <strong>Example</strong><br />

www.state-machine.com<br />

UART_InitStruct.UART_HardwareFlowControl = UART_HardwareFlowControl_None;<br />

UART_InitStruct.UART_Mode = UART_Mode_Tx;<br />

UART_InitStruct.UART_FIFO = UART_FIFO_Enable;<br />

UART_InitStruct.UART_TxFIFOLevel = UART_FIFOLevel_1_8;<br />

UART_InitStruct.UART_RxFIFOLevel = UART_FIFOLevel_1_8;<br />

UART_Init(UART0, &UART_InitStruct); /* initialize UART0 */<br />

UART_Cmd(UART0, ENABLE); /* enable UART0 */<br />

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

QS_FILTER_OFF(...);<br />

...<br />

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

(15)<br />

}<br />

return (uint8_t)1; /* indicate successfull QS initialization */<br />

/*..........................................................................*/<br />

(16) void QS_onCleanup(void) {<br />

}<br />

/*..........................................................................*/<br />

/* NOTE: getTime is invoked within a critical section (inetrrupts disabled) */<br />

(17) uint32_t QS_onGetTime(void) {<br />

(18) uint16_t currTime16 = (uint16_t)TIM3->CNTR;<br />

(19)<br />

(20)<br />

l_currTime32 += (currTime16 - l_prevTime16) & 0xFFFF;<br />

l_prevTime16 = currTime16;<br />

(21) return l_currTime32;<br />

}<br />

/*..........................................................................*/<br />

(22) void QS_onFlush(void) {<br />

uint16_t nBytes = BSP_UART_TX_FIFO; /* the capacity of the UART TX FIFO */<br />

uint8_t const *block;<br />

(23) while ((block = QS_getBlock(&nBytes)) != (uint8_t *)0) {<br />

(24) while ((UART0->FR & 0x80) == 0) {<br />

}<br />

/* TX FIFO not empty? */<br />

/* keep waiting... */<br />

(25) while (nBytes-- != 0) {<br />

}<br />

UART0->DR = *block++; /* stick the byte to the TX FIFO */<br />

nBytes = BSP_UART_TX_FIFO; /* for the next time around */<br />

}<br />

}<br />

#endif /* Q_SPY */<br />

/*--------------------------------------------------------------------------*/<br />

Listing 5 QS implementation to send data out of the UART0 of the STR912 device.<br />

(1) The QS instrumentation is enabled only when the macro Q_SPY is defined<br />

(2) The static l_currTime32 variable is used to hold the 32-bit-wide timestamp.<br />

(3) The static l_prevTime16 variable is used to hold the last 16-bit-wide reading of the free-running<br />

16-bit Timer 3 (the same used to generate the system clock tick interrupt).<br />

(4) This enumeration defines application-specific QS trace record(s), to demonstrate how to use<br />

them.<br />

(5) You need to define the QS_onStartup() callback to initialize the QS software tracing.<br />

(6) You should adjust the QS buffer size (in bytes) to your particular application<br />

(7) You always need to call QS_initBuf() from QS_onStartup() to initialize the trace buffer.<br />

(8-9) The clock to the UART0 peripheral is enabled. Also, the clock to the GPIO3 peripheral is enabled.<br />

GPIO3 controls the UART0 transmit and receive pins.<br />

(10-11) The UART0 and GPIO3 peripherals are removed from reset.<br />

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

24 of 29

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

Saved successfully!

Ooh no, something went wrong!