/**
  ******************************************************************************
  * @file    ys32md211_it.c 
  * @author  YSPRING Application Team
  * @version V1.0.1
  * @date    2022.12.7
  * @brief   Main Interrupt Service Routines.
  *          This file provides template for all exceptions handler and 
  *          peripherals interrupt service routine.
  ******************************************************************************
 */

/* Includes ------------------------------------------------------------------*/
#include "ys32md211_it.h"
#include "motor.h"
#include "key.h"
extern 	uint8_t  M_1ms_flag;
/** @addtogroup ys32md211_StdPeriph_Examples
  * @{
  */

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/******************************************************************************/
/*            Cortex-M0 Processor Exceptions Handlers                         */
/******************************************************************************/

/**
  * @brief  This function handles NMI exception.
  * @param  None
  * @retval None
  */
void NMI_Handler(void)
{
}

/**
  * @brief  This function handles Hard Fault exception.
  * @param  None
  * @retval None
  */
void HardFault_Handler(void)
{
  /* Go to infinite loop when Hard Fault exception occurs */
  while (1)
  {
  }
}
//********************************************//
void TIM1_CC_IRQHandler(void)
{
	
   
  if(TIM_GetITStatus(TIM1,TIM_IT_CC4) != RESET ) 
  {
		 //LED_TOGGLE;
     TIM_ClearITPendingBit(TIM1 ,TIM_IT_CC4);
		 motor_commutate_process();
  }
}
/**
  * @brief  This function handles SVCall exception.
  * @param  None
  * @retval None
  */
void SVC_Handler(void)
{
}

/**
  * @brief  This function handles PendSVC exception.
  * @param  None
  * @retval None
  */
void PendSV_Handler(void)
{
}

/**
  * @brief  This function handles SysTick Handler.
  * @param  None
  * @retval None
  */
void SysTick_Handler(void)
{
	// M_1ms_flag=1;
}

/******************************************************************************/
/*                 ys32md211 Peripherals Interrupt Handlers                   */
/*  Add here the Interrupt Handler for the used peripheral(s) (PPP), for the  */
/*  available peripheral interrupt handler's name please refer to the startup */
/*  file (startup_ys32md211.s).                                               */
/******************************************************************************/

void ADC_COMP_IRQHandler (void)
{
    extern uint8_t AdcEOC_Flag;
    extern uint16_t AdcData[];
    
    if(ADC_GetFlagStatus(ADC,ADC_FLAG_JEOSEQ) != RESET ) 
    {
        AdcData[0] = ADC_GetInjectedConversionValue(ADC, 1);
        AdcData[1] = ADC_GetInjectedConversionValue(ADC, 2);
        AdcData[2] = ADC_GetInjectedConversionValue(ADC, 3);
        AdcData[3] = ADC_GetInjectedConversionValue(ADC, 4);
        AdcData[4] = ADC_GetInjectedConversionValue(ADC, 5);
        AdcEOC_Flag = 1;
        ADC_ClearFlag(ADC, ADC_FLAG_JEOSEQ);
    }
}
/**
  * @brief  This function handles TIM3_CC_IRQn.
  * @param  None
  * @retval None
  */
void TIM3_IRQHandler(void)
{
  extern void PwmCap_IRQ(void);
  
  PwmCap_IRQ();
  
  TIM3->SR=0;
}
//**********************************************************************//
void TIM17_IRQHandler (void)
{
   // extern uint32_t time;
    if(TIM_GetITStatus(TIM17,TIM_IT_Update) != RESET ) 
    {
       // time++;
			  //LED_TOGGLE; 
			  sf_check();
        TIM_ClearITPendingBit(TIM17 ,TIM_IT_Update);
    }
}
//**********************************************************************//
void TIM14_IRQHandler (void)
{
   // extern uint32_t time;
    if(TIM_GetITStatus(TIM14,TIM_IT_Update) != RESET ) 
    {
			  //LED_TOGGLE; 
        M_1ms_flag=1;
        TIM_ClearITPendingBit(TIM14 ,TIM_IT_Update);
    }
}
/**
  * @}
  */

/**
  * @}
  */

