MXC-A36-Demo/MCU/examples/application/bootloader/Inc/app_ota.h

113 lines
3.5 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef APP_OTA_H
#define APP_OTA_H
#include <stdint.h>
#include "fr30xx.h"
/******************************************************************************
* MACROS (ºê¶¨Òå)
*/
/*****************************************************************************
* CONSTANTS (³£Á¿¶¨Òå)
*/
#define DOCUMENT_CHECK 1
#define BOOT_A_INFO_ADDRESS 0
#define BOOT_B_INFO_ADDRESS 0x1000
#define BOOTLOADER_IMG_RSV_SIZE (220*1024)
#define OTA_B_STORAGE_ADDRESS ((4+4)*1024 + BOOTLOADER_IMG_RSV_SIZE)
#define IMAGE_INFO_RSV_SIZE 0x2000 //8K
#define APP_CODE_INFO_OFFSET 0x148
#define IMGAE_INFO_SIZE 0x10
#define OTA_BOOT_INFO_ADDRESS (OTA_B_STORAGE_ADDRESS + BOOTLOADER_IMG_RSV_SIZE)
#define APP_CODE_STORAGE_ADDRESS (OTA_BOOT_INFO_ADDRESS+IMAGE_INFO_RSV_SIZE)
#define RETARGET_APP_CODE_ADDRESS (FLASH_DAC_BASE+APP_CODE_STORAGE_ADDRESS) //APPµØ÷
#define FILE_CODE_ADDRESS_OFFSET IMGAE_INFO_SIZE
#define FLASH_SIZE 0x200000 // flash 2M
#define DSP_CODE_MAX_SIZE (256*1024) // the maximun size of DSP code
#define CONTROLLER_CODE_MAX_SIZE (80*1024) // the maximun size of CONTROLLER code
#define BOOT_CODE_MAX_SIZE BOOTLOADER_IMG_RSV_SIZE // the maximun size of BOOT
#define APP_CODE_MAX_SIZE (FLASH_SIZE-DSP_CODE_MAX_SIZE-CONTROLLER_CODE_MAX_SIZE) // the maximun size of APP
#define DSP_STORAGE_ADDRESS (FLASH_SIZE-DSP_CODE_MAX_SIZE)
#define CONTROLLER_STORAGE_ADDRESS (DSP_STORAGE_ADDRESS-CONTROLLER_CODE_MAX_SIZE)
#define OTA_START_TIMOUT 5000
#define OTA_ADV_TIMEOUT 1000*60*1
#define OTA_HDR_RESULT_LEN 1
#define OTA_HDR_OPCODE_LEN 1
#define OTA_HDR_LENGTH_LEN 2
/*file type*/
#define FILE_TYPE_APP 0x01
#define FILE_TYPE_CONTROLLER 0x02
#define FILE_TYPE_DSP 0x04
typedef enum
{
OTA_CMD_NVDS_TYPE,
OTA_CMD_GET_STR_BASE,
OTA_CMD_READ_FW_VER, //read firmware version
OTA_CMD_PAGE_ERASE,
OTA_CMD_CHIP_ERASE,
OTA_CMD_WRITE_DATA,
OTA_CMD_READ_DATA,
OTA_CMD_WRITE_MEM,
OTA_CMD_READ_MEM,
OTA_CMD_REBOOT,
OTA_CMD_START,
OTA_CMD_NULL,
} ota_cmd_t;
typedef enum
{
FILE_BOOT_LOADER =1,
FILE_APP,
FILE_CONTROLLER,
FILE_DSP,
}ota_file_type_t;
typedef enum
{
OTA_RSP_SUCCESS,
OTA_RSP_ERROR,
OTA_RSP_UNKNOWN_CMD,
}ota_rsp_t;
/*****************************************************************************
* TYPEDEFS (ÀàÐͶ¨Òå)
*/
struct app_otas_status_t
{
uint8_t read_opcode;
uint8_t length;
uint32_t base_addr;
};
typedef struct
{
volatile uint32_t MSP;
volatile uint32_t Reset_Handler;
}str_CoreRemapStart_t;
/******************************************************************************
* GLOBAL VARIABLES (È«¾Ö±äÁ¿)
*/
/******************************************************************************
* FUNCTION DESCRIPTION
*/
uint16_t app_otas_read_data(uint8_t *p_data);
void app_otas_recv_data(uint8_t conidx,uint8_t *p_data,uint16_t len);
void ota_init(void);
void ota_deinit(void);
void ota_set_imagesize(uint32_t imagesize);
uint32_t ota_get_imagesize(void);
void platform_reset(void);
void ota_check(void);
void jump_to_app(void);
void check_file_integrity(void);
void ota_info_init(void);
void ota_boot_start(void);
#endif