Esempio n. 1
0
void USART2_IRQHandler(void)
{
	u8 SendData;
    if(SET == USART_GetITStatus(USART2, USART_IT_TXE))
    {
        USART_ClearITPendingBit(USART2, USART_IT_TXE);
	#if 1
		if(FIFO_GET_ONE(McuUart2_TxFifo,&SendData))
		{
		   USART_SendData(USART2,SendData);
		}				  
		else
		{
		 	USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
		 	USART_ITConfig(USART2, USART_IT_TC, ENABLE);
		}
	#else
        if (m_SendBuff.len > 0 )
        {
            USART_SendData(USART2, m_SendBuff.buf[m_SendBuff.ind++]);
            m_SendBuff.len--;
        }
        else
        {
            USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
            USART_ITConfig(USART2, USART_IT_TC, ENABLE);
        }
	#endif
    }
    if (USART_GetITStatus(USART2, USART_IT_TC) != RESET)//去掉else
    {
        USART_ClearITPendingBit(USART2, USART_IT_TC);
        USART_ITConfig(USART2, USART_IT_TC, DISABLE);
        m_SendBuff.len = 0;
        eTXIdle = TRUE;
    }
    if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)//去掉else
    {
        u8 ch;
        
        USART_ClearITPendingBit(USART2, USART_IT_RXNE);	
        ch = USART_ReceiveData(USART2);
        if(UpgradeReady == 1)
		{
			ReceOneChar(ch);	//IAP
		}
		else
		{
			#ifdef ANDROID_UPGRADE
				FIFO_PUT_ONE(McuUart2_RxFifo,ch);
				//ReceOneCharByandroid(ch);
			#else
				ReceOneCharVerify(ch);
			#endif
		}
//        if (receChar != NULL)
//            (*receChar)(ch);
		
    }	
}
Esempio n. 2
0
/*
*********************************************************************************************************
*                                Rx/Tx Communication handler for uC/OS-View
*
* Description: This function is  called in stm32f10x_it.c 
*********************************************************************************************************
*/ 
void  OSView_RxTxISRHandler (void)
{
    CPU_SR          cpu_sr;

    CPU_CRITICAL_ENTER();                                       /* Tell uC/OS-II that we are starting an ISR            */
    OSIntNesting++;
    CPU_CRITICAL_EXIT();


    if (USART_GetITStatus(OS_VIEW_USART, USART_IT_RXNE) != RESET) {
                      /* Read one byte from the receive data register         */
        OSView_RxHandler( USART_ReceiveData(OS_VIEW_USART) & 0xFF );

        USART_ClearITPendingBit(OS_VIEW_USART, USART_IT_RXNE);          /* Clear the USART Receive interrupt                   */

    }

    if (USART_GetITStatus(OS_VIEW_USART, USART_IT_TXE) != RESET) {
        OSView_TxHandler();

        USART_ClearITPendingBit(OS_VIEW_USART, USART_IT_TXE);           /* Clear the USART transmit interrupt                  */

    }

    OSIntExit();                                                /* Tell uC/OS-II that we are leaving the ISR            */
}
Esempio n. 3
0
void USART3_IRQHandler(void)
{

    //用户程序..
    UartType *P2data = &UartAppData3;

    /* enter interrupt */
    rt_interrupt_enter();
    if ( USART_GetITStatus(USART3, USART_IT_RXNE) != RESET )
    {
        UCHAR ucChar;    
        USART_ClearITPendingBit(USART3, USART_IT_RXNE);
        ucChar = USART_ReceiveData(USART3);

        if ( !P2data->Flags.Solo.RecFlame )
        {
            P2data->RxTimeout = __25ms__;
            if ( P2data->RecCnt < (UART_BUFF_SIZE-1) )
            {
                P2data->TxRxBuf[P2data->RecCnt] = ucChar;
                P2data->RecCnt++;
                if ( P2data->RecCnt == 8 )
                {
                    P2data->Flags.Solo.ShortFrame =1;
                }
                if ( P2data->RecCnt == UART_BUFF_SIZE-1 )
                {
                    P2data->Flags.Solo.RecFlame =1;
                }
                //if (P2data->RecCnt == UART_SHORT_LEN)
                //{
                //    P2data->Flags->Solo->ShortFrame =1;
                //}
            }
        }

    }
    else if ( USART_GetITStatus(USART3,USART_IT_TXE) )
    {
        USART_ClearITPendingBit(USART3,USART_IT_TXE);
        USART_ClearFlag(USART3,USART_FLAG_TC);
        if ( P2data->SentCnt <  P2data->ToSend )
        {
            USART_SendData(USART3,P2data->TxRxBuf[P2data->SentCnt++]);        
        }
        else
        {
            USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
            USART_ITConfig(USART3, USART_IT_TC,  ENABLE);
        }
    }
    else if ( USART_GetITStatus(USART3,USART_IT_TC) )
    {
        P2data->Flags.Solo.TxStart = 0;
        Run_void(P2data->DisTxPin);
        USART_ITConfig(USART3, USART_IT_TC,  DISABLE);
    }
    /* leave interrupt */
    rt_interrupt_leave();
}
Esempio n. 4
0
/*******************************************************************************
* Function Name  : USART1_IRQHandler
* Description    : This function handles USART1 global interrupt request.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void USART1_IRQHandler(void)
{
  int i;
  if(USART_GetITStatus(USART1,USART_IT_RXNE) != RESET)
  {
    cRxBuffer[nRxCounter]	= (USART_ReceiveData(USART1)&0x7F);
    USART_ClearITPendingBit(USART1,USART_IT_RXNE);
    if(cRxBuffer[nRxCounter] == ')')
    {
      for(i=0;i<nRxCounter;i++)
        cTxBuffer[i]	= cRxBuffer[i];
      nRxCounter=0;
      nGotData  =1;
    }
    else
      nRxCounter++;
  }

  if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)
  {
    USART_SendData(USART1, cTxBuffer[nTxCounter]);
    USART_ClearITPendingBit(USART1, USART_IT_TXE);
    if(cTxBuffer[nTxCounter] == ')')
    {
      nTxCounter = 0;
      while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
      GPIO_ResetBits(GPIOA, GPIO_Pin_8);
      USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
      USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
      GPIO_ResetBits(GPIOA, GPIO_Pin_8);
    }
    else
      nTxCounter++;
  }
}
void USART1_IRQHandler(void)
{
	uint32_t data;
	static BaseType_t xHigherPriorityTaskWoken;

	xHigherPriorityTaskWoken = pdFALSE;

	if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
	{
		USART_ClearITPendingBit(USART1, USART_IT_RXNE);

		data = USART_ReceiveData(USART1);

		CircularBuffer_Write(ptxcbuf, &data, 1);
		
		USART_ITConfig(USART1, USART_IT_IDLE, ENABLE);

	}
	else if(USART_GetITStatus(USART1, USART_IT_IDLE) != RESET)
	{
		USART_ClearITPendingBit(USART1, USART_IT_IDLE);
		USART_ITConfig(USART1, USART_IT_IDLE, DISABLE);
			
		data = (CircularBuffer_Length(ptxcbuf) -  
				(lastHead- CircularBuffer_HeadPosition(ptxcbuf)))%CircularBuffer_Length(ptxcbuf);

		lastHead = CircularBuffer_HeadPosition(ptxcbuf);

		xQueueSendFromISR(frameLengthQueue, &data, &xHigherPriorityTaskWoken);

	}

	portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
Esempio n. 6
0
static u8 usart1_hard_init(USART_InitTypeDef* desc)
{
#if (USART1_RX_MODE == RX_PACKET_MODE)
	usart_timer_init();																									//启用定时器计算包接收超时
#endif
	baudRate = desc->USART_BaudRate;
  usart1_update_timeout(baudRate,N_char_timeout);
	USART_Cmd(USART1, DISABLE);  																		//使能失能串口外设
	usart1_commu_param_init(desc);												//串口初始化
	usart1_gpio_init();																							//串口引脚初始化	
	
	usart1_event_init();
	usart1_fifo_init();
	
	usart1_nvic_init();	
	USART_ClearITPendingBit(USART1,USART_IT_RXNE);//清接收标志
	USART_ClearITPendingBit(USART1,USART_IT_TXE);
	USART_ClearITPendingBit(USART1,USART_IT_TC);
	#if(USART1_TX_MODE==TX_IRQ)

	#elif(USART1_TX_MODE==TX_DMA)
		usart1_dmatxd_init();
	#endif
	
	USART_ITConfig(USART1,USART_IT_RXNE, ENABLE);	//开启接收中断
	USART_Cmd(USART1, ENABLE);  									//使能失能串口外设
	
	return 0;
}
Esempio n. 7
0
void STM32_M0_UART::hal_uartIRQ_Handler(void)
{
    // RX IRQ HANDLER
    if (USART_GetITStatus(USART_PORT, USART_IT_RXNE) != RESET)
    {
        USART_ClearITPendingBit(USART_PORT, USART_IT_RXNE);
        if (rx_buf.write(USART_ReceiveData(USART_PORT)) == -1)
        {
            USART_ITConfig(USART_PORT, USART_IT_RXNE, DISABLE);
        }
    }
    // TX IRQ HANDLER
    if (USART_GetITStatus(USART_PORT, USART_IT_TC) != RESET)
    {
        uint8_t tx_byte;
		
        USART_ClearITPendingBit(USART_PORT, USART_IT_TC);
		
        if (tx_buf.read(&tx_byte) == -1)
        {
            USART_ITConfig(USART_PORT, USART_IT_TC, DISABLE);
            tx_state = UART_TX_STATE_COMPLETE;
        }
        else
        {
            USART_SendData(USART_PORT, tx_byte);
            tx_state = UART_TX_STATE_SENDING;
        }
    }
}
Esempio n. 8
0
/*----------------------------------------------------------------------------*/
void USART1_IRQHandler(void)
{
  if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
  {
    USART_ClearITPendingBit(USART1, USART_IT_RXNE); //?????????
    /* Read one byte from the receive data register */
    lb_push(&uart_buffer.rx, USART_ReceiveData(USART1));
  }

  if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)
  {
    uint8_t c;
    USART_ClearITPendingBit(USART1, USART_IT_TXE); //??????????
 /* Write one byte to the transmit data register */
    /* Write one byte to the transmit data register */

    if(lb_pop(&uart_buffer.tx, &c))
      USART_SendData(USART1, c);
    else
    {
      /* Disable the USART1 Transmit interrupt */
      USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
    }
  }

}
Esempio n. 9
0
void serial_int1_send(void)	   //send data to USAR1		   
{

    if (counter_send <= cmd_send_lenth)
//	   UDR1=txd1_buffer[counter_send++];
	{
		USART_SendData(USART2, wifi_send_packet_buf_pub[counter_send]);
		USART_ClearITPendingBit(USART2, USART_IT_TXE);
		counter_send++;
	}
    else
	   {
	   	USART_SendData(USART2, wifi_send_packet_buf_pub[counter_send]);
		USART_ClearITPendingBit(USART2, USART_IT_TXE);
	    counter_send = 0;
		txd1_buff_cFlag = 1;
		USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
		
		time_tick_cnt2 = 0;
        RS485_RX_ENABLE;
	   }
    
    if (counter_send>40)
        counter_send=0; 
}
Esempio n. 10
0
void USART2_IRQHandler()
{
	//RX Interrupt Mode
	if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
	{		
		if(USART_GetFlagStatus(USART2,USART_FLAG_PE|USART_FLAG_FE|USART_FLAG_ORE)==0)
		{
			RX_Buffer[RX_IN_Index]=USART_ReceiveData(USART2);
			if (++RX_IN_Index == sizeof(RX_Buffer)) RX_IN_Index = 0;
			if (++RX_Count == sizeof(RX_Buffer))		RX_Count = 0;
		}
		USART_ClearITPendingBit(USART2,USART_IT_RXNE); 
	}	
	
	//TX_Buffer Interrupt Mode
	if(USART_GetITStatus(USART2, USART_IT_TC) != RESET)
	{
		if(TX_Count)
		{	
			--TX_Count;
			USART_SendData(USART2, TX_Buffer[TX_OUT_Index]); 
			if(++TX_OUT_Index == sizeof(TX_Buffer)) 
				TX_OUT_Index=0;						 
		}
		USART_ClearITPendingBit(USART2,USART_IT_TC);
	}		
	
} 
void USART3_IRQHandler(void)
{
    struct stm32_uart* uart;

    uart = &uart3;

    /* enter interrupt */
    rt_interrupt_enter();
    if(USART_GetITStatus(uart->uart_device, USART_IT_RXNE) != RESET)
    {
        rt_hw_serial_isr(&serial3, RT_SERIAL_EVENT_RX_IND);
        /* clear interrupt */
        USART_ClearITPendingBit(uart->uart_device, USART_IT_RXNE);
    }
    if (USART_GetITStatus(uart->uart_device, uart->tx_irq_type) != RESET)
    {
        /* clear interrupt */
        if (uart->tx_irq_type == USART_IT_TC)
        {
            USART_ClearITPendingBit(uart->uart_device, uart->tx_irq_type);
        }
    }
    if (USART_GetFlagStatus(uart->uart_device, USART_FLAG_ORE) == SET)
    {
        stm32_getc(&serial3);
    }

    /* leave interrupt */
    rt_interrupt_leave();
}
Esempio n. 12
0
/**
  * @brief  This function handles USART1 global interrupt request.
  * @param  None
  * @retval None
  */
