void UART4_IRQHandler(void)
{
#ifdef RT_USING_UART4
    extern struct rt_device uart4_device;
    extern void rt_hw_serial_isr(struct rt_device *device);
     u8  data=0;
    /* enter interrupt */
    rt_interrupt_enter();

    // rt_hw_serial_isr(&uart4_device); 
    	if (USART_GetITStatus(UART4, USART_IT_RXNE) != RESET) {
        data = USART_ReceiveData(UART4) & 0xFF;
	 GSM_RxHandler(data);
        USART_ClearITPendingBit(UART4, USART_IT_RXNE);          	
    		}
    /* leave interrupt */
    rt_interrupt_leave();
#endif
}
Beispiel #2
0
void UART2_IRQHandler(void)
{
    struct mm32_uart *uart;
    uart = &uart2;
    /* enter interrupt */
    rt_interrupt_enter();
    if (UART_GetITStatus(uart->uart_device, UART_IT_RXIEN) != RESET)
    {
        UART_ClearITPendingBit(uart->uart_device, UART_IT_RXIEN);
        rt_hw_serial_isr(&serial2, RT_SERIAL_EVENT_RX_IND);
    }
    if (UART_GetITStatus(uart->uart, UART_IT_TXIEN) != RESET)
    {
        /* clear interrupt */
        UART_ClearITPendingBit(uart->uart, UART_IT_TXIEN);
    }
    /* leave interrupt */
    rt_interrupt_leave();
}
Beispiel #3
0
/*******************************************************************************
* Function Name  : TIM4_IRQHandler
* Description    : This function handles TIM3 interrupt request.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void TIM4_IRQHandler(void)
{
	static uint8_t cnt1 = 0;
//	static uint8_t cnt2 = 0;
	
	/* enter interrupt */
	rt_interrupt_enter();
	
	TIM_ClearITPendingBit(BSP_TIM, TIM_IT_Update);

	if((cnt1++ % 5) == 0)
	{
		rt_sem_release(&sem_adio_task);
//		Bsp_can_send_cycle_event();
	}
	Bsp_can_send_cycle_event();
	/* leave interrupt */
	rt_interrupt_leave();
}
Beispiel #4
0
void USART3_IRQHandler(void)
{
    struct stm32_uart *uart;

    uart = &uart3;

    /* enter interrupt */
    rt_interrupt_enter();

    /* UART in mode Receiver ---------------------------------------------------*/
    if ((__HAL_UART_GET_IT(&uart->UartHandle, UART_IT_RXNE) != RESET) && (__HAL_UART_GET_IT_SOURCE(&uart->UartHandle, UART_IT_RXNE) != RESET))
    {
        rt_hw_serial_isr(&serial3, RT_SERIAL_EVENT_RX_IND);
        /* Clear RXNE interrupt flag */
        __HAL_UART_SEND_REQ(&uart->UartHandle, UART_RXDATA_FLUSH_REQUEST);
    }
    /* leave interrupt */
    rt_interrupt_leave();
}
/**
  * @}
  */
