/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdio.h>
#include "PE43711.h"
#include "uart.h"
#include "Bluecell_operate.h"
#include "eeprom.h"
#include "flash.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc1;
ADC_HandleTypeDef hadc3;
DMA_HandleTypeDef hdma_adc1;
DMA_HandleTypeDef hdma_adc3;

I2C_HandleTypeDef hi2c2;

IWDG_HandleTypeDef hiwdg;

TIM_HandleTypeDef htim6;

UART_HandleTypeDef huart1;
UART_HandleTypeDef huart2;
DMA_HandleTypeDef hdma_usart1_tx;
DMA_HandleTypeDef hdma_usart2_tx;

/* USER CODE BEGIN PV */
volatile uint16_t ADC1value[ADC1_CNT];
volatile uint16_t ADC3value[ADC3_CNT];

volatile uint32_t HFR_ADC1value[ADC1_CNT];
volatile uint32_t HFR_ADC3value[ADC3_CNT];

volatile uint16_t ADC1valuearray[ADC1_CNT][ADC_AVERAGECNT];
volatile uint16_t ADC3valuearray[ADC3_CNT][ADC_AVERAGECNT];
volatile uint16_t ADC1Desc_valuearray[4][ADC_AVERAGECNT];
volatile uint16_t ADC3Desc_valuearray[5][ADC_AVERAGECNT];

volatile uint32_t AdcTimerCnt = 0;
volatile uint32_t LedTimerCnt = 0;
volatile uint32_t UartRxTimerCnt = 0;
volatile uint32_t LDTimerCnt = 0;

volatile uint32_t ALCTimerCnt = 0;
volatile uint32_t AGCTimerCnt = 0;
volatile uint32_t MBIC_ShutdownCnt[MBIC_Shutdown_MaxIndex] ={ 0,};


volatile uint32_t AGC_On_AlarmTimerCnt[AGC_Alarm_DL_Index_MAX] = {0,};
volatile uint32_t AGC_Off_AlarmTimerCnt[AGC_Alarm_DL_Index_MAX] = {0,};

volatile uint32_t ALC_On_AlarmTimerCnt[ALC_Alarm_UL_Index_MAX] = {0,};
volatile uint32_t ALC_Off_AlarmTimerCnt[ALC_Alarm_UL_Index_MAX] = {0,};


volatile uint32_t DET_UL_On_AlarmTimerCnt[DET_Alarm_UL_Index_MAX] = {0,};
volatile uint32_t DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL_Index_MAX] = {0,};

volatile uint32_t DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL_Index_MAX] = {0,};
volatile uint32_t DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL_Index_MAX] = {0,};
volatile uint32_t DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL_Index_MAX] = {0,};
volatile uint32_t DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL_Index_MAX] = {0,};

volatile uint32_t DET_DL_Normal_Shutdown_On_AlarmTimerCnt[DET_Alarm_UL_Index_MAX] = {0,};
volatile uint32_t DET_UL_Normal_Shutdown_On_AlarmTimerCnt[DET_Alarm_UL_Index_MAX] = {0,};


volatile uint32_t DET_UL_Shutdown_On_AlarmTimerCnt[DET_Alarm_UL_Index_MAX] = {0,};
volatile uint32_t DET_UL_Shutdown_Off_AlarmTimerCnt[DET_Alarm_UL_Index_MAX] = {0,};

volatile uint32_t DET_DL_Shutdown_On_AlarmTimerCnt[DET_Alarm_DL_Index_MAX] = {0,};
volatile uint32_t DET_DL_Shutdown_Off_AlarmTimerCnt[DET_Alarm_DL_Index_MAX] = {0,};


volatile uint32_t AlarmTimerOffCnt = 0;
volatile uint32_t AlarmTimerOnCnt = 0;


volatile uint32_t Alarm_Temp_TimerOffCnt = 0;
volatile uint32_t Alarm_Temp_TimerOnCnt = 0;

volatile uint32_t Alarm_DL_Level_TimerOffCnt = 0;
volatile uint32_t Alarm_DL_Level_TimerOnCnt = 0;

volatile uint32_t Alarm_UL_Level_TimerOffCnt = 0;
volatile uint32_t Alarm_UL_Level_TimerOnCnt = 0;

volatile uint32_t SelfTestLifeCnt = 0;

volatile uint32_t ADC_100ms_Cnt = 0;

volatile uint32_t AlarmReport_TimerCnt = 0;

volatile uint32_t ALC_Delay_Cnt[ALC_Alarm_UL_Index_MAX] = {0,};


volatile bool     AlarmTimerOnSet = 0;
volatile bool     AlarmTimerOffSet = 0;


//extern bool AGC_AlarmTimerSet[AGC_Alarm_DL_Index_MAX];
extern bool ADC_Alarm_DL_High_Set[DET_Alarm_DL_Index_MAX];
extern bool ADC_Alarm_DL_Low_Set[DET_Alarm_DL_Index_MAX];

extern bool ADC_Alarm_UL_Set[DET_Alarm_UL_Index_MAX];
extern uint8_t ALC_AlarmSet[ALC_Alarm_UL_Index_MAX];
extern bool AGC_AlarmSet[AGC_Alarm_DL_Index_MAX];
extern bool ADC_Alarm_UL_Shutdown_Set[DET_Alarm_UL_Shutdown_Index_MAX];
extern bool ADC_Alarm_DL_Shutdown_Set[DET_Alarm_DL_Shutdown_Index_MAX];
extern bool ADC_Alarm_DL_Normal_Shutdown_Set[DET_Alarm_DL_Shutdown_Index_MAX];
extern bool ADC_Alarm_UL_Normal_Shutdown_Set[DET_Alarm_UL_Shutdown_Index_MAX];
uint8_t* MBIC_UL_ShutdownCount;
uint8_t* MBIC_DL_ShutdownCount;
uint8_t* PrevMBIC_UL_ShutdownCount;
uint8_t* PrevMBIC_DL_ShutdownCount;
uint8_t Led_ToggleCntSet = 0;


/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_ADC1_Init(void);
static void MX_ADC3_Init(void);
static void MX_USART2_UART_Init(void);
static void MX_TIM6_Init(void);
static void MX_I2C2_Init(void);
static void MX_IWDG_Init(void);
static void MX_NVIC_Init(void);
/* USER CODE BEGIN PFP */
extern void Booting_LedInit(void);
extern void Bluecell_AttenInitialize();
extern void DET_LevelAlarmCheck();
extern void Alarm_Check();
extern void SelfTestTimer_Operate();
extern void FRBT_Operate();
extern void AlarmLog_Report();
extern void Flash_InitRead();
extern void HFR_TypeInit();


/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
uint32_t ShutdownCnt_Get(uint8_t index){
    return MBIC_ShutdownCnt[index];
}
void ShutdownCnt_Set(uint8_t index,uint8_t val){
    MBIC_ShutdownCnt[index] = val;
}

void Pol_Delay_us(volatile uint32_t microseconds)
{
  /* Go to number of cycles for system */
  microseconds *= (SystemCoreClock / 1000000);
 
  /* Delay till end */
  while (microseconds--);
}