void USART1_IRQHandler(void)
{
  uint16_t l_tmp; //Received char from USART1
  
  if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
  {
    USART_ClearITPendingBit(USART1, USART_IT_RXNE);
    //Read one byte from the receive data register
    l_tmp  = USART_ReceiveData(USART1);
    if(rcv_buff_full){
      //rcv buffer is full ==> trash rcv char
      rcv_buff_overload++;
    } else {
      *pt_rcv_write++ = (char)l_tmp; //put rcv char in buffer
      nb_rcv_buff_char++; //One char more to be read in buffer
      if(pt_rcv_write > &rcv_buff[BUFFER_RCV_SIZE]) {
        //pointer rollover rcv_buffer
        pt_rcv_write = rcv_buff;
      }
      if(pt_rcv_write == pt_rcv_read) {
        //Test if rcv buffer is full
        rcv_buff_full = 1;
      }      
    }
  }
  USART_ClearITPendingBit(USART1, USART_IT_ORE);
}
Esempio n. 13
0
void USART1_IRQHandler(void)
{
	 //Rx
	 if (USART_GetITStatus(HAL_COM, USART_IT_RXNE) != RESET)
   {
     /* Send the received data to the PC Host*/
		 _Reg.status=(HAL_COM->SR);
		 HAL_COM->SR=0;
		 _Reg.data=USART_ReceiveData(HAL_COM);		 		
		 
		 if( _USART1_RX_Event)	_USART1_RX_Event();
		 
		 USART_ClearITPendingBit(HAL_COM, USART_IT_RXNE);		
   }

 	 /* If overrun condition occurs, clear the ORE flag and recover communication */
   if (USART_GetFlagStatus(HAL_COM, USART_FLAG_ORE) != RESET)
   {
     (void)USART_ReceiveData(HAL_COM);
     USART_ClearITPendingBit(HAL_COM, USART_IT_RXNE);
   }		
	 
	 //buffer hardware TX vuoto
   if(USART_GetITStatus(HAL_COM, USART_IT_TXE) != RESET)
   {   
				if( _USART1_TX_Event)	_USART1_TX_Event();
				USART_ClearITPendingBit(HAL_COM, USART_IT_TXE);
   }
}
Esempio n. 14
0
/*******************************************************************************
* Function Name  : uart_irq_handler
* Description    : Interrupt handle function
* Input          : - Uart: Select the USART or the UART peripheral.
* Output         : None
* Return         : None
*******************************************************************************/
void uart_irq_handler(const _Uart_Descriptor *Uart)
{
  //
  __hw_enter_interrupt();
  //
  if (*Uart->Ctrl && (*Uart->Ctrl)->DmaBufSize)
  {
    if (USART_GetITStatus(Uart->UARTx, USART_IT_IDLE) != RESET)                          // Idle line
    {
      NVIC_SetPendingIRQ(Uart->DMAx_IRQn);
      USART_ReceiveData(Uart->UARTx);
    }
  }
  else if (USART_GetITStatus(Uart->UARTx, USART_IT_RXNE) != RESET)                       // Received Data Ready to be Read
  {
    if (*Uart->Ctrl && ((*Uart->Ctrl)->RxCnt < (*Uart->Ctrl)->RxBufSize))
    {
      (*Uart->Ctrl)->RxBufPtr[(*Uart->Ctrl)->RxiPut++] = (char)USART_ReceiveData(Uart->UARTx);
      //lepton
      if(!(*Uart->Ctrl)->RxCnt){
        if(Uart->board_uart_info && Uart->board_uart_info->desc_r!=-1)
           __fire_io_int(ofile_lst[Uart->board_uart_info->desc_r].owner_pthread_ptr_read);
      }
      //lepton
      (*Uart->Ctrl)->RxCnt++;
      if ((*Uart->Ctrl)->RxiPut >= (*Uart->Ctrl)->RxBufSize) (*Uart->Ctrl)->RxiPut = 0;
      if (((*Uart->Ctrl)->HwCtrl & UART_HW_FLOW_CTRL_RX) && ((*Uart->Ctrl)->RxCnt > ((*Uart->Ctrl)->RxBufSize - (*Uart->Ctrl)->DmaBufSize))) uart_set_rx_hw_fc(Uart);
    }
    else USART_ClearITPendingBit(Uart->UARTx, USART_IT_RXNE);
    #ifdef _UART_OS_SUPPORT
      isr_evt_set((*Uart->Ctrl)->Event, (*Uart->Ctrl)->Task);
    #endif
  }

  if (USART_GetITStatus(Uart->UARTx, USART_IT_TXE) != RESET)                             // Transmit Data Register Empty
  {
    if (*Uart->Ctrl && (*Uart->Ctrl)->TxCnt)
    {
      USART_SendData(Uart->UARTx, (*Uart->Ctrl)->TxBufPtr[(*Uart->Ctrl)->TxiGet++]);
      (*Uart->Ctrl)->TxCnt--;
      if ((*Uart->Ctrl)->TxiGet >= (*Uart->Ctrl)->TxBufSize) (*Uart->Ctrl)->TxiGet = 0;
    }
    else{
      USART_ITConfig(Uart->UARTx, USART_IT_TXE, DISABLE);
      //lepton
        if(Uart->board_uart_info && Uart->board_uart_info->desc_w!=-1)
           __fire_io_int(ofile_lst[Uart->board_uart_info->desc_w].owner_pthread_ptr_write);
      //lepton
    }
  }

  if (USART_GetITStatus(Uart->UARTx, USART_IT_TC) != RESET)                              // Transmission complete
  {
    if (*Uart->Ctrl && ((*Uart->Ctrl)->HwCtrl & UART_HALF_DUPLEX)) 
      uart_tx_disable(Uart);
    USART_ClearITPendingBit(Uart->UARTx, USART_IT_TC);
  }
  //
  __hw_leave_interrupt();
}
Esempio n. 15
0
/* ISR for serial interrupt */
void rt_hw_serial_isr(rt_device_t device)
{
	struct stm32_serial_device* uart = (struct stm32_serial_device*) device->user_data;

	if(USART_GetITStatus(uart->uart_device, USART_IT_RXNE) != RESET)
	{
		/* interrupt mode receive */
		RT_ASSERT(device->flag & RT_DEVICE_FLAG_INT_RX);

		/* save on rx buffer */
		while (uart->uart_device->SR & USART_FLAG_RXNE)
		{
			rt_base_t level;

			/* disable interrupt */
			level = rt_hw_interrupt_disable();

			/* save character */
			uart->int_rx->rx_buffer[uart->int_rx->save_index] = uart->uart_device->DR & 0xff;
			uart->int_rx->save_index ++;
			if (uart->int_rx->save_index >= UART_RX_BUFFER_SIZE)
				uart->int_rx->save_index = 0;

			/* if the next position is read index, discard this 'read char' */
			if (uart->int_rx->save_index == uart->int_rx->read_index)
			{
				uart->int_rx->read_index ++;
				if (uart->int_rx->read_index >= UART_RX_BUFFER_SIZE)
					uart->int_rx->read_index = 0;
			}

			/* enable interrupt */
			rt_hw_interrupt_enable(level);
		}

		/* clear interrupt */
		USART_ClearITPendingBit(uart->uart_device, USART_IT_RXNE);

		/* invoke callback */
		if (device->rx_indicate != RT_NULL)
		{
			rt_size_t rx_length;

			/* get rx length */
			rx_length = uart->int_rx->read_index > uart->int_rx->save_index ?
				UART_RX_BUFFER_SIZE - uart->int_rx->read_index + uart->int_rx->save_index :
				uart->int_rx->save_index - uart->int_rx->read_index;

			device->rx_indicate(device, rx_length);
		}
	}

	if (USART_GetITStatus(uart->uart_device, USART_IT_TC) != RESET)
	{
		/* clear interrupt */
		USART_ClearITPendingBit(uart->uart_device, USART_IT_TC);
	}
}
Esempio n. 16
0
static void  OSView_RxTxISRHandler (void)
{

    USART_TypeDef  *usart;
    CPU_INT08U      rx_data;
    CPU_SR          cpu_sr;


    CPU_CRITICAL_ENTER();                                       /* Tell uC/OS-II that we are starting an ISR            */
    OSIntNesting++;
    CPU_CRITICAL_EXIT();


#if   (OS_VIEW_COMM_SEL == OS_VIEW_UART_1)
    usart = USART1;
#elif (OS_VIEW_COMM_SEL == OS_VIEW_UART_2)
    usart = USART2;
#elif (OS_VIEW_COMM_SEL == OS_VIEW_UART_3)
    usart = USART3;
#else
    OSIntExit();
    return;
#endif

    if (USART_GetITStatus(usart, USART_IT_RXNE) != RESET) 
	{
        rx_data = USART_ReceiveData(usart) & 0xFF;              /* Read one byte from the receive data register         */
        USART_SendData( USART1, rx_data);
        ////////////////////////////////////////////
        #if 1        
        if(com_app.com_cnt == 10) {
            com_app.buf_ok  =com_app.buf_ok | (1<<com_buf_cnt);
            com_buf_cnt++;
            if(com_buf_cnt == 3)  com_buf_cnt = 0;
            com_app.com_cnt = 0;                
        }
       
        sprintf(com_rev_tmp,"%x",rx_data);
        strcat(com_app.app_buf[com_buf_cnt], com_rev_tmp);
    
        
        com_app.com_cnt ++;
        #endif
        ////////////////////////////////////////////
        OSView_RxHandler(rx_data);

        USART_ClearITPendingBit(usart, USART_IT_RXNE);          /* Clear the USART1 Receive interrupt                   */
    }

    if (USART_GetITStatus(usart, USART_IT_TXE) != RESET) 
	{
        OSView_TxHandler();

        USART_ClearITPendingBit(usart, USART_IT_TXE);           /* Clear the USART1 transmit interrupt                  */
    }

    OSIntExit();                                                /* Tell uC/OS-II that we are leaving the ISR            */
}
Esempio n. 17
0
/* proto usart1 Tx handler */
void usart1_handler(void) {
    if (USART_GetITStatus(USART1, USART_IT_TC) != RESET) {
        proto_send_sm();
        USART_ClearITPendingBit(USART1, USART_IT_TC);
    }
    if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) {
        proto_get_sm();
        USART_ClearITPendingBit(USART1, USART_IT_RXNE);
    }
}
Esempio n. 18
0
void USART3_IRQHandler(void)
{
    volatile char temp = 0;
    BaseType_t xHigherPriorityTaskWoken, xResult;

    // xHigherPriorityTaskWoken must be initialised to pdFALSE.
    xHigherPriorityTaskWoken = pdFALSE;
    
    if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
    {
        temp = USART_ReceiveData(USART3);
        xResult = xQueueSendToBackFromISR(uart3_rx_queue, (void *)&temp, &xHigherPriorityTaskWoken);
        if (errQUEUE_FULL == xResult)
        {
            //TODO: do something.
//            __ASM("nop;");
        }
        if(USART_GetFlagStatus(USART3, USART_FLAG_ORE) != RESET)
        {
            USART_ClearFlag(USART3, USART_FLAG_ORE);
            USART_ReceiveData(USART3);
        }
    }
  
    if(USART_GetITStatus(USART3, USART_IT_TXE) != RESET)
    {
        xResult = xQueueReceiveFromISR(uart3_tx_queue, (void *)&temp, &xHigherPriorityTaskWoken);
        if (pdPASS == xResult)
        {
            USART_SendData(USART3, temp);
        }
        else //empty
        {
            USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
        }
    }
    
    // error happen
    if(USART_GetITStatus(USART3, USART_IT_PE) != RESET)
    {
        USART_ClearITPendingBit(USART3, USART_IT_PE);
//        udprintf("\r\n===============Uart3.Parity error");
    }
    
    if(USART_GetITStatus(USART3, USART_IT_FE | USART_IT_NE) != RESET)
    {
        USART_ClearITPendingBit(USART3, USART_IT_FE | USART_IT_NE);
    }

    if(xHigherPriorityTaskWoken)
    {
        taskYIELD ();
    }
}
Esempio n. 19
0
void _Device_Uart_Enable(void){

    GPIO_Init(USART_RX_PORT, USART_RX_PIN, GPIO_Mode_In_FL_No_IT);  // Input floating, no external interrupt

    USART_DeInit(USART1);
    USART_ClearITPendingBit(USART1, USART_IT_TC);
    USART_ClearITPendingBit(USART1, USART_IT_RXNE);

#if defined(_USE_UART_PORT_MAPPING_)
    SYSCFG_REMAPPinConfig((REMAP_Pin_TypeDef)REMAP_Pin_USART1TxRxPortA, ENABLE);  /*!< USART1 Tx- Rx (PC3- PC2) remapping to PA2- PA3 */
#elif defined(_USE_UART_PORT_WITHOUT_MAPPING_)
#else
    #error "Please select Use Usart_Port_Mapping 0(disable)/1(enable)"
#endif

    GPIO_Init(USART_TX_PORT, USART_TX_PIN, GPIO_Mode_Out_PP_High_Fast); // USART1 TX
    GPIO_ExternalPullUpConfig(USART_TX_PORT, USART_TX_PIN, ENABLE);

    GPIO_Init(USART_RX_PORT, USART_RX_PIN, GPIO_Mode_In_PU_No_IT);  // USART1 RX
    GPIO_ExternalPullUpConfig(USART_RX_PORT, USART_RX_PIN, ENABLE);

    /* Enable USART1 clock */
    CLK_PeripheralClockConfig(CLK_Peripheral_USART1, ENABLE);

    /* USART configured as follow:
        - BaudRate = 115200 baud
        - Word Length = 8 Bits
        - One Stop Bit
        - Odd parity
        - Receive and transmit enabled
        - USART Clock disabled
    */
    USART_Init(USART1, UratBaudRates, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No, (USART_Mode_TypeDef)(USART_Mode_Tx | USART_Mode_Rx));
    //USART_Init(USART1, (uint32_t)115200, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No, (USART_Mode_TypeDef)USART_Mode_Tx );
    USART_ClearITPendingBit(USART1, USART_IT_TC);
    USART_ClearITPendingBit(USART1, USART_IT_RXNE);

    /* Enable the USART Receive interrupt: this interrupt is generated when the USART
    receive data register is not empty */
    USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

    /* Enable the USART Transmit complete interrupt: this interrupt is generated when the USART
    transmit Shift Register is empty */
    //USART_ITConfig(USART1, USART_IT_TC, ENABLE);


    SendingWhileTimeOutCount = 0;
    Interrupt_USART1_ReceiveData_ptr_fuc = Empty_USART1_fun;
    Usart_Peripheral_Flag = 0;
    Usart_Peripheral_Flag |= fUart_Enable;

    /* Enable USART */
    USART_Cmd(USART1, ENABLE);
}
//***************************************************************************
//Обработчик прерывания USART1 
//***************************************************************************
void USART1_IRQHandler(void)
{
	//Receive Data register not empty interrupt
	if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
	{
		USART_ClearITPendingBit(USART1, USART_IT_RXNE);
		modbus1.rxtimer=0;
		if(modbus1.rxcnt>(BUF_SZ-2)){
			modbus1.rxcnt=0;
		}
		modbus1.buffer[modbus1.rxcnt++] = USART_ReceiveData (USART1);
	}

	//Transmission complete interrupt
	if(USART_GetITStatus(USART1, USART_IT_TC) != RESET)
	{
		USART_ClearITPendingBit(USART1, USART_IT_TC);
		USART_ClearITPendingBit(USART1, USART_IT_FE);
		if(modbus1.txcnt<modbus1.txlen)
		{
			USART_SendData(USART1, modbus1.buffer[modbus1.txcnt++]);
//			countReqUSART1 = 0; //сброс счётчика запросов
		}
		else
		{
//			USART1->CR1 &= (uint32_t)~((uint32_t)USART_CR1_UE);
//			USART1->CR1 |= USART_CR1_UE;
			USART_ReceiveData (USART1);
			modbus1.txlen=0;
			//rs485 DE disable
			//GPIOA->BRR = GPIO_Pin_12;
//			GPIO_WriteBit(PIN_USART_DE, Bit_RESET);
			USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
			USART_ITConfig(USART1, USART_IT_TC, DISABLE);
			
			/* Configure USART1 TX (PA9) as alternate function push-pull*/	
//			GPIO_InitTypeDef  GPIO_InitStructure;
//			GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_9;
//			GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
//			GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IN;
//			GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
//			GPIO_Init(GPIOA, &GPIO_InitStructure);
		}
	}

		//Error interrupt.
	if((USART1->ISR & USART_ISR_ORE) || (USART1->ISR & USART_ISR_FE) || (USART1->ISR & USART_ISR_PE) || (USART2->ISR & USART_ISR_CMF))
	{
		USART1->ICR |= USART_ICR_ORECF;
		USART1->ICR |= USART_ICR_FECF;
		USART1->ICR |= USART_ICR_PECF;
		USART2->ICR |= USART_ICR_CMCF;
	}
}
Esempio n. 21
0
void CloseCon(void)
{
//		SerialPutString("jump to app\r\n\n");
		USART_Cmd(USARTx, DISABLE);
		USART_ITConfig(USARTx, USART_IT_TXE, DISABLE);
		USART_ITConfig(USARTx, USART_IT_RXNE, DISABLE);
		USART_ITConfig(USARTx, USART_IT_TC, DISABLE);

		USART_ClearITPendingBit(USARTx, USART_IT_TXE);
		USART_ClearITPendingBit(USARTx, USART_IT_TC);
		USART_ClearITPendingBit(USARTx, USART_IT_RXNE);
}
Esempio n. 22
0
// not api
static void uart_irq(USART_TypeDef* usart, int id) {
    if (serial_irq_ids[id] != 0) {
        if (USART_GetITStatus(usart, USART_IT_TC) != RESET) {
            irq_handler(serial_irq_ids[id], TxIrq);
            USART_ClearITPendingBit(usart, USART_IT_TC);
        }
        if (USART_GetITStatus(usart, USART_IT_RXNE) != RESET) {
            irq_handler(serial_irq_ids[id], RxIrq);
            USART_ClearITPendingBit(usart, USART_IT_RXNE);
        }
    }
}
Esempio n. 23
0
void BspUsart1Close(void)
{
    while (sb->eTXIdle != TRUE);
    USART_Cmd(USART1, DISABLE);

    USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
    USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
    USART_ITConfig(USART1, USART_IT_TC, DISABLE);

    USART_ClearITPendingBit(USART1, USART_IT_TXE);
    USART_ClearITPendingBit(USART1, USART_IT_TC);
    USART_ClearITPendingBit(USART1, USART_IT_RXNE);	
}
Esempio n. 24
0
static void  OSView_RxTxISRHandler (void)
{

    USART_TypeDef  *usart;
    CPU_INT08U      rx_data;
    CPU_SR          cpu_sr;


    CPU_CRITICAL_ENTER();                                       /* Tell uC/OS-II that we are starting an ISR            */
    OSIntNesting++;
    CPU_CRITICAL_EXIT();


#if   (OS_VIEW_COMM_SEL == OS_VIEW_UART_1)
    usart = USART1;
#elif (OS_VIEW_COMM_SEL == OS_VIEW_UART_2)
    usart = USART2;
#elif (OS_VIEW_COMM_SEL == OS_VIEW_UART_3)
    usart = USART3;
#else
    OSIntExit();
    return;
#endif

    if (USART_GetITStatus(usart, USART_IT_RXNE) != RESET) 
	{
        rx_data = USART_ReceiveData(usart) & 0xFF;              /* Read one byte from the receive data register         */
        
        //////////////////hepeng//////////////////////////
        #if (GPRS_SEND_MODULE == DEF_ENABLED)
        USART_SendData( USART1, rx_data);
        //data_analysis(rx_data);
        #endif
        ////////////////////////////////////////////
        
        OSView_RxHandler(rx_data);

        USART_ClearITPendingBit(usart, USART_IT_RXNE);          /* Clear the USART1 Receive interrupt                   */
    }

    if (USART_GetITStatus(usart, USART_IT_TXE) != RESET) 
	{
        OSView_TxHandler();

        USART_ClearITPendingBit(usart, USART_IT_TXE);           /* Clear the USART1 transmit interrupt                  */
    }

    OSIntExit();                                                /* Tell uC/OS-II that we are leaving the ISR            */
}
Esempio n. 25
0
File: UART6.c Progetto: welbur/zj
void USART6_IRQHandler(void)
{
	u16 i;
 	if(USART_GetITStatus(USART6, USART_IT_IDLE) != RESET)//如果为空闲总线中断
    {
			#if UART6_DMA_RX_ENABLE
	    DMA_Cmd(DMA2_Stream2, DISABLE);//关闭DMA,防止处理其间有数据
  	  UART6_Str.Recv_Len = UART6_MAX_RECV_LEN - DMA_GetCurrDataCounter(DMA2_Stream2); 
	    if(UART6_Str.Recv_Len > 0)
       {			
				 UART6_Str.data = UART6_Recv_Buf[UART6_User_Buf_No];
         UART6_Str.Recv_Flag = 1;		
				 UART6_User_Buf_No++;
				 if(UART6_User_Buf_No >= UART6_MAX_ARR)
					 UART6_User_Buf_No = 0;
		   }
			DMA_ClearFlag(DMA2_Stream2,DMA_FLAG_DMEIF2 | DMA_FLAG_FEIF2 | DMA_FLAG_TCIF2 | DMA_FLAG_TEIF2 | DMA_FLAG_HTIF2);//清标志
			DMA_SetCurrDataCounter(DMA2_Stream2,UART6_MAX_RECV_LEN);//重装填
			UART6_DMA_RX.DMA_Memory0BaseAddr = (u32)&UART6_Recv_Buf[UART6_User_Buf_No];
			DMA_Init(DMA2_Stream2, &UART6_DMA_RX);	
			//DMA_SetCurrDataCounter(DMA2_Stream2,MAX_RCV_LEN);//重装填
			DMA_Cmd(DMA2_Stream2, ENABLE);//处理完,重开DMA
			 
			#else
			 UART6_Str.data = UART6_Recv_Buf[UART6_Str.User_Buf_No];
			 UART6_Str.Recv_Flag = 1;
			 UART6_Str.User_Buf_No++;
			 if(UART6_Str.User_Buf_No >= UART_MAX_ARR)
				 UART6_Str.User_Buf_No = 0;
			#endif
			//读SR后读DR清除Idle
			i = USART6->SR;
			i = USART6->DR;
			 
	}
	if(USART_GetITStatus(USART6, USART_IT_RXNE) != RESET)//如果为接收中断
	{
		UART6_Recv_Buf[UART6_User_Buf_No][UART6_Str.Recv_Len] = USART6->DR;
		UART6_Str.Recv_Len++;
		if(UART6_Str.Recv_Len > UART6_MAX_RECV_LEN)
			UART6_Str.Recv_Len = 0;
	}
	if(USART_GetITStatus(USART6, USART_IT_PE | USART_IT_FE | USART_IT_NE) != RESET)//出错
	{
		USART_ClearITPendingBit(USART6, USART_IT_PE | USART_IT_FE | USART_IT_NE);
	}
  	USART_ClearITPendingBit(USART6, USART_IT_IDLE);
}
Esempio n. 26
0
void usartIrqHandler(uartPort_t *s)
{
    uint32_t ISR = s->USARTx->ISR;

    if (!s->rxDMAChannel && (ISR & USART_FLAG_RXNE)) {
        if (s->port.callback) {
            s->port.callback(s->USARTx->RDR);
        } else {
            s->port.rxBuffer[s->port.rxBufferHead++] = s->USARTx->RDR;
            if (s->port.rxBufferHead >= s->port.rxBufferSize) {
                s->port.rxBufferHead = 0;
            }
        }
    }

    if (!s->txDMAChannel && (ISR & USART_FLAG_TXE)) {
        if (s->port.txBufferTail != s->port.txBufferHead) {
            USART_SendData(s->USARTx, s->port.txBuffer[s->port.txBufferTail++]);
            if (s->port.txBufferTail >= s->port.txBufferSize) {
                s->port.txBufferTail = 0;
            }
        } else {
            USART_ITConfig(s->USARTx, USART_IT_TXE, DISABLE);
        }
    }

    if (ISR & USART_FLAG_ORE)
    {
        USART_ClearITPendingBit (s->USARTx, USART_IT_ORE);
    }
}
Esempio n. 27
0
/**
  * @}
  */ 
