/******************************************************************************
�� �� ����main.h
�����������������ļ�
          ����ϵͳ��ʼ����������Լ���Դ����
��    �ߣ�����
��    ����V1.0
��    �ڣ�2016.11.1
******************************************************************************/
//20210422 �޸����Ѵ���ʱ��
//20210621 �޸���Ӳ���汾��
//20220115 ���TFT����Ƶ��(61194оƬ����9967оƬ)
//20231114 TYW-2023-0695�����������Ȼ�������ơ�����Һ����Ϊ��Ȼ����
//20231122 �޸Ĳ�����Ϊ500k
//20231204 ȡ��RVM������
//20231205 �޸ı������������⣺35470��35462��35101
//20231206 �޸�ȼ����ָ��ָʾ��������
//V00.10
//20240122 �޸Ĳ����㣬����ȼ���ⷢ
//20240123 ȥ����ѹ�������ã��޸���������汾��
//20240130 �޸���֡�����ⷢʱ�䣨������200ms���ڣ�
//20240201 �޸��谴OK����γ��ڴ�Ʋ�����������(��ʷ���⣩
//20240227 ͬ������޸ģ���׷�ӱ����ȡ��ʱ�Ӻ������¶���ʾ
//20240228 ȥ��ʱ�����ò˵�
//20240305 ȥ�� 20240201 �޸��谴OK����γ��ڴ�Ʋ�����������(��ʷ���⣩���ָ�ԭ��
//20240307 �޸�ȼ�Ͳ������⣨���������3300�����

#include "main.h"
#include "fuelconfig.h"
#include "UDS_ISO14229_Services.h"

#include "CAN_Communication_Matrix.h"

extern uint8_t sleepFl1g, sleepFlg;

uint8_t ScheduleCtrlCnt;
volatile ScheduleUpdateUnion  ScheduleUpdate;
TaskGroupStruct TaskGroup;

uint8_t ODOtime;

FuelStruct FuelInitPara;
AFC_PARA   AFCPara;
AFC_INIT   AFC_Init;
INT16U     FuelResistanceV;
INT32U     Sum_FuelConsumption ;