int _write (int file, uint8_t *ptr, uint16_t len)
{
#if 1 // PYJ.2020.06.03_BEGIN --
    HAL_UART_Transmit(&hTest, ptr, len,10);
#else
    HAL_UART_Transmit(&hTerminal, ptr, len,10);    
#endif // PYJ.2020.06.03_END -- 

    return len;
}
uint32_t adc1cnt = 0 ;
uint32_t adc3cnt = 0 ;
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
#if 0 // PYJ.2020.08.07_BEGIN -- 
    if(hadc->Instance == hadc1.Instance)
    {
        if(adc1cnt < ADC_AVERAGECNT){
            for(int i = 0; i < 4; i++){
                ADC1valuearray[i][adc1cnt] = ADC1value[i];
            }
            adc1cnt++;
        }
    }
    if(hadc->Instance == hadc3.Instance)
    {
        if(adc3cnt < ADC_AVERAGECNT){
            for(int i = 0; i < 5; i++){
                ADC3valuearray[i][adc3cnt] = ADC3value[i];
            }
            adc3cnt++;
        }
    }
#else
    if(adc1cnt == ADC_AVERAGECNT)
        adc1cnt = 0;
    if(adc3cnt == ADC_AVERAGECNT)
        adc3cnt = 0;
    if(hadc->Instance == hadc1.Instance)
    {
        for(int i = 0; i < 4; i++){
            ADC1valuearray[i][adc1cnt] = ADC1value[i];
            HFR_ADC1value[i] += ADC1value[i];

        }
        adc1cnt++;
    }
   
    if(hadc->Instance == hadc3.Instance)
    {
        for(int i = 0; i < 5; i++){
            ADC3valuearray[i][adc3cnt] = ADC3value[i];
            HFR_ADC3value[i] += ADC3value[i];            
        }
        adc3cnt++;
    }    
    
//    printf("ADC_100ms_Cnt : %d \r\n",ADC_100ms_Cnt);
    

#endif // PYJ.2020.08.07_END -- 
}

extern void DET_LevelAlarmCheck();


extern void ALC_Function();
extern void Boot_LED_Toggle(void);
extern void ADC_Check(void);
extern void ADC_Sampling_Func();

