Example #1
0
//HW层中断函数,用户无需调用
void UART3_IRQHandler(void)
{
#if (UCOS_II > 0u)
  OS_CPU_SR  cpu_sr = 0u;
  OS_ENTER_CRITICAL(); //告知系统此时已经进入了中断服务子函数
  OSIntEnter();
  OS_EXIT_CRITICAL();
#endif
  
  //进入接收中断函数
  if((UART3->S1 & UART_S1_RDRF_MASK) && (UART3->C2 & UART_C2_RIE_MASK))
  {
    UART_R_ISR[3]();
  }
  //进入发送中断函数
  if((UART3->S1 & UART_S1_TDRE_MASK) && (UART3->C2 & UART_C2_TIE_MASK))
  {
    UART_T_ISR[3]();
  }
  
#if (UCOS_II > 0u)
  OSIntExit();          //告知系统此时即将离开中断服务子函数
#endif
}
Example #2
0
/**
 * @brief  This function handles TIM3 interrupt request.
 * @param  None
 * @retval None
 */
void TIM2_IRQHandler(void)
{
    uint8_t retval = OS_ERR_NONE;    
    static TASK1_MBOX_TypeDef mbox;

    OSIntEnter();

    LEDS_Toggle(LED_7);

    //
    // Clear the timer.  Failure to do so and you will just 
    // stay here since the timer will keep the IRQ asserted
    //
    //TIM2->SR &= ~TIM_SR_UIF;
    TIM_ClearFlag(TIM2, TIM_SR_UIF);
    
    
    //
    // Clear the interrupt at the NVIC level
    //
    NVIC_ClearPendingIRQ(TIM2_IRQn);

    //
    // Wake up task 1
    //
    mbox.action = 0x01;    
    retval = OSMboxPost(task1_mbox, (void *) &mbox);
    if (retval != OS_ERR_NONE){
	//Uh oh....??????
//	while(1);
    }
    
    OSIntExit();

    return;    
}
/*******************************************************************************
* Function Name  : TMR0_IRQHandler
* Description    : This function handles timer 0 interrupt.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
__irq void TMR0_IRQHandler(void)
{
    UINT32 RegEoi;
    
    OSIntEnter();
    
  //  ASSERT(NVIC_GetIRQChannelPendingBitStatus(TMR0_IRQn) == SET);
  //  ASSERT(*Tmr0IntStatus & 0x01);
    //  关中断
    NVIC_DisableIRQ(TMR0_IRQn);
  
    NVIC_ClearIRQChannelPendingBit(TMR0_IRQn);

// clear timer interrupt
    RegEoi = *Tmr0Eoi;
    RegEoi = *TmrsEoi;
    RegEoi = RegEoi;
    

   // 开中断
    NVIC_EnableIRQ(TMR0_IRQn);

    OSIntExit();
}
Example #4
0
//systick中断服务函数,系统心跳
void SysTick_Handler(void)
{
 OSIntEnter();//进入中断
 OSTimeTick();//调用ucos的时钟服务程序
 OSIntExit();//触发任务切换软中断
}
/*********************************************************************************************************
* Function Name:        TIMER3_IRQHandler
* Description:          定时器3中断处理函数
* Input:                None
* Output:               None
* Return:               None
*********************************************************************************************************/
void TIMER3_IRQHandler (void)
{
	OSIntEnter();
	T3IR = 1;	
	OSIntExit();
}
/*********************************************************************************************************
* Function Name:        TIMER2_IRQHandler
* Description:          定时器2中断处理函数
* Input:                None
* Output:               None
* Return:               None
*********************************************************************************************************/
void TIMER2_IRQHandler (void)
{
	OSIntEnter();
	T2IR = 1;	
	OSIntExit();
}
void USART1_IRQHandler(void)                	//����1�жϷ������
	{
	u8 Res;
		u16 len;
		u16 t;

#ifdef OS_TICKS_PER_SEC	 	//���ʱ�ӽ�����������,˵��Ҫʹ��ucosII��.
	OSIntEnter();    
#endif
	if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)  //�����ж�(���յ������ݱ�����0x0d 0x0a��β)
		{
		Res =USART_ReceiveData(USART1);//(USART1->DR);	//��ȡ���յ�������
		
		if((USART_RX_STA&0x8000)==0)//������
			{
			if(USART_RX_STA&0x4000)//���յ���0x0d
				{
				if(Res!=0x0a)USART_RX_STA=0;//���մ���,���¿�ʼ
				else USART_RX_STA|=0x8000;	//��������� 
				}
			else //��û�յ�0X0D
				{	
				if(Res==0x0d)USART_RX_STA|=0x4000;
				else
					{
					USART_RX_BUF[USART_RX_STA&0X3FFF]=Res ;
					USART_RX_STA++;
					if(USART_RX_STA>(USART_REC_LEN-1))USART_RX_STA=0;//�������ݴ���,���¿�ʼ����	  
					}		 
				}
			}   
				if (USART_RX_STA & 0x8000)//bit15??	?��?��3��?? ?��?���?????�??��?���?
			{
					len = USART_RX_STA & 0x3FFF;////?��?�?�?3�?�'�13-0
					printf("usart_flag1::%d   and usart_flag2:: %d\n",usart_flag1,usart_flag2);
				 // printf("_usart_recv_packet1::%s   and usart_flag2:: %s\n",_usart_recv_packet1,_usart_recv_packet2);
				 
					printf("USART_RX_BUF::%s \n",USART_RX_BUF);
					
							//USART1->DR = USART_RX_BUF[t];
					if( usart_flag1==0){
						USART_ERR_NOMESSAGE=0;
						for (t = 0; t<len; t++){
							_usart_recv_packet1[t]=USART_RX_BUF[t];
							while ((USART1->SR & 0X40) == 0);
						}
						usart_flag1=1;
					}
					else if (	 usart_flag2==0&&usart_flag1==1){
						USART_ERR_NOMESSAGE=0;
						for (t = 0; t<len; t++){
							_usart_recv_packet2[t]=USART_RX_BUF[t];
							while ((USART1->SR & 0X40) == 0);
						}
						usart_flag2=1;	
						
						}
					
					printf("over\n");
					
				USART_RX_STA=0;

		}
			 	// _usart_recv_packet_len=sizeof(_usart_recv_packet_current);
			 
     } 
