Beispiel #1
0
/*---------------------------------------------------------------------------------------------------------*/
void UART_FunctionTest()
{
    printf("+-----------------------------------------------------------+\n");
    printf("|  UART Function Test                                       |\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|  Description :                                            |\n");
    printf("|    The sample code will print input char on terminal      |\n");
    printf("|    Please enter any to start     (Press '0' to exit)      |\n");
    printf("+-----------------------------------------------------------+\n");

    /*
        Using a RS232 cable to connect UART0 and PC.
        UART0 is set to debug port. UART0 is enable RDA and RLS interrupt.
        When inputing char to terminal screen, RDA interrupt will happen and
        UART0 will print the received char on screen.
    */

    /* Enable Interrupt and install the call back function */
    UART_ENABLE_INT(UART0, (UART_IER_RDA_IEN_Msk | UART_IER_THRE_IEN_Msk | UART_IER_RTO_IEN_Msk));
    NVIC_EnableIRQ(UART0_IRQn);
    while(g_bWait);

    /* Disable Interrupt */
    UART_DISABLE_INT(UART0, (UART_IER_RDA_IEN_Msk | UART_IER_THRE_IEN_Msk | UART_IER_RTO_IEN_Msk));
    NVIC_DisableIRQ(UART0_IRQn);
    g_bWait = TRUE;
    printf("\nUART Sample Demo End.\n");

}
Beispiel #2
0
/**
 *  @brief The function is used to disable UART specified interrupt and disable NVIC UART IRQ.
 *
 *  @param[in] tUART            Specify UART0/UART1
 *  @param[in] u32InterruptFlag \n
 *                              \b DRVUART_LININT    : LIN Interrupt Enable \n
 *                              \b DRVUART_ABAUDINT  : Auto-Baud Rate Interrupt Enable \n
 *                              \b DRVUART_WAKEINT   : Wakeup Interrupt \n
 *                              \b DRVUART_BUFERRINT : Buffer Error Interrupt Enable \n
 *                              \b DRVUART_TOUTINT   : Time-out Interrupt Enable \n
 *                              \b DRVUART_MOSINT    : MODEM Status Interrupt Enable \n
 *                              \b DRVUART_RLSNT     : Receive Line Status Interrupt Enable \n
 *                              \b DRVUART_THREINT   : Transmit Holding Register Empty Interrupt Enable \n
 *                              \b DRVUART_RDAINT    : Receive Data Available Interrupt Enable 
 *
 *  @par Include:
 *       nano1xx_drivers/nano1xx_uart.h
 *
 *  @return None
 *
 *  @note Use "|" to connect the interrupt flags to disable multiple interrupts simultaneously.
 *
 *  @par Example:
 *  @code
 *   //To disable the THRE interrupt enable flag
 *   UART_DisableInt (UART_PORT0, DRVUART_THREINT);
 *  @endcode
 *
 */
void DrvUART_DisableInt(UART_T  *tUART, uint32_t u32InterruptFlag)
{
    UART_DISABLE_INT(tUART, u32InterruptFlag);
    if (tUART == UART0)
    {
        NVIC_DisableIRQ(UART0_IRQn);   
    }
    else
    {
       	NVIC_DisableIRQ(UART1_IRQn);    
    }
}
Beispiel #3
0
/**
 *    @brief        Disable UART specified interrupt
 *
 *    @param[in]    uart                The pointer of the specified UART module.
 *    @param[in]    u32InterruptFlag    The specified interrupt of UART module.
 *                                      - \ref UART_INTEN_WKCTSIEN_Msk   : CTS wake-up interrupt
 *                                      - \ref UART_INTEN_WKDATIEN_Msk   : Data wake-up interrupt
 *                                      - \ref UART_INTEN_LINIEN_Msk     : Lin bus interrupt
 *                                      - \ref UART_INTEN_BUFERRIEN_Msk  : Buffer Error interrupt
 *                                      - \ref UART_INTEN_RXTOIEN_Msk    : Rx time-out interrupt
 *                                      - \ref UART_INTEN_MODEMIEN_Msk   : Modem status interrupt
 *                                      - \ref UART_INTEN_RLSIEN_Msk     : Receive Line status interrupt
 *                                      - \ref UART_INTEN_THREIEN_Msk    : Tx empty interrupt
 *                                      - \ref UART_INTEN_RDAIEN_Msk     : Rx ready interrupt *
 *
 *    @return       None
 *
 *    @details      The function is used to disable UART specified interrupt and disable NVIC UART IRQ.
 */