uint8_t MBICTest_Firmdata[8]  = {1,2,3,4,5,6,7,8};

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
  {
  /* USER CODE BE1GIN 1 */


  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_USART1_UART_Init();
  MX_ADC1_Init();
  MX_ADC3_Init();
  MX_USART2_UART_Init();
  MX_TIM6_Init();
  MX_I2C2_Init();
  MX_IWDG_Init();

  /* Initialize interrupts */
  MX_NVIC_Init();
  /* USER CODE BEGIN 2 */
  while(!(HAL_ADCEx_Calibration_Start(&hadc3)==HAL_OK));
  while(!(HAL_ADCEx_Calibration_Start(&hadc1)==HAL_OK));
  HAL_ADC_Start_DMA(&hadc3, (uint16_t*)ADC3value, 5);
  HAL_ADC_Start_DMA(&hadc1, (uint16_t*)ADC1value, 4);
  HAL_TIM_Base_Start_IT(&htim6);


  setbuf(stdout, NULL);
  uint32_t  CurrApiAddress = 0,Bank1Address=0,Bank2Address = 0;
  int32_t CrcLength = 0;
        
        
        

  PE43711_PinInit();
  EEPROM_M24C08_Init();
  Flash_InitRead();
  Booting_LedInit();
  HFR_TypeInit();
  Flash_TempDataRead(bluecell_Currdatastatus.CPU_Current_Bank);
  InitUartQueue(&TerminalQueue);
  bluecell_Currdatastatus.LED_TEST = true;
  Led_ToggleCntSet = 6; // Booting Led 3Cnt  ,Led Test 10Cnt


#if 1 // PYJ.2020.05.06_BEGIN --
    printf("****************************************\r\n");
    printf("MBIC Project\r\n");
    printf("Build at %s %s\r\n", __DATE__, __TIME__);
    printf("Copyright (c) 2020. BLUECELL\r\n");
    printf("****************************************\r\n");
    printf("Alarm Test mode Status : %d \r\n",bluecell_Currdatastatus.ALARM_TESTMODE);
#endif // PYJ.2020.05.06_END --  
    /* whachdog Reset Operated? */
  //   if(__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) == SET)
  // {
  //   __HAL_RCC_CLEAR_RESET_FLAGS();
  // }

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    //ADC_Sampling_Func();
    Uart_Check();      /*Usart Rx*/
    ADC_Check();       /*Det Calc + DL/UL Alarm Check Function*/
    Boot_LED_Toggle(); /*LED Check*/
    ALC_Function();    /*ALC Function*/
    AGC_Function();    /*AGC Function*/
    Alarm_Check();     /*Function to check all alarm status variables*/
    SelfTestTimer_Operate();
    FRBT_Operate();
    AlarmLog_Report();
    HAL_IWDG_Refresh(&hiwdg);
#if 0 // PYJ.2020.08.11_BEGIN -- 
      for(int i = 0; i < ADC1_CNT; i++){
          ADC_Sampling_Func(1,HFR_ADC1value[i]/adc1cnt,i);
          HFR_ADC1value[i] = 0;
      }
      for(int i = 0; i < ADC3_CNT; i++){
          ADC_Sampling_Func(3,HFR_ADC3value[i]/adc3cnt,i);
          HFR_ADC3value[i] = 0;
      }
      
      adc1cnt = 0;
      adc3cnt = 0;     
#endif // PYJ.2020.08.11_END -- 
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
 
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

  /** Initializes the CPU, AHB and APB busses clocks 
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL14;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the CPU, AHB and APB busses clocks 
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
  PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV4;
  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief NVIC Configuration.
  * @retval None
  */
static void MX_NVIC_Init(void)
{
  /* USART1_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(USART1_IRQn);
  /* DMA1_Channel1_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
  /* DMA2_Channel4_5_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA2_Channel4_5_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA2_Channel4_5_IRQn);
  /* TIM6_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(TIM6_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(TIM6_IRQn);
  /* ADC3_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(ADC3_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(ADC3_IRQn);
  /* DMA1_Channel7_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn);
  /* DMA1_Channel4_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA1_Channel4_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Channel4_IRQn);
  /* ADC1_2_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(ADC1_2_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(ADC1_2_IRQn);
  /* USART2_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(USART2_IRQn);
}

/**
  * @brief ADC1 Initialization Function
  * @param None
  * @retval None
  */
static void MX_ADC1_Init(void)
{

  /* USER CODE BEGIN ADC1_Init 0 */

  /* USER CODE END ADC1_Init 0 */

  ADC_ChannelConfTypeDef sConfig = {0};

  /* USER CODE BEGIN ADC1_Init 1 */

  /* USER CODE END ADC1_Init 1 */
  /** Common config 
  */
  hadc1.Instance = ADC1;
  hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
  hadc1.Init.ContinuousConvMode = ENABLE;
  hadc1.Init.DiscontinuousConvMode = DISABLE;
  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc1.Init.NbrOfConversion = 4;
  if (HAL_ADC_Init(&hadc1) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Regular Channel 
  */
  sConfig.Channel = ADC_CHANNEL_4;
  sConfig.Rank = ADC_REGULAR_RANK_1;
  sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Regular Channel 
  */
  sConfig.Channel = ADC_CHANNEL_5;
  sConfig.Rank = ADC_REGULAR_RANK_2;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Regular Channel 
  */
  sConfig.Channel = ADC_CHANNEL_6;
  sConfig.Rank = ADC_REGULAR_RANK_3;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Regular Channel 
  */
  sConfig.Channel = ADC_CHANNEL_12;
  sConfig.Rank = ADC_REGULAR_RANK_4;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN ADC1_Init 2 */

  /* USER CODE END ADC1_Init 2 */

}

/**
  * @brief ADC3 Initialization Function
  * @param None
  * @retval None
  */
static void MX_ADC3_Init(void)
{

  /* USER CODE BEGIN ADC3_Init 0 */

  /* USER CODE END ADC3_Init 0 */

  ADC_ChannelConfTypeDef sConfig = {0};

  /* USER CODE BEGIN ADC3_Init 1 */

  /* USER CODE END ADC3_Init 1 */
  /** Common config 
  */
  hadc3.Instance = ADC3;
  hadc3.Init.ScanConvMode = ADC_SCAN_ENABLE;
  hadc3.Init.ContinuousConvMode = ENABLE;
  hadc3.Init.DiscontinuousConvMode = DISABLE;
  hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc3.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc3.Init.NbrOfConversion = 5;
  if (HAL_ADC_Init(&hadc3) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Regular Channel 
  */
  sConfig.Channel = ADC_CHANNEL_4;
  sConfig.Rank = ADC_REGULAR_RANK_1;
  sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
  if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Regular Channel 
  */
  sConfig.Channel = ADC_CHANNEL_5;
  sConfig.Rank = ADC_REGULAR_RANK_2;
  if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Regular Channel 
  */
  sConfig.Channel = ADC_CHANNEL_6;
  sConfig.Rank = ADC_REGULAR_RANK_3;
  if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Regular Channel 
  */
  sConfig.Channel = ADC_CHANNEL_7;
  sConfig.Rank = ADC_REGULAR_RANK_4;
  if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Regular Channel 
  */
  sConfig.Channel = ADC_CHANNEL_8;
  sConfig.Rank = ADC_REGULAR_RANK_5;
  if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN ADC3_Init 2 */

  /* USER CODE END ADC3_Init 2 */

}

/**
  * @brief I2C2 Initialization Function
  * @param None
  * @retval None
  */
static void MX_I2C2_Init(void)
{

  /* USER CODE BEGIN I2C2_Init 0 */

  /* USER CODE END I2C2_Init 0 */

  /* USER CODE BEGIN I2C2_Init 1 */

  /* USER CODE END I2C2_Init 1 */
  hi2c2.Instance = I2C2;
  hi2c2.Init.ClockSpeed = 100000;
  hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2;
  hi2c2.Init.OwnAddress1 = 0;
  hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  hi2c2.Init.OwnAddress2 = 0;
  hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  if (HAL_I2C_Init(&hi2c2) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN I2C2_Init 2 */

  /* USER CODE END I2C2_Init 2 */

}

/**
  * @brief IWDG Initialization Function
  * @param None
  * @retval None
  */
static void MX_IWDG_Init(void)
{

  /* USER CODE BEGIN IWDG_Init 0 */

  /* USER CODE END IWDG_Init 0 */

  /* USER CODE BEGIN IWDG_Init 1 */

  /* USER CODE END IWDG_Init 1 */
  hiwdg.Instance = IWDG;
  hiwdg.Init.Prescaler = IWDG_PRESCALER_128;
  hiwdg.Init.Reload = 4095;
  if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN IWDG_Init 2 */

  /* USER CODE END IWDG_Init 2 */

}

/**
  * @brief TIM6 Initialization Function
  * @param None
  * @retval None
  */
static void MX_TIM6_Init(void)
{

  /* USER CODE BEGIN TIM6_Init 0 */

  /* USER CODE END TIM6_Init 0 */

  TIM_MasterConfigTypeDef sMasterConfig = {0};

  /* USER CODE BEGIN TIM6_Init 1 */

  /* USER CODE END TIM6_Init 1 */
  htim6.Instance = TIM6;
  htim6.Init.Prescaler = 5600 - 1;
  htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim6.Init.Period = 10;
  htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
  {
    Error_Handler();
  }
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN TIM6_Init 2 */

  /* USER CODE END TIM6_Init 2 */

}

/**
  * @brief USART1 Initialization Function
  * @param None
  * @retval None
  */
static void MX_USART1_UART_Init(void)
{

  /* USER CODE BEGIN USART1_Init 0 */

  /* USER CODE END USART1_Init 0 */

  /* USER CODE BEGIN USART1_Init 1 */

  /* USER CODE END USART1_Init 1 */
  huart1.Instance = USART1;
  huart1.Init.BaudRate = 115200;
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
  huart1.Init.StopBits = UART_STOPBITS_1;
  huart1.Init.Parity = UART_PARITY_NONE;
  huart1.Init.Mode = UART_MODE_TX_RX;
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN USART1_Init 2 */

  /* USER CODE END USART1_Init 2 */

}

/**
  * @brief USART2 Initialization Function
  * @param None
  * @retval None
  */
static void MX_USART2_UART_Init(void)
{

  /* USER CODE BEGIN USART2_Init 0 */

  /* USER CODE END USART2_Init 0 */

  /* USER CODE BEGIN USART2_Init 1 */

  /* USER CODE END USART2_Init 1 */
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 115200;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart2) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN USART2_Init 2 */

  /* USER CODE END USART2_Init 2 */

}

/** 
  * Enable DMA controller clock
  */
static void MX_DMA_Init(void) 
{

  /* DMA controller clock enable */
  __HAL_RCC_DMA1_CLK_ENABLE();
  __HAL_RCC_DMA2_CLK_ENABLE();

}

/**
  * @brief GPIO Initialization Function
  * @param None
  * @retval None
  */
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOE_CLK_ENABLE();
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOF_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOG_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOE, LED_FAIL2_Pin|FAIL_MBIC_Pin|ATT_CLOCK4_Pin|ATT_DATA4_Pin 
                          |ATT_EN_DL4_Pin|ATT_EN_UL4_Pin|PATH_EN_DL4_Pin|PATH_EN_UL4_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOC, BOOT_LED_Pin|PATH_EN_UL1_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOG, ATT_CLOCK3_Pin|ATT_DATA3_Pin|ATT_EN_DL3_Pin|ATT_EN_UL3_Pin 
                          |PATH_EN_DL3_Pin|PATH_EN_UL3_Pin|_PATH_SW1_Pin|PATH_SW1_Pin 
                          |_PATH_SW2_Pin|PATH_SW2_Pin|_PATH_SW3_Pin|PATH_SW3_Pin 
                          |_PATH_SW4_Pin|PATH_SW4_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, ATT_EN_UL1_Pin|PATH_EN_DL1_Pin|ATT_CLOCK1_Pin|ATT_DATA1_Pin 
                          |ATT_EN_DL1_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOD, PATH_EN_DL2_Pin|PATH_EN_UL2_Pin|LED_ACT_Pin|LED_FAIL_Pin 
                          |ATT_CLOCK2_Pin|ATT_DATA2_Pin|ATT_EN_DL2_Pin|ATT_EN_UL2_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pins : LED_FAIL2_Pin FAIL_MBIC_Pin ATT_CLOCK4_Pin ATT_DATA4_Pin 
                           ATT_EN_DL4_Pin ATT_EN_UL4_Pin PATH_EN_DL4_Pin PATH_EN_UL4_Pin */
  GPIO_InitStruct.Pin = LED_FAIL2_Pin|FAIL_MBIC_Pin|ATT_CLOCK4_Pin|ATT_DATA4_Pin 
                          |ATT_EN_DL4_Pin|ATT_EN_UL4_Pin|PATH_EN_DL4_Pin|PATH_EN_UL4_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

  /*Configure GPIO pins : BOOT_LED_Pin PATH_EN_UL1_Pin */
  GPIO_InitStruct.Pin = BOOT_LED_Pin|PATH_EN_UL1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  /*Configure GPIO pins : ATT_CLOCK3_Pin ATT_DATA3_Pin ATT_EN_DL3_Pin ATT_EN_UL3_Pin 
                           PATH_EN_DL3_Pin PATH_EN_UL3_Pin _PATH_SW1_Pin PATH_SW1_Pin 
                           _PATH_SW2_Pin PATH_SW2_Pin _PATH_SW3_Pin PATH_SW3_Pin 
                           _PATH_SW4_Pin PATH_SW4_Pin */
  GPIO_InitStruct.Pin = ATT_CLOCK3_Pin|ATT_DATA3_Pin|ATT_EN_DL3_Pin|ATT_EN_UL3_Pin 
                          |PATH_EN_DL3_Pin|PATH_EN_UL3_Pin|_PATH_SW1_Pin|PATH_SW1_Pin 
                          |_PATH_SW2_Pin|PATH_SW2_Pin|_PATH_SW3_Pin|PATH_SW3_Pin 
                          |_PATH_SW4_Pin|PATH_SW4_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);

  /*Configure GPIO pins : ATT_EN_UL1_Pin PATH_EN_DL1_Pin ATT_CLOCK1_Pin ATT_DATA1_Pin 
                           ATT_EN_DL1_Pin */
  GPIO_InitStruct.Pin = ATT_EN_UL1_Pin|PATH_EN_DL1_Pin|ATT_CLOCK1_Pin|ATT_DATA1_Pin 
                          |ATT_EN_DL1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pins : PATH_EN_DL2_Pin PATH_EN_UL2_Pin LED_ACT_Pin LED_FAIL_Pin 
                           ATT_CLOCK2_Pin ATT_DATA2_Pin ATT_EN_DL2_Pin ATT_EN_UL2_Pin */
  GPIO_InitStruct.Pin = PATH_EN_DL2_Pin|PATH_EN_UL2_Pin|LED_ACT_Pin|LED_FAIL_Pin 
                          |ATT_CLOCK2_Pin|ATT_DATA2_Pin|ATT_EN_DL2_Pin|ATT_EN_UL2_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  /*Configure GPIO pins : UNIT_ID0_Pin UNIT_ID1_Pin UNIT_ID2_Pin */
  GPIO_InitStruct.Pin = UNIT_ID0_Pin|UNIT_ID1_Pin|UNIT_ID2_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  /*Configure GPIO pin : UNIT_ID3_Pin */
  GPIO_InitStruct.Pin = UNIT_ID3_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(UNIT_ID3_GPIO_Port, &GPIO_InitStruct);

}

/* USER CODE BEGIN 4 */
void DL_Shutdown_Timer(uint8_t Table_num){
    if(bluecell_Currdatastatus.DLI_Shutdown_ON_OFF == true){
          if(ADC_Alarm_DL_Shutdown_Set[DET_Alarm_DL1_Shutdown_Index + Table_num] == true){
              DET_DL_Shutdown_Off_AlarmTimerCnt[DET_Alarm_DL1_Shutdown_Index + Table_num] = 0; // OFF CNT = 0;
              DET_DL_Shutdown_On_AlarmTimerCnt[DET_Alarm_DL1_Shutdown_Index + Table_num]++;
              if(DET_DL_Shutdown_On_AlarmTimerCnt[DET_Alarm_DL1_Shutdown_Index + Table_num] == 0xFFFFFFFF){
                  DET_DL_Shutdown_On_AlarmTimerCnt[DET_Alarm_DL1_Shutdown_Index + Table_num] = MBIC_ON_SHUTDOWN_MAINTAIN_SEC;
              }
          }else{
              DET_DL_Shutdown_On_AlarmTimerCnt[DET_Alarm_DL1_Shutdown_Index + Table_num] = 0;
              DET_DL_Shutdown_Off_AlarmTimerCnt[DET_Alarm_DL1_Shutdown_Index + Table_num]++;
              if(DET_DL_Shutdown_Off_AlarmTimerCnt[DET_Alarm_DL1_Shutdown_Index + Table_num] == 0xFFFFFFFF){
                  DET_DL_Shutdown_Off_AlarmTimerCnt[DET_Alarm_DL1_Shutdown_Index + Table_num] = MBIC_RECOVERY_SHUTDOWN_MAINTAIN_SEC;
              }
          }
          if(ADC_Alarm_DL_Normal_Shutdown_Set[DET_Alarm_DL1_Shutdown_Index + Table_num] == true){
              DET_DL_Normal_Shutdown_On_AlarmTimerCnt[DET_Alarm_DL1_Shutdown_Index + Table_num]++;
              if(DET_DL_Normal_Shutdown_On_AlarmTimerCnt[DET_Alarm_DL1_Shutdown_Index + Table_num] == 0xFFFFFFFF){
                  DET_DL_Normal_Shutdown_On_AlarmTimerCnt[DET_Alarm_DL1_Shutdown_Index + Table_num] = MBIC_OFF_MAINTAIN_SEC;
              }                
          }else{
              DET_DL_Normal_Shutdown_On_AlarmTimerCnt[DET_Alarm_DL1_Shutdown_Index + Table_num] = 0;
          }
  }
}
void UL_Shutdown_Timer(uint8_t Table_num){
    if(bluecell_Currdatastatus.ULO_Shutdown_ON_OFF == true){/*Shutdown Function On !! */
          if(ADC_Alarm_UL_Shutdown_Set[DET_Alarm_UL1_Shutdown_Index + Table_num] == true){
              DET_UL_Shutdown_Off_AlarmTimerCnt[DET_Alarm_UL1_Shutdown_Index + Table_num] = 0; // OFF CNT = 0;
              DET_UL_Shutdown_On_AlarmTimerCnt[DET_Alarm_UL1_Shutdown_Index + Table_num]++;
              if(DET_UL_Shutdown_On_AlarmTimerCnt[DET_Alarm_UL1_Shutdown_Index + Table_num] == 0xFFFFFFFF){
                  DET_UL_Shutdown_On_AlarmTimerCnt[DET_Alarm_UL1_Shutdown_Index + Table_num] = MBIC_ON_SHUTDOWN_MAINTAIN_SEC;
              }
          }else{
              DET_UL_Shutdown_On_AlarmTimerCnt[DET_Alarm_UL1_Shutdown_Index + Table_num] = 0;
              DET_UL_Shutdown_Off_AlarmTimerCnt[DET_Alarm_UL1_Shutdown_Index + Table_num]++;
              if(DET_UL_Shutdown_Off_AlarmTimerCnt[DET_Alarm_UL1_Shutdown_Index + Table_num] == 0xFFFFFFFF){
                  DET_UL_Shutdown_Off_AlarmTimerCnt[DET_Alarm_UL1_Shutdown_Index + Table_num] = MBIC_RECOVERY_SHUTDOWN_MAINTAIN_SEC;
              }
          }
          
          if(ADC_Alarm_UL_Normal_Shutdown_Set[DET_Alarm_UL1_Shutdown_Index + Table_num] == true){
              DET_UL_Normal_Shutdown_On_AlarmTimerCnt[DET_Alarm_UL1_Shutdown_Index + Table_num]++;
              if(DET_UL_Normal_Shutdown_On_AlarmTimerCnt[DET_Alarm_UL1_Shutdown_Index + Table_num] == 0xFFFFFFFF){
                  DET_UL_Normal_Shutdown_On_AlarmTimerCnt[DET_Alarm_UL1_Shutdown_Index + Table_num] = MBIC_OFF_MAINTAIN_SEC;
              }                
          }else{
              DET_UL_Normal_Shutdown_On_AlarmTimerCnt[DET_Alarm_UL1_Shutdown_Index + Table_num] = 0;
          }
  }
}
void UL_SelfTestTimer(uint8_t* selftest_status){
    if((*selftest_status) == true){
        SelfTestLifeCnt++;
//        printf("selftest_status : %d SelfTestLifeCnt , :%d\r\n",(*selftest_status),SelfTestLifeCnt);
    }else{
        SelfTestLifeCnt = 0;
    }

}
/* USER CODE END 4 */

 /**
  * @brief  Period elapsed callback in non blocking mode
  * @note   This function is called  when TIM2 interrupt took place, inside
  * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  * a global variable "uwTick" used as application time base.
  * @param  htim : TIM handle
  * @retval None
  */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
  /* USER CODE BEGIN Callback 0 */
  //  uint8_t* pdata;
  /* USER CODE END Callback 0 */
  if (htim->Instance == TIM2) {
    HAL_IncTick();
  }
  /* USER CODE BEGIN Callback 1 */
  if(htim->Instance == TIM6){
      UartRxTimerCnt++;
      LedTimerCnt++;
      AdcTimerCnt++;
      LDTimerCnt++;
      ALCTimerCnt++;
      AGCTimerCnt++;
      ADC_100ms_Cnt++;
      AlarmReport_TimerCnt++;

      for(int i =0 ; i < 4; i++){
        if(ALC_DelayCnt_Get(i) == true){
            ALC_Delay_Cnt[i]++;
        }else{
            ALC_Delay_Cnt[i] = 0;
        }
      }
//    pdata = &bluecell_Currdatastatus.ATT_UL1_PATH;
    UL_Shutdown_Timer(DET_Alarm_UL1_Shutdown_Index);
//    pdata = &bluecell_Currdatastatus.ATT_UL2_PATH;
    UL_Shutdown_Timer(DET_Alarm_UL2_Shutdown_Index);
//    pdata = &bluecell_Currdatastatus.ATT_UL3_PATH;
    UL_Shutdown_Timer(DET_Alarm_UL3_Shutdown_Index);
//    pdata = &bluecell_Currdatastatus.ATT_UL4_PATH;
    UL_Shutdown_Timer(DET_Alarm_UL4_Shutdown_Index);

//    pdata = &bluecell_Currdatastatus.ATT_DL1_PATH;
    DL_Shutdown_Timer(DET_Alarm_DL1_Shutdown_Index);
//    pdata = &bluecell_Currdatastatus.ATT_DL2_PATH;
    DL_Shutdown_Timer(DET_Alarm_DL2_Shutdown_Index);
//    pdata = &bluecell_Currdatastatus.ATT_DL3_PATH;
    DL_Shutdown_Timer(DET_Alarm_DL3_Shutdown_Index);
//    pdata = &bluecell_Currdatastatus.ATT_DL4_PATH;
    DL_Shutdown_Timer(DET_Alarm_DL4_Shutdown_Index);


    UL_SelfTestTimer(&bluecell_Currdatastatus.SelfTest);
        
    
      /*ALC Alarm timer start*/
      if(ALC_AlarmSet[ALC_Alarm_UL1_Index] == true){
          ALC_Off_AlarmTimerCnt[ALC_Alarm_UL1_Index] = 0;
          ALC_On_AlarmTimerCnt[ALC_Alarm_UL1_Index]++;
          if(ALC_On_AlarmTimerCnt[ALC_Alarm_UL1_Index] == 0xFFFFFFFF){
            ALC_On_AlarmTimerCnt[ALC_Alarm_UL1_Index] = MBIC_ON_MAINTAIN_SEC;
          }
      }else{
          ALC_On_AlarmTimerCnt[ALC_Alarm_UL1_Index] = 0;
          ALC_Off_AlarmTimerCnt[ALC_Alarm_UL1_Index]++;
          if(ALC_Off_AlarmTimerCnt[ALC_Alarm_UL1_Index] == 0xFFFFFFFF){
            ALC_Off_AlarmTimerCnt[ALC_Alarm_UL1_Index] = MBIC_OFF_MAINTAIN_SEC;
          }          
      }

      if(ALC_AlarmSet[ALC_Alarm_UL2_Index] == true){
          ALC_On_AlarmTimerCnt[ALC_Alarm_UL2_Index]++;
          ALC_Off_AlarmTimerCnt[ALC_Alarm_UL2_Index] = 0;
          if(ALC_On_AlarmTimerCnt[ALC_Alarm_UL2_Index] == 0xFFFFFFFF){
            ALC_On_AlarmTimerCnt[ALC_Alarm_UL2_Index] = MBIC_ON_MAINTAIN_SEC;
          }
      }else{
          ALC_On_AlarmTimerCnt[ALC_Alarm_UL2_Index] = 0;
          ALC_Off_AlarmTimerCnt[ALC_Alarm_UL2_Index]++;
          if(ALC_Off_AlarmTimerCnt[ALC_Alarm_UL2_Index] == 0xFFFFFFFF){
            ALC_Off_AlarmTimerCnt[ALC_Alarm_UL2_Index] = MBIC_OFF_MAINTAIN_SEC;
          }          
      }
      if(ALC_AlarmSet[ALC_Alarm_UL3_Index] == true){
          ALC_On_AlarmTimerCnt[ALC_Alarm_UL3_Index]++;
          ALC_Off_AlarmTimerCnt[ALC_Alarm_UL3_Index] = 0;
          if(ALC_On_AlarmTimerCnt[ALC_Alarm_UL3_Index] == 0xFFFFFFFF){
            ALC_On_AlarmTimerCnt[ALC_Alarm_UL3_Index] = MBIC_ON_MAINTAIN_SEC;
          }
      }else{
          ALC_On_AlarmTimerCnt[ALC_Alarm_UL3_Index] = 0;
          ALC_Off_AlarmTimerCnt[ALC_Alarm_UL3_Index]++;
          if(ALC_Off_AlarmTimerCnt[ALC_Alarm_UL3_Index] == 0xFFFFFFFF){
            ALC_Off_AlarmTimerCnt[ALC_Alarm_UL3_Index] = MBIC_OFF_MAINTAIN_SEC;
          }          
      }
      
      if(ALC_AlarmSet[ALC_Alarm_UL4_Index] == true){
          ALC_On_AlarmTimerCnt[ALC_Alarm_UL4_Index]++;
          ALC_Off_AlarmTimerCnt[ALC_Alarm_UL4_Index] = 0;
          if(ALC_On_AlarmTimerCnt[ALC_Alarm_UL4_Index] == 0xFFFFFFFF){
            ALC_On_AlarmTimerCnt[ALC_Alarm_UL4_Index] = MBIC_ON_MAINTAIN_SEC;
          }
      }else{
          ALC_On_AlarmTimerCnt[ALC_Alarm_UL4_Index] = 0;
          ALC_Off_AlarmTimerCnt[ALC_Alarm_UL4_Index]++;
          if(ALC_Off_AlarmTimerCnt[ALC_Alarm_UL4_Index] == 0xFFFFFFFF){
            ALC_Off_AlarmTimerCnt[ALC_Alarm_UL4_Index] = MBIC_OFF_MAINTAIN_SEC;
          }          
      }     

      /*AGC Alarm timer start*/      
      if(AGC_AlarmSet[AGC_Alarm_DL1_Index] == true){
          AGC_On_AlarmTimerCnt[AGC_Alarm_DL1_Index]++;
          AGC_Off_AlarmTimerCnt[AGC_Alarm_DL1_Index] = 0;
          if(AGC_On_AlarmTimerCnt[AGC_Alarm_DL1_Index] == 0xFFFFFFFF){
            AGC_On_AlarmTimerCnt[AGC_Alarm_DL1_Index] = MBIC_ON_MAINTAIN_SEC;
          }
      }else{
          AGC_On_AlarmTimerCnt[AGC_Alarm_DL1_Index] = 0;
          AGC_Off_AlarmTimerCnt[AGC_Alarm_DL1_Index]++;
          if(AGC_Off_AlarmTimerCnt[AGC_Alarm_DL1_Index] == 0xFFFFFFFF){
            AGC_Off_AlarmTimerCnt[AGC_Alarm_DL1_Index] = MBIC_OFF_MAINTAIN_SEC;
          }          
      }

      if(AGC_AlarmSet[AGC_Alarm_DL2_Index] == true){
          AGC_On_AlarmTimerCnt[AGC_Alarm_DL2_Index]++;
          AGC_Off_AlarmTimerCnt[AGC_Alarm_DL2_Index] = 0;
          if(AGC_On_AlarmTimerCnt[AGC_Alarm_DL2_Index] == 0xFFFFFFFF){
            AGC_On_AlarmTimerCnt[AGC_Alarm_DL2_Index] = MBIC_ON_MAINTAIN_SEC;
          }
      }else{
          AGC_On_AlarmTimerCnt[AGC_Alarm_DL2_Index] = 0;
          AGC_Off_AlarmTimerCnt[AGC_Alarm_DL2_Index]++;
          if(AGC_Off_AlarmTimerCnt[AGC_Alarm_DL2_Index] == 0xFFFFFFFF){
            AGC_Off_AlarmTimerCnt[AGC_Alarm_DL2_Index] = MBIC_OFF_MAINTAIN_SEC;
          }          
      }
      if(AGC_AlarmSet[AGC_Alarm_DL3_Index] == true){
          AGC_On_AlarmTimerCnt[AGC_Alarm_DL3_Index]++;
          AGC_Off_AlarmTimerCnt[AGC_Alarm_DL3_Index] = 0;
          if(AGC_On_AlarmTimerCnt[AGC_Alarm_DL3_Index] == 0xFFFFFFFF){
            AGC_On_AlarmTimerCnt[AGC_Alarm_DL3_Index] = MBIC_ON_MAINTAIN_SEC;
          }
      }else{
          AGC_On_AlarmTimerCnt[AGC_Alarm_DL3_Index] = 0;
          AGC_Off_AlarmTimerCnt[AGC_Alarm_DL3_Index]++;
          if(AGC_Off_AlarmTimerCnt[AGC_Alarm_DL3_Index] == 0xFFFFFFFF){
            AGC_Off_AlarmTimerCnt[AGC_Alarm_DL3_Index] = MBIC_OFF_MAINTAIN_SEC;
          }          
      }
      if(AGC_AlarmSet[AGC_Alarm_DL4_Index] == true){
          AGC_On_AlarmTimerCnt[AGC_Alarm_DL4_Index]++;
          AGC_Off_AlarmTimerCnt[AGC_Alarm_DL4_Index] = 0;
          if(AGC_On_AlarmTimerCnt[AGC_Alarm_DL4_Index] == 0xFFFFFFFF){
            AGC_On_AlarmTimerCnt[AGC_Alarm_DL4_Index] = MBIC_ON_MAINTAIN_SEC;
          }
      }else{
          AGC_On_AlarmTimerCnt[AGC_Alarm_DL4_Index] = 0;
          AGC_Off_AlarmTimerCnt[AGC_Alarm_DL4_Index]++;
          if(AGC_Off_AlarmTimerCnt[AGC_Alarm_DL4_Index] == 0xFFFFFFFF){
            AGC_Off_AlarmTimerCnt[AGC_Alarm_DL4_Index] = MBIC_OFF_MAINTAIN_SEC;
          }          
      }      
    


    /*********************UL LEVEL HIGH START****************************/

    if(ADC_Alarm_UL_Set[DET_Alarm_UL1_Index ] == true){
        
        DET_UL_On_AlarmTimerCnt[DET_Alarm_UL1_Index]++;
        DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL1_Index] = 0;
        if(DET_UL_On_AlarmTimerCnt[DET_Alarm_UL1_Index] == 0xFFFFFFFF){
            DET_UL_On_AlarmTimerCnt[DET_Alarm_UL1_Index] = MBIC_ON_MAINTAIN_SEC;
        }
    }
    else{
        DET_UL_On_AlarmTimerCnt[DET_Alarm_UL1_Index] = 0;
        DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL1_Index]++;
        if(DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL1_Index] == 0xFFFFFFFF){
            DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL1_Index] = MBIC_OFF_MAINTAIN_SEC;
        }    
    }

    if(ADC_Alarm_UL_Set[DET_Alarm_UL2_Index ] == true){
        DET_UL_On_AlarmTimerCnt[DET_Alarm_UL2_Index]++;
        DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL2_Index] = 0;
        if(DET_UL_On_AlarmTimerCnt[DET_Alarm_UL2_Index] == 0xFFFFFFFF){
            DET_UL_On_AlarmTimerCnt[DET_Alarm_UL2_Index] = MBIC_ON_MAINTAIN_SEC;
        }    
    }
    else{
        DET_UL_On_AlarmTimerCnt[DET_Alarm_UL2_Index] = 0;
        DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL2_Index]++;
        if(DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL2_Index] == 0xFFFFFFFF){
            DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL2_Index] = MBIC_OFF_MAINTAIN_SEC;
        }     
    }

    if(ADC_Alarm_UL_Set[DET_Alarm_UL3_Index ] == true){
        DET_UL_On_AlarmTimerCnt[DET_Alarm_UL3_Index]++;
        DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL3_Index] = 0;     
        if(DET_UL_On_AlarmTimerCnt[DET_Alarm_UL3_Index] == 0xFFFFFFFF){
            DET_UL_On_AlarmTimerCnt[DET_Alarm_UL3_Index] = MBIC_ON_MAINTAIN_SEC;
        }    
    }
    else{
        DET_UL_On_AlarmTimerCnt[DET_Alarm_UL3_Index] = 0;
        DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL3_Index]++;  
        if(DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL3_Index] == 0xFFFFFFFF){
            DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL3_Index] = MBIC_OFF_MAINTAIN_SEC;
        }     
    }

    if(ADC_Alarm_UL_Set[DET_Alarm_UL4_Index ] == true){
        DET_UL_On_AlarmTimerCnt[DET_Alarm_UL4_Index]++;
        DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL4_Index] = 0;    
        if(DET_UL_On_AlarmTimerCnt[DET_Alarm_UL4_Index] == 0xFFFFFFFF){
            DET_UL_On_AlarmTimerCnt[DET_Alarm_UL4_Index] = MBIC_ON_MAINTAIN_SEC;
        }    
    }
    else{
        DET_UL_On_AlarmTimerCnt[DET_Alarm_UL4_Index] = 0;
        DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL4_Index]++;       
        if(DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL4_Index] == 0xFFFFFFFF){
            DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL4_Index] = MBIC_OFF_MAINTAIN_SEC;
        }     
    }





    /*********************DL LEVEL LOW START****************************/
    if(ADC_Alarm_DL_Low_Set[DET_Alarm_DL1_Index ] == true){
        
        DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL1_Index]++;
        DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL1_Index] = 0;
        if(DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL1_Index] == 0xFFFFFFFF){
            DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL1_Index] = MBIC_ON_MAINTAIN_SEC;
        }
    }
    else{
        DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL1_Index] = 0;
        DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL1_Index]++;
        if(DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL1_Index] == 0xFFFFFFFF){
            DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL1_Index] = MBIC_OFF_MAINTAIN_SEC;
        }    
    }

    if(ADC_Alarm_DL_Low_Set[DET_Alarm_DL2_Index ] == true){
        DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL2_Index]++;
        DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL2_Index] = 0;
        if(DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL2_Index] == 0xFFFFFFFF){
            DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL2_Index] = MBIC_ON_MAINTAIN_SEC;
        }    
    }
    else{
        DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL2_Index] = 0;
        DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL2_Index]++;
        if(DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL2_Index] == 0xFFFFFFFF){
            DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL2_Index] = MBIC_OFF_MAINTAIN_SEC;
        }     
    }

    if(ADC_Alarm_DL_Low_Set[DET_Alarm_DL3_Index ] == true){
        DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL3_Index]++;
        DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL3_Index] = 0;     
        if(DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL3_Index] == 0xFFFFFFFF){
            DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL3_Index] = MBIC_ON_MAINTAIN_SEC;
        }    
    }
    else{
        DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL3_Index] = 0;
        DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL3_Index]++;  
        if(DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL3_Index] == 0xFFFFFFFF){
            DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL3_Index] = MBIC_OFF_MAINTAIN_SEC;
        }     
    }

    if(ADC_Alarm_DL_Low_Set[DET_Alarm_DL4_Index ] == true){
        DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL4_Index]++;
        DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL4_Index] = 0;    
        if(DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL4_Index] == 0xFFFFFFFF){
            DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL4_Index] = MBIC_ON_MAINTAIN_SEC;
        }    
    }
    else{
        DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL4_Index] = 0;
        DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL4_Index]++;       
        if(DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL4_Index] == 0xFFFFFFFF){
            DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL4_Index] = MBIC_OFF_MAINTAIN_SEC;
        }     
    }
    /*********************DL LEVEL LOW END****************************/    
    /*********************DL LEVEL HIGH START***************************/
    if(ADC_Alarm_DL_High_Set[DET_Alarm_DL1_Index ] == true){
        
        DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL1_Index]++;
        DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL1_Index] = 0;
        if(DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL1_Index] == 0xFFFFFFFF){
            DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL1_Index] = MBIC_ON_MAINTAIN_SEC;
        }
    }
    else{
        DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL1_Index] = 0;
        DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL1_Index]++;
        if(DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL1_Index] == 0xFFFFFFFF){
            DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL1_Index] = MBIC_OFF_MAINTAIN_SEC;
        }    
    }

    if(ADC_Alarm_DL_High_Set[DET_Alarm_DL2_Index ] == true){
        DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL2_Index]++;
        DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL2_Index] = 0;
        if(DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL2_Index] == 0xFFFFFFFF){
            DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL2_Index] = MBIC_ON_MAINTAIN_SEC;
        }    
    }
    else{
        DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL2_Index] = 0;
        DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL2_Index]++;
        if(DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL2_Index] == 0xFFFFFFFF){
            DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL2_Index] = MBIC_OFF_MAINTAIN_SEC;
        }     
    }

    if(ADC_Alarm_DL_High_Set[DET_Alarm_DL3_Index ] == true){
        DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL3_Index]++;
        DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL3_Index] = 0;     
        if(DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL3_Index] == 0xFFFFFFFF){
            DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL3_Index] = MBIC_ON_MAINTAIN_SEC;
        }    
    }
    else{
        DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL3_Index] = 0;
        DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL3_Index]++;  
        if(DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL3_Index] == 0xFFFFFFFF){
            DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL3_Index] = MBIC_OFF_MAINTAIN_SEC;
        }     
    }

    if(ADC_Alarm_DL_High_Set[DET_Alarm_DL4_Index ] == true){
        DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL4_Index]++;
        DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL4_Index] = 0;    
        if(DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL4_Index] == 0xFFFFFFFF){
            DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL4_Index] = MBIC_ON_MAINTAIN_SEC;
        }    
    }
    else{
        DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL4_Index] = 0;
        DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL4_Index]++;       
        if(DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL4_Index] == 0xFFFFFFFF){
            DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL4_Index] = MBIC_OFF_MAINTAIN_SEC;
        }     
    }
      /*********************DL LEVEL HIGH END***************************/

