#ifndef _DMK_VF12_03_H
#define _DMK_VF12_03_H


#include "r_cg_macrodriver.h"

#include "r_cg_userdefine.h"
#include "r_rl78_can_sfr.h"
#include "r_rl78_can_drv.h"
#include "can_user.h"
#include "pfdl.h"
#include "dcm.h"
#include "CanNw.h"


/***********************************************/
typedef struct{
    unsigned int start;
    unsigned int zysoft1;
    unsigned int zysoft2;
    unsigned int zynow;
    unsigned int kbsoft1;
    unsigned int kbsoft2;
    unsigned int kbnow;
    unsigned int checksum;
    unsigned int stop;
}MotorStateEE_Type;
extern MotorStateEE_Type MotorStateEE;



#define IGN_ON            	0u
#define IGN_OFF             1u


typedef unsigned char u8;
typedef unsigned int u16;

extern unsigned char TB9102_Enable,TB9102_Disable_count;
extern unsigned char Motor_init_15s_count;

extern u16 ad[8];
extern u8 ad_voltage_fact[8];


extern unsigned long Can_1ms_count_alive;

extern u8 RES_CYC_SET,RES_RDEF_SET,RES_CYC_SET_last;
extern u8 RES_MODE_SET,RES_MODE_SET_last;
extern u8 LAST_FAN_SET;

extern unsigned int EEL_SAVE_CNT_DOWN_TIMER;

extern unsigned char AppliTick;
extern unsigned char AppliSchedule;
extern u8 RDEF_OUT_FLAG,RDEF_CNT;
extern u16 key_dither;
extern u16 RecurrenceRunTime;

extern unsigned char OFF_state,OFF_to_Fre,OFF_Fan_0,OFF_AC_off,OFF_Temp_0;
extern unsigned char FrontDef,FrontDef_to_Fre,FrontDef_AC_on,FrontDef_Fan_6;

/*********************Network Manage****************************/
extern unsigned char ucIgnStus;
extern unsigned int uiBusOffCnt;  


void Apply_task(void);

void EEL_READ(void);
void EEL_WRITE(void);
void EEL_Write_Enable_Check(void);

void DID_data_save_init(void);
void BusOff_Detect(void);

void IGN_Voltage_Detect(void);
void WakeUP(void);




void TAU0_Channel1_ChangeDuty(unsigned char ratio);


/**************************VF12*************************************/
extern unsigned char Timer_1ms_flag;
extern unsigned char Timer_5ms_flag;
extern unsigned char Timer_10ms_flag;
extern unsigned char Timer_20ms_flag;
extern unsigned char Timer_50ms_flag;
extern unsigned char Timer_1000ms_flag;


#define PWN_KEY         P1_bit.no3
#define I_IGN_SIGN		P1_bit.no7




extern unsigned char IGN_Lost,IGN_Lost_Count;
extern unsigned char IGN_On,IGN_On_Count;



void KeyPro(void);
void Can_Msg_Change(void);
void CAN_RX_Data_Handle(void);

void SleepDetect(void);
void WakeUP(void);
void Signal_Lost_Detect(unsigned char Pin,unsigned char Lost_state,unsigned char *Signal_Lost,unsigned char *Signal_Lost_count,unsigned char Lost_time);
void IGN_Detect(void);
void LED_Light_Ctrl(void);
void value_init(void);
void R_MAIN_UserInit(void);

void XN_Pro(void);
void XN_Scan(void);
void getIGNVoltage(unsigned char* data);

#endif