Exemplo n.º 1
0
int platform_s_uart_recv( unsigned id, timer_data_type timeout )
{
  u8 buffer;
  
  if( timeout == 0 )
  {
    if ( UART_Receive(uart[ id ], &buffer, 1, NONE_BLOCKING) == 0 )
      return -1;
    else
      return ( int )buffer;
  }
  
  UART_Receive(uart[ id ], &buffer, 1, BLOCKING);
  return ( int )buffer;
}
Exemplo n.º 2
0
void UART_IntReceive(int which_port)
{
	uint8_t tmpc;
	uint32_t rLen;
	LPC_UART_TypeDef *UARTx;

	UARTx=(LPC_UART_TypeDef *)uartDrvDataArray[which_port].reg_base;
	while(1){
		// Call UART read function in UART driver
		rLen = UART_Receive(UARTx, &tmpc, 1, NONE_BLOCKING);
		// If data received
		if (rLen){
#if 0			
			/* Check if buffer is more space
			 * If no more space, remaining character will be trimmed out
			 */
			if (!__BUF_IS_FULL(rb.rx_head,rb.rx_tail)){
				rb.rx[rb.rx_head] = tmpc;
				__BUF_INCR(rb.rx_head);
			}
#else
			uartDrvDataArray[which_port].cb_rcv(&tmpc,rLen);
#endif
		}
		// no more data
		else {
			break;
		}
	}
}
Exemplo n.º 3
0
/**
 * @brief     This function is used to get connection with finger print device
 * @param[in] none
 * @return    connection status
 */