#if 0 // PYJ.2020.06.19_BEGIN -- 
    if(ADC_Alarm_DL_Shutdown_Set[DET_Alarm_DL1_Shutdown_Index] == true){
        MBIC_ShutdownCnt[MBIC_Shutdown_DL1]++;
    }else{
        MBIC_ShutdownCnt[MBIC_Shutdown_DL1] = 0;        
    }
    if(ADC_Alarm_DL_Shutdown_Set[DET_Alarm_DL2_Shutdown_Index] == true){
        MBIC_ShutdownCnt[MBIC_Shutdown_DL2]++;
    }else{
        MBIC_ShutdownCnt[MBIC_Shutdown_DL2] = 0;        
    }
    if(ADC_Alarm_DL_Shutdown_Set[DET_Alarm_DL3_Shutdown_Index] == true){
        MBIC_ShutdownCnt[MBIC_Shutdown_DL3]++;
    }else{
        MBIC_ShutdownCnt[MBIC_Shutdown_DL3] = 0;        
    }
    if(ADC_Alarm_DL_Shutdown_Set[DET_Alarm_DL4_Shutdown_Index] == true){
        MBIC_ShutdownCnt[MBIC_Shutdown_DL4]++;
    }else{
        MBIC_ShutdownCnt[MBIC_Shutdown_DL4] = 0;        
    }

    if(ADC_Alarm_UL_Shutdown_Set[DET_Alarm_UL1_Shutdown_Index] == true){
        MBIC_ShutdownCnt[MBIC_Shutdown_UL1]++;
    }else{
        MBIC_ShutdownCnt[MBIC_Shutdown_UL1] = 0;        
    }
    if(ADC_Alarm_UL_Shutdown_Set[DET_Alarm_UL2_Shutdown_Index] == true){
        MBIC_ShutdownCnt[MBIC_Shutdown_UL2]++;
    }else{
        MBIC_ShutdownCnt[MBIC_Shutdown_UL2] = 0;        
    }
    if(ADC_Alarm_UL_Shutdown_Set[DET_Alarm_UL3_Shutdown_Index] == true){
        MBIC_ShutdownCnt[MBIC_Shutdown_UL3]++;
    }else{
        MBIC_ShutdownCnt[MBIC_Shutdown_UL3] = 0;        
    }
    if(ADC_Alarm_UL_Shutdown_Set[DET_Alarm_UL4_Shutdown_Index] == true){
        MBIC_ShutdownCnt[MBIC_Shutdown_UL4]++;
    }else{
        MBIC_ShutdownCnt[MBIC_Shutdown_UL4] = 0;        
    }
