示例#1
0
/*********************************************************************//**
 * @brief		UART1 interrupt handler sub-routine
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void UART1_IRQHandler(void)
{
	// Call Standard UART 0 interrupt handler
	uint32_t intsrc, tmp, tmp1;

	/* Determine the interrupt source */
	intsrc = UART_GetIntId(LPC_UART0);
	tmp = intsrc & UART_IIR_INTID_MASK;

	// Receive Line Status
	if (tmp == UART_IIR_INTID_RLS){
		// Check line status
		tmp1 = UART_GetLineStatus(LPC_UART0);
		// Mask out the Receive Ready and Transmit Holding empty status
		tmp1 &= (UART_LSR_OE | UART_LSR_PE | UART_LSR_FE \
				| UART_LSR_BI | UART_LSR_RXFE);
		// If any error exist
		if (tmp1) {
			UART_IntErr(tmp1);
		}
	}

	// Receive Data Available or Character time-out
	if ((tmp == UART_IIR_INTID_RDA) || (tmp == UART_IIR_INTID_CTI)){
		UART_IntReceive();
	}
}
示例#2
0
文件: uart.c 项目: nedos/ddk-arm
void UART3_IRQHandler(void)
{
    g_u3char_available=0;
    g_u3char = 0;

    unsigned int id = UART_GetIntId((LPC_UART_TypeDef *)FPGA_UART3_PORT);
    unsigned int temp = 0;

    switch(id) {
        case 6:
            // RX Line Status / Error
            temp = FPGA_UART3_PORT->LSR;
            break;

        case 4:
            g_u3char = UART_ReceiveByte((LPC_UART_TypeDef *)FPGA_UART3_PORT);
            g_u3char_available=1;
            break;

        case 0xc:
            // Character Time-out indication
            temp = FPGA_UART3_PORT->RBR;
            break;
        case 2:
            // THRE
            temp = FPGA_UART3_PORT->IIR;
            break;
        default:
            break;
    }

   return;
}
示例#3
0
void UART1_IRQHandler() {
    uint32_t interruptSource = UART_GetIntId(UART1_DEVICE)
        & UART_IIR_INTID_MASK;

    if(interruptSource == 0) {
        // Check Modem status
        uint8_t modemStatus = UART_FullModemGetStatus(LPC_UART1);
        // Check CTS status change flag
        if (modemStatus & UART1_MODEM_STAT_DELTA_CTS) {
            // if CTS status is active, continue to send data
            if (modemStatus & UART1_MODEM_STAT_CTS) {
                CTS_STATE = ACTIVE;
                UART_TxCmd(UART1_DEVICE, ENABLE);
            } else {
                // Otherwise, Stop current transmission immediately
                CTS_STATE = INACTIVE;
                UART_TxCmd(UART1_DEVICE, DISABLE);
            }
        }
    }

    switch(interruptSource) {
        case UART_IIR_INTID_RDA:
        case UART_IIR_INTID_CTI:
            handleReceiveInterrupt();
            break;
        case UART_IIR_INTID_THRE:
            handleTransmitInterrupt();
            break;
    }
}
示例#4
0
/*******************************************************************************
 * Function Name  : USART4_IRQHandler
 * Description    : This function handles USART0 global interrupt request.
 * Input          : None
 * Output         : None
 * Return         : None
 *******************************************************************************/