uint8_t BSP_FP_Connect(void)
{
  uint8_t i,DataBuf[25]={0},RxBuf[25]={0};

  DataBuf[0]=0x7E;
  DataBuf[4]=0x01;                  //command stream to fingerprint
  DataBuf[24]=0x01;                 //0x7e,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1

  UART_Transmit(&DataBuf,25,10);
  UART_Receive(&RxBuf,25,100);

  /**
   *RxBuf[4]==0x01 : Received command must be same as transmitted command
   *RxBuf[8]==0x01 : Stands for successful execution of transmitted command
   *If not executed successfully RxBuf[8] is used to determine error status
   */
  if((RxBuf[4] == 0x01) && (RxBuf[8] == 0x01))
  {
    return(RESULT_SUCCEEDED);
  }
  else
  {
    return(RxBuf[8]);
  }
}
Exemplo n.º 4
0
/*************************************************************
  Function: uint32_t UARTReceive(LPC_UART_TypeDef *UARTPort, uint8_t *rxbuf, uint32_t buflen)
  Description: UART数据接收函数,读取UART FIFO中数据
  Calls:       UART_Receive
  Called By:   UARTx_IRQHandler
  Input:       UARTPort 指定UART端口
               buflen 暂未使用
  Output:      rxbuf 指定接收缓冲区
  Return:      接收到的数据长度
  Others:      无
*************************************************************/
uint32_t UARTReceive ( LPC_UART_TypeDef *UARTPort, uint8_t *rxbuf, uint32_t buflen )
{
    uint8_t tmpc;
    uint32_t rLen, bytes;
    bytes = 0 ;

    while ( 1 )
    {
        // Call UART read function in UART driver
        rLen = UART_Receive ( UARTPort, &tmpc, 1, NONE_BLOCKING );

        // If data received
        if ( rLen )
        {
            *rxbuf = tmpc;
            rxbuf++;
            bytes++;
        }
        // no more data
        else
        {
            break;
        }
    }

    return bytes;
}
Exemplo n.º 5
0
//发生接收中断时调用,基本上是发生8字节中断后调用,或者超时后调用
void UART_IntReceive(void)
{
	uint8_t rlen;//接收数据的长度
	uint8_t chars[16];
	uint8_t index = 0;	
	//接收一个字符
	rlen = UART_Receive((LPC_UART_TypeDef *)_LPC_UART,chars,16,NONE_BLOCKING);
	for(index=0;index<rlen;index++)
	{
		//my_printf("%d ",chars[index]);
		
		if(! ISBufFull(&bufSerialRec))
		{
			//如果缓冲区未满 
			BufPush(&bufSerialRec,chars[index]);
		}
		//获得包结束位
		if(chars[index] == PACKET_EOI)
		{
			//UART_Send((LPC_UART_TypeDef *)_LPC_UART,chars,index,BLOCKING);
			if(!ISBufEmpty(&bufSerialRec))
			{
				OSSemPost(semSerialCommand);
			}
		}
		
	}
}
Exemplo n.º 6
0
uint8_t BSP_FP_DeleteAll(void)
{
  uint8_t DataBuf[25]={0},RxBuf[25]={0};

  DataBuf[0]=0x7e;
  DataBuf[4]=0x23;                      //command stream to fingerprint
  DataBuf[24]=0x23;                     //0x7e,0,0,0,0x37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x37

  UART_Transmit(&DataBuf,25,10);     //send command
  UART_Receive(&RxBuf,25,5000);      //receive acknoledgement

  /**
   *RxBuf[4]==0x23 : Received command must be same as transmitted command
   *RxBuf[8]==0x01 : Stands for successful execution of transmitted command
   *If not executed successfully RxBuf[8] is used to determine error status
   */

  if((RxBuf[4] == 0x23) && (RxBuf[8] == 0x01))
  {
    return(RESULT_SUCCEEDED);
  }
  else
  {
    return(RxBuf[8]);
  }
}
Exemplo n.º 7
0
void tempinit() {
	UART_Receive(&TempUart, UartRom, 8);
	UART_ClearFlag(&TempUart,
			(XMC_UART_CH_STATUS_FLAG_RECEIVER_START_INDICATION
					| XMC_UART_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION));
	UART_TransmitWord(&TempUart, 6); //startet übertragung vom arduino
}
// Function __readc() / __sys_readc
//
// Called by bottom level of scanf routine within RedLib C library to read
// a character. With the default semihosting stub, this would read the character
// from the debugger console window (which acts as stdin). But this version reads
// the character from the LPC1768/RDB1768 UART.
int __sys_readc (void)
{
	/*-- UARTGetChar --*/
	uint8_t tmp = 0;
	UART_Receive(DEBUG_UART_PORT, &tmp, 1, BLOCKING);
	return (int) tmp;
}
Exemplo n.º 9
0
/********************************************************************//**
 * @brief 		UART receive function (ring buffer used)
 * @param[in]	None
 * @return 		None
 *********************************************************************/
static void UART_IntReceive(void)
{
	uint8_t tmpc;
	uint32_t rLen;

	while (1)
	{
		// Call UART read function in UART driver
		rLen = UART_Receive(TEST_UART, &tmpc, 1, NONE_BLOCKING);
		// If data received
		if (rLen)
		{
			/* Check if buffer is more space
			 * If no more space, remaining character will be trimmed out
			 */
			if (!__BUF_IS_FULL(rb.rx_head,rb.rx_tail))
			{
				rb.rx[rb.rx_head] = tmpc;
				__BUF_INCR(rb.rx_head);
			}
		}
		// no more data
		else
		{
			break;
		}
	}
}
Exemplo n.º 10
0
/*-----------------------------------------------------------------------------
 * Receive Call-back dispatch for UART driver
 *-----------------------------------------------------------------------------*/
