#ifndef __MCU_FLASH_H
#define __MCU_FLASH_H


#define XRAM_MAP_ADDR				0x0000
#define MCUFLASH_BK1_ADDR			0x0000
#define	MCUFLASH_BK2_ADDR			(MCUFLASH_BK1_ADDR + 512)
#define MCUFLASH_BK1_FLG_ADDR		(MCUFLASH_BK1_ADDR + 510)
#define MCUFLASH_BK2_FLG_ADDR		(MCUFLASH_BK2_ADDR + 510)
#define MCUFLASH_SECTOR_SIZE		512			//1Sector的长度为512字节

#define MCU_FLASH_WATI_DELAY		2

/**************************************************************************************/
//MCU Flash中区块地址定义
/**************************************************************************************/
//系统信息区开始 SubClassID=0x00
#define SYS_PARA_MAP_ADDR		    XRAM_MAP_ADDR
#define SYS_PARA_LEN				48

//用户自定义参数区开始 SubClassID=0x01
#define SYSINFO_MAP_ADDR			(SYS_PARA_MAP_ADDR+SYS_PARA_LEN)
#define SYSINFO_LEN					50

//充电参数区开始 SubClassID=0x02
#define CHG_PARA_MAP_ADDR			(SYSINFO_MAP_ADDR+SYSINFO_LEN)	
#define	CHG_PARA_LEN				18

//放电参数区开始 SubClassID=0x03
#define	DSG_PARA_MAP_ADDR			(CHG_PARA_MAP_ADDR+CHG_PARA_LEN)
#define DSG_PARA_LEN				21

//预留参数区开始 SubClassID=0x04
//Reserved

//放电PWM参数区开始 SubClassID=0x05
#define DSG_PWM_PARA_MAP_ADDR		(DSG_PARA_MAP_ADDR+DSG_PARA_LEN)
#define DSG_PWM_PARA_LEN			5

//充电温度保护参数开始 SubClassID=0x06
#define CHG_TEMP_PARA_MAP_ADDR		(DSG_PWM_PARA_MAP_ADDR+DSG_PWM_PARA_LEN)
#define CHG_TEMP_PARA_LEN			11

//放电温度保护参数开始 SubClassID=0x07
#define DSG_TEMP_PARA_MAP_ADDR		(CHG_TEMP_PARA_MAP_ADDR+CHG_TEMP_PARA_LEN)
#define	DSG_TEMP_PARA_LEN			9

//平衡参数区开始 SubClassID=0x08
#define	BAL_PARA_MAP_ADDR			(DSG_TEMP_PARA_MAP_ADDR+DSG_TEMP_PARA_LEN)
#define	BAL_PARA_LEN				8

//容量统计参数开始 SubClassID=0x09
#define	SOC_PARA_MAP_ADDR			(BAL_PARA_MAP_ADDR+BAL_PARA_LEN)
#define	SOC_PARA_LEN				17

//AFE参数区开始 SubClassID=0x0A
#define	AFE_PARA_MAP_ADDR			(SOC_PARA_MAP_ADDR+SOC_PARA_LEN)
#define	AFE_PARA_LEN				4

//校准参数区开始 SubClassID=0x0B
#define CALI_PARA_MAP_ADDR			(AFE_PARA_MAP_ADDR+AFE_PARA_LEN)
#define	CALI_PARA_LEN				12

#define RESERVED_DATA_MAP_ADDR		(CALI_PARA_MAP_ADDR+CALI_PARA_LEN)
#define	RESERVED_DATA_LEN			(510-(RESERVED_DATA_MAP_ADDR))

#define DataflashCheck_Map_ADDR		0xfe
#define DataflashCheck_LEN			0x0002


extern BOOL	bMcuFlashWrWaitFlg;
extern BOOL	bMcuFlashWrFlg;
extern BOOL	bMcuFlashErr;
extern U8	xdata	ucMcuFlashWrValid;
extern U8	xdata	bMcuFlashWrWaitCnt;

extern BOOL McuFlashRead(U16 SourceAddr, U8 xdata *TargetAddr, U16 Length);
extern BOOL McuFlashWrite(U16 McuFlashAddr, U16 XramAddr);
extern void McuFlashWrOneByte(U16 McuFlashAddr,U8 WrData);
extern void McuFlashProcess(void);
extern void McuFlashWrWaitCheck(void);
extern BOOL McuFlashCheckFlg(U16 Saddr);


#endif