void USART4_IRQHandler(void)
{
	uint32_t intsrc;
	uint8_t lineStatus;
	
	OSIntEnter();																		/****通知os进入中断*/
	
	intsrc=UART_GetIntId(UART_4);
	if((intsrc&0x0f)==UART_IIR_INTID_RLS)						/****接收线中断****/
	{
		//2.1 检查线状态
		lineStatus = UART_GetLineStatus(UART_4);//读取LSR时中断会被清除
		prvvUARTRxISR(RS485_4);
					
	}
	/****接收数据或者超时中断****/
	else if (((intsrc&0x0f) == UART_IIR_INTID_RDA) || ((intsrc&0x0f) == UART_IIR_INTID_CTI))
	{
		prvvUARTRxISR(RS485_4);
	}
	/******发送中断*************/
	else if((intsrc&0x0f) == UART_IIR_INTID_THRE)
	{	
		prvvUARTTxReadyISR(RS485_4);
	}
	OSIntExit();											/*****通知os退出中断******/
}
示例#5
0
/*********************************************************************//**
 * @brief		UART1 interrupt handler sub-routine
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void UART1_IRQHandler(void)
{
	uint8_t modemsts;
	uint32_t intsrc, tmp, tmp1;

	/* Determine the interrupt source */
	intsrc = UART_GetIntId((LPC_UART_TypeDef *)LPC_UART1);
	tmp = intsrc & UART_IIR_INTID_MASK;

	/*
	 * In case of using UART1 with full modem,
	 * interrupt ID = 0 that means modem status interrupt has been detected
	 */

	if (tmp == 0){
		// Check Modem status
		modemsts = UART_FullModemGetStatus(LPC_UART1);
		#if (AUTO_RTS_CTS_USE == 0)
			// Check CTS status change flag
			if (modemsts & UART1_MODEM_STAT_DELTA_CTS) {
				// if CTS status is active, continue to send data
				if (modemsts & UART1_MODEM_STAT_CTS) {
					// Re-Enable Tx
					UART_TxCmd((LPC_UART_TypeDef *)LPC_UART1, ENABLE);
				}
				// Otherwise, Stop current transmission immediately
				else{
					// Disable Tx
					UART_TxCmd((LPC_UART_TypeDef *)LPC_UART1, DISABLE);
				}
			}
		#endif
	}

	// Receive Line Status
	if (tmp == UART_IIR_INTID_RLS){
		// Check line status
		tmp1 = UART_GetLineStatus((LPC_UART_TypeDef *)LPC_UART1);
		// Mask out the Receive Ready and Transmit Holding empty status
		tmp1 &= (UART_LSR_OE | UART_LSR_PE | UART_LSR_FE \
				| UART_LSR_BI | UART_LSR_RXFE);
		// If any error exist
		if (tmp1) {
			UART1_IntErr(tmp1);
		}
	}

	// Receive Data Available or Character time-out
	if ((tmp == UART_IIR_INTID_RDA) || (tmp == UART_IIR_INTID_CTI)){
		UART1_IntReceive();
	}

	// Transmit Holding Empty
	if (tmp == UART_IIR_INTID_THRE){
		UART1_IntTransmit();
	}
}
示例#6
0
void UART3_IRQHandler(void)
{
  volatile uint32_t intId = UART_GetIntId(SERIAL_USART);

  if(intId & 0x02)
    sendDataToFifo();

  NVIC_ClearPendingIRQ(UART3_IRQn);

}
示例#7
0
/*********************************************************************//**
 * @brief	UART0 interrupt handler sub-routine
 * @param	None
 * @return	None
 **********************************************************************/