uint8_t  AverageFuel_LL;
uint8_t  AverageFuel_LH;
uint8_t  AverageFuel_HL;
uint8_t  AverageFuel_HH;
uint16_t TankLevel_temp;
uint8_t  RESET_ODO_count;
/******************************************************************************
��������main
��  �ܣ�������
��  ������
����ֵ����
******************************************************************************/
void main(void)
{
  Power_Management_Init();

  if ((NVM_CONFIG_FUELBOX == 1) || (NVM_CONFIG_FUELBOX == 2))
  { 
    FuelInitPara.FuelShortCircuitR = 5;
    FuelInitPara.FuelOpenCircuitR  = 2900;        //1900����С��2000     
    
    FuelInitPara.DisplayZoneBoundary[0]  = 1101;
    FuelInitPara.DisplayZoneBoundary[1]  = 1101;
    FuelInitPara.DisplayZoneBoundary[2]  = 921;   //��ֲ
    FuelInitPara.DisplayZoneBoundary[3]  = 621;
    FuelInitPara.DisplayZoneBoundary[4]  = 471;   //��ֲ
    FuelInitPara.DisplayZoneBoundary[5]  = 321;
    FuelInitPara.DisplayZoneBoundary[6]  = 258;   //��ֲ
    FuelInitPara.DisplayZoneBoundary[7]  = 172;
    FuelInitPara.DisplayZoneBoundary[8]  = 96;    //��ֲ
    FuelInitPara.DisplayZoneBoundary[9]  = 30;
    FuelInitPara.DisplayZoneBoundary[10] = 10;
    
    FuelInitPara.FuelCapacityBoundary[0]  = 0;
    FuelInitPara.FuelCapacityBoundary[1]  = 0;    //60;
    FuelInitPara.FuelCapacityBoundary[2]  = 105;  //110; //130
    FuelInitPara.FuelCapacityBoundary[3]  = 444;
    FuelInitPara.FuelCapacityBoundary[4]  = 675;  //250;
    FuelInitPara.FuelCapacityBoundary[5]  = 907;  //310;
    FuelInitPara.FuelCapacityBoundary[6]  = 1139; //370;
    FuelInitPara.FuelCapacityBoundary[7]  = 1369; //440;
    FuelInitPara.FuelCapacityBoundary[8]  = 1595; //480;
    FuelInitPara.FuelCapacityBoundary[9]  = 1743; //540->580
    FuelInitPara.FuelCapacityBoundary[10] = 1743; 
  }
  else if (NVM_CONFIG_FUELBOX == 3)
  {
    FuelInitPara.FuelShortCircuitR = 5;
    FuelInitPara.FuelOpenCircuitR  = 2900;        //1900����С��2000     
    
    FuelInitPara.DisplayZoneBoundary[0]  = 1102;
    FuelInitPara.DisplayZoneBoundary[1]  = 1102;
    FuelInitPara.DisplayZoneBoundary[2]  = 922;   //��ֲ
    FuelInitPara.DisplayZoneBoundary[3]  = 620;
    FuelInitPara.DisplayZoneBoundary[4]  = 470;   //��ֲ
    FuelInitPara.DisplayZoneBoundary[5]  = 320;
    FuelInitPara.DisplayZoneBoundary[6]  = 247;   //��ֲ
    FuelInitPara.DisplayZoneBoundary[7]  = 169;
    FuelInitPara.DisplayZoneBoundary[8]  = 97;    //��ֲ
    FuelInitPara.DisplayZoneBoundary[9]  = 31;
    FuelInitPara.DisplayZoneBoundary[10] = 10;
    
    FuelInitPara.FuelCapacityBoundary[0]  = 0;
    FuelInitPara.FuelCapacityBoundary[1]  = 0;    //60;
    FuelInitPara.FuelCapacityBoundary[2]  = 70;   //110; //130    
    FuelInitPara.FuelCapacityBoundary[3]  = 213;
    FuelInitPara.FuelCapacityBoundary[4]  = 358;  //250;
    FuelInitPara.FuelCapacityBoundary[5]  = 505;  //310;
    FuelInitPara.FuelCapacityBoundary[6]  = 652;  //370;
    FuelInitPara.FuelCapacityBoundary[7]  = 797;  //440;
    FuelInitPara.FuelCapacityBoundary[8]  = 940;  //480;
    FuelInitPara.FuelCapacityBoundary[9]  = 1041; //540->580
    FuelInitPara.FuelCapacityBoundary[10] = 1041; 
  }
  
  AFC_Init.CalcAFCMaxNum = 100;                    //50�������100����һ����
  AFC_Init.AFCMin        = 30;                     //�ͺ���Сֵʮ��
  AFC_Init.AFCMax        = 300;                    //�ͺ����ֵ
  AFC_Init.AFCPreinstall = 150;                    //��ʼֵ 8        20200310
  AFC_Init.CurODO        = NVMODO.Sig.Value * 100; //�ܹ�����100��
  AFC_Init.MaxDRMileage  = 999900;                 //����������ֵ

	InitFuelParamter((FuelStruct*)&FuelInitPara);
	InitAFC((AFC_INIT *)&AFC_Init);

  SetFuelSensorRecoverGroupCnt(24);                //���
  SetFuelSensorOpenCircuitGroupCnt(24);            //��·
  SetFuelSensorShortCircuitGroupCnt(24);           //��·
 
  Read_CZSYBKPILSFR_FLASH();                       //����ָ��Ƕ�

  Task_Scheduler_Init();
  Stepper_Motor_Reset();
      
  for (;;)
  {
    wdt_reset(); 
    Power_Management_Service();   
    Task_Scheduling_Service();
    DoCAN_Communication_Service();
    UDS_Server_Application_Service();              //���
    EEPROM_RW_Service();
    TFT_LCD_General_Table_Write_Service();
    UDS_KL15_init();
    if(SYS_IGN_OFF_DISP_MODE)
    { 
      TFT_LCD_General_Table_Write_Service(); 
      TFT_LCD_General_Table_Write_Service(); 
      TFT_LCD_General_Table_Write_Service(); 
      TFT_LCD_General_Table_Write_Service(); 
      TFT_LCD_General_Table_Write_Service(); 
      TFT_LCD_General_Table_Write_Service(); 
      TFT_LCD_General_Table_Write_Service(); 
      TFT_LCD_General_Table_Write_Service(); 
      TFT_LCD_General_Table_Write_Service(); 
      TFT_LCD_General_Table_Write_Service(); 
      TFT_LCD_General_Table_Write_Service(); 
      TFT_LCD_General_Table_Write_Service(); 
    }    
    
    Stepper_Motor_Speed_Control_Service();
    
    APIBGNMEnable = 0;
    TSzhen_mode();                                                         //�������ģʽ

    TASK_1ms_ALL       CoCAN_Signal_Update_Service();
    TASK_2ms_GROUP_0   {
                         Randomcnt();
                         Analog_Signal_Conversion_Service();                //AD�źŲɼ�
						 SaveDTCsToEEPROM();
                      	 //DoCAN_Get_Multi_frame_Recv();                    //�㲥֡���շ���--hyq
                        }
    TASK_2ms_GROUP_1    {
                         TFT_LCD_Display_Update_Service();                  //tft
                         CanLoseDetected ();
                        //DTCAgingCount();      
                        }
    TASK_10ms_GROUP_0   NVM_Data_Update_Service();                          //eep
    TASK_10ms_GROUP_1   EEPROM_Access_Service();                            //дeep
   // TASK_10ms_GROUP_2   Telltales_Left_Right_Management_Service();          //ת��
    TASK_10ms_GROUP_4   Sound_Play_Service();                               //��������
    TASK_10ms_GROUP_5 {
                             Data_Engine_Speed_Processing_Service();             //ת��
                             enableDTCTimer(10);
                             MsgLostTimer(10);
                      }
    TASK_10ms_GROUP_6   Fuel_Process();                                     //ȼ��         
    //TASK_10ms_GROUP_7   Radar_R3_Receiving_Service();                     //�״�   
    TASK_10ms_GROUP_9   Startup_Animation_Play_Service();                   //��������
    
    TASK_20ms_GROUP_0  Sys_Status_Update_Service();                        //��Դ״̬
    TASK_20ms_GROUP_1  {   
                         MSCAN0_Bus_Off_Monitoring_Service();              //MSCAN0 Bus-off״̬��ط���
                         BL_Management_Service();                          //�������
                       }
    TASK_20ms_GROUP_2  {
                         Line_In_Debounce_Service();                       //Ӳ��
                         //Menu_Processing_Service();                        //�˵���������
                         Key_Status_Detect_Service();                      //����������
                       }
    TASK_20ms_GROUP_3  IO_Management_Service();                            //�������
    TASK_20ms_GROUP_4  Gauges_Management_Service();                        //��תˮ����ʾ
    TASK_20ms_GROUP_5  {
                         Data_Vehicle_Speed_Processing_Service();          //����  
                       }
    TASK_20ms_GROUP_6  {
                         Data_Coolant_ADblue_Processing_Service();         //����Һ  LCD 
                       }
    TASK_20ms_GROUP_7  {
                         Data_Coolant_Temp_Processing_Service();           //ˮ��
                       }
    TASK_20ms_GROUP_8  { 
                         Data_Coolant_Oil_Processing_Service();            //���� 
                       }
    TASK_20ms_GROUP_9	 {

                       }
    TASK_50ms_GROUP_0  Flash_Sync_Signal_Generation_Service();             //��˸
    TASK_50ms_GROUP_1  Telltales_Management();                             //ָʾ��
    TASK_50ms_GROUP_2  Sound_Scheduling_Service();                         //���� 
    TASK_50ms_GROUP_3  {
                         Data_AirO_Level_Processing_Service();             //��ѹ1
                       }
    TASK_50ms_GROUP_4  {
                         Data_AirT_Level_Processing_Service();             //��ѹ2        
                       }
    TASK_100ms_GROUP_0 CAN_NORMAL_TIME_PRG();
    TASK_100ms_GROUP_1 Popups_Management_Service();                        //�����߼� ��ʾ
    TASK_100ms_GROUP_2 {
                         Drive_Info_Display_Update_Service();              //��ʾ
                       }
   TASK_100ms_GROUP_3  {
                         /*if (NVM_ODO_VALUE < 29980)
                         {
                           NVM_ODO_VALUE = 29980;
                           NVM_Data_Update(NVM_ODO_DATA);
                         }*/ 
                         
                         if ( CLEAR_ODO_STAR == 1 ) 
                         {
                           if (NVM_ODO_VALUE < 20000)
                           {
                             if (KeyEnterinStatus == 1) 
                             {
                               if (RESET_ODO_count < 220) 
                                 RESET_ODO_count++;
                               else
                                 RESET_ODO_count = 100;
                               
                               if (RESET_ODO_count >= 100)
                               {
                                 CLEAR_ODO_STAR = 0;
                                 RESET_ODO_count = 0;
                                 Data_Clear_TripA();
                                 NVM_ODO_VALUE = 0;
                                 NVM_Data_Update(NVM_ODO_DATA);
                                 NVM_RESET_ODO_FLAG = 1;
                                 NVM_Data_Update(NVM_RESET_ODO);
                               }
                             }
                             else
                               CLEAR_ODO_STAR = 0;
                           }
                           else
                             CLEAR_ODO_STAR=0;
                         }
                       }

    TASK_100ms_GROUP_4 {
                         RTI_Timing_Service();                             //ʱ�䶨ʱ��
                         Data_IGN_Off_Timing_Service();                    //IGN_IGOFF��ʱ
                         Drive_Info_Import_Export_Service();               //������� �����ⷢ
                       }
    TASK_100ms_GROUP_5 {
                         Data_Drive_Info_Group1_Processing_Service();      //ODO/TRIP
                         Data_Drive_Info_Group2_Processing_Service();      //˲ʱ�ͺ�
                       }
    TASK_100ms_GROUP_6 {
                         Popup_Scheduling_Service();                       //�������� 
                       }
    TASK_100ms_GROUP_7 SaveDTCsToEEPROM();
    //TASK_100ms_GROUP_8   Warning_Processing_Service();                     //�����߼� ״̬     
    TASK_100ms_GROUP_9 {
                         Factory_ClearOdoM();                              //����������G                     
                       }
  }
}
/******************************************************************************
��������Fuel_Process
��  �ܣ�
��  ������
����ֵ����
******************************************************************************/
uint8_t   Fuel_Seg, FuelStatus;
uint16_t  AVYOUHAO;
uint16_t  DataDTE;
uint16_t  FuelConsumeSum;
uint16_t  DataAvgFuelConsByLF;        //ƽ���ͺ�

void Fuel_Process(void)               //��ƽ���ͺĵ�ͬʱ����Ҳ������
{
  uint32_t result;
  uint16_t DataAvgFuel;               //ƽ���ͺ�
  
  wdt_reset();
  
  if (NVM_CONFIG_POWER == 1)
  {  
    if ((IO_DISPLAY_MODE != IO_DISP_MODE_IGN_OFF) && (ANALOG_KL15_VOLTAGE >= 18000))
    {
      SetPowerSt(1);
      AFCTimerCall();
      FuelConsumeSum = (FuelConsumptionRateH << 8) | (FuelConsumptionRateL);
      FuelConsumeSum = (FuelConsumeSum  * 5 / 9) >> 2;
      AFCPara.FuleConsume = (uint16_t)FuelConsumeSum; //unit ul    
         
      FuelConsumeSum = 0;                   
    
      AFCPara.CurODO = NVMODO.Sig.Value * 100; //��G   
     	       
    	AFCPara.RPM = DataESpeedActual;          //ת��  
    	AFCPara.Speed = (uint8_t)(DataVSpeedActual / 10); //����
     
    	SetAFCPara((AFC_PARA *)&AFCPara);
    
    	if (AnalogFuelSensorRes < 10) 
    	{
    	  AnalogFuelSensorRes = 10;  
    	}
    	
    	//if (AnalogFuelSensorRes < 30)
    	//  AnalogFuelSensorRes = 30;
    	
      SaveSampleVal(AnalogFuelSensorRes);
      FuelFSM();
      
      FuelResistanceV = GetFuelResistance(); //ȼ�͵����ȡ
      
      FuelStatus = GetFuelSensorState();     //ȼ��״̬��ȡ
     
      /*if (FuelStatus == FuelSensorNormal)
    	  DataDTE=GetDRMileage(); //unit:km,accuracy:1�������
      else
        DataDTE = 0;*/
      
      if (FuelStatus == FuelSensorNormal) 
      { 
        if (DataFuelVolRemaining == 0) 
        {
          DataDTE = 0;
        } 
        else
        {                                                                 
          DataDTE = GetDRMileage(); //unit:km,accuracy:1������� //�����������Ϊ0 2021.1.19
        }
      }
      else
        DataDTE = 0;
      
     	DataAvgFuelConsByLF = GetCurAFC();          //ƽ���ͺ�
     	DataAvgFuel    = DataAvgFuelConsByLF / 10;
    	AverageFuel_LL = (DataAvgFuel << 1) & 0xFF; //ϵ��0.5
    	AverageFuel_LH = (DataAvgFuel >> 7) & 0xFF;
    	AverageFuel_HL = (DataAvgFuel >> 15) & 0xFF;
    	AverageFuel_HH = (DataAvgFuel >> 23) & 0xFF;
      
      if (FuelResistanceV) 
      {
        Fuel_Seg = GetFuelStep();
      }
      
      if (FuelStatus == FuelSensorOpenCircuit) //2021.2.8  ȡ����·
        Fuel_Seg = 0;
      
      /*if ((Fuel_Seg >= 20) && (Fuel_Seg < 40)) //ϵ��1
        TankLevel_temp = 1;
      else if ((Fuel_Seg >= 40) && (Fuel_Seg < 60))
        TankLevel_temp = 2;
      else if ((Fuel_Seg >= 60) && (Fuel_Seg < 80))
        TankLevel_temp = 3;
      else if (Fuel_Seg >= 80)
        TankLevel_temp = 4;
      //else if (Fuel_Seg > 90)
      //  TankLevel = 5;
      else
        TankLevel_temp = 0;  
      */
      
      DataFuelVolRemaining = GetFuelCapacityVal(); //ʣ������
      TankLevel_temp = DataFuelVolRemaining;
      
      if ((NVM_CONFIG_FUELBOX == 1) || (NVM_CONFIG_FUELBOX == 2))
      {
        TankLevel_temp = TankLevel_temp / 8; //TankLevel_temp = DataFuelVolRemaining / 2000 * 100 / 0.4;
      }
      else 
      {
        TankLevel_temp=TankLevel_temp * 5 / 24; //TankLevel_temp = DataFuelVolRemaining / 1200 * 100 / 0.4;
      }
    }
  }
  else
  {
    if ((IO_DISPLAY_MODE != IO_DISP_MODE_IGN_OFF) && (ANALOG_KL15_VOLTAGE >= 8000))
    {
      SetPowerSt(1);
      AFCTimerCall();
      FuelConsumeSum = (FuelConsumptionRateH << 8) | (FuelConsumptionRateL);
      FuelConsumeSum = (FuelConsumeSum * 5 / 9) >> 2;
      AFCPara.FuleConsume = (uint16_t)FuelConsumeSum; //unit ul    
         
      FuelConsumeSum = 0;                  
           
      //FuelConsumeSum = FuelConsumeSumData / 10;     
      //FuelConsumeSumData = 0;    
    
      AFCPara.CurODO = NVMODO.Sig.Value * 100; //��G
     	       
    	AFCPara.RPM = DataESpeedActual;          //ת��
    	AFCPara.Speed = (uint8_t)(DataVSpeedActual / 10);   //����
     
    	SetAFCPara((AFC_PARA *)&AFCPara);
    
    	if (AnalogFuelSensorRes < 10) 
    	{
    	  AnalogFuelSensorRes = 10;  
    	}
    	
    	//if (AnalogFuelSensorRes < 30)
    	//  AnalogFuelSensorRes = 30;
    	
      SaveSampleVal(AnalogFuelSensorRes);
      FuelFSM();
      
      FuelResistanceV = GetFuelResistance(); //ȼ�͵����ȡ
      
      FuelStatus = GetFuelSensorState();     //ȼ��״̬��ȡ
     
      /*if (FuelStatus == FuelSensorNormal)
    	  DataDTE = GetDRMileage(); //unit:km,accuracy:1�������
      else
        DataDTE = 0;*/
      
      if (FuelStatus == FuelSensorNormal) 
      { 
        if (DataFuelVolRemaining == 0) 
        {
          DataDTE = 0;
        } 
        else
        {                                                                 
          DataDTE = GetDRMileage(); //unit:km,accuracy:1������� //�����������Ϊ0 2021.1.19
        }
      }
      else
        DataDTE = 0;
      
     	DataAvgFuelConsByLF = GetCurAFC();  //ƽ���ͺ�    	
    	DataAvgFuel    = DataAvgFuelConsByLF / 10;
    	AverageFuel_LL = (DataAvgFuel << 1) & 0xFF; //ϵ��0.5
    	AverageFuel_LH = (DataAvgFuel >> 7) & 0xFF;
    	AverageFuel_HL = (DataAvgFuel >> 15) & 0xFF;
    	AverageFuel_HH = (DataAvgFuel >> 23) & 0xFF;
    	
      if (FuelResistanceV) 
      {
        Fuel_Seg = GetFuelStep();
      }
      
      if (FuelStatus == FuelSensorOpenCircuit) //2021.2.8
        Fuel_Seg = 0;
              
      /*if ((Fuel_Seg >= 20) && (Fuel_Seg < 40)) //ϵ��1
        TankLevel_temp = 1;
      else if ((Fuel_Seg >= 40) && (Fuel_Seg < 60))
        TankLevel_temp = 2;
      else if ((Fuel_Seg >= 60) && (Fuel_Seg < 80))
        TankLevel_temp = 3;
      else if (Fuel_Seg >= 80)
        TankLevel_temp = 4;
      //else if (Fuel_Seg > 90)
      //  TankLevel = 5;
      else
        TankLevel_temp = 0;
      */
      
      DataFuelVolRemaining = GetFuelCapacityVal(); //ʣ������
      TankLevel_temp = DataFuelVolRemaining;
      if ((NVM_CONFIG_FUELBOX == 1) || (NVM_CONFIG_FUELBOX == 2))
      {
        TankLevel_temp = TankLevel_temp / 8;
      }
      else 
      {
        TankLevel_temp = TankLevel_temp * 5 / 24;
      }
    }
  }
  
  if (FuelStatus == FuelSensorOpenCircuit)
  {
    ICM_FuelLevel = 0xFF;
  }
  else
  {
    result = YOUB_FBJD_MHL;
    result *= 125; //1000; 
    result /= 978; //1956*4;
    ICM_FuelLevel = (uint8_t)result;
  }
}
/******************************************************************************
��������Task_Scheduler_Init
��  �ܣ������������ʼ��
��  ������
����ֵ����
******************************************************************************/
void Task_Scheduler_Init(void)
{
  uint8_t i;
  uint8_t *p;
  
  ScheduleCtrlCnt            = 0;
  ScheduleUpdate.TaskFlagAll = 0;
  
  p = (uint8_t *)(&TaskGroup);
  
  for (i = 0; i < sizeof(TaskGroup); i++)
    *(p + i) = 0xFF;
}
/******************************************************************************
��������Task_Scheduling_Service
��  �ܣ�������ȷ�����
��  ������
����ֵ����
*******************************************************************************
ע  �⣺�÷��������뱻ʵʱ����
******************************************************************************/
void Task_Scheduling_Service(void)
{
  ScheduleUpdate.TaskFlagAll = 0;         //��������±�־
  
  if (API_1ms_Timer_Update())
  {
    ScheduleUpdate.TaskFlagAll = TaskScheduleTable[ScheduleCtrlCnt];

    if (ScheduleUpdate.Task.Flag2ms)      //���µ�ǰ2ms��������
    {
      if (TaskGroup.ID2ms)
        TaskGroup.ID2ms = 0;
      else 
        TaskGroup.ID2ms = 1;
    }
    if (ScheduleUpdate.Task.Flag10ms)     //���µ�ǰ10ms��������
    {
      if (TaskGroup.ID10ms >= 9)
        TaskGroup.ID10ms = 0;
      else
        TaskGroup.ID10ms++;
    }
    if (ScheduleUpdate.Task.Flag20ms)     //���µ�ǰ20ms��������
    {
      if (TaskGroup.ID20ms >= 9)
        TaskGroup.ID20ms = 0;
      else
        TaskGroup.ID20ms++;
    }
    if (ScheduleUpdate.Task.Flag50ms)     //���µ�ǰ50ms��������
    {
      if (TaskGroup.ID50ms >= 9)
        TaskGroup.ID50ms = 0;
      else
        TaskGroup.ID50ms++;
    }
    if (ScheduleUpdate.Task.Flag100ms)    //���µ�ǰ100ms��������
    {
      if (TaskGroup.ID100ms >= 9)
        TaskGroup.ID100ms = 0;
      else
        TaskGroup.ID100ms++;
    }
    if (ScheduleCtrlCnt >= 9)             //���µ��ȼ�����
      ScheduleCtrlCnt = 0;
    else
      ScheduleCtrlCnt++;
  }
}