#ifdef OS_TICKS_PER_SEC	 	//���ʱ�ӽ�����������,˵��Ҫʹ��ucosII��.
	OSIntExit();  											 
#endif
} 
Example #8
0
/**
  * @brief  This function handles SysTick Handler.
  * @param  None
  * @retval None
  */
void SysTick_Handler(void)
{
    OSIntEnter();
    OSTimeTick();
    OSIntExit();
}
void I2C0_IRQHandler(void)
{
	OSIntEnter();
	(*i2c0HandlerPtr)();
	OSIntExit();
}
Example #10
0
////        }
////		/*加速处理过程结束*/
////        
////		/*减速处理过程*/
////		 if(MotorFreqD == 1)
////		 {
////		     MotorFreqD = 2;
////			 FreqFlag = 0;
////		 }
////		 if(MotorFreqD == 2)
////		 {
////		     TIM_Cmd(TIM1,DISABLE);
////			 if(FreqFlag < MotorFreqFlag)
////			 {  
////		     	if(FreqFlag != (MotorFreqFlag - 1))
////			 	{
////			 		PTO_HZ_Period(MotorFreqNow - DEC_HZ_MIN, DEC_PERIOD);
////			 	}
////			 	else if(FreqFlag == (MotorFreqFlag - 1))
////				{
////					PTO_Stop();
////				    TIM_Cmd(TIM5,DISABLE);//关闭定时
////					
////					MotorFreqD = 0;
////					MotorFreqFlag = 0;/*恢复初值*/
////		            FreqFlag = 0; /*恢复中间变量初值*/
////				}
////				FreqFlag ++; 
////		     }
////		 }
////	} 
////	TIM_ClearITPendingBit(TIM5, TIM_IT_Update  );  //清除TIMx的中断待处理位:TIM 中断源 
////    OSIntExit();    
////}
////定时器1更新中断服务程序	 
void TIM1_UP_IRQHandler(void)
{ 	
    static u8 tempflag = 0;

    OSIntEnter();

    if(MotorDir == 1)
        PulseNum_Global++;
    else if(MotorDir == 2)
        PulseNum_Global--;
    if(TIM_GetITStatus(TIM1, TIM_IT_Update) != RESET) //检查指定的TIM中断发生与否:TIM 中断源 
	{        
        switch(MotorActionState)
        {
            case 1://启动加速状态 
                tempflag = 0;	/*计算中间变量 设定初值 0*/
                PulseNum_TEMP =(MotorDir > 1)? (PulseNum_Global +1):(PulseNum_Global - 1);/*记录初始加速脉冲初值*/
                MotorActionState = 2;//转移状态 2 加速过程中
            break;
            case 2://加速过程 处理
                if((u32)abs(PulseNum_Global - PulseNum_TEMP) > (PulseNum_Buf[tempflag] - 1)) //输出达到指定脉冲数
                {
                    PulseNum_TEMP = PulseNum_Global;/*记录初始加速脉冲初值*/
                    tempflag++;  
                    if(tempflag == ACC_Status_Flag) // 
                    {                        
                        if(PulseNum_ConstantVel == 0) /*如果设定脉冲数等于2倍的加减速所需脉冲个数 即匀速动作脉冲数为 0 加速完毕直接进入减速过程*/
                        {
                            tempflag = 0;
                            MotorActionState = 4;//跳至减速状态 
                            break;                            
                        }
                        else
                        {
                            MotorActionState = 3;//进入恒速动作过程
                            PTO_Cycle(MotorCycleTarget);
                            break;                            
                        }              
                    }
                    if(tempflag < ACC_Status_Flag) //未达到目标频率 继续加速
                    {
                        PTO_Cycle(MotorCycle_Buf[tempflag]);
                    }
                }
                break;
            case 3://恒速动作 
                if((u32)abs(PulseNum_Global - PulseNum_TEMP) > (PulseNum_ConstantVel - 1))//输出达到指定脉冲数
                {
                    tempflag = 0;
                    MotorActionState = 4;  //转移状态 4 需要进入减速
                }
                break;
            case 4://启动减速
                tempflag = DEC_Status_Flag;	/*计算中间变量 设定初值 0*/
                PulseNum_TEMP =(MotorDir > 1)? (PulseNum_Global +1):(PulseNum_Global - 1);               
                PTO_Cycle(MotorCycle_Buf[tempflag - 1]); 
                MotorActionState = 5; //转移状态5 减速过程中           
                break;
            case 5://减速过程中
                if((u32)abs(PulseNum_Global - PulseNum_TEMP) > ((PulseNum_Buf[tempflag -1] - 1)))//达到指定脉冲数
                {
                    PulseNum_TEMP = PulseNum_Global;/*记录脉冲值*/
                    tempflag--;
                    if(tempflag == 0) //达到0
                    {
                        PTO_Stop();                   
                    }
                    if(tempflag > 0) 
                    {
                        PTO_Cycle(MotorCycle_Buf[tempflag - 1]);
                    }            
                } 
                break;
            default:
                break;
        }
    }
    TIM_ClearITPendingBit(TIM1, TIM_IT_Update);  //清除TIMx的中断待处理位:TIM 中断源 
    OSIntExit();
}
Example #11
0
void OSTickISR()
{
    OSIntEnter();
    OSTimeTick();
    OSIntExit();
}
void Uart0IsrHandler (void)
{
	unsigned char i,ch,crc;
	OSIntEnter();   
	read_in = 0;	
    while((U0IIR & 0x01) == 0) {                         			//判断是否有中断挂起
        switch(U0IIR & 0x0E){ 										//判断中断标志                                     
            case 0x04 : for(i = 0;i < 8;i++){
							read_buf[read_in++] = U0RBR;
						}
					break;
            case 0x0C : while((U0LSR & 0x01) == 0x01){                         
		                	read_buf[read_in++] = U0RBR;
		                }
		                break;
            default	: break;
        }
    }
	
	if(uart0_req == 0){
		for(i = 0;i < read_in;i++){
			ch = read_buf[i];
			if(uart0_in == 0){
				if(ch == HEAD_PC){
					uart0_buf[uart0_in++] = ch;
					Timer.uart0_timeout = 50;
				}
			}
			else if(uart0_in == 1){ 
				uart0_len = ch;
				if(uart0_len >= UART0_BUF_SIZE){
					uart0_in = 0;
				}
				else{
					uart0_buf[uart0_in++] = ch;
				}
			}
			else if(uart0_in >= uart0_len){ 
				uart0_buf[uart0_in++] = ch; 
				crc = XorCheck((unsigned char *)uart0_buf,uart0_len);
				if(crc == ch){
					uart0_req = 1;
				}
				else{
					uart0_req = 0;
				}
				uart0_len = uart0_in;
				uart0_in = 0;
			}
			else{
				uart0_buf[uart0_in++] = ch;
			}
			
			if(uart0_in > 0 && Timer.uart0_timeout == 0){
				uart0_in = 0;
				//uart0_req = 0;
			}
		}
	}
	
    OSIntExit();

}
Example #13
0
 void TIM4_IRQHandler(void)   //TIM4中断
{	 
	OSIntEnter();   
	if (TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET)  //检查TIM4更新中断发生与否
		{	  
		TIM_ClearITPendingBit(TIM4, TIM_IT_Update  );  //清除TIMx更新中断标志
	if(mybox.master==0)	
		{
		
		if(dog_clock==0)
		   { 
		   // LED0=!LED0;
			turn_master_id(mybox.myid);
			  cont++;
			}
			if(dog_clock>0){dog_clock--;cont=1;}
		 }
		 if (mystatus.work_status[0]==1)  //工作时间的计时
		    {  life_time_1++;
		       if(life_time_1==10)
			   { mystatus.work_time[0]++;
			     life_time_1=0;
				  }
			        if(mystatus.work_time[0]==37)mystatus.work_time[0]=39;
				  if(mystatus.work_time[0]==254)mystatus.work_time[0]=0;
			   }
		 	
		 if(mystatus.work_status[1]==1)
		 	{ life_time_2++;
              if(life_time_2==10)
			  	{  mystatus.work_time[1]++;
			       life_time_2=0;
              	         }   
                   if(mystatus.work_time[1]==37)mystatus.work_time[1]=39;
			 if(mystatus.work_time[1]==254)mystatus.work_time[1]=0;	   
			    
		     }

		 		 if (mystatus.work_status[2]==1)  //工作时间的计时
		    {  life_time_3++;
		       if(life_time_3==10)
			   { mystatus.work_time[2]++;
			     life_time_3=0;
				  }
			        if(mystatus.work_time[2]==37)mystatus.work_time[2]=39;
				  if(mystatus.work_time[2]==254)mystatus.work_time[2]=0;
			   }

		   if (mystatus.work_status[0]==0)  //工作时间清零
		    {   mystatus.work_time[0]=0;}
		    if (mystatus.work_status[1]==0)  //工作时间清零
		    {   mystatus.work_time[1]=0;}

		    if (mystatus.work_status[2]==0)  //工作时间清零
		    {   mystatus.work_time[2]=0;}

			if(mybox.master==1)
		       {  idle_time++;
			if(idle_time==65535)idle_time=0;
			}
		}
   	OSIntExit();  
}
Example #14
0
void SysTick_Handler(void)
{
	OSIntEnter(); 	 //用于统计中断的嵌套层数,对嵌套层数+1
	OSTimeTick();	   //统计时间,遍历任务,对延时任务计时减1
	OSIntExit();	   //对嵌套层数减1,在退出中断前启动任务调度
}
Example #15
0
void SysTick_Handler(void)			// 非常重要   系统滴答
{
	OSIntEnter();
	OSTimeTick();
	OSIntExit();
}
Example #16
0
void EXTI15_10_IRQHandler()
{
    uint32 bit;
	OSIntEnter();
    if(EXTI_GetITStatus(EXTI_Line10) == SET)
    {
        if(gExtiTrigerFlag[10] == RISE_EDGE)
        {
            gExtiTrigerFlag[10] = FALLING_EDGE;
            EXTI->RTSR &= (uint32)~(1 << 10);
            EXTI->FTSR |= (uint32)(1 << 10);
            ExtiISR(10,RISE_EDGE);
        }
        else
        {
            gExtiTrigerFlag[10] = RISE_EDGE;
            EXTI->RTSR |= (uint32)(1 << 10);
            EXTI->FTSR &= (uint32)~(1 << 10);
            ExtiISR(10,FALLING_EDGE);

        }

        EXTI_ClearITPendingBit(EXTI_Line10);

    }
	if(EXTI_GetITStatus(EXTI_Line11) == SET)
    {
        EXTI_ClearITPendingBit(EXTI_Line11);

    }
    if(EXTI_GetITStatus(EXTI_Line12) == SET)
    {
        EXTI_ClearITPendingBit(EXTI_Line12);

    }
    if(EXTI_GetITStatus(EXTI_Line13) == SET)
    {
        EXTI_MaskIRQ(13);
        delayMs(20);
        if(gExtiTrigerFlag[13] == RISE_EDGE)
        {
            gExtiTrigerFlag[13] = FALLING_EDGE;
            EXTI->RTSR &= (uint32)~(1 << 13);
            EXTI->FTSR |= (uint32)(1 << 13);
            ExtiISR(13,RISE_EDGE);
        }
        else
        {
            gExtiTrigerFlag[13] = RISE_EDGE;
            EXTI->RTSR |= (uint32)(1 << 13);
            EXTI->FTSR &= (uint32)~(1 << 13);
            ExtiISR(13,FALLING_EDGE);

        }
        EXTI_ClearITPendingBit(EXTI_Line13);
        EXTI_UnMaskIRQ(13);

    }
    if(EXTI_GetITStatus(EXTI_Line14) == SET)
    {
        EXTI_ClearITPendingBit(EXTI_Line14);

    }
    if(EXTI_GetITStatus(EXTI_Line15) == SET)
    {
        EXTI_ClearITPendingBit(EXTI_Line15);

    }

	OSIntExit();

}