void UartRxCallBack(void)
{
	uint8_t tmpc, len;
	len = UART_Receive(UARTInfo.pUart, &tmpc, 1, NONE_BLOCKING);
	if ((!__BUF_FULL(BufRx)) && len) {
		__BUF_WR(BufRx, tmpc);
	}
}
Exemplo n.º 11
0
uint8_t comm_get2(int name){
	(void)name; /* avoid warning */
	uint8_t buffer[2], len;
	while (len == 0){
		len = UART_Receive(LPC_UART0, buffer, sizeof(buffer), NONE_BLOCKING);
	}
	return buffer;// buffer;
}
Exemplo n.º 12
0
uint8_t comm_gets(void){
	uint8_t buffer[100];
	uint32_t len;
	while (len == 0){
		len = UART_Receive(LPC_UART0, buffer, sizeof(buffer), NONE_BLOCKING);
	}
	return buffer;
}
Exemplo n.º 13
0
uint8_t BSP_FP_List(uint8_t *database, uint8_t *count)
{
  uint8_t DataBuf[25]={0},RxBuf[25]={0},XtraBuf[998]={0},i,t;
  DataBuf[0]=0x7E;
  DataBuf[4]=0x30;                      //command stream to fingerprint
  DataBuf[24]=0x30;                     //0x7e,0,0,0,0x12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x12

  UART_Transmit(&DataBuf,25,10);         //send command
  UART_Receive(&RxBuf,25,5000);          //receive acknowledgment
  UART_Receive(&XtraBuf,(RxBuf[16]+4),5000);   //receive acknowledgment

  *count=0;
  for(i=0;i<100;i++)
    database[i]=0;

  if(RxBuf[16]>8)
  {
    for(i=4;i<(RxBuf[16]);i+=10)
    {
      t=((XtraBuf[i+2]-0x30)*10+(XtraBuf[i+3]-0x30));
      database[t]=1;                    //storing database.
      *count=*count+1;
    }
  }
  /**
   *RxBuf[4]==0x30 : Received command must be same as transmitted command
   *RxBuf[8]==0x01 : Stands for successful execution of transmitted command
   *If not executed successfully RxBuf[8] is used to determine error status
   */

  if((RxBuf[4] == 0x30) && (RxBuf[8] == 0x01))
  {
    return(RESULT_SUCCEEDED);
  }
  else
  {
    return(RxBuf[8]);
  }
}
Exemplo n.º 14
0
void uartTask(void *data)
{
    data = data;

    while (1) {
        uint32_t bytes_received;
        uint8_t c;

        bytes_received = UART_Receive(LPC_UART, &c, 1, NONE_BLOCKING);
        if (bytes_received > 0) {
            HandleInputChar(c);
        }
    }
}
Exemplo n.º 15
0
void handleReceiveInterrupt() {
    while(!QUEUE_FULL(uint8_t, &listener.serial->receiveQueue)) {
        uint8_t byte;
        uint32_t received = UART_Receive(UART1_DEVICE, &byte, 1, NONE_BLOCKING);
        if(received > 0) {
            QUEUE_PUSH(uint8_t, &listener.serial->receiveQueue, byte);
            if(QUEUE_FULL(uint8_t, &listener.serial->receiveQueue)) {
                pauseReceive();
            }
        } else {
            break;
        }
    }
}
Exemplo n.º 16
0
Arquivo: gps.c Projeto: Feyre/345Final
void GPS_print()
{
	// Print the UART output straight to the terminal screen
	char receive;

	while(1){
		// For all time
		receive = UART_Receive();

		if (receive > 0){
			usb_serial_putchar(receive);
			// Send it back to the computer to print in the console
		}

	}
}
Exemplo n.º 17
0
uint8_t comm_get(void){
#if 0
//	xprintf("%s{\n",__func__);
	uint8_t tmp = 0;
	UART_Receive(LPC_UART0, &tmp, 1, BLOCKING);
	return(tmp);
#endif
#if 1
	uint8_t buffer[1], len;
	while (len == 0){
		len = UARTReceive(LPC_UART0, buffer, 1);
	}
	UART_LINE_LEN=0;
	UART_LINE[0]='\0';
	return buffer;
#endif
}
Exemplo n.º 18
0
	void UART_Main()
	{
		if(UART->RxGO)
		{
			UART->RxGO=0;
			UART_Receive();
			setSegmentDisplayNumber(UART->RxData[5]);
			RCIE=1;	
		}
		else
		{
			if(UART->TxGO)
			{
				UART->TxGO=0;
				UART_Transmit();
			}
		} 
	}
