#ifndef __UART_APP_H
#define __UART_APP_H

#define UART_SLAVE_ADDR			0x00
#define UART_CMD_NO				0x01
#define UART_LENGTH				0x02
#define UART_DATA				0x03

#define CMD_RD_EEPROM       	0x78

//主信息扫描命令字
#define CELL1					0X01
#define CELL2					0X02
#define CELL3					0X03
#define CELL4					0X04
#define CELL5					0X05
#define CELL6					0X06
#define CELL7					0X07
#define CELL8					0X08
#define CELL9					0X09
#define CELL10					0X0A
#define TOTAL_VOLTAGE			0X0B
#define EXT_TEMP1				0X0C
#define EXT_TEMP2				0X0D
#define DIE_TEMP1				0X0E
#define DIE_TEMP2				0X0F
#define CADC_CURRENT			0X10
#define FULL_CHG_CAP			0X11
#define REMAIN_CAP				0X12
#define R_SOC					0X13
#define CYCLE_COUNT				0X14
#define PACK_STATUS				0X15
#define BATTERY_STATUS			0X16
#define PACK_CONFIG				0X17
#define MANUFACTURE_COMMAND		0X18

//MCU参数区子命令号
#define	DATA_FLASH_COMMAND		0x77
#define SUB_PAGE1				0x78
#define SUB_PAGE2				0x79
#define SUB_PAGE3				0x7A
#define SUB_PAGE4				0x7B
#define SUB_PAGE5				0x7C
#define SUB_PAGE6				0x7D
#define SUB_PAGE7				0x7E
#define SUB_PAGE8				0x7F
#define RTC_SUBID				0x0C

//校准命令字
#define CALI_VOL_COMMAND		0xA0
#define CALI_TS1_COMMAND		0xA1
#define CALI_TS2_COMMAND		0xA2
#define CALI_CUR_COMMAND		0xA3
#define CALI_ZERO_CUR_COMMAND	0xA4
#define CALI_RTC_COMMAND		0xAF

#define CMD_E2PROM_ERASE 		0xB0
#define CMD_E2PROM_ERASE_4K 	0xB1

#define CMD_VALID_ACK			0x5A
#define CMD_INVALID_ACK			0xFF

#define Uart0SendAck()			Uart0TxEn(CMD_VALID_ACK)
#define Uart0SendNack()			Uart0TxEn(CMD_INVALID_ACK)
#define Uart0SendData()			Uart0TxEn(ucUart0Buf[ucUart0BufPT])

#define Uart1SendAck()			Uart1TxEn(CMD_VALID_ACK)
#define Uart1SendNack()			Uart1TxEn(CMD_INVALID_ACK)
#define Uart1SendData()			Uart1TxEn(ucUart1Buf[ucUart1BufPT])

#define Uart2SendAck()			Uart2TxEn(CMD_VALID_ACK)
#define Uart2SendNack()			Uart2TxEn(CMD_INVALID_ACK)
#define Uart2SendData()			Uart2TxEn(ucUart2Buf[ucUart2BufPT])


//IAP相关定义
#define HEARD1                  0x00
#define HEARD2                  0x01
#define LENGTH                  0x02
#define SOURCE                  0x03
#define TARGET                  0x04
#define COMMAND                 0x05
#define INDEXES                 0x06
#define DATA                    0x07
#define IAP_BMSID				0x07		//电池管理系统1
#define IAP_PCID				0x3D        //上位机系统
//IAP&ISP Command
#define IAP_CMD_HANDSHAKE		0x06
#define IAP_CMD_BEGIN			0x07
#define IAP_CMD_TRANS			0x08
#define IAP_CMD_VERIFY			0x09
#define IAP_CMD_RESET			0x0A

#define IAPERROR_CHECKSUM		0x80
#define IAPERROR_ADDR			0x40
#define IAPERROR_CMD			0x20

extern BOOL	bISPFlg;                        //ISP升级标志，进入ISP程序
extern BOOL	bUart0ReadFlg;
extern BOOL	bUart0WriteFlg;
extern BOOL	bUart0SndAckFlg;                 //UART已经发送ACK给主机

extern BOOL	bUart1ReadFlg;
extern BOOL	bUart1WriteFlg;
extern BOOL	bUart1SndAckFlg;                 //UART已经发送ACK给主机

extern BOOL	bUart2ReadFlg;
extern BOOL	bUart2WriteFlg;
extern BOOL	bUart2SndAckFlg;                 //UART已经发送ACK给主机

extern U8	xdata	ucSubClassID;
extern U8	xdata	ucUart0Buf[];
extern U8	xdata	ucUart0BufPT;
extern U8	xdata	ucUart0SndLength;
extern U8	xdata	ucUart0TimeoutCnt;

extern U8	xdata	ucUart1Buf[];
extern U8	xdata	ucUart1BufPT;
extern U8	xdata	ucUart1SndLength;
extern U8	xdata	ucUart1TimeoutCnt;

extern U8	xdata	ucUart2Buf[];
extern U8	xdata	ucUart2BufPT;
extern U8	xdata	ucUart2SndLength;
extern U8	xdata	ucUart2TimeoutCnt;

extern void InterruptUart0AppRx(U8 RxData);
extern void InterruptUart0AppTx(void);
extern void Uart0Check(void);

extern void InterruptUart1AppRx(U8 RxData);
extern void InterruptUart1AppTx(void);
extern void Uart1Check(void);

extern void InterruptUart2AppRx(U8 RxData);
extern void InterruptUart2AppTx(void);
extern void Uart2Check(void);


#endif