/*******************************************************************************
 * charger_ecan.h
 *
 *  Created on: 2013-5-16
 *      Author: Administrator
*******************************************************************************/

#ifndef CHARGER_ECAN_H_
#define CHARGER_ECAN_H_

//#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File

#define DEVICE_SYSCLK_FREQ          (100000000U)
//接受配置

#define RX_MBOX0		5		
#define RX_MBOX1		6		
#define	RX_MBOX2		7		
#define	RX_MBOX3		8		
#define	RX_MBOX4		9		
#define	RX_MBOX5		10		
#define RX_MBOX6		5		
#define RX_MBOX7		6		
#define	RX_MBOX8		7		
#define	RX_MBOX9		8		

#define	RX_addrID       	(0x15555555)


// 发送配置
#define	TX_addr_MBOX11		11		
#define TX_megs_MBOX12		12	

#define	TX_addrID_MBOX11	(0xB)		
#define TX_megsID_MBOX12	(0xC)	

//PTP
#define BORAD_ALL           1
#define BORAD_TO            0

//ADDRcmd
#define ADDRcmd_end           1
#define ADDRcmd_on            0

#define	recnum       	   (8)
#define uCalADDR_Cyle_15S  (3000)

#define uCAN_fault_1min     (12000)

#define HWREGB(x)    __byte((int16 *)(x),0)

struct  CANMSGID_BITS 
{        // bits  description
   Uint32      ADDR:19;		// 0-18
   Uint16      LogADDR:8;		// 19-26
   Uint16      PTP:1;		//27
   Uint16      ADDRcmd:1;	//28 
   Uint16      res:3;          // 29-31   
};

union CANMSGID_REG {
   Uint32                all;
   struct CANMSGID_BITS  bit;
};

struct  CANDATAWORD 
{        // bits  description
   Uint32      WORD_l;		// 0-26
   Uint32      WORD_h;		//27 
};

struct  CANDATABYTES 
{        // bits  description
   Uint16      Byte0;		// 
   Uint16      Byte1;		// 25-26
   Uint16      Byte2;		//27
   Uint16      Byte3;	//28 
};


union CANDATA_REG 
{   
   struct CANDATAWORD     CANWord;
   struct  CANDATABYTES   CANBytes;
   Uint16		 Dat[8];
};


typedef struct 
{
	union CANMSGID_REG 	CanId;
	union CANDATA_REG   CanData; 
}DATACanType;


//地址排序状态
struct  CANADDSTATE_BITS 
{        // bits  description
   Uint16      bCalIDCmd:1;		// 0 请求排序指令
   Uint16      bSendIDCMD:1;		// 1
   Uint16      bStopAddr:1;		//2
   Uint16      res:13;          // 3-15   
};

union CANADDSTATE
{
    Uint16  all;
    struct  CANADDSTATE_BITS bits;
};
struct MDADDRMES
{
    union CANADDSTATE uCanState;
    Uint16 uReqIDnum;//请求排序发送次数
    
    Uint16 uTranEND_num;//地址排序信息
	Uint16 uIndex;//地址排序信息
	Uint16 MDADDRID_num;//地址数组，存储的当前数
	Uint32 uSelfID;
	Uint32 MDADDRID[recnum+1];//存储地址信息
	Uint16 uRecMdl_Cur[recnum+1];//存储电流信息信息
	Uint16 uRecMdl_onoff[recnum+1];//存储开关机信息信息
};

struct SCANMES
{
	Uint16 uCalADDR_Cyle;//地址排序时间
	Uint16 uCanRec_count;//判断can功能故障
};

extern DATACanType CanRecData;
extern DATACanType CanTrsData;
extern struct MDADDRMES uMdlAddMes;
extern struct SCANMES sCanMes;



void init_can(void);
void V_Can_Fun_tran(void);
void V_Can_Fun_rece(void);
void v_CAN_time(void);


#endif /* ACDC_ECAN_H_ */