Exemplo n.º 19
0
uint8_t BSP_FP_Delete(uint8_t *id)
{
  uint8_t checksum= 0xc0,DataBuf[25]={0},RxBuf[25]={0};
  int8_t i=0;
  DataBuf[0]=0x7E;
  DataBuf[4]=0x22;
  DataBuf[16]=0x0A;                   //command stream to fingerprint
  DataBuf[24]=0x2C;                   //0x7e,0,0,0,0x22,0,0,0,0,0,0,0,0,0,0,0,0x0a,0,0,0,0,0,0,0,0x2c

  UART_Transmit(&DataBuf,25,10);

  for(i=3;i>=0;i--)
  {
    uprintf("%c",id[i]);             //send  ascii value of id no. digit by digit
    checksum+=id[i] - 0x30;
  }

  for(i=0;i<9;i++)
  {
    uprintf("%c",0x0);               //send command
  }

  uprintf("%c",checksum);            //send checksum

  UART_Receive(&RxBuf,25,5000);    //receive acknowledgment


  /**
   *RxBuf[4]==0x22 : Received command must be same as transmitted command
   *RxBuf[8]==0x01 : Stands for successful execution of transmitted command
   *If not executed successfully RxBuf[8] is used to determine error status
   */

  if((RxBuf[4] == 0x22) && (RxBuf[8] == 0x01))
  {
    return(RESULT_SUCCEEDED);
  }
  else
  {
    return(RxBuf[8]);
  }
}
Exemplo n.º 20
0
/********************************************************************//**
 * @brief 		UART receive function (ring buffer used)
 * @param[in]	None
 * @return 		None
 *********************************************************************/
