#ifndef _CAN_USER_H
#define _CAN_USER_H

#include "r_rl78_can_drv.h"


typedef union{
	unsigned int Msg_Word[4];
	unsigned char Msg_Byte[8];
	struct{
		unsigned char MSW_PsdBtnReq:2;//byte1
		unsigned char MSW_RotReq:2;
		unsigned char MSW_TogReq:4;
		unsigned char MSW_BtnFltSts:1;//byte2
		unsigned char Reserve_1:7;
		unsigned char MSW_RotStep:8;//byte3
        unsigned char Reserve_3:8;//byte4
        unsigned char Reserve_4:8;//byte5
        unsigned char Reserve_5:8;//byte6
        unsigned char Reserve_6:8;//byte7
        unsigned char Reserve_7:8;//byte8
	}Msg_Part;
}Can_Msg_Type_212;




extern can_frame_t RxCanMessage;

extern unsigned char BusOff_flag;
extern unsigned char BusOff_IGN_cycle_count;
extern unsigned int BusOff_Detect_delay_count;

extern unsigned char Engine_Temperature,Engine_Temperature_temp;
extern unsigned int  Vehicle_Speed,Vehicle_Speed_temp;
extern unsigned char Engine_Temperature_already,Vehicle_Speed_already;


extern uint16_t air_req_timer;
extern unsigned char CAN_SEND_COMPLETE;

extern unsigned char Can_2F_SET_run;
extern unsigned char DiagnosticSession_Present;//1,2,3
extern unsigned char Tx_Rx_Enable;//0:none 1:Tx 2:Rx 3:Tx Rx

extern unsigned char Nw28sTxRxStatus;//0:none 1:Tx 2:Rx 3:Tx Rx  
extern unsigned char App28sTxRxStatus;//0:none 1:Tx 2:Rx 3:Tx Rx

#define DCM28S_MASK_TX_DISABLE         0X01
#define DCM28S_MASK_RX_DISABLE         0X02

void TxServe(void);
void CAN_TX_MESSAGE_INIT(void);
void Copy_Array_to_Array(unsigned char *dest, unsigned char *src,unsigned char count);




/*************************VF12***********************************/

typedef union{
	unsigned int Msg_Word[4];
	unsigned char Msg_Byte[8];
	struct{
		unsigned char :8;               //1 0-7
		unsigned char :8;               //2 8-15
		unsigned char :8;               //3 16-23
		unsigned char :8;               //4 24-31
		unsigned char :3;               //5 32-34
        unsigned char Backlightadjust:5;//5 35-39
		unsigned char :8;               //6 40-47
		unsigned char :8;               //7 48-55
		unsigned char :8;               //8 56-63
	}Msg_Bit;
}Can_Msg_Type_26D;


typedef union{
	unsigned int Msg_Word[4];
	unsigned char Msg_Byte[8];
	struct{
		unsigned char :8;//1
		unsigned char VCU_VehSpd1:3;//2
		unsigned char :5;
		unsigned char VCU_VehSpd2:8;//3
		unsigned char :6;//4
		unsigned char VCU_VehSpd3:2;

		unsigned char :8;//5
		unsigned char :8;//6
		unsigned char :8;//7
		unsigned char :8;//8
	}Msg_Bit;
}Can_Msg_Type_403;


extern Can_Msg_Type_403 CAN_403;
extern Can_Msg_Type_26D CAN_26D;
extern Can_Msg_Type_212 CAN_212;
extern unsigned int CAN_LostCount;












extern void Can_init_id(can_frame_t *TxMessage,unsigned int canid);
void TxTestMsg(void);
void ClearTxCounter(void);


#endif