Beispiel #1
0
    /*******************************************************************************
    * Function Name: UART_1_UartGetByte
    ********************************************************************************
    *
    * Summary:
    *  Retrieves the next data element from the receive buffer, returns the
    *  received byte and error condition.
    *   - The RX software buffer is disabled: returns the data element retrieved
    *     from the RX FIFO. Undefined data will be returned if the RX FIFO is
    *     empty.
    *   - The RX software buffer is enabled: returns data element from the
    *     software receive buffer.
    *
    * Parameters:
    *  None
    *
    * Return:
    *  Bits 7-0 contain the next data element from the receive buffer and
    *  other bits contain the error condition.
    *
    * Side Effects:
    *  The errors bits may not correspond with reading characters due to RX FIFO
    *  and software buffer usage.
    *  RX software buffer is disabled: The internal software buffer overflow
    *  is not returned as status by this function.
    *  Check SCB_rxBufferOverflow to capture that error condition.
    *
    *******************************************************************************/
    uint32 UART_1_UartGetByte(void)
    {
        uint32 rxData;
        uint32 tmpStatus;

        #if (UART_1_CHECK_RX_SW_BUFFER)
        {
            UART_1_DisableInt();
        }
        #endif

        if (0u != UART_1_SpiUartGetRxBufferSize())
        {
            /* Enables interrupt to receive more bytes: at least one byte is in
            * buffer.
            */
            #if (UART_1_CHECK_RX_SW_BUFFER)
            {            
                UART_1_EnableInt();
            }
            #endif

            /* Get received byte */
            rxData = UART_1_SpiUartReadRxData();
        }
        else
        {
            /* Reads a byte directly from RX FIFO: underflow is raised in the case
            * of empty. Otherwise the first received byte will be read.
            */
            rxData = UART_1_RX_FIFO_RD_REG;

            /* Enables interrupt to receive more bytes.
            * The RX_NOT_EMPTY interrupt is cleared by the interrupt routine
            * in case the byte was received and read by code above.
            */
            #if (UART_1_CHECK_RX_SW_BUFFER)
            {
                UART_1_EnableInt();
            }
            #endif
        }

        /* Get and clear RX error mask */
        tmpStatus = (UART_1_GetRxInterruptSource() & UART_1_INTR_RX_ERR);
        UART_1_ClearRxInterruptSource(UART_1_INTR_RX_ERR);

        /* Puts together data and error status:
        * MP mode and accept address: 9th bit is set to notify mark.
        */
        rxData |= ((uint32) (tmpStatus << 8u));

        return (rxData);
    }
Beispiel #2
0
/*******************************************************************************
* Function Name: UART_1_ScbModeEnableIntr
********************************************************************************
*
* Summary:
*  Enables an interrupt for a specific mode.
*
* Parameters:
*  None
*
* Return:
*  None
*
*******************************************************************************/
static void UART_1_ScbEnableIntr(void)
{
#if(UART_1_SCB_IRQ_INTERNAL)
    #if(UART_1_SCB_MODE_UNCONFIG_CONST_CFG)
        /* Enable interrupt in NVIC */
        if(0u != UART_1_scbEnableIntr)
        {
            UART_1_EnableInt();
        }
    #else
        UART_1_EnableInt();

    #endif /* (UART_1_SCB_MODE_UNCONFIG_CONST_CFG) */
#endif /* (UART_1_SCB_IRQ_INTERNAL) */
}
    /*******************************************************************************
    * Function Name: UART_1_SpiUartClearRxBuffer
    ****************************************************************************//**
    *
    *  Clears the receive buffer and RX FIFO.
    *
    * \globalvars
    *  UART_1_rxBufferHead - the start index to put data into the 
    *  software receive buffer.
    *  UART_1_rxBufferTail - the start index to get data from the 
    *  software receive buffer.
    *
    *******************************************************************************/
    void UART_1_SpiUartClearRxBuffer(void)
    {
        #if (UART_1_CHECK_RX_SW_BUFFER)
        {
            /* Lock from component interruption */
            UART_1_DisableInt();

            /* Flush RX software buffer */
            UART_1_rxBufferHead = UART_1_rxBufferTail;
            UART_1_rxBufferOverflow = 0u;

            UART_1_CLEAR_RX_FIFO;
            UART_1_ClearRxInterruptSource(UART_1_INTR_RX_ALL);

            #if (UART_1_CHECK_UART_RTS_CONTROL_FLOW)
            {
                /* Enable RX Not Empty interrupt source to continue receiving
                * data into software buffer.
                */
                UART_1_INTR_RX_MASK_REG |= UART_1_INTR_RX_NOT_EMPTY;
            }
            #endif
            
            /* Release lock */
            UART_1_EnableInt();
        }
        #else
        {
            UART_1_CLEAR_RX_FIFO;
        }
        #endif
    }
    /*******************************************************************************
    * Function Name: UART_1_SpiUartClearTxBuffer
    ****************************************************************************//**
    *
    *  Clears the transmit buffer and TX FIFO.
    *
    * \globalvars
    *  UART_1_txBufferHead - the start index to put data into the 
    *  software transmit buffer.
    *  UART_1_txBufferTail - start index to get data from the software
    *  transmit buffer.
    *
    *******************************************************************************/
    void UART_1_SpiUartClearTxBuffer(void)
    {
        #if (UART_1_CHECK_TX_SW_BUFFER)
        {
            /* Lock from component interruption */
            UART_1_DisableInt();

            /* Flush TX software buffer */
            UART_1_txBufferHead = UART_1_txBufferTail;

            UART_1_INTR_TX_MASK_REG &= (uint32) ~UART_1_INTR_TX_NOT_FULL;
            UART_1_CLEAR_TX_FIFO;
            UART_1_ClearTxInterruptSource(UART_1_INTR_TX_ALL);

            /* Release lock */
            UART_1_EnableInt();
        }
        #else
        {
            UART_1_CLEAR_TX_FIFO;
        }
        #endif
    }