/********************�����������***************************/
//extern uint8_t ClrOdoEn;

void Factory_ClearOdoM(void)
{
  //uint16_t Checksum;
  
  if ((DataVSpeedDisp >= 1550 ) && (DataESpeedDisp >= 4850))
  {
    if (IO_CAN_KEY_ENTER == IO_KEY_PRESS)
    //if (ClrOdoEn)
    {
      IO_CAN_KEY_ENTER = IO_KEY_IDLE;
      //ClrOdoEn = 0;
      Data_Clear_TripA();
      NVM_ODO_VALUE = 0;
      NVM_Data_Update( NVM_ODO_DATA );
      Data_ODO_Update_Disable();
      
      if (NVM_USER_SETTINGS_FLASH_CHK_CNT)
      {
        if (NVM_USER_SETTINGS_FLASH_CHK_CNT > 3)
          NVM_USER_SETTINGS_FLASH_CHK_CNT = 0;
        else
        {
          NVM_USER_SETTINGS_FLASH_CHK_CNT -= 1;
          
          wdt_reset();
          //Checksum = YGV642_Calc_Pattern_Memory_CheckSum(ROMDATA_STARTADDR, ROMDATA_ENDADDR);
          
          //if (Checksum != ROMDATA_CHECKSUM)  //YVC_LYR_NUM_CPU
          //  TFT_LCD_Display_Sprite(YVC_LYR_NUM_CPU-1, SN_R_bmp, 0, 0, 64); //���  
        }
        
        //NVM_Data_Update(NVM_USER_SETTINGS);
      }
    }
  }
  else
  {
    //ClrOdoEn = 0;
  }
}

