1 | /*******************************************************************************
|
2 | * Function Name: SPI_SpiUartWriteTxData
|
3 | ********************************************************************************
|
4 | *
|
5 | * Summary:
|
6 | * Places a data entry into the transmit buffer to be sent at the next available
|
7 | * bus time.
|
8 | * This function is blocking and waits until there is space available to put the
|
9 | * requested data in the transmit buffer.
|
10 | *
|
11 | * Parameters:
|
12 | * txDataByte: the data to be transmitted.
|
13 | *
|
14 | * Return:
|
15 | * None
|
16 | *
|
17 | *******************************************************************************/
|
18 | void SPI_SpiUartWriteTxData(uint32 txData)
|
19 | {
|
20 | #if (SPI_INTERNAL_TX_SW_BUFFER_CONST)
|
21 | uint32 locHead;
|
22 | #endif /* (SPI_INTERNAL_TX_SW_BUFFER_CONST) */
|
23 |
|
24 | #if (SPI_CHECK_TX_SW_BUFFER)
|
25 | {
|
26 | /* Put data directly into the TX FIFO */
|
27 | if ((SPI_txBufferHead == SPI_txBufferTail) &&
|
28 | (SPI_SPI_UART_FIFO_SIZE != SPI_GET_TX_FIFO_ENTRIES))
|
29 | {
|
30 | /* TX software buffer is empty: put data directly in TX FIFO */
|
31 | SPI_TX_FIFO_WR_REG = txData;
|
32 | }
|
33 | /* Put data into TX software buffer */
|
34 | else
|
35 | {
|
36 | /* Head index to put data */
|
37 | locHead = (SPI_txBufferHead + 1u);
|
38 |
|
39 | /* Adjust TX software buffer index */
|
40 | if (SPI_TX_BUFFER_SIZE == locHead)
|
41 | {
|
42 | locHead = 0u;
|
43 | }
|
44 |
|
45 | /* Wait for space in TX software buffer */
|
46 | while (locHead == SPI_txBufferTail)
|
47 | {
|
48 | }
|
49 |
|
50 | /* TX software buffer has at least one room */
|
51 |
|
52 | /* Clear old status of INTR_TX_NOT_FULL. It sets at the end of transfer when TX FIFO is empty. */
|
53 | SPI_ClearTxInterruptSource(SPI_INTR_TX_NOT_FULL);
|
54 |
|
55 | SPI_PutWordInTxBuffer(locHead, txData);
|
56 |
|
57 | SPI_txBufferHead = locHead;
|
58 |
|
59 | /* Check if TX Not Full is disabled in interrupt */
|
60 | if (0u == (SPI_INTR_TX_MASK_REG & SPI_INTR_TX_NOT_FULL))
|
61 | {
|
62 | /* Enable TX Not Full interrupt source to transmit from software buffer */
|
63 | SPI_INTR_TX_MASK_REG |= (uint32) SPI_INTR_TX_NOT_FULL;
|
64 | }
|
65 | }
|
66 | }
|
67 | #else
|
68 | {
|
69 | /* Wait until TX FIFO has space to put data element */
|
70 | while (SPI_SPI_UART_FIFO_SIZE == SPI_GET_TX_FIFO_ENTRIES)
|
71 | {
|
72 | }
|
73 |
|
74 | SPI_TX_FIFO_WR_REG = txData;
|
75 | }
|
76 | #endif
|
77 | }
|