void UART0_IRQHandler(void)
{
	// Call Standard UART 0 interrupt handler
	uint32_t intsrc, tmp, tmp1;

	/* Determine the interrupt source */
	intsrc = UART_GetIntId(LPC_UART0);
	tmp = intsrc & UART_IIR_INTID_MASK;

	// Receive Line Status
	if (tmp == UART_IIR_INTID_RLS){
		// Check line status
		tmp1 = UART_GetLineStatus(LPC_UART0);
		// Mask out the Receive Ready and Transmit Holding empty status
		tmp1 &= (UART_LSR_OE | UART_LSR_PE | UART_LSR_FE \
				| UART_LSR_BI | UART_LSR_RXFE);
		// If any error exist
		if (tmp1) {

			while(tmp1){
				; //implement error handling here
			}
		}
	}


	intsrc &= (UART_IIR_ABEO_INT | UART_IIR_ABTO_INT);
	// Check if End of auto-baudrate interrupt or Auto baudrate time out
	if (intsrc){
		// Clear interrupt pending
		if(intsrc & UART_IIR_ABEO_INT)
			UART_ABClearIntPending(LPC_UART0, UART_AUTOBAUD_INTSTAT_ABEO);
		if (intsrc & UART_IIR_ABTO_INT)
			UART_ABClearIntPending(LPC_UART0, UART_AUTOBAUD_INTSTAT_ABTO);
			if (Synchronous == RESET)
			{
				/* Interrupt caused by End of auto-baud */
				if (intsrc & UART_AUTOBAUD_INTSTAT_ABEO){
					// Disable AB interrupt
					UART_IntConfig(LPC_UART0, UART_INTCFG_ABEO, DISABLE);
					// Set Sync flag
					Synchronous = SET;
				}

				/* Auto-Baudrate Time-Out interrupt (not implemented) */
				if (intsrc & UART_AUTOBAUD_INTSTAT_ABTO) {
					/* Just clear this bit - Add your code here */
					UART_ABClearIntPending(LPC_UART0, UART_AUTOBAUD_INTSTAT_ABTO);
				}
			}
	}
}
示例#8
0
/*******************************************************************************
 * Function Name  : USART0_IRQHandler
 * Description    : This function handles USART0 global interrupt request.
 * Input          : None
 * Output         : None
 * Return         : None
 *******************************************************************************/