void RTC_IRQHandler(void)
{
	static int delay_cnt;
	struct rtgui_event_command ecmd;

	/* enter interrupt */
	rt_interrupt_enter();

	++rtc_1s_int_cnt;

#if 1 == LCD_TEST_MALOOEI
	rt_kprintf("rtc:%d\n", rtc_1s_int_cnt);
#endif

	if (delay_cnt < 1) {
		++delay_cnt;
		goto ret_entry;
	}

	if (NULL == wb_thread)
		goto ret_entry;

	if (RTC_GetITStatus(RTC_IT_SEC) != RESET) {
		RTGUI_EVENT_COMMAND_INIT(&ecmd);
		ecmd.command_id = UPDATE_SYS_TIME;
		if (RT_EOK != rtgui_thread_send(wb_thread, &ecmd.parent, sizeof(struct rtgui_event_command)))
			rt_kprintf("[RTC_IRQHandler]send enent cmd fail\n");
	}
#if 0
	if(RTC_GetFlagStatus(RTC_FLAG_ALR) != RESET) {
	} else {
	}
#endif

ret_entry:
	RTC_ClearITPendingBit(RTC_IT_ALR | RTC_IT_SEC);

	/* leave interrupt */
	rt_interrupt_leave();

	return;
}
Beispiel #6
0
void UART5_IRQHandler( void )
{
    uint8_t			ch;
    rt_interrupt_enter( );
    if( USART_GetITStatus( UART5, USART_IT_RXNE ) != RESET )
    {
        ch = USART_ReceiveData( UART5 );
        if( ( ch == 0x0a ) && ( last_ch == 0x0d ) ) /*遇到0d 0a 表明结束*/
        {
            uart5_rxbuf.body[uart5_rxbuf.wr++] = ch;
            if( uart5_rxbuf.wr < 124 )
            {
                //--------- fliter  useful------
                if((strncmp((char *)uart5_rxbuf.body + 3, "RMC,", 4) == 0) || (strncmp((char *)uart5_rxbuf.body + 3, "TXT,", 4) == 0) ||  \
                        (strncmp((char *)uart5_rxbuf.body + 3, "GGA,", 4) == 0)) //||(strncmp((char*)uart5_rxbuf.body+3,"GSA,",4)==0))
                {
                    rt_mq_send( &mq_gps, (void *)&uart5_rxbuf, uart5_rxbuf.wr + 2 );
                }
            }
            uart5_rxbuf.wr = 0;
        }
        else
        {
            // 1. get  head char
            if(ch == '$')
                uart5_rxbuf.wr = 0;
            // 2.  judge  head char
            if(uart5_rxbuf.body[0] != '$') // add later
                uart5_rxbuf.wr = 0;
            // 3.  rx data
            uart5_rxbuf.body[uart5_rxbuf.wr++] = ch;
            if( uart5_rxbuf.wr == UART5_RX_SIZE )
            {
                uart5_rxbuf.wr = 0;
            }
            uart5_rxbuf.body[uart5_rxbuf.wr] = 0;
        }
        last_ch = ch;
        USART_ClearITPendingBit( UART5, USART_IT_RXNE );
    }
    rt_interrupt_leave( );
}
Beispiel #7
0
void DMA1_Stream0_IRQHandler(void) //I2C1 RX
{

	rt_interrupt_enter();

	if (DMA_GetITStatus(I2C1_DMA_CHANNEL_RX, DMA_IT_TCIF0))
    {
	   I2C_TRACE("RXTC\n");
	   /* clear DMA flag */
		DMA_ClearFlag(I2C1_DMA_CHANNEL_RX, DMA_FLAG_TCIF0 );
		DMA_ITConfig( I2C1_DMA_CHANNEL_RX, DMA_IT_TC, DISABLE);
		DMA_Cmd(I2C1_DMA_CHANNEL_RX, DISABLE);
		if( i2cStatus == S6 )
		{
			i2cStatus = S_STOP;
			I2C1->CR1 |= CR1_STOP_Set;
			rt_event_send(&i2c_event, I2C_COMPLETE);
		}
    }
	if (DMA_GetITStatus(I2C1_DMA_CHANNEL_RX, DMA_IT_HTIF0))
	{
		I2C_TRACE("RXHT\n");
		DMA_ClearFlag(I2C1_DMA_CHANNEL_RX, DMA_FLAG_HTIF0 );
	}
	if (DMA_GetITStatus(I2C1_DMA_CHANNEL_RX, DMA_IT_TEIF0))
	{
		I2C_TRACE("RXTE\n");
		DMA_ClearFlag(I2C1_DMA_CHANNEL_RX, DMA_FLAG_TEIF0 );
	}
	if (DMA_GetITStatus(I2C1_DMA_CHANNEL_RX, DMA_IT_FEIF0))
	{
		I2C_TRACE("RXFE\n");
		DMA_ClearFlag(I2C1_DMA_CHANNEL_RX, DMA_FLAG_FEIF0 );
	}
	if (DMA_GetITStatus(I2C1_DMA_CHANNEL_RX, DMA_IT_DMEIF0))
	{
		I2C_TRACE("RXDME\n");
		DMA_ClearFlag(I2C1_DMA_CHANNEL_RX, DMA_FLAG_DMEIF0 );
	}

	rt_interrupt_leave();	
}
Beispiel #8
0
void UART2_IRQHandler(void)
{
    struct lpc_uart *uart;
    uint32_t intsrc, temp;

    uart = &uart2;

    /* enter interrupt */
    rt_interrupt_enter();

    /* Determine the interrupt source */
    intsrc = uart->USART->IIR & UART_IIR_INTID_MASK;

    switch (intsrc)
    {

    case UART_IIR_INTID_RLS:                                            /* Receive Line Status interrupt*/
        /* read the line status */
        intsrc = uart->USART->LSR;
        /* Receive an error data */
        if (intsrc & UART_LSR_PE)
        {
            temp = LPC_USART0->RBR;
        }
        break;

    case UART_IIR_INTID_RDA:                                            /*  Receive data               */
    case UART_IIR_INTID_CTI:                                            /*  Receive data timeout       */
        /* read the data to buffer  */
        while (uart->USART->LSR & UART_LSR_RDR)
        {
            rt_hw_serial_isr(&serial0, RT_SERIAL_EVENT_RX_IND);
        }
        break;

    default:
        break;
    }

    /* leave interrupt */
    rt_interrupt_leave();
}
Beispiel #9
0
/***********************************************************
* Function:
* Description: uart4的中断服务函数
* Input:
* Input:
* Output:
* Return:
* Others:
***********************************************************/
void UART4_IRQHandler( void )
{
	rt_interrupt_enter( );
	if( USART_GetITStatus( UART4, USART_IT_RXNE ) != RESET )
	{
		rt_ringbuffer_putchar( &rb_uart4_rx, USART_ReceiveData( UART4 ) );
		USART_ClearITPendingBit( UART4, USART_IT_RXNE );
		//rt_sem_release( &sem_uart );
		last_tick = rt_tick_get( );
	}


/*
   if (USART_GetITStatus(UART4, USART_IT_TC) != RESET)
   {
   USART_ClearITPendingBit(UART4, USART_IT_TC);
   }
 */
	rt_interrupt_leave( );
}
Beispiel #10
0
/***********************************************************
* Function:
* Description: uart4的中断服务函数
* Input:
* Input:
* Output:
* Return:
* Others:
***********************************************************/
void UART4_IRQHandler( void )
{
	rt_interrupt_enter( );
	if( USART_GetITStatus( UART4, USART_IT_RXNE ) != RESET )
	{
		uart4_rxbuf[uart4_rxbuf_wr++]	= USART_ReceiveData( UART4 );
		uart4_rxbuf_wr					%= UART4_RX_SIZE;
		USART_ClearITPendingBit( UART4, USART_IT_RXNE );
		last_tick = rt_tick_get( );
	}


/*
   if (USART_GetITStatus(UART4, USART_IT_TC) != RESET)
   {
   USART_ClearITPendingBit(UART4, USART_IT_TC);
   }
 */
	rt_interrupt_leave( );
}
Beispiel #11
0
/*******************************************************************************
* Function Name  : EXTI4_IRQHandler
* Description    : This function handles External interrupt Line 4 request.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void EXTI4_IRQHandler(void)
{
#ifdef RT_USING_LWIP
	extern void rt_dm9000_isr(void);

	/* Clear the EXTI4 line pending bit */
	EXTI_ClearITPendingBit(EXTI_Line4);

	/* enter interrupt */
	rt_interrupt_enter();

	while(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_4))
	{
		rt_dm9000_isr();
	}

	/* leave interrupt */
	rt_interrupt_leave();
