void UART1_IRQHandler(void)
{
    while ((itid = UART_GetPendingITID(UART0)) != UART_ITID_None) {
        if (itid == UART_ITID_RxLineStatus) {
            tmp = UART_GetLineStatus(UART);
            if (tmp & UART_BI) { /* BREAK */
            } else if (tmp & (UART_OE | UART_PE | UART_FE)) {
                /* Overflow / Parity / Framing Error */
            }
            
            UART_Recv(UART0);
            continue;
        } else if ((itid == UART_ITID_RxDataAvailable) 
                || (itid == UART_ITID_CharacterTimeout))
        {
            tmp = UART_Recv(UART);
        } else if (itid == UART_ITID_TxEmpty) {
        } else if (itid == UART_ITID_ModemStatus) {
        } else {
            /* UART_ITID_CharacterTimeOut */
        }
        
        
    }
}
Beispiel #2
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退出中断******/
}
Beispiel #3
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();
	}
}
/** @brief  Send a character via UART
  *
  * @param  [in]  uart     The UART on which to send the character
  * @param  [in]  c        The character to send
  *
  * @return None.
  *
  * Blocks until the UART is ready to accept the new character, then
  *  writes it.
  */
void uart_putchar(UART_Type *uart, uint8_t c)
{
    /* Wait for tx holding register to empty */
    while ((UART_GetLineStatus(uart) & UART_LineStatus_TxEmpty) == 0);
    
    /* Send character */
    UART_Send(uart, c);
}
/*********************************************************************//**
 * @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();
	}
}
Beispiel #6
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);
				}
			}
	}
}
/** @brief  Receive a character via UART
  *
  * @param  [in]  uart     The UART on which to receive the character
  *
  * @return The received character
  *
  * Blocks until the UART has a character available to read.
  */
uint8_t uart_getchar(UART_Type *uart)
{
    uint8_t c;
    
    
    /* Wait for a character to be ready */
    while ((UART_GetLineStatus(uart) & UART_LineStatus_RxData) == 0);
    
    /* Receive it */
    c = UART_Recv(uart);
    
    return c;
}
Beispiel #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退出中断******/
	
}
Beispiel #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 ;

    }
}
Beispiel #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 ;
    }
}
Beispiel #11
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
      {   
               
      }
   }
}
Beispiel #12
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();
}
Beispiel #13
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
	}

}
/*
*@描述:串口中断
*@参数: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();
	
}
Beispiel #15
0
/*----------------------------------------------------------------------------
  Serial Device "LPC17xx"
  Send buffer
 *----------------------------------------------------------------------------*/
static int UartDev_BufTx (void *pData, int* pSize, unsigned int flags) {
  char *pChar;
   int   bytesToWrite, bytesWritten;
   uint8_t tmpc;

  if (UARTInfo.State != _STATE_INITIALIZED_) {
    return (-1);                                      /* Device not initialized */
  }

  if ((pData == 0 ) && (*pSize > 0)) {
    return (-1);                                      /* Parameter not valid */
  }

  pChar = (char *)pData;
  bytesToWrite = *pSize;

  if (flags == UartDev_FLAG_BLOCKING) {               /* Blocking transmission */

    while (bytesToWrite-- > 0) {
      while (__BUF_FULL(BufTx));                      /* Block until space is available */
      __BUF_WR(BufTx, *pChar++);

      if (TxRestart) {                                /* If transmit interrupt is disabled, enable it */
        // TxRestart = 0;
        if (UART_GetLineStatus(UARTInfo.pUart) & UART_LINESTAT_THRE){
        	if (!__BUF_EMPTY(BufTx)) {
        		TxRestart = 0;
        		tmpc = __BUF_RD(BufTx);
        		UART_Send(UARTInfo.pUart, &tmpc, 1, BLOCKING);
        		UART_IntConfig(UARTInfo.pUart, UART_INTCFG_THRE, ENABLE);     /* enable TX interrupt */
        	}
        }
        // UART_IntConfig(UARTInfo.pUart, UART_INTCFG_THRE, ENABLE);     /* enable TX interrupt */
      }
    }
  } else {                                            /* nonBlocking transmission */
    bytesWritten = 0;
    while (bytesToWrite-- > 0) {
      if (!__BUF_FULL(BufTx)) {
        __BUF_WR(BufTx, *pChar++);                    /* just fill buffer */
        bytesWritten++;
      } else {
        bytesToWrite = 0;
      }
    }
    *pSize = bytesWritten;                            /* return bytes written */
    if (TxRestart) {                                  /* If transmit interrupt is disabled, enable it */
      // TxRestart = 0;
      if (UART_GetLineStatus(UARTInfo.pUart) & UART_LINESTAT_THRE){
         	if (!__BUF_EMPTY(BufTx)){
         		TxRestart = 0;
         		tmpc = __BUF_RD(BufTx);
         		UART_Send(UARTInfo.pUart, &tmpc, 1, BLOCKING);
         		UART_IntConfig(UARTInfo.pUart, UART_INTCFG_THRE, ENABLE);	      /* enable TX interrupt */
         	}
         }
      // UART_IntConfig(UARTInfo.pUart, UART_INTCFG_THRE, ENABLE);	      /* enable TX interrupt */
    }
  }

  return(0);                                          /* success */
}
/** @brief  Determine whether the given UART has a character in the rcv buffer
  *
  * @param  [in]  uart     The UART to check
  *
  * @return 1 if the UART has at least 1 character available, 0 otherwise.
  */
int uart_available(UART_Type *uart)
{
    return (UART_GetLineStatus(uart) & UART_LineStatus_RxData) ? 1:0;
}
Beispiel #17
0
uint8	GetUart0Status(void)
{
	return	UART_GetLineStatus((LPC_UART_TypeDef *)LPC_UART0);
}