#ifndef __LEAF_OTA_H_
#define __LEAF_OTA_H_
#include "main.h"


/* 开关全局中断的宏 */
#define ENABLE_INT()	__set_PRIMASK(0)	/* 使能全局中断 */
#define DISABLE_INT()	__set_PRIMASK(1)	/* 禁止全局中断 */


#define PageSize		1024			//1K
#define Appear_si 128

/*=====用户配置(根据自己的分区进行配置)=====*/
#define BootLoader_Size 		0xA000			///< BootLoader的大小 40K
#define Appear_Size 		0x6000			///< BootLoader的大小 40K
#define Application_Size		0x20000			///< 应用程序的大小 128K

//#define Application_1_Addr		0x08010000		///< 应用程序1的首地址
//#define Application_2_Addr		0x08030000		///< 应用程序2的首地址
//#define Application_2_Addr		0x08017FFF		///< 应用程序2的首地址

#define Application_1_Addr		ADDR_FLASH_SECTOR_0		///< 应用程序1的首地址
#define Application_2_Addr		ADDR_FLASH_SECTOR_6		///< 应用程序2的首地址

#define Application_Buffer_Addr		ADDR_FLASH_SECTOR_7		///< 接收到的文件存储区
/*==========================================*/

#define StartMode_Addr		ADDR_FLASH_SECTOR_4		///< 应用程序2的首地址



/* 启动选项 */
#define Startup_Normal 	0xFFFFFFFF	///< 正常启动   跳转到APP1
#define Startup_Update 	0xAAAAAAAA	///< 升级再启动 
#define Startup_Reset  	0x5555AAAA	///< ***恢复出厂 目前没使用***
#define Startup_APP2  	0x5555BBBB	///< ***跳转到APP2***


/* Base address of the Flash sectors */ 
#define ADDR_FLASH_SECTOR_0     ((uint32_t)0x08000000) /* Base address of Sector 0, 32 Kbytes */
#define ADDR_FLASH_SECTOR_1     ((uint32_t)0x08008000) /* Base address of Sector 1, 32 Kbytes */
#define ADDR_FLASH_SECTOR_2     ((uint32_t)0x08010000) /* Base address of Sector 2, 32 Kbytes */
#define ADDR_FLASH_SECTOR_3     ((uint32_t)0x08018000) /* Base address of Sector 3, 32 Kbytes */
#define ADDR_FLASH_SECTOR_4     ((uint32_t)0x08020000) /* Base address of Sector 4, 128 Kbytes */
#define ADDR_FLASH_SECTOR_5     ((uint32_t)0x08040000) /* Base address of Sector 5, 256 Kbytes */
#define ADDR_FLASH_SECTOR_6     ((uint32_t)0x08080000) /* Base address of Sector 6, 256 Kbytes */
#define ADDR_FLASH_SECTOR_7     ((uint32_t)0x080C0000) /* Base address of Sector 7, 256 Kbytes */


void Start_BootLoader(void);
uint8_t Erase_page(uint32_t pageaddr, uint32_t num);
void WriteFlash2(uint32_t addr, uint32_t *buff, int word_size);
#endif