#endif
}
Beispiel #12
0
/*******************************************************************************
 * Function Name  : USART1_IRQHandler
 * Description    : This function handles USART1 global interrupt request.
 * Input          : None
 * Output         : None
 * Return         : None
 *******************************************************************************/
void USART1_IRQHandler(void)
{
	rt_interrupt_enter();
	//溢出错误
	if (USART_GetFlagStatus(USART1, USART_FLAG_ORE) == SET)
	{
		prvvUARTRxISR();
	}
	//接收中断
	if (USART_GetITStatus(USART1, USART_IT_RXNE) == SET)
	{
		USART_ClearITPendingBit(USART1, USART_IT_RXNE);
		prvvUARTRxISR();
	}
	//发送中断
	if (USART_GetITStatus(USART1, USART_IT_TXE) == SET)
	{
		prvvUARTTxReadyISR();
	}
	rt_interrupt_leave();
}
Beispiel #13
0
/*******************************************************************************
* Function Name  : DMA2_Channel2_IRQHandler
* Description    : This function handles DMA2 Channel 2 interrupt request.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void DMA2_Channel2_IRQHandler(void)
{
#if CODEC_USE_SPI3
    extern void codec_dma_isr(void);

    /* enter interrupt */
    rt_interrupt_enter();

    if (DMA_GetITStatus(DMA2_IT_TC2))
    {
        /* clear DMA flag */
        DMA_ClearFlag(DMA2_FLAG_TC2 | DMA2_FLAG_TE2);

        /* transmission complete, invoke serial dma tx isr */
        codec_dma_isr();
    }

    /* leave interrupt */
    rt_interrupt_leave();
