Пример #1
0
    /*******************************************************************************
    * Function Name: UART_SpiUartWriteTxData
    ********************************************************************************
    *
    * Summary:
    *  Places a data entry into the transmit buffer to be sent at the next available
    *  bus time.
    *  This function is blocking and waits until there is space available to put the
    *  requested data in the transmit buffer.
    *
    * Parameters:
    *  txDataByte: the data to be transmitted.
    *
    * Return:
    *  None
    *
    *******************************************************************************/
    void UART_SpiUartWriteTxData(uint32 txData)
    {
    #if (UART_INTERNAL_TX_SW_BUFFER_CONST)
        uint32 locHead;
    #endif /* (UART_INTERNAL_TX_SW_BUFFER_CONST) */

        #if (UART_CHECK_TX_SW_BUFFER)
        {
            /* Put data directly into the TX FIFO */
            if ((UART_txBufferHead == UART_txBufferTail) &&
                (UART_SPI_UART_FIFO_SIZE != UART_GET_TX_FIFO_ENTRIES))
            {
                /* TX software buffer is empty: put data directly in TX FIFO */
                UART_TX_FIFO_WR_REG = txData;
            }
            /* Put data into TX software buffer */
            else
            {
                /* Head index to put data */
                locHead = (UART_txBufferHead + 1u);

                /* Adjust TX software buffer index */
                if (UART_TX_BUFFER_SIZE == locHead)
                {
                    locHead = 0u;
                }

                /* Wait for space in TX software buffer */
                while (locHead == UART_txBufferTail)
                {
                }

                /* TX software buffer has at least one room */

                /* Clear old status of INTR_TX_NOT_FULL. It sets at the end of transfer when TX FIFO is empty. */
                UART_ClearTxInterruptSource(UART_INTR_TX_NOT_FULL);

                UART_PutWordInTxBuffer(locHead, txData);

                UART_txBufferHead = locHead;

                /* Check if TX Not Full is disabled in interrupt */
                if (0u == (UART_INTR_TX_MASK_REG & UART_INTR_TX_NOT_FULL))
                {
                    /* Enable TX Not Full interrupt source to transmit from software buffer */
                    UART_INTR_TX_MASK_REG |= (uint32) UART_INTR_TX_NOT_FULL;
                }
            }
        }
        #else
        {
            /* Wait until TX FIFO has space to put data element */
            while (UART_SPI_UART_FIFO_SIZE == UART_GET_TX_FIFO_ENTRIES)
            {
            }

            UART_TX_FIFO_WR_REG = txData;
        }
        #endif
    }
Пример #2
0
    /*******************************************************************************
    * Function Name: UART_SpiUartWriteTxData
    ********************************************************************************
    *
    * Summary:
    *  Places a data entry into the transmit buffer to be sent at the next available
    *  bus time.
    *  This function is blocking and waits until there is space available to put the
    *  requested data in the transmit buffer.
    *
    * Parameters:
    *  txDataByte: the data to be transmitted.
    *
    * Return:
    *  None
    *
    *******************************************************************************/
    void UART_SpiUartWriteTxData(uint32 txDataByte)
    {
        #if(UART_INTERNAL_TX_SW_BUFFER_CONST)
            uint32 locHead;
            uint32 intSourceMask;
        #endif /* (UART_INTERNAL_TX_SW_BUFFER_CONST) */

        #if(UART_CHECK_TX_SW_BUFFER)
        {
            /* Head index to put data */
            locHead = (UART_txBufferHead + 1u);

            /* Adjust TX software buffer index */
            if(UART_TX_BUFFER_SIZE == locHead)
            {
                locHead = 0u;
            }

            while(locHead == UART_txBufferTail)
            {
                /* Wait for space in the TX software buffer */
            }

            /* The TX software buffer has at least one room */

            if((UART_txBufferHead == UART_txBufferTail) &&
               (UART_FIFO_SIZE != UART_GET_TX_FIFO_ENTRIES))
            {
                /* TX software buffer is empty: put data directly in TX FIFO */
                UART_TX_FIFO_WR_REG = txDataByte;
            }
            /* Put data in the TX software buffer */
            else
            {
                /* Clear old status of INTR_TX_EMPTY. It sets at the end of transfer: TX FIFO empty. */
                UART_ClearTxInterruptSource(UART_INTR_TX_NOT_FULL);

                UART_PutWordInTxBuffer(locHead, txDataByte);

                UART_txBufferHead = locHead;

                /* Enable interrupt to transmit */
                intSourceMask  = UART_INTR_TX_NOT_FULL;
                intSourceMask |= UART_GetTxInterruptMode();
                UART_SpiUartEnableIntTx(intSourceMask);
            }
        }
        #else
        {
            while(UART_FIFO_SIZE == UART_GET_TX_FIFO_ENTRIES)
            {
                /* Block while TX FIFO is FULL */
            }

            UART_TX_FIFO_WR_REG = txDataByte;
        }
        #endif
    }
Пример #3
0
    /*******************************************************************************
    * Function Name: UART_SpiUartClearTxBuffer
    ********************************************************************************
    *
    * Summary:
    *  Clears the transmit buffer and TX FIFO.
    *
    * Parameters:
    *  None
    *
    * Return:
    *  None
    *
    *******************************************************************************/
    void UART_SpiUartClearTxBuffer(void)
    {
        #if (UART_CHECK_TX_SW_BUFFER)
        {
            /* Lock from component interruption */
            UART_DisableInt();

            /* Flush TX software buffer */
            UART_txBufferHead = UART_txBufferTail;

            UART_INTR_TX_MASK_REG &= (uint32) ~UART_INTR_TX_NOT_FULL;
            UART_CLEAR_TX_FIFO;
            UART_ClearTxInterruptSource(UART_INTR_TX_ALL);

            /* Release lock */
            UART_EnableInt();
        }
        #else
        {
            UART_CLEAR_TX_FIFO;
        }
        #endif
    }