/******************************************************************************
文 件 名：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配置项）
//20240313 取消0x18FFOA17外发（EF01报文矩阵里没有），修改30电15电同时上首帧网络管理报文外发超时问题
//20240315 修改诊断测出问题（李秉微）
//V00.11
//20240446 修改车厂问题：0x18FE8E17外发不对（新报文矩阵无平均油耗输出）
//20240430 修改软件版本号

#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;
  }
}