void USART0_IRQHandler(void)
{
//	rt_interrupt_enter();
//	//溢出错误
//	if (USART_GetFlagStatus(USART2, USART_FLAG_ORE) == SET)
//	{
//		prvvUARTRxISR();
//	}
//	//接收中断
//	if (USART_GetITStatus(USART2, USART_IT_RXNE) == SET)
//	{
//		USART_ClearITPendingBit(USART2, USART_IT_RXNE);
//		prvvUARTRxISR();
//	}
//	//发送中断
//	if (USART_GetITStatus(USART2, USART_IT_TXE) == SET)
//	{
//		prvvUARTTxReadyISR();
//	}
//	rt_interrupt_leave();
	
	uint32_t intsrc;
	uint8_t lineStatus;
	
	OSIntEnter();																		/****通知os进入中断*/
	
	intsrc=UART_GetIntId(UART_0);
	if((intsrc&0x0f)==UART_IIR_INTID_RLS)						/****接收线中断****/
	{
		//2.1 检查线状态
		lineStatus = UART_GetLineStatus(UART_0);//读取LSR时中断会被清除
		prvvUARTRxISR(RS485_1);
					
	}
	/****接收数据或者超时中断****/
	else if (((intsrc&0x0f) == UART_IIR_INTID_RDA) || ((intsrc&0x0f) == UART_IIR_INTID_CTI))
	{
		prvvUARTRxISR(RS485_1);
	}
	/******发送中断*************/
	else if((intsrc&0x0f) == UART_IIR_INTID_THRE)
	{	
		prvvUARTTxReadyISR(RS485_1);
	}
	OSIntExit();											/*****通知os退出中断******/
	
}
示例#9
0
/*************************************************************
  Function: void UART2_IRQHandler (void)
  Description: UART2中断函数,RS485接收中断
  Calls:
  Called By:   无
  Input:       无
  Output:      RS485Rx1.Len RS485Rx1.Idx RS485Rx1.Flag
  Return:      无
  Others:      无
*************************************************************/
void UART2_IRQHandler ( void )
{
    uint32_t intsrc, tmp, tmp1;

    /* Determine the interrupt source */
    intsrc = UART_GetIntId ( LPC_UART2 );
    tmp = intsrc & UART_IIR_INTID_MASK;

    // Receive Line Status
    if ( tmp == UART_IIR_INTID_RLS )
    {
        // Check line status
        tmp1 = UART_GetLineStatus ( LPC_UART2 );
        // Mask out the Receive Ready and Transmit Holding empty status
        tmp1 &= ( UART_LSR_OE | UART_LSR_PE | UART_LSR_FE \
                  | UART_LSR_BI | UART_LSR_RXFE );

        // If any error exist
        if ( tmp1 )
        {
            RS4852_Err++;
        }
    }

    // Receive Data Available
    if ( ( tmp == UART_IIR_INTID_RDA ) )
    {
        RS485Rx2.Len += UARTReceive ( LPC_UART2, &RS485Rx2.Buff[RS485Rx2.Idx], 0 );
        RS485Rx2.Idx = RS485Rx2.Len ;
        FrameCntRS4852 = 0 ;
    }

    //Character time-out
    if  ( tmp == UART_IIR_INTID_CTI )
    {
        RS485Rx2.Len += UARTReceive ( LPC_UART2, &RS485Rx2.Buff[RS485Rx2.Idx], 0 );
        RS485Rx2.Idx = RS485Rx2.Len ;
        RS485Rx2.Flag = 1 ;

    }
}
示例#10
0
/*************************************************************
  Function: void UART3_IRQHandler (void)
  Description: UART3中断函数,RS232接收中断
  Calls:
  Called By:   无
  Input:       无
  Output:      RS232Rx.Len RS232Rx.Idx RS232Rx.Flag
  Return:      无
  Others:      无
*************************************************************/
void UART3_IRQHandler ( void )
{
    uint32_t intsrc, tmp, tmp1;

    /* Determine the interrupt source */
    intsrc = UART_GetIntId ( RS232_UART );
    tmp = intsrc & UART_IIR_INTID_MASK;

    // Receive Line Status
    if ( tmp == UART_IIR_INTID_RLS )
    {
        // Check line status
        tmp1 = UART_GetLineStatus ( RS232_UART );
        // Mask out the Receive Ready and Transmit Holding empty status
        tmp1 &= ( UART_LSR_OE | UART_LSR_PE | UART_LSR_FE \
                  | UART_LSR_BI | UART_LSR_RXFE );

        // If any error exist
        if ( tmp1 )
        {
            RS232_Err++;//UART_DeInit(RS232_UART);UartInit ( 0, 115200, UART_PARITY_NONE );
        }
    }

    // Receive Data Available
    if ( ( tmp == UART_IIR_INTID_RDA ) )
    {
        RS232Rx.Len += UARTReceive ( RS232_UART, &RS232Rx.Buff[RS232Rx.Idx], 0 );
        RS232Rx.Idx = RS232Rx.Len ;
        FrameCntRS232 = 0 ;
    }

    //Character time-out
    if  ( tmp == UART_IIR_INTID_CTI )
    {
        RS232Rx.Len += UARTReceive ( RS232_UART, &RS232Rx.Buff[RS232Rx.Idx], 0 );
        RS232Rx.Idx = RS232Rx.Len ;
        RS232Rx.Flag = 1 ;
    }
}
示例#11
0
void UART0_IRQHandler(void)
{
    struct lpc_uart *uart;
    uint32_t intsrc, tmp, tmp1;

    uart = &uart0;

    /* enter interrupt */
    rt_interrupt_enter();

    /* Determine the interrupt source */
    intsrc = UART_GetIntId(uart->UART);
    tmp = intsrc & UART_IIR_INTID_MASK;

    // Receive Line Status
    if (tmp == UART_IIR_INTID_RLS)
    {
        // Check line status
        tmp1 = UART_GetLineStatus(uart->UART);
        // Mask out the Receive Ready and Transmit Holding empty status
        tmp1 &= (UART_LSR_OE | UART_LSR_PE | UART_LSR_FE \
                 | UART_LSR_BI | UART_LSR_RXFE);
        // If any error exist
        if (tmp1)
        {
            //
        }
    }

    // Receive Data Available or Character time-out
    if ((tmp == UART_IIR_INTID_RDA) || (tmp == UART_IIR_INTID_CTI))
    {
        rt_hw_serial_isr(&serial0);
    }

    /* leave interrupt */
    rt_interrupt_leave();
}
示例#12
0
void Uart_X_Isr(int which_port)
{
	uint32_t intsrc, tmp, tmp1;
	LPC_UART_TypeDef *UARTx;

	UARTx=(LPC_UART_TypeDef *)uartDrvDataArray[which_port].reg_base;
	/* Determine the interrupt source */
	intsrc = UART_GetIntId(UARTx);
	tmp = intsrc & UART_IIR_INTID_MASK;

	// Receive Line Status
	if (tmp == UART_IIR_INTID_RLS){
		// Check line status
		tmp1 = UART_GetLineStatus(UARTx);
		// Mask out the Receive Ready and Transmit Holding empty status
		tmp1 &= (UART_LSR_OE | UART_LSR_PE | UART_LSR_FE \
				| UART_LSR_BI | UART_LSR_RXFE);
		// If any error exist
		if (tmp1) {
				UART_IntErr(tmp1);
		}
	}

	// Receive Data Available or Character time-out
	if ((tmp == UART_IIR_INTID_RDA) || (tmp == UART_IIR_INTID_CTI)){
			UART_IntReceive(which_port);
	}

	// Transmit Holding Empty
	if (tmp == UART_IIR_INTID_THRE){
#if 0		
			UART_IntTransmit();
#else
			innerDeadNoOutput();
#endif
	}

}
示例#13
0
/*
*@描述:串口中断
*@参数:void
*@返回:无
*/
void _UART_IRQHander(void)
{
	
	uint32_t intsrc, tmp, tmp1;
	//OSIntEnter();
	// Determine the interrupt source 
	intsrc = UART_GetIntId((LPC_UART_TypeDef *)_LPC_UART);
	
	tmp = intsrc & UART_IIR_INTID_MASK;
	
	// Receive Line Status
	if (tmp == UART_IIR_INTID_RLS){
		// Check line status
		tmp1 = UART_GetLineStatus((LPC_UART_TypeDef *)_LPC_UART);
		// Mask out the Receive Ready and Transmit Holding empty status
		tmp1 &= (UART_LSR_OE | UART_LSR_PE | UART_LSR_FE \
				| UART_LSR_BI | UART_LSR_RXFE);
		// If any error exist
		if (tmp1) {
				UART_IntErr(tmp1);
		}
	}

	// Receive Data Available or Character time-out
	if ((tmp == UART_IIR_INTID_RDA) || (tmp == UART_IIR_INTID_CTI)){
		UART_IntReceive();
		//UART_Receive((LPC_UART_TypeDef *)_LPC_UART,&tmpchar,1,BLOCKING);
	}

	// Transmit Holding Empty
	if (tmp == UART_IIR_INTID_THRE){
			//UART_IntTransmit();
		
	}
	//OSIntExit();
	
}
示例#14
0
static void uart3_isr(void)
{
	rt_ubase_t level, iir;
    struct dev_uart* uart = &s_dev_uart;

    /* read IIR and clear it */
	iir = UART_GetIntId(LPC_DEV_UART);
	iir &= UART_IIR_INTID_MASK;

	if ((iir == UART_IIR_INTID_RDA) || (iir == UART_IIR_INTID_CTI))
	{
		/* Receive Data Available */
		while (LPC_DEV_UART->LSR & UART_LSR_RDR)
		{
			uart->rx_buffer[uart->save_index] = UART_ReceiveByte(LPC_DEV_UART);

			level = rt_hw_interrupt_disable();
			uart->save_index ++;
			if (uart->save_index >= RT_UART_RX_BUFFER_SIZE)
				uart->save_index = 0;
			rt_hw_interrupt_enable(level);
		}

		/* invoke callback */
		if(uart->parent.rx_indicate != RT_NULL)
		{
		    rt_size_t length;
		    if (uart->read_index > uart->save_index)
                length = RT_UART_RX_BUFFER_SIZE - uart->read_index + uart->save_index;
            else
                length = uart->save_index - uart->read_index;

            uart->parent.rx_indicate(&uart->parent, length);
		}
	}	
}
void UART3_IRQHandler( void )
{
uint32_t ulInterruptSource, ulReceived;
const uint32_t ulRxInterrupts = ( UART_IIR_INTID_RDA | UART_IIR_INTID_CTI );
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
const unsigned portBASE_TYPE uxUARTNumber = 3UL;
Transfer_Control_t *pxTransferStruct;

	/* Determine the interrupt source. */
	ulInterruptSource = UART_GetIntId( LPC_UART3 );

	if( ( ulInterruptSource & ulRxInterrupts ) != 0UL )
	{
		pxTransferStruct = pxRxTransferControlStructs[ uxUARTNumber ];
		if( pxTransferStruct != NULL )
		{
			switch( diGET_TRANSFER_TYPE_FROM_CONTROL_STRUCT( pxTransferStruct ) )
			{
				case ioctlUSE_CIRCULAR_BUFFER_RX :

					#if ioconfigUSE_UART_CIRCULAR_BUFFER_RX == 1
					{
						ioutilsRX_CHARS_INTO_CIRCULAR_BUFFER_FROM_ISR(
																	pxTransferStruct, 	/* The structure that contains the reference to the circular buffer. */
																	( ( LPC_UART3->LSR & UART_LSR_RDR ) != 0 ), 	/* While loop condition. */
																	LPC_UART3->RBR,			/* Register holding the received character. */
																	ulReceived,
																	xHigherPriorityTaskWoken
																);
					}
					#endif /* ioconfigUSE_UART_CIRCULAR_BUFFER_RX */
					break;


				case ioctlUSE_CHARACTER_QUEUE_RX :

					#if ioconfigUSE_UART_RX_CHAR_QUEUE == 1
					{
						ioutilsRX_CHARS_INTO_QUEUE_FROM_ISR( pxTransferStruct, ( ( LPC_UART3->LSR & UART_LSR_RDR ) != 0 ), LPC_UART3->RBR, ulReceived, xHigherPriorityTaskWoken );
					}
					#endif /* ioconfigUSE_UART_RX_CHAR_QUEUE */
					break;


				default :

					/* This must be an error.  Force an assert. */
					configASSERT( xHigherPriorityTaskWoken );
					break;
			}
		}
	}

	if( ( ulInterruptSource & UART_IIR_INTID_THRE ) != 0UL )
	{
		/* The transmit holding register is empty.  Is there any more data
		to send? */
		pxTransferStruct = pxTxTransferControlStructs[ uxUARTNumber ];
		if( pxTransferStruct != NULL )
		{
			switch( diGET_TRANSFER_TYPE_FROM_CONTROL_STRUCT( pxTransferStruct ) )
			{
				case ioctlUSE_ZERO_COPY_TX:

					#if ioconfigUSE_UART_ZERO_COPY_TX == 1
					{
						iouitlsTX_CHARS_FROM_ZERO_COPY_BUFFER_FROM_ISR( pxTransferStruct, ( ( LPC_UART3->FIFOLVL & uartTX_FIFO_LEVEL_MASK ) != uartTX_FIFO_LEVEL_MASK ), ( LPC_UART3->THR = ucChar ), xHigherPriorityTaskWoken );
					}
					#endif /* ioconfigUSE_UART_ZERO_COPY_TX */
					break;


				case ioctlUSE_CHARACTER_QUEUE_TX:

					#if ioconfigUSE_UART_TX_CHAR_QUEUE == 1
					{
						ioutilsTX_CHARS_FROM_QUEUE_FROM_ISR( pxTransferStruct, ( UART_FIFOLVL_TXFIFOLVL( LPC_UART3->FIFOLVL ) != ( UART_TX_FIFO_SIZE - 1 ) ), ( LPC_UART3->THR = ucChar ), xHigherPriorityTaskWoken );
					}
					#endif /* ioconfigUSE_UART_TX_CHAR_QUEUE */
					break;


				default :

					/* This must be an error.  Force an assert. */
					configASSERT( xHigherPriorityTaskWoken );
					break;
			}
		}
	}

	/* The ulReceived parameter is not used by the UART ISR. */
	( void ) ulReceived;

	/* If lHigherPriorityTaskWoken is now equal to pdTRUE, then a context
	switch should be performed before the interrupt exists.  That ensures the
	unblocked (higher priority) task is returned to immediately. */
	portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
}
示例#16
0
void UART0_IRQHandler(void)
{
	static char *line = &cmdbuf[0];
	static uint16_t frequency=1;
	float results[2];
	uint32_t temp;
	uint32_t U0IIR = 0;
	uint32_t baudrate;
	uint32_t result[2];
	
	extern uint8_t CorrectIndexesOverride;
	extern uint8_t CorrectIndexesBrute;
	extern uint8_t EqualIndexes;
	extern uint16_t FirstOverrideIndex;
	extern uint16_t SecondOverrideIndex;
	char *EndFromStrtoul;
	
	U0IIR=UART_GetIntId(LPC_UART0);
	if ((U0IIR & 0xE) == 0x4)
	{
		c = UART_ReceiveByte(LPC_UART0);
    if (c == CR) c = LF;  /* read character                 */
		if (c != LF)
		{
			if (c == BACKSPACE  ||  c == DEL) {     /* process backspace              */
				if (uart_rcv_len_cnt != 0)  {
					uart_rcv_len_cnt--;                              /* decrement count                */
					line--;                             /* and line pointer               */
					putchar (BACKSPACE);                /* echo backspace                 */
					putchar (' ');
					putchar (BACKSPACE);
				}
			}
			else if (c != CNTLQ && c != CNTLS) {    /* ignore Control S/Q             */
				putchar (*line = c);                  /* echo and store character       */
				line++;                               /* increment line pointer         */
				uart_rcv_len_cnt++;                                /* and count                      */
			}
			if (uart_rcv_len_cnt == sizeof(cmdbuf))
			{
				printf("\nError.");
				printf("\nBuffer full.");
			}
		}
		else
		{
			line = &cmdbuf[0];
			UART_pressed_enter = 1;
			if (command == none)
			{
				if ( (strcmp(cmdbuf, "cal") == 0) && uart_rcv_len_cnt == 3)
				{
					command = Calibrate;
					printf("\n Entered into calibrating state. Type calibrating command.\n>");
					UART_pressed_enter = 0;
				}
				else if ( (strcmp(cmdbuf, "m") == 0) && uart_rcv_len_cnt == 1)
				{
					wait(1);
					Measure(results, frequency);
					printf("\n Magnitude of impedance is: ");
					printf("%.1f Ohm.", results[0]);
					printf("\n Phase of impedance is: ");
					printf("%.2f graduses.", results[1]*57.295779513);
					printf("\nType next command.\n>");
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "f ", 2) == 0)
				{
					frequency = atoi(&(cmdbuf[2]));
					AD9833_SetFreq(frequency*1000);
					AD9833_Start();
					printf("\n New DDS frequency is %u kHz. ", frequency);
					printf("\n Type next command.\n>");
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "fmin ", 5) == 0)
				{
					f_min = atoi(&(cmdbuf[5]));
					printf("\n f_min are %u kHz.", f_min);
					printf("\n Type next command.\n>");
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "fmax ", 5) == 0)
				{
					f_max = atoi(&(cmdbuf[5]));
					printf("\n f_max are %u kHz.", f_max);
					printf("\n Type next command.\n>");
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "nf ", 3) == 0)
				{
					n_F = atoi(&(cmdbuf[3]));
					printf("\n n_F are %u.", n_F);
					printf("\n Type next command.\n>");
					UART_pressed_enter = 0;
				}
				else if ((strncmp(cmdbuf, "bg", 2) == 0) && uart_rcv_len_cnt == 2)
				{
					bg_flag = 1;
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "r ", 2) == 0)
				{
					temp = atoi(&(cmdbuf[2]));
					AD7793_SetRate(temp);
					printf("\n AD7793 rate field = are %u.", temp);
					printf("\n Type next command.\n>");
					UART_pressed_enter = 0;
				}
				else if ( uart_rcv_len_cnt == 0)
				{
					StartADC=1;
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "g", 1) == 0)
				{
					ADC_RUN(result);
					printf("\n  Magnitude are %u.", result[0]);
					printf("\n  Phase are %u.", result[1]);
					printf("\n Type next command.\n>");
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "d ", 2) == 0)
				{
					debug_mode = atoi(&(cmdbuf[2]));
					if (debug_mode == 0)
					{
						printf("\n Debug mode disabled.");
					}
					else
					{
						printf("\n Debug mode enabled.");
					}
					printf("\nType next command.\n>");
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "raw ", 4) == 0)
				{
					raw_data_mode = atoi(&(cmdbuf[4]));
					if (raw_data_mode == 0)
					{
						printf("\n Raw data mode disabled.");
					}
					else
					{
						printf("\n Raw data mode enabled.");
					}
					printf("\nType next command.\n>");
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "UartFifo ", 9) == 0)
				{
					UartWithFifo = atoi(&(cmdbuf[9]));
					if (UartWithFifo == 0)
					{
						printf("\n Software UART FIFO disabled.");
					}
					else
					{
						printf("\n Software UART FIFO enabled.");
					}
					printf("\nType next command.\n>");
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "UART ", 5) == 0)
				{
					baudrate = atoi(&(cmdbuf[5]));
					SER_Init(baudrate);
					printf("\n UART baudrate are %u bps.", baudrate);
					printf("\nType next command.\n>");
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "CIO ", 4) == 0)
				{
					CorrectIndexesOverride = atoi(&(cmdbuf[4]));
					if (CorrectIndexesOverride == 1)
					{
						printf("\nEnter correct override indexes:\n>");
						command = CorrectIndexesPutting;
					}
					else
					{
						printf("\n Index overriding disabled.");
						printf("\nType next command.\n>");
					}
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "CIB ", 4) == 0)
				{
					CorrectIndexesBrute = atoi(&(cmdbuf[4]));
					if (CorrectIndexesBrute == 1)
					{
						printf("\n Correct calibrating curves brute forcing enabled.");
						printf("\nType next command.\n>");
					}
					else
					{
						printf("\n Correct calibrating curves brute force disabled.");
						printf("\nType next command.\n>");
					}
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "EI ", 3) == 0)
				{
					EqualIndexes = atoi(&(cmdbuf[3]));
					if (EqualIndexes == 1)
					{
						printf("\n Equal calibrating indexes for mag and phase enabled.");
						printf("\nType next command.\n>");
					}
					else
					{
						printf("\n Equal calibrating indexes for mag and phase disabled.");
						printf("\nType next command.\n>");
					}
					UART_pressed_enter = 0;
				}
				else
				{
					printf("\nWrong command. Please type right command.\n");
					UART_pressed_enter = 0;
				}
				memset(cmdbuf,0,15);
				uart_rcv_len_cnt=0;
			}
			else if (command == CorrectIndexesPutting)
			{
				FirstOverrideIndex = strtoul(cmdbuf, &EndFromStrtoul, 10);
				SecondOverrideIndex = atoi(EndFromStrtoul);
				printf("\n FirstCorrectIndex = %u", FirstOverrideIndex);
				printf("\n SecondCorrectIndex = %u", SecondOverrideIndex);
				printf("\nType next command.\n>");
				UART_pressed_enter = 0;
				command = none;
				memset(cmdbuf,0,15);
				uart_rcv_len_cnt=0;
			}
		}
	}
	else if ((U0IIR & 0xE) == 0x2)
	{
		if (SW_UART_FIFO_STRUCT.count!=0)
		{
			LPC_UART0->THR = SW_UART_pop();
		}
		else
			UART_IntConfig(LPC_UART0,UART_INTCFG_THRE,DISABLE);			//Disable UART0 THRE Interrupt
	}
}