#endif // PYJ.2020.06.19_END -- 


        /*3 Sec Time Cnt */
    
      if(AlarmTimerOnSet == true){
        if(AlarmTimerOnCnt == 0xFFFFFFFF)
            AlarmTimerOnCnt = MBIC_ON_MAINTAIN_SEC;
        else{
            AlarmTimerOnCnt++;
        }
      }
      else{
        AlarmTimerOnCnt = 0;
      }

        
      /*10 Sec Time Cnt*/
      if(AlarmTimerOffSet == true){
        if(AlarmTimerOffCnt == 0xFFFFFFFF)
            AlarmTimerOffCnt = MBIC_OFF_MAINTAIN_SEC;
        else{
            AlarmTimerOffCnt++;
        }
      }
      else{
        AlarmTimerOffCnt = 0;
      }


      if(AlarmTimerOnSet == true){
        if(AlarmTimerOnCnt == 0xFFFFFFFF)
            AlarmTimerOnCnt = MBIC_ON_MAINTAIN_SEC;
        else{
            AlarmTimerOnCnt++;
        }
      }
      else{
        AlarmTimerOnCnt = 0;
      }

        
      /*10 Sec Time Cnt*/
      if(bluecell_Currdatastatus.Temp_High_Alarm == false){
        if(Alarm_Temp_TimerOffCnt >= 0xFFFFFFFF){
            Alarm_Temp_TimerOffCnt = MBIC_OFF_MAINTAIN_SEC;
        }
        else{
            Alarm_Temp_TimerOffCnt++;
        }
      }
      else{
        Alarm_Temp_TimerOffCnt = 0;
      }


      if(bluecell_Currdatastatus.Temp_High_Alarm == true){
        if(Alarm_Temp_TimerOnCnt >= 0xFFFFFFFF){
            Alarm_Temp_TimerOnCnt = MBIC_ON_MAINTAIN_SEC;
        }
        else{
            Alarm_Temp_TimerOnCnt++;
        }
      }
      else{
        Alarm_Temp_TimerOnCnt = 0;
      }







      /*10 Sec Time Cnt*/
      if(Alarm_DL_Level_TimerOffCnt == true){
        if(Alarm_DL_Level_TimerOffCnt == 0xFFFFFFFF)
            Alarm_DL_Level_TimerOffCnt = MBIC_OFF_MAINTAIN_SEC;
        else{
            Alarm_DL_Level_TimerOffCnt++;
        }
      }
      else{
        Alarm_DL_Level_TimerOffCnt = 0;
      }


      if(Alarm_DL_Level_TimerOnCnt == true){
        if(Alarm_DL_Level_TimerOnCnt == 0xFFFFFFFF)
            Alarm_DL_Level_TimerOnCnt = MBIC_ON_MAINTAIN_SEC;
        else{
            Alarm_DL_Level_TimerOnCnt++;
        }
      }
      else{
        Alarm_DL_Level_TimerOnCnt = 0;
      }        
      
     /*10 Sec Time Cnt*/
      if(Alarm_UL_Level_TimerOffCnt == true){
        if(Alarm_UL_Level_TimerOffCnt == 0xFFFFFFFF)
            Alarm_UL_Level_TimerOffCnt = MBIC_OFF_MAINTAIN_SEC;
        else{
            Alarm_UL_Level_TimerOffCnt++;
        }
      }
      else{
        Alarm_UL_Level_TimerOffCnt = 0;
      }


      if(Alarm_DL_Level_TimerOnCnt == true){
        if(Alarm_UL_Level_TimerOnCnt == 0xFFFFFFFF)
            Alarm_UL_Level_TimerOnCnt = MBIC_ON_MAINTAIN_SEC;
        else{
            Alarm_UL_Level_TimerOnCnt++;
        }
      }
      else{
        Alarm_UL_Level_TimerOnCnt = 0;
      }  
  }
  /* USER CODE END Callback 1 */
}

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */

  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{ 
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
