/*
 * @Description: 
 * @Version: 2.0
 * @Author: Seven
 * @Date: 2023-08-30 09:45:29
 * @LastEditors: Seven
 * @LastEditTime: 2023-11-16 09:50:11
 */
#ifndef UPDATE_H__
#define UPDATE_H__
#include "board.h"

typedef enum UPDATE_ENUM {
	UPDATE_ENUM_NONE,
	UPDATE_ENUM_BOOT,
	UPDATE_ENUM_APP1,
	UPDATE_ENUM_APP2,
	UPDATE_ENUM_APP3,
    UPDATE_ENUM_PT,
	UPDATE_ENUM_FPGA,
	UPDATE_ENUM_MAX	
} UPDATE_ENUM;

#define OTA_UPDATE_BOOTROM_SIZE               (0x10000)
#define OTA_UPDATE_BOOTROM_FLASH_START_ADDR   (0x80000000)                                                          //
#define OTA_UPDATE_BOOTROM_FLASH_END_ADDR     (OTA_UPDATE_BOOTROM_FLASH_START_ADDR+OTA_UPDATE_BOOTROM_SIZE-1)

#define OTA_UPDATE_PT_FLASH_SIZE              (0x10000)
#define OTA_UPDATE_PT_FLASH_START_ADDR        (0x80010000)
#define OTA_UPDATE_PT_FLASH_END_ADDR          (OTA_UPDATE_PT_FLASH_START_ADDR+OTA_UPDATA_PT_FLASH_SIZE-1)

#define OTA_UPDATE_APP1_FLASH_SIZE            (0x40000)                                                             //
#define OTA_UPDATE_APP1_FLASH_START_ADDR      (0x80020000)                                                          //
#define OTA_UPDATE_APP1_FLASH_END_ADDR        (OTA_UPDATE_APP1_FLASH_START_ADDR+OTA_UPDATE_APP1_FLASH_SIZE-1)       //

#define OTA_UPDATE_APP2_FLASH_SIZE            (0x40000)                                                             //
#define OTA_UPDATE_APP2_FLASH_START_ADDR      (0x80060000)                                                          //
#define OTA_UPDATE_APP2_FLASH_END_ADDR        (OTA_UPDATE_APP2_FLASH_START_ADDR+OTA_UPDATE_APP2_FLASH_SIZE-1)       //

#define OTA_UPDATE_APP3_FLASH_SIZE            (0x40000)                                                             //
#define OTA_UPDATE_APP3_FLASH_START_ADDR      (0x800A0000)                                                          //
#define OTA_UPDATE_APP3_FLASH_END_ADDR        (OTA_UPDATE_APP3_FLASH_START_ADDR+OTA_UPDATE_APP3_FLASH_SIZE-1)       //

#define OTA_UPDATE_FPGA_FLASH_SIZE            (0x19000)                                                             //
#define OTA_UPDATE_FPGA_FLASH_START_ADDR      (0x800E7000)                                                          //
#define OTA_UPDATE_FPGA_FLASH_END_ADDR        (OTA_UPDATE_FPGA_FLASH_START_ADDR+OTA_UPDATE_FPGA_FLASH_SIZE-1)       //

#define OTA_UPDATE_APP_FLASH_SIZE             (0x40000)

int erase_app(uint8_t app_num);
int copy_app(uint8_t from, uint8_t to);
int copy_app_specify_length(UPDATE_ENUM to, uint32_t addr, uint32_t len);
uint32_t run_app1(void);

int flash_addr_get(UPDATE_ENUM part, uint32_t addr, uint32_t len, uint32_t *phy_addr);
int flash_write_without(UPDATE_ENUM app_num, uint32_t addr, const void *p, uint32_t len);
int update_pkg_crc_check(UPDATE_ENUM part, uint32_t len, uint32_t check_crc);
#endif // !
