/*---------------------------------------------------------------------------------------------------------*/ void IrDA_FunctionTxTest() { uint8_t u8OutChar; printf("\n\n"); printf("+-----------------------------------------------------------+\n"); printf("| IrDA Function Tx Mode Test |\n"); printf("+-----------------------------------------------------------+\n"); printf("| 1). Input char by UART0 terminal. |\n"); printf("| 2). UART1 will send a char according to step 1. |\n"); printf("| 3). Return step 1. (Press '0' to exit) |\n"); printf("+-----------------------------------------------------------+\n\n"); printf("\nIRDA Sample Code Start. \n"); /* In IrDA Mode, Baud Rate configuration must be used MODE0*/ UART1->BAUD = UART_BAUD_MODE0 | UART_BAUD_DIV_MODE0(50000000, 115200); /* IrDA Function Enable */ _UART_SEL_FUNC(UART1,UART_FUNC_SEL_IrDA); /* Set IrDA Tx mode */ _UART_SET_IrDA_TXMODE(UART1,FALSE); /* Wait Terminal input to send data to UART1 TX pin */ do { u8OutChar = GetChar(); printf(" Input: %c , Send %c out\n",u8OutChar,u8OutChar); _UART_SENDBYTE(UART1,u8OutChar); } while(u8OutChar !='0'); }
/*---------------------------------------------------------------------------------------------------------*/ void UART_TEST_HANDLE() { uint8_t u8InChar=0xFF; uint32_t u32IntSts= UART0->ISR; if(u32IntSts & UART_ISR_RDA_INT_Msk) { printf("\nInput:"); /* Get all the input characters */ while(_UART_IS_RX_READY(UART0)) { /* Get the character from UART Buffer */ _UART_RECEIVEBYTE(UART0,u8InChar); /* Rx trigger level is 1 byte*/ printf("%c ", u8InChar); if(u8InChar == '0') { g_bWait = FALSE; } /* Check if buffer full */ if(g_u32comRbytes < RXBUFSIZE) { /* Enqueue the character */ g_u8RecData[g_u32comRtail] = u8InChar; g_u32comRtail = (g_u32comRtail == (RXBUFSIZE-1)) ? 0 : (g_u32comRtail+1); g_u32comRbytes++; } } printf("\nTransmission Test:"); } if(u32IntSts & UART_ISR_THRE_INT_Msk) { uint16_t tmp; tmp = g_u32comRtail; if(g_u32comRhead != tmp) { u8InChar = g_u8RecData[g_u32comRhead]; _UART_SENDBYTE(UART0,u8InChar); g_u32comRhead = (g_u32comRhead == (RXBUFSIZE-1)) ? 0 : (g_u32comRhead+1); g_u32comRbytes--; } } }
/*---------------------------------------------------------------------------------------------------------*/ void RS485_SendAddressByte(uint8_t u8data) { _UART_SET_DATA_FORMAT(UART1,UART_WORD_LEN_8 | UART_PARITY_MARK | UART_STOP_BIT_1); _UART_SENDBYTE(UART1,u8data); }
/*---------------------------------------------------------------------------------------------------------*/ void AutoFlow_FunctionTest() { uint8_t u8Item; uint32_t u32i; printf("+-----------------------------------------------------------+\n"); printf("| Pin Configure |\n"); printf("+-----------------------------------------------------------+\n"); printf("| _______ _______ |\n"); printf("| | | | | |\n"); printf("| |Master |---TXD1(pin46) <====> RXD1(pin45)---| Slave | |\n"); printf("| | |---RTS1(pin39) <====> CTS1(pin40)---| | |\n"); printf("| |_______|---CTS1(pin40) <====> RTS1(pin39)---|_______| |\n"); printf("| |\n"); printf("+-----------------------------------------------------------+\n\n"); /* Set RTS Trigger Level */ UART_SetRTS_TrgLev(UART1,UART_RTS_IS_HIGH_LEV_TRG,UART_FCR_RTS_TRI_LEV_14BYTES); /* Enable RTS and CTS autoflow control */ UART1->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_SENDBYTE(UART1,((u32i+1)&0xFF)); /* Slave will control RTS pin*/ while(_UART_GET_RTSPIN(UART1)); } printf("\n Transmit Done\n"); } else { g_i32pointer = 0; /* Enable RDA\RLS\RTO Interrupt */ _UART_ENABLE_INT(UART1, (UART_IER_RDA_IEN_Msk | UART_IER_THRE_IEN_Msk | UART_IER_RTO_IEN_Msk)); /* Set RX Trigger Level = 8 */ _UART_SET_RX_TRG_LEV(UART1,UART_FCR_RFITL_8BYTES); /* Set Timeout time 0x3E bit-time */ UART_SetTimeOutCounter(UART1,0x3E); NVIC_EnableIRQ(UART1_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(UART1_IRQn); _UART_DISABLE_INT(UART1, (UART_IER_RDA_IEN_Msk | UART_IER_THRE_IEN_Msk | UART_IER_RTO_IEN_Msk)); }