void UART_DisableInt(UART_T*  uart, uint32_t u32InterruptFlag)
{
    /* Disable UART specified interrupt */
    UART_DISABLE_INT(uart, u32InterruptFlag);

    /* Disable NVIC UART IRQ */
    if(uart == UART0)
        NVIC_DisableIRQ(UART0_IRQn);
    else if(uart == UART1)
        NVIC_DisableIRQ(UART1_IRQn);
    else if(uart == UART2)
        NVIC_DisableIRQ(UART2_IRQn);
    else
        NVIC_DisableIRQ(UART3_IRQn);
}
Beispiel #4
0
/*---------------------------------------------------------------------------------------------------------*/
void AutoFlow_FunctionTest()
{
    uint8_t u8Item;
    uint32_t u32i;
    printf("+-----------------------------------------------------------+\n");
    printf("|     Pin Configure                                         |\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|  _______                                      _______     |\n");
    printf("| |       |                                    |       |    |\n");  
    printf("| |Master |---TXD0(pin46) <====> RXD0(pin45)---| Slave |    |\n");  
    printf("| |       |---RTS0(pin37) <====> CTS0(pin38)---|       |    |\n");  
    printf("| |_______|---CTS0(pin38) <====> RTS0(pin37)---|_______|    |\n");  
    printf("|                                                           |\n");
    printf("+-----------------------------------------------------------+\n\n");  

    /* Set RTS Trigger Level */
    UART->MCR |= UART_RTS_IS_HIGH_LEV_TRG;
    UART->FCR = (UART->FCR &~ UART_FCR_RTS_TRI_LEV_Msk) | UART_FCR_RTS_TRI_LEV_14BYTES;
    
    /* Enable RTS and CTS autoflow control */
    UART->IER |= UART_IER_AUTO_RTS_EN_Msk | UART_IER_AUTO_CTS_EN_Msk;
    
    printf("+-----------------------------------------------------------+\n");
    printf("|       AutoFlow Function Test                              |\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("|  Please select Master or Slave test                       |\n");
    printf("|  [0] Master    [1] Slave                                  |\n");
    printf("+-----------------------------------------------------------+\n\n");
    u8Item = getchar();
    
    
    if(u8Item=='0')
    {
        for(u32i=0;u32i<(RXBUFSIZE-1);u32i++)
        {
            UART_WRITE(UART,((u32i+1)&0xFF));

            /* Slave will control RTS pin*/
            while(UART->MCR & UART_MCR_RTS_ST_Msk);
        }
        printf("\n Transmit Done\n");
    }
    else
    {
        g_i32pointer = 0;
    
        /* Enable RDA\RLS\RTO Interrupt  */
        UART_ENABLE_INT(UART, (UART_IER_RDA_IEN_Msk | UART_IER_THRE_IEN_Msk | UART_IER_RTO_IEN_Msk));

        /* Set RX Trigger Level = 8 */
        UART->FCR = (UART->FCR &~ UART_FCR_RFITL_Msk) | UART_FCR_RFITL_8BYTES;

        /* Set Timeout time 0x3E bit-time */
        UART_SetTimeoutCnt(UART,0x3E);
        
        NVIC_EnableIRQ(UART_IRQn);

        printf("Starting to recevice %d bytes data...\n", RXBUFSIZE);
        
        while(g_i32pointer<(RXBUFSIZE-1))
        {
            printf("%d\r",g_i32pointer);
        }

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

    NVIC_DisableIRQ(UART_IRQn);

    UART_DISABLE_INT(UART, (UART_IER_RDA_IEN_Msk | UART_IER_THRE_IEN_Msk | UART_IER_RTO_IEN_Msk));
}
Beispiel #5
0
/*---------------------------------------------------------------------------------------------------------*/
void PDMA_UART(int32_t i32option)
{    
    /* Source data initiation */    
	BuildSrcPattern((uint32_t)SrcArray, UART_TEST_LENGTH);
    ClearBuf((uint32_t)DestArray, UART_TEST_LENGTH, 0xFF);
    
    /* Reset PDMA module */
    SYS->IPRSTC1 |=  SYS_IPRSTC1_PDMA_RST_Msk;
    SYS->IPRSTC1 &= ~SYS_IPRSTC1_PDMA_RST_Msk;  

	if(i32option =='1')
	{
		printf("  [Using TWO PDMA channel].\n");
	 	printf("  This sample code will use PDMA to do UART1 loopback test 10 times.\n");
        printf("  Please connect UART1_RXD(PB.4) <--> UART1_TXD(PB.5) before testing.\n");
	    printf("  After connecting PB.4 <--> PB.5, press any key to start transfer.\n");  
	    g_u32TwoChannelPdmaTest = 1;
        getchar();
	}
	else
	{
		UART_TEST_LENGTH = 2;	   /* Test Length */
 		printf("  [Using ONE PDMA channel].\n");
	 	printf("  This sample code will use PDMA to do UART1 Rx test 10 times.\n");
        printf("  Please connect UART1_RXD(PB.4) <--> UART1_TXD(PB.5) before testing.\n");
	    printf("  After connecting PB.4 <--> PB.5, press any key to start transfer.\n");
        g_u32TwoChannelPdmaTest = 0; 
	    getchar();
		printf("  Please input %d bytes to trigger PDMA one time.(Ex: Press 'a''b')\n", UART_TEST_LENGTH);
	}
 
	if(g_u32TwoChannelPdmaTest==1)
	{                   
        /* Enable PDMA channel 1 clock */  
        PDMA_GCR->GCRCSR |= PDMA_GCRCSR_CLK1_EN_Msk;           

        /* UART Tx PDMA configuration */          
        PDMA_UART_TxTest();             
	}
        
    /* Enable PDMA channel 0 clock */  
    PDMA_GCR->GCRCSR |= PDMA_GCRCSR_CLK0_EN_Msk; 

    /* UART Rx PDMA configuration */          
    PDMA_UART_RxTest();  

	/* Enable PDMA Channel 0 Block Transfer Done Interrupt */ 
    PDMA0->IER |= PDMA_IER_BLKD_IE_Msk;      
 	IntCnt = 0;       
    IsTestOver = FALSE;        
    NVIC_EnableIRQ(PDMA_IRQn);
    
    /* Enable UART0 RDA interrupt */
    if(g_u32TwoChannelPdmaTest==0)
    {
        UART_ENABLE_INT(UART0, UART_IER_RDA_IEN_Msk);
        NVIC_EnableIRQ(UART02_IRQn); 
    }
    
	/* Trigger PDMA */
    PDMA0->CSR |= (PDMA_CSR_TRIG_EN_Msk | PDMA_CSR_PDMACEN_Msk);    

	if(g_u32TwoChannelPdmaTest==1)
        PDMA1->CSR |= (PDMA_CSR_TRIG_EN_Msk | PDMA_CSR_PDMACEN_Msk);  
    
    /* Enable UART Tx and Rx PDMA function */
    if(g_u32TwoChannelPdmaTest==1)
        UART1->IER |= UART_IER_DMA_TX_EN_Msk;   
    else
        UART1->IER &= ~UART_IER_DMA_TX_EN_Msk;
        
    UART1->IER |= UART_IER_DMA_RX_EN_Msk; 

    /* Wait for PDMA operation finish */
    while(IsTestOver == FALSE);   

    /* Disable UART Tx and Rx PDMA function */    
	UART1->IER &= ~(UART_IER_DMA_TX_EN_Msk|UART_IER_DMA_RX_EN_Msk);   
    
    /* Disable PDMA channel */
    PDMA_GCR->GCRCSR = 0;   
    
	/* Disable PDMA Interrupt */
    PDMA0->IER &= ~PDMA_IER_BLKD_IE_Msk; 
    NVIC_DisableIRQ(PDMA_IRQn);    
    
    /* Disable UART0 RDA interrupt */
    UART_DISABLE_INT(UART0, UART_IER_RDA_IEN_Msk);
    NVIC_DisableIRQ(UART02_IRQn);   	
}
Beispiel #6
0
/*---------------------------------------------------------------------------------------------------------*/
void RS485_9bitModeSlave()
{

    printf("\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|     Pin Configure                                         |\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|    _______                                    _______     |\n");
    printf("|   |       |                                  |       |    |\n");
    printf("|   |Master |---TXD1(P1.3) <====> RXD1(P1.2)---| Slave |    |\n");
    printf("|   |       |---RTS1(P0.1) <====> RTS1(P0.1)---|       |    |\n");
    printf("|   |_______|                                  |_______|    |\n");
    printf("|                                                           |\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|           RS485  Function Test (9-bit Slave)              |\n");
    printf("+-----------------------------------------------------------+\n");

    /*
        The sample code is used to test RS485 9-bit mode and needs
        two Module test board to complete the test.
        Master:
            1.Set AUD mode and HW will control RTS pin. LEV_RTS is set to '0'.
            2.Master will send four different address with 10 bytes data to test Slave.
            3.Address bytes : the parity bit should be '1'. (Set UA_LCR = 0x2B)
            4.Data bytes : the parity bit should be '0'. (Set UA_LCR = 0x3B)
            5.RTS pin is low in idle state. When master is sending,
              RTS pin will be pull high.

        Slave:
            1.Set AAD and AUD mode firstly. LEV_RTS is set to '0'.
            2.The received byte, parity bit is '1' , is considered "ADDRESS".
            3.The received byte, parity bit is '0' , is considered "DATA".  (Default)
            4.AAD: The slave will ignore any data until ADDRESS match ADDR_MATCH value.
              When RLS and RDA interrupt is happened,it means the ADDRESS is received.
              Check if RS485_ADD_DETF is set and read UA_RBR to clear ADDRESS stored in rx_fifo.

              NMM: The slave will ignore data byte until disable RX_DIS.
              When RLS and RDA interrupt is happened,it means the ADDRESS is received.
              Check the ADDRESS is match or not by user in UART_IRQHandler.
              If the ADDRESS is match,clear RX_DIS bit to receive data byte.
              If the ADDRESS is not match,set RX_DIS bit to avoid data byte stored in FIFO.
    */

    /* Select UART RS485 function mode */
    UART1->FUN_SEL = UART_FUNC_SEL_RS485;

    /* Set Data Format, Only need parity enable whenever parity ODD/EVEN */
    UART1->LCR = (UART_WORD_LEN_8 | UART_PARITY_EVEN | UART_STOP_BIT_1);

    /* Set RTS pin active level as low level active */
    UART1->MCR = UART1->MCR & (~UART_MCR_LEV_RTS_Msk) | UART_RTS_IS_LOW_LEV_ACTIVE;

#if(IS_USE_RS485NMM == 1)

    printf("\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|    Normal Multidrop Operation Mode                        |\n");
    printf("+-----------------------------------------------------------+\n");
    printf("| The function is used to test 9-bit slave mode.            |\n");
    printf("| Only Address %x and %x,data can receive                   |\n", MATCH_ADDRSS1, MATCH_ADDRSS2);
    printf("+-----------------------------------------------------------+\n");

    /* Set RX_DIS enable before set RS485-NMM mode */
    UART1->FCR |= UART_FCR_RX_DIS_Msk;

    /* Set RS485-NMM Mode, RS485 address detection enable */
    UART1->ALT_CSR = UART_ALT_CSR_RS485_NMM_Msk    |
                     UART_ALT_CSR_RS485_ADD_EN_Msk |
                     UART_ALT_CSR_RS485_AUD_Msk;

#else
    printf("Auto Address Match Operation Mode\n");
    printf("+-----------------------------------------------------------+\n");
    printf("| The function is used to test 9-bit slave mode.            |\n");
    printf("|    Auto Address Match Operation Mode                      |\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|Only Address %x,data can receive                           |\n", MATCH_ADDRSS1);
    printf("+-----------------------------------------------------------+\n");

    /* Set RS485-AAD Mode, address match is 0xC0 and RS485 address detection enable */
    UART1->ALT_CSR = UART_ALT_CSR_RS485_AAD_Msk    |
                     UART_ALT_CSR_RS485_ADD_EN_Msk |
                     UART_ALT_CSR_RS485_AUD_Msk    |
                     ((uint32_t)(MATCH_ADDRSS1) << UART_ALT_CSR_ADDR_MATCH_Pos) ;

#endif

    /* Enable RDA\RLS\Time-out Interrupt */
    UART1->IER |= UART_IER_RDA_IEN_Msk | UART_IER_RLS_IEN_Msk | UART_IER_RTO_IEN_Msk;

    /* Enable UART1 IRQ */
    NVIC_EnableIRQ(UART1_IRQn);

    printf("Ready to receive data...(Press any key to stop test)\n");
    GetChar();

    /* Flush Rx FIFO */
    UART1->FCR |= UART_FCR_RFR_Msk;

    /* Disable RDA\RLS\Time-out Interrupt */
    UART_DISABLE_INT(UART1, (UART_IER_RDA_IEN_Msk | UART_IER_RLS_IEN_Msk | UART_IER_RTO_IEN_Msk));

    printf("\nEnd test\n");

}
Beispiel #7
0
/*---------------------------------------------------------------------------------------------------------*/
void UART_PDMATest()
{
    uint32_t i;
    uint32_t TEST_SIZE = 100;

    printf("+-----------------------------------------------------------+\n");
    printf("|  UART PDMA Test                                           |\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|  Description :                                            |\n");
    printf("|    The sample code will demo uart PDMA function.          |\n");
    printf("|    Please connect UART1 Tx, Rx pin.                       |\n");
    printf("+-----------------------------------------------------------+\n");

    /*
        connect UART1 Tx, Rx pin.
        UART1 will transfer data from Tx PDMA buffer.
        And will receive data to Rx PDMA buffer.
        This test function will compare Tx and Rx buffer data.
    */

    for(i = 0; i < TEST_SIZE; i++)
    {
        TX_Buffer[i] = (i & 0xff);
        RX_Buffer[i] = 0;
    }

    /* Enable Interrupt and install the call back function */
    UART_ENABLE_INT(UART1, (UART_IER_RLS_IE_Msk | UART_IER_BUF_ERR_IE_Msk) );
    NVIC_EnableIRQ(UART1_IRQn);

    // Rx PDMA Setting
    PDMA_Open(1 << RX_CH);
    PDMA_SetTransferCnt(RX_CH, PDMA_WIDTH_8, TEST_SIZE);
    PDMA_SetTransferAddr(RX_CH, UART1_BASE, PDMA_SAR_FIX, (uint32_t)RX_Buffer, PDMA_DAR_INC);
    PDMA_SetTransferMode(RX_CH, PDMA_UART1_RX, 0, 0);
    PDMA_SetTimeOut(RX_CH, 0, 0x5555);
    PDMA_EnableInt(RX_CH, PDMA_IER_TD_IE_Msk);
    NVIC_EnableIRQ(PDMA_IRQn);
    u32IsTestOver = 0;

    // Tx PDMA Setting
    PDMA_Open(1 << TX_CH);
    PDMA_SetTransferCnt(TX_CH, PDMA_WIDTH_8, TEST_SIZE);
    PDMA_SetTransferAddr(TX_CH, (uint32_t)TX_Buffer, PDMA_SAR_INC, UART1_BASE, PDMA_DAR_FIX);
    PDMA_SetTransferMode(TX_CH, PDMA_UART1_TX, 0, 0);
    PDMA_SetTimeOut(TX_CH, 0, 0x5555);
    PDMA_EnableInt(TX_CH, PDMA_IER_TD_IE_Msk);
    NVIC_EnableIRQ(PDMA_IRQn);
    u32IsTestOver = 0;

    PDMA_Trigger(RX_CH);
    PDMA_Trigger(TX_CH);

    UART1->CTL |= UART_CTL_DMA_RX_EN_Msk;
    UART1->CTL |= UART_CTL_DMA_TX_EN_Msk;

    while(u32IsTestOver == 0);

    for(i = 0; i < TEST_SIZE; i++)
    {
        if(TX_Buffer[i] != RX_Buffer[i])
        {
            printf("\n Test fail!!");
            while(1);
        }
    }

    printf("\n Tx/Rx data compare pass!!");

    /* Disable Interrupt */
    UART_DISABLE_INT(UART1, (UART_IER_RLS_IE_Msk | UART_IER_BUF_ERR_IE_Msk));
    NVIC_DisableIRQ(UART1_IRQn);

    printf("\n UART PDMASample Demo End.\n");

}