void UART1_IntReceive(void)
{
	uint8_t tmpc;
	uint32_t rLen;

	while (1){
		// Call UART read function in UART driver
		rLen = UART_Receive((LPC_UART_TypeDef *)LPC_UART1, &tmpc, 1, NONE_BLOCKING);
		// If data received
		if (rLen){

			/* If buffer will be full and RTS is driven manually,
			 * RTS pin should be forced into INACTIVE state
			 */
#if (AUTO_RTS_CTS_USE == 0)
			if (__BUF_WILL_FULL(rb.rx_head, rb.rx_tail))
			{
				if (RTS_State == ACTIVE)
				{
					// Disable request to send through RTS line
					UART_FullModemForcePinState(LPC_UART1, UART1_MODEM_PIN_RTS, \
							INACTIVE);
					RTS_State = INACTIVE;
				}
			}
#endif

			/* Check if buffer is more space
			 * If no more space, remaining character will be trimmed out
			 */
			if (!__BUF_IS_FULL(rb.rx_head,rb.rx_tail)){
				rb.rx[rb.rx_head] = tmpc;
				__BUF_INCR(rb.rx_head);
			}
		}
		// no more data
		else {
			break;
		}
	}
}
Exemplo n.º 21
0
void TurnOnRelays()
{
	unsigned char T = 0;
	
	// wait for command input
	while (!(T))
	{
		T = UART_Receive();
	}	
	
	if(T == '4')
		PORTB = PORTB | 0b00000001;
	else if(T == '3')
		PORTB = PORTB | 0b00000010;
	else if(T == '2')	
		PORTB = PORTB | 0b00000100;
	else if(T == '1')
		PORTB = PORTB | 0b00001000;
	
	EvaluateStatus(FORCE_UPDATE);
}
Exemplo n.º 22
0
int _UARTSendandReceive(uint8_t * args)
{
	int n;
	uint8_t * arg_ptr;
	uint8_t  txbuf[13],		rxbuf[18];
	uint32_t txbuflen=13, rxbuflen=18, length;
	
	for(n=0;n<txbuflen;n++)
	{
		if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1;
			txbuf[n] = (uint8_t) strtoul((char *) arg_ptr, NULL, 16);
	}
	UART_Send((LPC_UART_TypeDef*) LPC_UART1, txbuf, txbuflen, BLOCKING);
	
	//Reception
	length = UART_Receive((LPC_UART_TypeDef*) LPC_UART1, rxbuf, rxbuflen, NONE_BLOCKING);
	sprintf((char *) str, "%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\r\n", rxbuf[0], rxbuf[1], rxbuf[2], rxbuf[3], rxbuf[4], rxbuf[5],rxbuf[6], rxbuf[7], rxbuf[8], rxbuf[9], rxbuf[10], rxbuf[11], rxbuf[12], rxbuf[13], rxbuf[14], rxbuf[15], rxbuf[16], rxbuf[17]);
	writeUSBOutString(str);
	
	return 0;
}
Exemplo n.º 23
0
Arquivo: gps.c Projeto: Feyre/345Final
void GPS_parse(struct GPS_info_struct *GPS_data)
{
	//declare variables
	char receive, rec_G, rec_P;
	char rec_1, rec_2, rec_3;
	
	int8_t RMC_check = -1;
	int8_t VTG_check = -1;

	while(1) // we want to continue to receive data until we are happy with what we have
	{
		// switch LED on to indicate we are in loop
		PORTB |= (1 << 2);

		// continue to receive data until we are at the start of a NMEA sentence (with $)
		receive = UART_Receive();
		if((receive > 0) && receive == '$')
		{
			// The first two characters should be GP, if this is not true continue to cycle data
			rec_G = UART_Receive();
			rec_P = UART_Receive();
			if((rec_G == 'G') && (rec_P == 'P'))
			{
				// Now receive the next three characters - this will tell us what data we are now receiving
				rec_1 = UART_Receive();
				rec_2 = UART_Receive();
				rec_3 = UART_Receive();

				if((rec_1 == 'R') && (rec_2 == 'M') && (rec_3 == 'C'))
					RMC_check = GPS_RMC(GPS_data); // This contains recommended core minimum data
				else if((rec_1 == 'V') && (rec_2 == 'T') && (rec_3 == 'G'))
					VTG_check = GPS_VTG(GPS_data); // This contains speed and course information
				// else if((rec_1 == 'G') && (rec_2 == 'G') && (rec_3 == 'A')) // This contains altitude as well as RMC information - not required for this project
				// else if((rec_1 == 'G') && (rec_2 == 'S') && (rec_3 == 'A')) // This contains sattelite information - not required for project 
				// else if((rec_1 == 'G') && (rec_2 == 'S') && (rec_3 == 'V')) // More sattelite information, again note required for project 
				// else if((rec_1 == 'G') && (rec_2 == 'L') && (rec_3 == 'L')) // Repeat of long/lat/time - already aquired with RMC
				// else // not recognised loop

				if(RMC_check == 0 && VTG_check == 0) // we are happy with the data to send out
				{
					PORTB &= ~(1 << 2);
					break;
				}
			}
		}
	}
}
Exemplo n.º 24
0
// determine command by header character
void AcceptCommands()
{
	unsigned char Temp = 0;
	
	// wait for command input
	while (!(Temp))
	{
		Temp = UART_Receive();
		EvaluateStatus(UPDATE_ONLY_ON_CHANGE);
	}		

	// process command input by inspecting header character
	if (Temp == '?') 
	{
		EvaluateStatus(FORCE_UPDATE);
	}				
	else if (Temp == '=') 
	{
		ControlRelays(); 
	}		
	else if (Temp == '+') 
	{
		TurnOnRelays(); 
	}		
	else if (Temp == '-') 
	{
		TurnOffRelays(); 
	}		
	else if (Temp == 'v') 
	{
		PrintWelcome(); 
	}		
	else
	{
		// unknown command
		PrintError();
	}
}
Exemplo n.º 25
0
void UART0_IRQHandler(void)
{
   uint8_t tmpc;
   uint32_t  tmp, tmp1;
   tmp = ((LPC_UART0->IIR) & UART_IIR_BITMASK) & UART_IIR_INTID_MASK;
   if (tmp == UART_IIR_INTID_RLS)	// Receive Line Status
   {
     tmp1 = UART_GetLineStatus(UART_0);// Check line status
     tmp1 &= (UART_LSR_OE | UART_LSR_PE | UART_LSR_FE | UART_LSR_BI | UART_LSR_RXFE);// Mask out the Receive Ready and Transmit Holding empty status
   }
   if ((tmp == UART_IIR_INTID_RDA) || (tmp == UART_IIR_INTID_CTI))	// Receive Data Available or Character time-out
   {	
       UART_Receive(UART_0, &tmpc, 1, NONE_BLOCKING);
      if(tmpc >= GUI_KEY_MENU  &&  tmpc <= GUI_KEY_PGDOWN)   
      {        
               isKeyTrigged  = 1;
               switch(tmpc)
               {                  
                 case GUI_KEY_TRACE_ENABLE:
                   break;
                 case GUI_KEY_TRACE_DISABLE:
                   break;
                 default:
                    GUI_StoreKeyMsg(tmpc, 1);
                   break;
               }
               
      }   
      else if(tmpc >= 0x80  &&  tmpc <(0x80+21))
      {
         GUI_StoreKeyMsg(GUI_KEY_RELEASE, 1);
      }
      else
      {   
               
      }
   }
}
Exemplo n.º 26
0
void CheckMasterCommand(void)
{
    uint16 CRC=0;

    pDataIn = UART_Receive(&SizeIn);

    if (pDataIn != NULL)
    {
        pDataOut = UART_GetSendBuf();

        pDataOut[0] = UART_SA_CHAR;

        if(ProcessMasterCommand(pDataIn, SizeIn, pDataOut+1, &SizeOut) )
        {


            CRC = CalcCRC16(&pDataOut[1], SizeOut);
            SizeOut++;
            pDataOut[SizeOut++] = CRC & 0xFF;
            pDataOut[SizeOut++] = CRC >> 8;

            UART_SendAnswer(SizeOut);
        }
Exemplo n.º 27
0
/********************************************************************//**
 * @brief 		UART receive function (ring buffer used)
 * @param[in]	None
 * @return 		None
 *********************************************************************/
void UART_IntReceive(void)
{
	uint8_t tmpc;
	uint32_t rLen;
/*
	if(RX_TOG)
		GPIO_SetValue(LED_3_PORT, LED_3_BIT);
	else
		GPIO_ClearValue(LED_3_PORT, LED_3_BIT);
	RX_TOG=!RX_TOG;
*/
	while(1){
		// Call UART read function in UART driver
		rLen = UART_Receive((LPC_UART_TypeDef *)LPC_UART0, &tmpc, 1, NONE_BLOCKING);
		// If data received
		if (rLen){
			UART_LINE[UART_LINE_LEN++]=tmpc;
			if((tmpc=='\r')||(tmpc=='\n')){
				LINE_READY = 1;
				UART_LINE[UART_LINE_LEN-1]='\0';
				UART_LINE_LEN=0;
			}
			/* Check if buffer is more space
			 * If no more space, remaining character will be trimmed out
			 */
			if (!__BUF_IS_FULL(rb.rx_head,rb.rx_tail)){
				rb.rx[rb.rx_head] = tmpc;
				__BUF_INCR(rb.rx_head);
			}
		}
		// no more data
		else {
			break;
		}
	}
}
Exemplo n.º 28
0
uint32_t serialRecv(uint8_t* rxbuf, uint32_t len) {
	return(UART_Receive(LPC_UART3, rxbuf, len, BLOCKING));
}
Exemplo n.º 29
0
uint32_t board_uart_recv(uint8_t *p_buffer, uint32_t length)
{
  return UART_Receive((LPC_USARTn_Type*) LPC_USART0, p_buffer, length, BLOCKING);
}
Exemplo n.º 30
0
/*********************************************************************//**
 * @brief	Main UART testing example sub-routine
 * 			Print welcome screen first, then press any key to have it
 * 			read in from the terminal and returned back to the terminal.
 * 			- Press ESC to exit
 * 			- Press 'r' to print welcome screen menu again
 **********************************************************************/
int c_entry(void)
{
	// UART Configuration structure variable
	UART_CFG_Type UARTConfigStruct;
	// UART FIFO configuration Struct variable
	UART_FIFO_CFG_Type UARTFIFOConfigStruct;
	// Pin configuration for UART0
	PINSEL_CFG_Type PinCfg;

	uint32_t idx, len;
	__IO FlagStatus exitflag;
	uint8_t buffer[10];

	// DeInit NVIC and SCBNVIC
	NVIC_DeInit();
	NVIC_SCBDeInit();

	/* Configure the NVIC Preemption Priority Bits:
	 * two (2) bits of preemption priority, six (6) bits of sub-priority.
	 * Since the Number of Bits used for Priority Levels is five (5), so the
	 * actual bit number of sub-priority is three (3)
	 */
	NVIC_SetPriorityGrouping(0x05);

	//  Set Vector table offset value
#if (__RAM_MODE__==1)
	NVIC_SetVTOR(0x10000000);
#else
	NVIC_SetVTOR(0x00000000);
#endif

#if (UART_PORT == 0)
	/*
	 * Initialize UART0 pin connect
	 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 2;
	PinCfg.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 3;
	PINSEL_ConfigPin(&PinCfg);
#endif

#if (UART_PORT == 1)
	/*
	 * Initialize UART1 pin connect
	 */
	PinCfg.Funcnum = 2;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 0;
	PinCfg.Portnum = 2;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 1;
	PINSEL_ConfigPin(&PinCfg);
#endif

	/* Initialize UART Configuration parameter structure to default state:
	 * Baudrate = 9600bps
	 * 8 data bit
	 * 1 Stop bit
	 * None parity
	 */
	UART_ConfigStructInit(&UARTConfigStruct);

	// Initialize UART0 peripheral with given to corresponding parameter
	UART_Init(TEST_UART, &UARTConfigStruct);

	/* Initialize FIFOConfigStruct to default state:
	 * 				- FIFO_DMAMode = DISABLE
	 * 				- FIFO_Level = UART_FIFO_TRGLEV0
	 * 				- FIFO_ResetRxBuf = ENABLE
	 * 				- FIFO_ResetTxBuf = ENABLE
	 * 				- FIFO_State = ENABLE
	 */
	UART_FIFOConfigStructInit(&UARTFIFOConfigStruct);

	// Initialize FIFO for UART0 peripheral
	UART_FIFOConfig(TEST_UART, &UARTFIFOConfigStruct);


	// Enable UART Transmit
	UART_TxCmd(TEST_UART, ENABLE);

	// print welcome screen
	print_menu();

	// Reset exit flag
	exitflag = RESET;

    /* Read some data from the buffer */
    while (exitflag == RESET)
    {
       len = 0;
        while (len == 0)
        {
            len = UART_Receive(TEST_UART, buffer, sizeof(buffer), NONE_BLOCKING);
        }

        /* Got some data */
        idx = 0;
        while (idx < len)
        {
            if (buffer[idx] == 27)
            {
                /* ESC key, set exit flag */
            	UART_Send(TEST_UART, menu3, sizeof(menu3), BLOCKING);
                exitflag = SET;
            }
            else if (buffer[idx] == 'r')
            {
                print_menu();
            }
            else
            {
                /* Echo it back */
            	UART_Send(TEST_UART, &buffer[idx], 1, BLOCKING);
            }
            idx++;
        }
    }

    // wait for current transmission complete - THR must be empty
    while (UART_CheckBusy(TEST_UART) == SET);

    // DeInitialize UART0 peripheral
    UART_DeInit(TEST_UART);

    /* Loop forever */
    while(1);
    return 1;
}