void USART1_IRQHandler(void) 
{
	  u8 Cache_num;
		if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)//判断是否发生接受中断
		{
  			//GPIO_ResetBits(GPIOC, GPIO_Pin_12); //LED_RED
        g_DatRev[g_DatRev_num]=USART_ReceiveData(USART1);   //接收数据,
			  Cache_num=USART_ReceiveData(USART1);  //放入比较缓冲中
//				USART_SendData(USART1,g_DatRev[g_DatRev_num]);
			  if(Cache_num==0x0A | g_DatRev_num>=(Max_UART_String-1))  //判断当接收到'\n' 或者超出缓冲时
				{
						if(Cache_num==0x0A)  //如果是接受到'\n'标志位第一位置1
						{
								UART_FLAG |= 0x01;
 //               USART_SendData(USART1,'Z');
						}
						else                 //如果不是,则说明是溢出职位,第2位置1
								UART_FLAG |= 0x02;
        }
				else
            g_DatRev_num++;   //记录个数
//				while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET){}//等待接受结束
				USART_ClearITPendingBit(USART1, USART_IT_RXNE);              //清除中断标志    
		}
		USART_ClearFlag(USART1,USART_FLAG_TC);                     //发送完成标志位
}
Esempio n. 28
0
/******************************************************************
** 函数名: TIMy_IRQHandler
** 输  入: none
** 描  述: 该定时器用作检测和LED控制计时使用                                            
** 全局变量: 
** 调用模块: 
** 作  者:   zcs
** 日  期:   2015-04-21
** 修  改:
** 日  期:

** 版  本: 1.0
*******************************************************************/
void USARTx_IRQHandler(void)
{	
//	if (USART_GetITStatus(USARTx,USART_IT_RXNE) != RESET)
//	{
//		EnQueue(&Queue,USART_ReceiveData(USARTx));           	/*  把串口接收的数据放入环形缓冲区   */
//		USART_ClearITPendingBit(USARTx,USART_IT_RXNE); 
//		TIM_Cmd(TIMz,DISABLE);
//		TIM_SetCounter(TIMz,0);
//		TIM_Cmd(TIMz,ENABLE);
//	}	
	
	if(USART_GetITStatus(USARTx, USART_IT_IDLE) != RESET)
	{
		USART_ClearITPendingBit(USARTx, USART_IT_IDLE);//空闲
		USARTx->SR;
		USARTx->DR;

		cur_count = DMA_GetCurrDataCounter(DMA1_Channel6);
		Queue.front = ( Queue.front + pre_remain_count + CAPACITY - cur_count)%CAPACITY;
		pre_remain_count = DMA_GetCurrDataCounter(DMA1_Channel6);
		
//		USART_SendData(USARTx,Queue.front);
//		while(USART_GetFlagStatus(USARTx, USART_FLAG_TXE) == RESET); //等待字符发送完毕
		get_whole_data = 1;
	}
}
Esempio n. 29
0
void uartIsr(void)
{
  if (USART_GetITStatus(UART_TYPE, USART_IT_TXE))
  {
    if (dataIndex < dataSize)
    {
      USART_SendData(UART_TYPE, outBuffer[dataIndex] & 0xFF);
      dataIndex++;
      if (dataIndex < dataSize - 1 && dataIndex > 1)
      {
        outBuffer[crcIndex] = (outBuffer[crcIndex] + outBuffer[dataIndex]) % 0xFF;
      }
    }
    else
    {
      USART_ITConfig(UART_TYPE, USART_IT_TXE, DISABLE);
      xHigherPriorityTaskWoken = pdFALSE;
      xSemaphoreGiveFromISR(waitUntilSendDone, &xHigherPriorityTaskWoken);
    }
  }
  USART_ClearITPendingBit(UART_TYPE, USART_IT_TXE);
  if (USART_GetITStatus(UART_TYPE, USART_IT_RXNE))
  {
    rxDataInterrupt = USART_ReceiveData(UART_TYPE) & 0xFF;
    xQueueSendFromISR(uartDataDelivery, &rxDataInterrupt, &xHigherPriorityTaskWoken);
  }
}
Esempio n. 30
0
void USART1_IRQHandler(void) {
	static uint8_t buffer[64];
	static int index = 0;

	uint8_t dat;
	if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) {
		dat = USART_ReceiveData(USART1);
		USART_ClearITPendingBit(USART2, USART_IT_RXNE);
		if (dat == '\r' || dat == '\n') {
			uint8_t *msg;
			portBASE_TYPE xHigherPriorityTaskWoken;

			buffer[index++] = 0;
			msg = __uartDebugCreateMessage(buffer, index);
			if (pdTRUE == xQueueSendFromISR(__uartDebugQueue, &msg, &xHigherPriorityTaskWoken)) {
				if (xHigherPriorityTaskWoken) {
					portYIELD();
				}
			}
			index = 0;

		} else {
			buffer[index++] = dat;
		}
	}
}