예제 #1
0
파일: UART.c 프로젝트: iotexpert/Pinball
/*******************************************************************************
* Function Name: UART_Stop
****************************************************************************//**
*
*  Disables the UART component: disable the hardware and internal 
*  interrupt. It also disables all TX interrupt sources so as not to cause an 
*  unexpected interrupt trigger because after the component is enabled, the 
*  TX FIFO is empty.
*  Refer to the function UART_Enable() for the interrupt 
*  configuration details.
*  This function disables the SCB component without checking to see if 
*  communication is in progress. Before calling this function it may be 
*  necessary to check the status of communication to make sure communication 
*  is complete. If this is not done then communication could be stopped mid 
*  byte and corrupted data could result.
*
*******************************************************************************/
void UART_Stop(void)
{
#if (UART_SCB_IRQ_INTERNAL)
    UART_DisableInt();
#endif /* (UART_SCB_IRQ_INTERNAL) */

    /* Call Stop function specific to current operation mode */
    UART_ScbModeStop();

    /* Disable SCB IP */
    UART_CTRL_REG &= (uint32) ~UART_CTRL_ENABLED;

    /* Disable all TX interrupt sources so as not to cause an unexpected
    * interrupt trigger after the component will be enabled because the 
    * TX FIFO is empty.
    * For SCB IP v0, it is critical as it does not mask-out interrupt
    * sources when it is disabled. This can cause a code lock-up in the
    * interrupt handler because TX FIFO cannot be loaded after the block
    * is disabled.
    */
    UART_SetTxInterruptMode(UART_NO_INTR_SOURCES);

#if (UART_SCB_IRQ_INTERNAL)
    UART_ClearPendingInt();
#endif /* (UART_SCB_IRQ_INTERNAL) */
}
예제 #2
0
    /*******************************************************************************
    * Function Name: UART_SpiUartClearRxBuffer
    ********************************************************************************
    *
    * Summary:
    *  Clears the receive buffer and RX FIFO.
    *
    * Parameters:
    *  None
    *
    * Return:
    *  None
    *
    *******************************************************************************/
    void UART_SpiUartClearRxBuffer(void)
    {
        #if (UART_CHECK_RX_SW_BUFFER)
        {
            /* Lock from component interruption */
            UART_DisableInt();

            /* Flush RX software buffer */
            UART_rxBufferHead = UART_rxBufferTail;
            UART_rxBufferOverflow = 0u;

            UART_CLEAR_RX_FIFO;
            UART_ClearRxInterruptSource(UART_INTR_RX_ALL);

            #if (UART_CHECK_UART_RTS_CONTROL_FLOW)
            {
                /* Enable RX Not Empty interrupt source to continue receiving
                * data into software buffer.
                */
                UART_INTR_RX_MASK_REG |= UART_INTR_RX_NOT_EMPTY;
            }
            #endif

            /* Release lock */
            UART_EnableInt();
        }
        #else
        {
            UART_CLEAR_RX_FIFO;
        }
        #endif
    }
예제 #3
0
    /*******************************************************************************
    * Function Name: UART_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_UartGetByte(void)
    {
        uint32 rxData;
        uint32 tmpStatus;

        #if (UART_CHECK_RX_SW_BUFFER)
        {
            UART_DisableInt();
        }
        #endif

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

            /* Get received byte */
            rxData = UART_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_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_CHECK_RX_SW_BUFFER)
            {
                UART_EnableInt();
            }
            #endif
        }

        /* Get and clear RX error mask */
        tmpStatus = (UART_GetRxInterruptSource() & UART_INTR_RX_ERR);
        UART_ClearRxInterruptSource(UART_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);
    }
예제 #4
0
파일: gps.c 프로젝트: tlshen/FUSIONSDK
char GPSBufferRead()
{
  char u8InChar;
  //int test;
  u8InChar = g_u8RecData[g_u32comRhead];
  g_u32comRhead = (g_u32comRhead == (RXBUFSIZE - 1)) ? 0 : (g_u32comRhead + 1);
  //test = g_u32comRbytes;
  UART_DisableInt(UART1, UART_INTEN_RDAIEN_Msk);
  g_u32comRbytes--;
  UART_EnableInt(UART1, UART_INTEN_RDAIEN_Msk);
  //printf("<%d\n",g_u32comRbytes);
 // if(g_u32comRbytes==0xFFFFFFFF)
  //  printf("Error:0x%x\n",test);
  return u8InChar;
}
예제 #5
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
    }
예제 #6
0
/*---------------------------------------------------------------------------------------------------------*/
void AutoFlow_FunctionRxTest()
{
    uint32_t u32i;

    printf("\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|     Pin Configure                                         |\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|  ______                                            _____  |\n");
    printf("| |      |                                          |     | |\n");
    printf("| |Master|--UART1_TXD(PB.5)  <==>  UART1_RXD(PB.4)--|Slave| |\n");
    printf("| |      |--UART1_nCTS(PB.7) <==> UART1_nRTS(PB.6)--|     | |\n");
    printf("| |______|                                          |_____| |\n");
    printf("|                                                           |\n");
    printf("+-----------------------------------------------------------+\n");

    printf("\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|       AutoFlow Function Test (Slave)                      |\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|  Description :                                            |\n");
    printf("|    The sample code needs two boards. One is Master and    |\n");
    printf("|    the other is slave. Master will send 1k bytes data     |\n");
    printf("|    to slave.Slave will check if received data is correct  |\n");
    printf("|    after getting 1k bytes data.                           |\n");
    printf("|    Press any key to start...                              |\n");
    printf("+-----------------------------------------------------------+\n");
    GetChar();

    /* Enable RTS and CTS autoflow control */
    UART_EnableFlowCtrl(UART1);

    /* Set RTS Trigger Level as 8 bytes */
    UART1->FCR &= ~UART_FCR_RTS_TRI_LEV_Msk;
    UART1->FCR |= UART_FCR_RTS_TRI_LEV_8BYTES;

    /* Set RX Trigger Level as 8 bytes */
    UART1->FCR &= ~UART_FCR_RFITL_Msk;
    UART1->FCR |= UART_FCR_RFITL_8BYTES;

    /* Set Timeout time 0x3E bit-time and time-out counter enable */
    UART_SetTimeoutCnt(UART1, 0x3E);

    /* Enable RDA\RLS\RTO Interrupt  */
    UART_EnableInt(UART1, (UART_IER_RDA_IEN_Msk | UART_IER_RLS_IEN_Msk | UART_IER_TOUT_IEN_Msk));

    printf("\n Starting to receive data...\n");

    /* Wait for receive 1k bytes data */
    while(g_i32pointer < RXBUFSIZE);

    /* Compare Data */
    for(u32i = 0; u32i < RXBUFSIZE; u32i++) {
        if(g_u8RecData[u32i] != (u32i & 0xFF)) {
            printf("Compare Data Failed\n");
            while(1);
        }
    }
    printf("\n Receive OK & Check OK\n");

    /* Disable RDA\RLS\RTO Interrupt */
    UART_DisableInt(UART1, (UART_IER_RDA_IEN_Msk | UART_IER_RLS_IEN_Msk | UART_IER_TOUT_IEN_Msk));

}