Files
kunlun/export/inc/cli/iot_cli_upgrade_api.h
2024-09-28 14:24:04 +08:00

182 lines
6.3 KiB
C

/****************************************************************************
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
be copied by any method or incorporated into another program without
the express written consent of Aerospace C.Power. This Information or any portion
thereof remains the property of Aerospace C.Power. The Information contained herein
is believed to be accurate and Aerospace C.Power assumes no responsibility or
liability for its use in any way and conveys no license or title under
any patent or copyright and makes no representation or warranty that this
Information is free from patent or copyright infringement.
****************************************************************************/
#ifndef IOT_CLI_UPGRADE_API_H
#define IOT_CLI_UPGRADE_API_H
#include "os_types_api.h"
#include "iot_config_api.h"
#include "iot_cli_upgrade_status_type_def.h"
#ifdef __cplusplus
extern "C" {
#endif
#if PLC_SUPPORT_CCO_ROLE
#if (IOT_PSRAM_SIZE >= 4)
/* 0 - cache in flash, 1 - cache in psram */
#define IOT_CLI_UPGRADE_CACHE_TYPE RUN_IN_PSRAM
#else /* (IOT_PSRAM_SIZE >= 4) */
/* 0 - cache in flash, 1 - cache in psram */
#define IOT_CLI_UPGRADE_CACHE_TYPE 0
#endif /* (IOT_PSRAM_SIZE >= 4) */
/*
* maximal fw size is (444 + 256)K. maximal pib size is 64K.
* since spec require minimal supported upgrade file size is (512 + 256)K,
* extra 4K is added here.
*/
#if (IOT_PSRAM_SIZE >= 8)
/* modify 8m psram cco support sta upgrade file of 1 MB */
#define IOT_CLI_UPGRADE_MAX_STA_FW_SIZE ((444 + 64 + 4 + 256 + 256) * 1024)
#else /* IOT_PSRAM_SIZE >= 8 */
#if (PLC_NETWORK_SCALE <= 1015)
#define IOT_CLI_UPGRADE_MAX_STA_FW_SIZE ((444 + 64 + 4 + 256) * 1024) /* 768k */
#else /* PLC_NETWORK_SCALE <= 1015 */
#define IOT_CLI_UPGRADE_MAX_STA_FW_SIZE ((444 + 64 + 4) * 1024) /* 512k */
#endif /* PLC_NETWORK_SCALE <= 1015 */
#endif /* IOT_PSRAM_SIZE >= 8 */
#if IOT_CLI_UPGRADE_CACHE_TYPE
#define IOT_CLI_UPGRADE_MAX_FILE_SIZE IOT_CLI_UPGRADE_MAX_STA_FW_SIZE
#else
#define IOT_CLI_UPGRADE_MAX_FILE_SIZE 0
#endif
/*
* @brief iot_cli_upgrade_completed_handler - upgrade completed handler
*/
typedef void(*iot_cli_upgrade_completed_handler)();
/*
* @brief app upgrade handler for trigger app upgrade by CLI.
* @param cmd: cli data type. see - UPGRADE_CLI_UPGRADE_XXX.
* @param data: pointer to data of upgrading file.
* @param len: length of upgrading file.
* @retval: ERR_OK if sg upgrading started.
* ERR_FAIL if failed to start app upgrading.
*/
typedef uint32_t (*iot_cli_upgrade_app_handler)(uint8_t cmd, uint8_t *data,
uint32_t len);
/*
* @brief: register app upgrading handler
* @param handler: the handler to process app upgrading through CLI.
*/
void iot_cli_upgrade_app_register_handler(iot_cli_upgrade_app_handler handler);
/**
* @brief iot_cli_upgrade_prepare - prepare for app trigger cli upgrade
* @param handler: completed handler
* @param file_size: size of upgrade file
* @param data: output para, data buffer pointer
* @param file_hdr: first block data of upgrade file
* @param block_size: block size: 100,200,300,400
* @param upgrade_type: upgrade type, see IOT_PLC_UPGRADE_XXX
*/
uint32_t iot_cli_upgrade_prepare(iot_cli_upgrade_completed_handler handler,
uint32_t file_size, uint8_t **data, uint8_t *file_hdr, uint16_t block_size,
uint8_t upgrade_type);
/**
* @brief iot_cli_upgrade_start - app trigger cli upgrade start
* @param upgrade_type: upgrade style see - IOT_PLC_UPGRADE_XXX
* @param control_flag: cco controllable upgrade sta flag
* @retval: 0 - success, others - error number.
*/
uint8_t iot_cli_upgrade_start(uint8_t upgrade_type, uint8_t control_flag);
/**
* @brief iot_cli_upgrade_stop - app trigger cli upgrade stop, this state
* and will remain for 600ms.
*/
void iot_cli_upgrade_stop();
/**
* @brief iot_cli_upgrade_set_dst_list - app set destination node list to cli.
* @param data: destination node list.
* @param is_renew: 1 - clean upgrade list node, then add node to upgrade list.
* 0 - continue add node to upgrade list.
* @retval: 0 - success, others - fail.
*/
uint8_t iot_cli_upgrade_set_dst_list(iot_plc_upgrade_dst_list_t *data,
uint8_t is_renew);
/**
* @brief iot_cli_upgrade_qr_dst_status_list - query STA upgrade status
* @param start_index: start index of STA about upgrade msg
* @param count count of the STA upgrade msg
* @param ug_progress_status STA upgrade msg
*/
void iot_cli_upgrade_qr_dst_status_list(uint16_t start_idx,
uint8_t count, iot_plc_upgrade_dst_status_list *status_list);
/**
* @brief iot_cli_upgrade_qr_dst_status search upgrade status
* @param query: upgrade msg
*/
void iot_cli_upgrade_qr_dst_status(iot_plc_upgrade_dst_status_query *query);
/**
* @brief iot_cli_upgrade_write - write upgrade file data.
* @param offset: upgrade file data offset.
* @param buf: upgrade data.
* @param buf_len: upgrade data length.
* @retval: 0 - success, others - fail.
*/
uint32_t iot_cli_upgrade_write(uint32_t offset, uint8_t *buf,
uint16_t buf_len);
/**
* @brief iot_cli_upgrade_read - read upgrade file data.
* @param offset: upgrade file data offset.
* @param buf: upgrade data.
* @param buf_len: upgrade data length.
* @retval: 0 - success, others - fail.
*/
uint32_t iot_cli_upgrade_read(uint32_t offset, uint8_t *buf,
uint16_t buf_len);
/**
* @brief iot_cli_upgrade_get_file_limit - get support upgrade file max limit.
* @param local_upgrade: 1- local upgrade, 0 - other upgrade.
* @param file_hdr: local upgrade - file header data, other - NULL.
* @retval: file limit value.
*/
uint32_t iot_cli_upgrade_get_file_limit(uint8_t local_upgrade,
uint8_t *file_hdr);
#if (!IOT_SMART_GRID_ENABLE)
/**
* @brief iot_cli_upgrade_set_renew_nodelist renew sta upgrade list, upgrade
* sta in phase3 progress
* @param dstlist: sta mac list
* @param cnt: sta count
* @retval: renew sta count
*/
uint16_t iot_cli_upgrade_set_renew_nodelist(uint8_t *dstlist, uint16_t cnt);
#endif /* end !IOT_SMART_GRID_ENABLE */
#endif
#ifdef __cplusplus
}
#endif
#endif /* IOT_CLI_UPGRADE_API_H */