#endif
}
Beispiel #14
0
/*******************************************************************************
* Function Name  : DMA1_Channel2_IRQHandler
* Description    : This function handles DMA1 Channel 2 interrupt request.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void DMA1_Channel2_IRQHandler(void)
{
#ifdef RT_USING_UART3
    extern struct rt_device uart3_device;

    /* enter interrupt */
    rt_interrupt_enter();

    if (DMA_GetITStatus(DMA1_IT_TC2))
    {
        /* transmission complete, invoke serial dma tx isr */
        rt_hw_serial_dma_tx_isr(&uart3_device);
    }

    /* clear DMA flag */
    DMA_ClearFlag(DMA1_FLAG_TC2 | DMA1_FLAG_TE2);

    /* leave interrupt */
    rt_interrupt_leave();
#endif
}
Beispiel #15
0
void UART0_IRQHandler(void)
{
    volatile  uint32_t  INTSTAT, tmp;
    /* enter interrupt */
    rt_interrupt_enter();

    INTSTAT = LPC_USART0->INTSTAT;

    INTSTAT &= 0x01;
    switch (INTSTAT)
    {
    case 0x01:
        rt_hw_serial_isr(&serial0, RT_SERIAL_EVENT_RX_IND);
        break;
    default :
        tmp = LPC_USART0->INTSTAT;
        break;
    }
    /* leave interrupt */
    rt_interrupt_leave();
}
Beispiel #16
0
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);
    }
    if (USART_GetITStatus(uart->uart_device, USART_IT_TC) != RESET)
    {
        /* clear interrupt */
        USART_ClearITPendingBit(uart->uart_device, USART_IT_TC);
    }

    /* leave interrupt */
    rt_interrupt_leave();
}
Beispiel #17
0
void UART1_IRQHandler(void)
{
	rt_ubase_t level, iir;
    struct rt_uart_lpc* uart = &uart1_device;

	/* enter interrupt */
	rt_interrupt_enter();

    /* read IIR and clear it */
	iir = uart->UART->IIR;

	if (iir == UART_IIR_INTID_RDA)	    /* Receive Data Available */
	{
		/* Receive Data Available */
        uart->rx_buffer[uart->save_index] = uart->UART->RBR;

        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);
		}
	}

	/* leave interrupt */
	rt_interrupt_leave();

	return;
}
Beispiel #18
0
/*******************************************************************************
* Function Name  : DMA1_Channel5_IRQHandler
* Description    : This function handles DMA1 Channel 5 interrupt request.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void DMA1_Channel5_IRQHandler(void)
{
#if !CODEC_USE_SPI3
    extern void codec_dma_isr(void);

    /* enter interrupt */
    rt_interrupt_enter();

    if (DMA_GetITStatus(DMA1_IT_TC5))
    {
        /* clear DMA flag */
        DMA_ClearFlag(DMA1_FLAG_TC5 | DMA1_FLAG_TE5);

        // rt_kprintf("DMA\n");
        /* transmission complete, invoke serial dma tx isr */
        codec_dma_isr();
    }

    /* leave interrupt */
    rt_interrupt_leave();
