182 lines
6.3 KiB
C
Executable File
182 lines
6.3 KiB
C
Executable File
/****************************************************************************
|
|
|
|
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_PIB_API_H
|
|
#define IOT_PIB_API_H
|
|
|
|
/* os shim includes */
|
|
#include "os_types_api.h"
|
|
|
|
/* common includes */
|
|
#include "iot_module_api.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* pack for the structures in the whole file */
|
|
#pragma pack(push) // save the pack status
|
|
#pragma pack(1) // 1 byte align
|
|
|
|
#define CCO_PIB_TYPE (0)
|
|
#define STA_PIB_TYPE (1)
|
|
#define MAX_PIB_TYPE STA_PIB_TYPE
|
|
|
|
#define iot_pib_type_t uint8_t
|
|
|
|
#define IOT_PIB_CCO_APP_READ_SECTION_SIZE (32)
|
|
#define IOT_PIB_STA_APP_READ_SECTION_SIZE (32)
|
|
#define IOT_PIB_BOARD_SECTION_SIZE (128)
|
|
|
|
#if RUN_IN_PSRAM
|
|
#define IOT_PIB_CCO_APP_WRITE_SECTION_SIZE (7416 + 8192 + 4132)
|
|
#else
|
|
#define IOT_PIB_CCO_APP_WRITE_SECTION_SIZE (1272)
|
|
#endif
|
|
#define IOT_PIB_STA_APP_WRITE_SECTION_SIZE (312 + 512)
|
|
|
|
/* get section in read only memory */
|
|
#define IOT_PIB_APP_GET_READ_SECTION (0)
|
|
/* get section in writable memory */
|
|
#define IOT_PIB_APP_GET_WRITE_SECTION (1)
|
|
|
|
/* commit request received */
|
|
#define IOT_PIB_APP_STATUS_COMMIT_REC 1
|
|
/* commit request done */
|
|
#define IOT_PIB_APP_STATUS_COMMIT_DONE 2
|
|
|
|
/* 16 bits, should +1 when pib written part format not compatible */
|
|
#define IOT_PIB_VERSION_MAJOR (11)
|
|
/* 16 bits, should +1 when pib written part format change and compatible */
|
|
#define IOT_PIB_VERSION_MINOR (8)
|
|
/* numerically encoded version */
|
|
#define IOT_PIB_VERSION_HEX ((IOT_PIB_VERSION_MAJOR << 16) | \
|
|
(IOT_PIB_VERSION_MINOR))
|
|
|
|
/** \defgroup PIB_APIs PIB APIs
|
|
* @brief WQ30x1 Product Information Block
|
|
*
|
|
* System configuration parameters save in chip flash
|
|
*
|
|
*/
|
|
|
|
/** @addtogroup PIB_APIs
|
|
* @{
|
|
*/
|
|
|
|
/**
|
|
* @brief iot_pib_get_app_section() - function used to get app section address.
|
|
* @param psection: return pointer to app section start address.
|
|
* @param pibtype: return pib type.
|
|
* @param rw: get section in read only memory or writable memory,
|
|
* see IOT_PIB_APP_GET_XXX_SECTION.
|
|
*
|
|
* @return 0 - success.
|
|
* @return otherwise - error code.
|
|
*/
|
|
uint32_t iot_pib_get_app_section(uint8_t **psection, iot_pib_type_t *pibtype,
|
|
uint8_t rw);
|
|
|
|
/**
|
|
* @brief iot_pib_acquire_app_commit_ref() - function to hold pib commit
|
|
* execute until free commit reference. app should call
|
|
* this function before pib modification.
|
|
* @param cur_refcount: current app pib reference counter, unless
|
|
* this value is 0, commit won't take effect.
|
|
* @return 0 - success.
|
|
* @return otherwise - error.
|
|
*/
|
|
uint32_t iot_pib_acquire_app_commit_ref(uint8_t *cur_refcount);
|
|
|
|
/**
|
|
* @brief iot_pib_release_app_commit_ref() - function to release pib commit
|
|
* referecne count. app should call this function after
|
|
* pib modification.
|
|
* @param cur_refcount: current app pib reference counter, unless this
|
|
* value is 0, commit won't take effect.
|
|
* @return 0 - success.
|
|
* @return otherwise - error.
|
|
*/
|
|
uint32_t iot_pib_release_app_commit_ref(uint8_t *cur_refcount);
|
|
|
|
/**
|
|
* @brief iot_pib_app_commit() - function used by app to trigger write pib
|
|
* to flash.
|
|
* @param commit_ticket: pib assigned commit request id. can be used in
|
|
* commit callback function to adjust whether
|
|
* request done.
|
|
* @return 0 - success.
|
|
* @return otherwise - error.
|
|
*/
|
|
uint32_t iot_pib_app_commit(uint16_t* commit_ticket);
|
|
|
|
/**
|
|
* @brief iot_pib_app_report_commit_status_func_t() - function callback for
|
|
* app to receive pib commit status.
|
|
* @param status: pib commit status. see IOT_PIB_APP_STATUS_COMMIT_XXX.
|
|
* @param commit_ticket: commit ticket number which already done saving
|
|
*/
|
|
typedef void(*iot_pib_app_report_commit_status_func_t)(uint8_t status,
|
|
uint16_t commit_ticket);
|
|
|
|
/**
|
|
* @brief iot_pib_register_commit_cb() - register pib commit status callback
|
|
* function.
|
|
* @param cb: callback function provide by app to receive pib commit status.
|
|
* @return 0 - success.
|
|
* @return otherwise - error.
|
|
*/
|
|
uint32_t iot_pib_register_app_commit_cb(
|
|
iot_pib_app_report_commit_status_func_t cb);
|
|
|
|
/**
|
|
* @brief iot_pib_app_get_crc_status(uint8_t *r_crc, uint8_t* w_crc) - get
|
|
* read/write section crc status. caller module
|
|
* should not use cfg data if crc is wrong
|
|
* @param r_crc: 0 -crc wrong. 1 - crc valid
|
|
* @param w_crc: 0 -crc wrong. 1 - crc valid
|
|
* @return 0 - success.
|
|
* @return otherwise - fail.
|
|
*/
|
|
void iot_pib_app_get_crc_status(uint8_t* r_crc, uint8_t* w_crc);
|
|
|
|
/**
|
|
* @brief iot_pib_upgrade_app_cfg(void) - upgrade app cfg pib section
|
|
* @param No params
|
|
* @return 0 - success.
|
|
* @return otherwise - fail.
|
|
*/
|
|
uint32_t iot_pib_upgrade_app_cfg(void);
|
|
|
|
/**
|
|
* @brief iot_pib_app_upgrade_flag(void) - get upgrade flag
|
|
* @param No params
|
|
* @return true/false
|
|
*/
|
|
bool_t iot_pib_app_upgrade_flag(void);
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
#pragma pack(pop) // restore the pack status
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* IOT_PIB_API_H */
|