#include "EXIT.h"
#include "delay.h" 
#include "Probe_MSO7000X_2d5g.h"
#include "AnalogChannelCtrl_2d5g_base.h"

//////////////////////////////////////////////////////////////////////////////
//       2203/7/X GHz_ljw 合并版
//////////////////////////////////////////////////////////////////////////////

//中断2服务程序
void EXTI2_IRQHandler(void)
{
	delay_ms(20);	//消抖
	if(Probe3_Btn == 0 && probeBtn3_Exit==1)	 
	{
		probeBtn3_Exit = 0; 
	}		 
	 EXTI_ClearITPendingBit(EXTI_Line2); //清除LINE0上的中断标志位 
}	
//中断4服务程序
void EXTI4_IRQHandler(void)
{
	delay_ms(20);	//消抖
	if(Probe2_Btn == 0 && probeBtn2_Exit==1)	 
	{
		probeBtn2_Exit = 0; 
	}		 
	 EXTI_ClearITPendingBit(EXTI_Line4);//清除LINE2上的中断标志位 
}
//中断6服务程序
//CH1保护触发
void EXTI9_5_IRQHandler(void)
{
	if(EXTI_GetFlagStatus(EXTI_Line6) == SET)		
	{
		delay_ms(20);	//消抖
		if(Probe1_Btn == 0 && probeBtn1_Exit==1)	 
		{
			probeBtn1_Exit = 0; 
		}		 
		 EXTI_ClearITPendingBit(EXTI_Line6);  //清除LINE3上的中断标志位  
	}
	else if(EXTI_GetFlagStatus(EXTI_Line5) == SET)
	{	
		//if(CH4_InPut==1)
		{
			CH4_PROTECT_EN=1;
		}
    EXTI_ClearITPendingBit(EXTI_Line5); //清除LINE3上的中断标志位
	}
	else if(EXTI_GetFlagStatus(EXTI_Line8) == SET)
	{
		//if(CH2_InPut==1)
		{
				CH2_PROTECT_EN=1;	
		}
		EXTI_ClearITPendingBit(EXTI_Line8); //清除中断标志位
	}
}

//中断10服务程序
//CH1保护触发
void EXTI15_10_IRQHandler(void)
{
		if(EXTI_GetFlagStatus(EXTI_Line10) == SET)		
		{
			delay_ms(20);	//消抖
			if(Probe_Res_On == 0 && probeBtnRes_Exit==1)	 
			{
				probeBtnRes_Exit = 0; 
			}		 
			EXTI_ClearITPendingBit(EXTI_Line10);//清除中断标志位  
		}
		else if(EXTI_GetFlagStatus(EXTI_Line12) == SET)		
		{
			delay_ms(20);	//消抖
			if(Probe4_Btn == 0 && probeBtn4_Exit==1)	 
			{
				probeBtn4_Exit = 0; 
			}		 
			EXTI_ClearITPendingBit(EXTI_Line12);//清除中断标志位  
		}
		else
		{		
			if(EXTI_GetFlagStatus(EXTI_Line11) == SET)
			{
				//if(CH1_InPut==1)
				//{
						CH1_PROTECT_EN=1;	
				//}
				EXTI_ClearITPendingBit(EXTI_Line11); //清除中断标志位
			}
			
		}
}

void EXTI3_IRQHandler(void)//CH2保护触发
{
	//if(CH3_InPut==1){
    CH3_PROTECT_EN=1;
	//}
    EXTI_ClearITPendingBit(EXTI_Line3); //清除LINE1上的中断标志位
}


//void EXTI8_IRQHandler(void)//CH3保护触发
//{
//	 CH3_PROTECT_EN=1;
//	 EXTI_ClearITPendingBit(EXTI_Line8); //清除LINE2上的中断标志位
//}
 
//中断12服务程序
void EXTI12_IRQHandler(void)
{
	delay_ms(10);	//消抖
	if(Probe_Res_Btn == 0 && probeBtnRes_Exit ==1)	 
	{
		probeBtnRes_Exit = 0; 
	}		 
	EXTI_ClearITPendingBit(EXTI_Line12);//清除LINE4上的中断标志位  
}
	   
//外部中断初始化程序
//初始化PE2~4,PA0为中断输入.
void EXTIX_Init(void)
{
	NVIC_InitTypeDef   NVIC_InitStructure;
	EXTI_InitTypeDef   EXTI_InitStructure;
 
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);//使能SYSCFG时钟
	 
	SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOD, EXTI_PinSource2); 
	SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOD, EXTI_PinSource4); 
	SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOD, EXTI_PinSource6); 
	SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOD, EXTI_PinSource8); 
	SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource10); 
	SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource12); 
	SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource5); 
	
	/* 配置EXTI_Line */
	EXTI_InitStructure.EXTI_Line = EXTI_Line2 | EXTI_Line6 |  EXTI_Line5 |EXTI_Line4 |  EXTI_Line8 |EXTI_Line10| EXTI_Line12;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//中断事件
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;  
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;//中断线使能
  EXTI_Init(&EXTI_InitStructure);//配置

	NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn; 
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;//抢占优先级3
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;//子优先级2
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能外部中断通道
  NVIC_Init(&NVIC_InitStructure);//配置
	
	NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn; 
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;//抢占优先级1
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;//子优先级2
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能外部中断通道
  NVIC_Init(&NVIC_InitStructure);//配置
	 
	NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; 
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x03;//抢占优先级2
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;//子优先级2
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能外部中断通道
  NVIC_Init(&NVIC_InitStructure);//配置
	 
	NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; 
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x04;//抢占优先级2
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;//子优先级2
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能外部中断通道
  NVIC_Init(&NVIC_InitStructure);//配置
	  
}

 