#endif
}
Beispiel #19
0
void ENET_IRQHandler(void)
{
    rt_uint32_t status;

    /* enter interrupt */
    rt_interrupt_enter();

    status = LPC_EMAC->IntStatus;

    if (status & INT_RX_DONE)
    {
        /* Disable EMAC RxDone interrupts. */
        LPC_EMAC->IntEnable = INT_TX_DONE;

        /* a frame has been received */
        eth_device_ready(&(lpc_emac_device.parent));
    }
    else if (status & INT_TX_DONE)
    {
        /* set event */
        rt_event_send(&tx_event, 0x01);
    }

    if (status & INT_RX_OVERRUN)
    {
        rt_kprintf("rx overrun\n");
    }

    if (status & INT_TX_UNDERRUN)
    {
        rt_kprintf("tx underrun\n");
    }

    /* Clear the interrupt. */
    LPC_EMAC->IntClear = status;

    /* leave interrupt */
    rt_interrupt_leave();
}
Beispiel #20
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 #21
0
/*******************************************************************************
 * Function Name  : USART1_IRQHandler
 * Description    : This function handles USART1 global interrupt request.
 * Input          : None
 * Output         : None
 * Return         : None
 *******************************************************************************/
void USART1_IRQHandler(void)
{
	rt_interrupt_enter();
	//接收中断
	if (USART_GetITStatus(USART1, USART_IT_RXNE) == SET)
	{
		USART_ClearITPendingBit(USART1, USART_IT_RXNE);
		if(master_slave != 0)
			prvvUARTRxISR();
		else
			prvvUARTRxISR_Master();
	}
	//发送中断
	if (USART_GetITStatus(USART1, USART_IT_TXE) == SET)
	{
//		USART_ClearITPendingBit(USART1, USART_IT_TXE);
		if(master_slave != 0)
		prvvUARTTxReadyISR();
		else
		prvvUARTTxReadyISR_Master();
	}
	rt_interrupt_leave();
}
Beispiel #22
0
void EXTI4_IRQHandler(void)
{
    rt_interrupt_enter();
    GD32_GPIO_EXTI_IRQHandler(4);
    rt_interrupt_leave();
}
Beispiel #23
0
void TIM8_UP_TIM13_IRQHandler(void)
{
	float I1 = 0, I2 = 0, power = 0;
	static float percent = 0, percent1 = 0 ;
	float error_pid = 0;
	static uint16_t interrupt_times = 0;
//	static uint8_t flag_modbus = 0;
//	rt_enter_critical();/*调度器上锁*/
	rt_interrupt_enter();
	logic_out(1,1);
	I1 = adc_get(0);//电流值
//	I2 = adc_get(1);
	power = adc_get(2);//功率百分比
	trig_adc();
	if(interrupt_times < 500) 
	{
		p_get[interrupt_times] = power;
		i_get[interrupt_times] = I1;
	}
	if(TIM_GetITStatus(TIM8, TIM_IT_Update) != RESET)
	{	
		TIM_ClearITPendingBit(TIM8, TIM_IT_Update);
		if(pwm_struct[select_pwm].mode == 0)
		{
//			TIM_SetCompare1(TIM8, (uint16_t)(percent * pwm_period));
			
			if(interrupt_times < pwm_struct[select_pwm]. positive_pulse)
			{			
					pwm_struct[select_pwm].busy_flag = 1;
					pwm_ena(1);
				
				{	
					error_pid = pwm_struct[select_pwm].p_array[interrupt_times] \
								* program_data[select_pwm].current_max - I1;
//					logic_out(1,1);
					percent = pid3(error_pid);	
//					logic_out(1,0);					

					if(percent > 0.98f) percent = 0.98f;
					if(percent < 0.0f) percent = 0.0f;
//					percent = 0.3f;
					interrupt_times++;
				}
				
			}
			else
			{
				interrupt_times++;
				percent = 0;

				if( interrupt_times > pwm_struct[select_pwm].positive_pulse + pwm_struct[select_pwm].negative_pulse)
				{
					TIM_Cmd(TIM8, DISABLE);
					TIM_ClearITPendingBit(TIM8, TIM_IT_Update);
					pwm_ena(0);
					interrupt_times = 0;
					pwm_struct[select_pwm].busy_flag = 0;
					IntTerm_C3 = 0;
					PrevError_C3 = 0; 

				}
			}
	
			
		}
		else
		{
			if(interrupt_times < pwm_struct[select_pwm]. positive_pulse)
			{			
					pwm_struct[select_pwm].busy_flag = 1;
					pwm_ena(1);
				
				{	
//					logic_out(1,1);
					error_pid = pwm_struct[select_pwm].p_array[interrupt_times] - power;
					percent1 = pid1(error_pid);//percent1为计算得出的电流值
					if(percent1 > program_data[select_pwm].current_max)
						percent1 = program_data[select_pwm].current_max;
					if(percent1 < 0.0f) percent1 = 0.0f;
					error_pid = percent1 - I1;
					percent = pid3(error_pid);	
//					logic_out(1,0);					

					if(percent > 0.98f) percent = 0.98f;
					if(percent < 0.0f) percent = 0.0f;
//					percent = 0.3f;
					interrupt_times++;
				}
				
			}
			else
			{
				interrupt_times++;
				percent = 0;

				if( interrupt_times > pwm_struct[select_pwm].positive_pulse + pwm_struct[select_pwm].negative_pulse)
				{
					TIM_Cmd(TIM8, DISABLE);
					TIM_ClearITPendingBit(TIM8, TIM_IT_Update);
					pwm_ena(0);
					interrupt_times = 0;
					pwm_struct[select_pwm].busy_flag = 0;
					IntTerm_C3 = 0;
					PrevError_C3 = 0;
					IntTerm_C1 = 0;
					PrevError_C1 = 0; 

				}
			}
		}
		TIM_SetCompare1(TIM8, (uint16_t)(pwm_period * percent));
		
		if(interrupt_times < 500) 
		{
			pid_out[interrupt_times] = percent;
			code[interrupt_times] = TIM8->CCR1;
		}
	}
	
	logic_out(1,0);
	rt_interrupt_leave();
//	rt_exit_critical();/* 退出临界区*/
}
Beispiel #24
0
/* 
	Only 1 byte READ using Interrupt or Polling otherwise using DMA
*/
void I2C1_EV_IRQHandler()
{
	__IO uint16_t regSR1, regSR2;
	__IO uint32_t regSR;
	int i=10;

	rt_interrupt_enter();
	//rt_hw_led_on(10);
	regSR1 = I2C1->SR1;
	regSR2 = I2C1->SR2;
	regSR =  (regSR2 << 16) | regSR1;
	//rt_kprintf("EV=> SR1: 0x%x\tSR2: 0x%x\tSR: 0x%x status: %d\n", regSR1, regSR2, regSR, i2cStatus);
 
	if( (regSR & I2C_EVENT_MASTER_MODE_SELECT) == I2C_EVENT_MASTER_MODE_SELECT)	//EV5
	{

		if( i2cStatus == S1 ) //Send TX Command
		{
			I2C1->DR = DevAddr & 0xFE;
			i2cStatus = S2;
		}
		else if( i2cStatus == S4 ) //Send RX Command
		{
			I2C1->DR = DevAddr | 0x01;
			i2cStatus = S5;
		}


		regSR1 = 0;
		regSR2 = 0;

	}
	if( (regSR & I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)== I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED )			//EV6
	{
		switch( i2cStatus )
		{
			case S2: //Send 1st memory address phase
			{
				//I2C_DMACmd(I2C1, ENABLE);
				I2C1->DR = MemAddr[0];
				if( memtype == I2C_MEM_1Byte ) 
					i2cStatus = S2_2;
				else if( memtype == I2C_MEM_2Bytes )
					i2cStatus = S2_1;
			}
			break;
			case S5: //Set RX buffer phase
			{
				if( i2cFlag == I2C_READ_DMA )
				{
					I2C_DMAConfig(I2C1, i2c_buf, BufSize, I2C_DIRECTION_RX);
					I2C1->CR2 |= CR2_LAST_Set | CR2_DMAEN_Set;
					DMA_ITConfig( I2C1_DMA_CHANNEL_RX, DMA_IT_TC, ENABLE);
				}
				else if( i2cFlag == I2C_READ_INTERRUPT )
				{ 
					I2C1->CR2 |= I2C_IT_BUF;
					I2C1->CR1 &= CR1_ACK_Reset;
	                /* Program the STOP */
	                I2C1->CR1 |= CR1_STOP_Set;
				}
				i2cStatus = S6;
			}
			break;
		}
		
		regSR1 = 0;
		regSR2 = 0;
		//dump_i2c_register(I2C1);
	}
	if((regSR & I2C_EVENT_MASTER_BYTE_RECEIVED) == I2C_EVENT_MASTER_BYTE_RECEIVED) //EV7
	{
		//Interrupt RX complete phase
		if( i2cStatus == S6	&& i2cFlag == I2C_READ_INTERRUPT )
		{
			*i2c_buf = I2C1->DR;
			i2cStatus = S_STOP;
			rt_event_send(&i2c_event, I2C_COMPLETE);
		}
	} 
	if( (regSR & I2C_EVENT_MASTER_BYTE_TRANSMITTED) == I2C_EVENT_MASTER_BYTE_TRANSMITTED ) //EV8_2
	{
		//Start TX/RX phase
		if(i2cStatus == S3)
		{
			DMA_ClearFlag(I2C1_DMA_CHANNEL_TX, DMA_FLAG_TCIF6 );
			DMA_Cmd(I2C1_DMA_CHANNEL_TX, DISABLE);
			switch (i2cFlag)
			{
				case I2C_WRITE:
					i2cStatus = S_STOP;
					I2C1->CR1 |= CR1_STOP_Set;
					rt_event_send(&i2c_event, I2C_COMPLETE);					
				break;

				case I2C_READ_DMA:
					i2cStatus = S4;
					I2C1->CR1 |= CR1_START_Set;
				break;

				case I2C_READ_POLLING:
					i2cStatus = S_STOP;
					rt_event_send(&i2c_event, I2C_COMPLETE);
					I2C1->CR2 &= ~(CR2_LAST_Set | I2C_IT_EVT | CR2_DMAEN_Set);
					I2C1->CR1 |= CR1_START_Set;
				break;

				case I2C_READ_INTERRUPT:
					i2cStatus = S4;
					I2C1->CR1 |= CR1_START_Set;
				break;
			}
		}
		if( i2cStatus == S2_1 ) //Send 2nd memory address
		{
			if( memtype == I2C_MEM_2Bytes ) //memory address has 2 bytes
			{
				I2C1->DR = MemAddr[1];
				i2cStatus = S2_2;
			}
			if( i2cFlag == I2C_READ_POLLING || i2cFlag == I2C_READ_DMA || i2cFlag == I2C_READ_INTERRUPT)
			{
				i2cStatus = S3;
			}
		}
		if( i2cStatus == S2_2 ) //Set TX DAM phase
		{
			I2C_DMAConfig(I2C1, i2c_buf, BufSize, I2C_DIRECTION_TX);
			I2C1->CR2 |= CR2_DMAEN_Set;
			i2cStatus = S3;
		}			   
	} 

	rt_interrupt_leave();

}
void  _485_RxHandler(u8 data)
{
    //      Large   LCD   Data

    rt_interrupt_enter( );
    _485_dev_rx[_485dev_wr++] = data;


    switch(_485_RXstatus._485_receiveflag)
    {
    case  IDLE_485:
        if((0xAA != _485_dev_rx[0]) && (0x40 != _485_dev_rx[0]))
        {
            //    判断 第一个字节是否合法,否则直接清除
            _485dev_wr = 0;
            break;
        }
        switch (_485dev_wr)
        {
        case  2 :
            if((0x55 != _485_dev_rx[1]) && (0x40 != _485_dev_rx[1]))
                _485dev_wr = 0;
            break;
        case   3:
            //----------  Check  LCD  --------------------------
            if((0xAA == _485_dev_rx[0]) && (0x55 == _485_dev_rx[1]))
            {
                //AA 55 08 83 30 00 02 1E FF FF 00                     08 是长度(包含1BYTE 指令2 BYTES  地址)
                _485_RXstatus._485_RxLen = _485_dev_rx[2];
                _485_RXstatus._485_receiveflag = LARGE_LCD;
            }
            else if(0x40 != _485_dev_rx[0])
                _485dev_wr = 0;
            break;
        case    8:      //        -------  Camera  Data  -----------
            if((0x40 == _485_dev_rx[0]) && (0x40 == _485_dev_rx[1]) && (0x63 == _485_dev_rx[2]))
            {
                //  40  40  63  FF  FF  00  02           00  02  是长度  (小端)
                _485_RXstatus._485_RxLen = ((u16)_485_dev_rx[6] << 8) + (u16)_485_dev_rx[5];
                //----------------------------------
                _485dev_wr = 0; //clear now  , the bytes  receiving  later  is  pic data
                _485_RXstatus._485_receiveflag = CAMERA_Related; //  return Idle
            }
            else
                _485dev_wr = 0; // clear
            break;
        }


        break;
    case  LARGE_LCD:
        if(_485dev_wr >= (_485_RXstatus._485_RxLen + 3)) //  AA  55  08
        {
            //  send msg_queue
            _485_MsgQue_sruct.info = _485_dev_rx;
            _485_MsgQue_sruct.len = _485dev_wr;
            _485dev_wr = 0; // clear
            _485_RXstatus._485_receiveflag = IDLE_485;
        }
        break;
    case   CAMERA_Related:
        if(_485dev_wr >= _485_RXstatus._485_RxLen)
        {
            memset(_485_content, 0, sizeof(_485_content));
            //--------------------------------------------------
            memcpy(_485_content, _485_dev_rx, _485_RXstatus._485_RxLen);
            _485_content_wr = _485_RXstatus._485_RxLen; // Packet info len
            _485_CameraData_Enable = 1; // 图片数据过来了
            //---------------------------------------------------
            _485dev_wr = 0; // clear
            _485_RXstatus._485_receiveflag = IDLE_485;
        }
        break;
    default:
        _485dev_wr = 0;
        _485_RXstatus._485_receiveflag =	IDLE_485;
        break ;
    }

    rt_interrupt_leave( );
}
Beispiel #26
0
void USART2_IRQHandler(void)
{


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

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

        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(USART2,USART_IT_TXE) )
    {
        USART_ClearITPendingBit(USART2,USART_IT_TXE);
        USART_ClearFlag(USART2,USART_FLAG_TC);
        if ( P2data->SentCnt <  P2data->ToSend )
        {
            USART_SendData(USART2,P2data->TxRxBuf[P2data->SentCnt++]);        
        }
        else
        {
            USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
            USART_ITConfig(USART2, USART_IT_TC,  ENABLE);
        }
    }
    else if ( USART_GetITStatus(USART2,USART_IT_TC) )
    {
        P2data->Flags.Solo.TxStart = 0;
        Run_void(P2data->DisTxPin);
        USART_ITConfig(USART2, USART_IT_TC,  DISABLE);
    }
    /* leave interrupt */
    rt_interrupt_leave();
}
Beispiel #27
0
/*******************************************************************************
 * Function Name  : TIM4_IRQHandler
 * Description    : This function handles TIM2 global interrupt request.
 * Input          : None
 * Output         : None
 * Return         : None
 *******************************************************************************/
void TIM4_IRQHandler(void)
{
	rt_interrupt_enter();

	rt_interrupt_leave();
}
Beispiel #28
0
void EXTI4_IRQHandler(void)
{
    rt_interrupt_enter();
    HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
    rt_interrupt_leave();
}