827 lines
29 KiB
C
827 lines
29 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_PIB_H
|
||
|
#define IOT_PIB_H
|
||
|
|
||
|
/* os shim includes */
|
||
|
#include "os_types.h"
|
||
|
#include "iot_utils.h"
|
||
|
|
||
|
/* common includes */
|
||
|
#include "iot_module.h"
|
||
|
|
||
|
/* export includes */
|
||
|
#include "iot_pib_api.h"
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
extern "C" {
|
||
|
#endif
|
||
|
|
||
|
/*
|
||
|
* Chip reserved 56K for PIB module to use.
|
||
|
* Need spit it into two section, one is current working section. Another
|
||
|
* section used for upgrade.
|
||
|
* PIB section start at 0x40, since PIB partition need 64 bytes reserved for
|
||
|
* bsp use to manager sections.
|
||
|
* So, each section usable size is 28649 bytes.
|
||
|
* The CCO/STA Full flash include read only part and writable part.
|
||
|
* The read only part size is 1k bytes at CCO or STA.
|
||
|
* The writable part size is 2K(no psram) or 16K(with psram) at CCO and 1K at STA.
|
||
|
* The read only part and writable part have a similar structure.
|
||
|
* CCO Full flash layout shows like below
|
||
|
* --- ---------------------
|
||
|
* /|\ | pib head | 8 bytes
|
||
|
* | |-------------------|
|
||
|
* | | board config | 128 bytes
|
||
|
* r |-------------------|
|
||
|
* e | cli config | 32 bytes
|
||
|
* a |-------------------|
|
||
|
* d | mac config | 32 bytes
|
||
|
* o |-------------------|
|
||
|
* n | halphy config | 32 bytes
|
||
|
* l |-------------------|
|
||
|
* y | cvg config | 32 bytes
|
||
|
* | |-------------------|
|
||
|
* | | app config | 32 bytes
|
||
|
* | |-------------------|
|
||
|
* \|/ | reserved | 728 bytes
|
||
|
* --- |-------------------|
|
||
|
* /|\ | rw hdr | 28 bytes
|
||
|
* | |-------------------|
|
||
|
* | | pib head | 8 bytes
|
||
|
* | |-------------------|
|
||
|
* | | board config | 128 bytes
|
||
|
* w |-------------------|
|
||
|
* r | cli config | 128 bytes
|
||
|
* i |-------------------|
|
||
|
* t | mac config | 128 bytes
|
||
|
* a |-------------------|
|
||
|
* b | halphy config | 256 bytes
|
||
|
* l |-------------------|
|
||
|
* e | cvg config | 64 bytes
|
||
|
* | |-------------------|
|
||
|
* \|/ | app config | 7416 + 8192 + 4132(with psram), 1272(no psram) bytes
|
||
|
* --- |-------------------|
|
||
|
*
|
||
|
*
|
||
|
*-----------------------------------------------------------------------------
|
||
|
* STA Full flash layout shows like below
|
||
|
* --- ---------------------
|
||
|
* /|\ | pib head | 8 bytes
|
||
|
* | |-------------------|
|
||
|
* | | board config | 128 bytes
|
||
|
* r |-------------------|
|
||
|
* e | cli config | 32 bytes
|
||
|
* a |-------------------|
|
||
|
* d | mac config | 32 bytes
|
||
|
* o |-------------------|
|
||
|
* n | halphy config | 32 bytes
|
||
|
* l |-------------------|
|
||
|
* y | cvg config | 32 bytes
|
||
|
* | |-------------------|
|
||
|
* | | app config | 32 bytes
|
||
|
* | |-------------------|
|
||
|
* \|/ | reserved | 728 bytes
|
||
|
* --- |-------------------|
|
||
|
* /|\ | rw hdr | 28 bytes
|
||
|
* | |-------------------|
|
||
|
* | | pib head | 8 bytes
|
||
|
* | |-------------------|
|
||
|
* | | board config | 128 bytes
|
||
|
* w |-------------------|
|
||
|
* r | cli config | 128 bytes
|
||
|
* i |-------------------|
|
||
|
* t | mac config | 128 bytes
|
||
|
* a |-------------------|
|
||
|
* b | halphy config | 256 bytes
|
||
|
* l |-------------------|
|
||
|
* e | cvg config | 64 bytes
|
||
|
* | |-------------------|
|
||
|
* \|/ | app config | 312 + 512 bytes
|
||
|
* --- |-------------------|
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
/* pack for the structures in the whole file */
|
||
|
#pragma pack(push) // save the pack status
|
||
|
#pragma pack(1) // 1 byte align
|
||
|
|
||
|
/* get section in read only memory */
|
||
|
#define IOT_PIB_GET_READ_SECTION (0)
|
||
|
/* get section in writable memory */
|
||
|
#define IOT_PIB_GET_WRITE_SECTION (1)
|
||
|
|
||
|
#if (HW_PLATFORM == HW_PLATFORM_SIMU)
|
||
|
#define IOT_PIB_R_SECTION_START_ADDR (0)
|
||
|
#else
|
||
|
#define IOT_PIB_R_SECTION_START_ADDR (64)
|
||
|
#endif
|
||
|
#define IOT_PIB_W_SECTION_START_ADDR (4096)
|
||
|
|
||
|
#define IOT_PIB_HEAD_ID (0)
|
||
|
#define IOT_PIB_BOARD_ID (1)
|
||
|
#define IOT_PIB_APP_ID (2)
|
||
|
#define IOT_PIB_CVG_ID (3)
|
||
|
#define IOT_PIB_MAC_ID (4)
|
||
|
#define IOT_PIB_HALPHY_ID (5)
|
||
|
#define IOT_PIB_CLI_ID (6)
|
||
|
#define IOT_PIB_UPGRADE_ID (7)
|
||
|
#define IOT_PIB_MAX_ID (IOT_PIB_UPGRADE_ID + 1)
|
||
|
|
||
|
/*
|
||
|
* need set fix size, and cco and sta read only all is 1K bytes,
|
||
|
* writable section is sta: 1K bytes, cco, 8K bytes
|
||
|
*/
|
||
|
#define IOT_PIB_R_HEAD_SIZE (8)
|
||
|
#define IOT_PIB_R_BOARD_SIZE (128)
|
||
|
#define IOT_PIB_R_APP_SIZE (32)
|
||
|
#define IOT_PIB_R_CVG_SIZE (32)
|
||
|
#define IOT_PIB_R_MAC_SIZE (32)
|
||
|
#define IOT_PIB_R_HALPHY_SIZE (32)
|
||
|
#define IOT_PIB_R_CLI_SIZE (32)
|
||
|
|
||
|
#define IOT_PIB_W_HEAD_SIZE (8)
|
||
|
#define IOT_PIB_W_BOARD_SIZE (128)
|
||
|
#define IOT_PIB_W_CVG_SIZE (64)
|
||
|
#define IOT_PIB_W_MAC_SIZE (128)
|
||
|
#define IOT_PIB_W_HALPHY_SIZE (256)
|
||
|
#define IOT_PIB_W_CLI_SIZE (16)
|
||
|
#define IOT_PIB_W_APP_STA_SIZE_V0 (312)
|
||
|
#define IOT_PIB_W_APP_STA_SIZE_V1 (312 + 512)
|
||
|
#define IOT_PIB_W_UPGRADE_SIZE (112)
|
||
|
|
||
|
#if RUN_IN_PSRAM
|
||
|
#define IOT_PIB_W_APP_CCO_SIZE_V0 (7416 + 8192)
|
||
|
#define IOT_PIB_W_APP_CCO_SIZE_V1 (7416 + 8192 + 4132)
|
||
|
#define IOT_PIB_CCO_BLOCK_SIZE (4096 * 5)
|
||
|
#define IOT_PIB_CCO_VALID_RW_NUM_MAX (1)
|
||
|
#else /* RUN_IN_PSRAM */
|
||
|
#define IOT_PIB_W_APP_CCO_SIZE_V0 (1272)
|
||
|
#define IOT_PIB_W_APP_CCO_SIZE_V1 IOT_PIB_W_APP_CCO_SIZE_V0
|
||
|
#define IOT_PIB_CCO_BLOCK_SIZE (4096)
|
||
|
#define IOT_PIB_CCO_VALID_RW_NUM_MAX (5)
|
||
|
#endif
|
||
|
/* sta pib loop write part size */
|
||
|
#define IOT_PIB_STA_BLOCK_SIZE (4096)
|
||
|
#define IOT_PIB_STA_VALID_RW_NUM_MAX (5)
|
||
|
|
||
|
/* When pib commit 10 times, execute a checkout block */
|
||
|
#define IOT_PIB_CHECKOUT_BLOCK_COMMIT_CNT (10)
|
||
|
|
||
|
#define IOT_PIB_CCO_TARGET_SIZE (9216)
|
||
|
#define IOT_PIB_STA_TARGET_SIZE (2048)
|
||
|
#define IOT_PIB_MAX_SIZE (28640)
|
||
|
|
||
|
#define IOT_PIB_PHY_MASK_CHIPID (0)
|
||
|
#define IOT_PIB_PHY_MASK_TX_DC (1)
|
||
|
#define IOT_PIB_PHY_MASK_RX_DC (2)
|
||
|
#define IOT_PIB_PHY_MASK_BW_FILTER (3)
|
||
|
|
||
|
/* add rw hdr pib minor version */
|
||
|
#define IOT_PIB_VERSION_MINOR_V1_START (7)
|
||
|
#define IOT_PIB_VERSION_MAJOR_V1_START (11)
|
||
|
|
||
|
/* commit request received */
|
||
|
#define IOT_PIB_STATUS_COMMIT_REC 1
|
||
|
/* commit request done */
|
||
|
#define IOT_PIB_STATUS_COMMIT_DONE 2
|
||
|
/* define the magic number to identify if the wr head is valid. */
|
||
|
#define IOT_PIB_RW_HEAD_MAGIC (0xF2D5B13A)
|
||
|
|
||
|
typedef enum {
|
||
|
COMMIT_TYPE_NONE = 0,
|
||
|
/* wait all module reference count to zero, then write. more graceful way */
|
||
|
COMMIT_TYPE_WAIT_REFZERO = 1,
|
||
|
/* write flash now, regardless of pib commit reference count not zero */
|
||
|
//COMMIT_TYPE_NOW = 2,
|
||
|
COMMIT_TYPE_MAX = 1,
|
||
|
} iot_pib_commit_type_t;
|
||
|
|
||
|
typedef struct _iot_pib_hdr {
|
||
|
/* read only fixed at 1K both CCO and STA
|
||
|
* writable fixed at 8K as CCO, and 1K as STA
|
||
|
*/
|
||
|
uint16_t piblen;
|
||
|
/* crc result, start from pibtype to end of pib(64 + 1K) */
|
||
|
uint8_t pibcrc8;
|
||
|
iot_pib_type_t pibtype;
|
||
|
uint16_t pib_minor_version;
|
||
|
uint16_t pib_major_version;
|
||
|
} iot_pib_hdr_t;
|
||
|
|
||
|
/* board readonly cfg setting */
|
||
|
typedef struct _pib_r_board_info {
|
||
|
uint8_t build_time[6];
|
||
|
} pib_r_board_info_t;
|
||
|
|
||
|
#define PIB_R_BOARD_LOG_FLOW_FALSH 0
|
||
|
#define PIB_R_BOARD_LOG_FLOW_CLI 1
|
||
|
#define PIB_R_BOARD_LOG_FDUMP_NONEED 0
|
||
|
#define PIB_R_BOARD_LOG_FDUMP_NEED 1
|
||
|
typedef struct _pib_r_board_log {
|
||
|
uint8_t flow;
|
||
|
uint8_t is_fdump;
|
||
|
} pib_r_board_log_t;
|
||
|
|
||
|
typedef struct _pib_board_fake_build_info {
|
||
|
/* software version */
|
||
|
uint16_t sw_ver;
|
||
|
/* software build time */
|
||
|
uint8_t year;
|
||
|
uint8_t month;
|
||
|
uint8_t day;
|
||
|
uint8_t hour;
|
||
|
uint8_t min;
|
||
|
uint8_t sec;
|
||
|
} pib_board_fake_build_info_t;
|
||
|
|
||
|
typedef struct _pib_board_vendor_info {
|
||
|
/* vendor id */
|
||
|
uint16_t vendor_id;
|
||
|
/* flag to mark if passcode valid */
|
||
|
uint8_t passcode_valid : 1,
|
||
|
/* reserved for future */
|
||
|
reserved : 7;
|
||
|
/* simple pair passcode value */
|
||
|
uint16_t passcode;
|
||
|
} pib_board_vendor_info_t;
|
||
|
|
||
|
typedef struct _pib_board_tsfm_build_info {
|
||
|
/* tsfm cfg info, see IOT_PLC_HW_REC_MODE_ID_XXX */
|
||
|
uint8_t rec_mode: 2,
|
||
|
/* reserve for future */
|
||
|
reserve : 6;
|
||
|
} pib_board_tsfm_build_info_t;
|
||
|
|
||
|
typedef struct _pib_board_user_cfg {
|
||
|
/* flag to mark if user type valid */
|
||
|
uint8_t user_type_valid : 1,
|
||
|
reserved : 7;
|
||
|
/* user type, see USER_TYPE_XXX */
|
||
|
uint8_t user_type;
|
||
|
uint16_t reserved2;
|
||
|
} pib_board_user_cfg_t;
|
||
|
|
||
|
typedef struct _iot_pib_r_board_cfg {
|
||
|
pib_r_board_info_t info_cfg;
|
||
|
pib_r_board_log_t log_cfg;
|
||
|
pib_board_fake_build_info_t build_cfg;
|
||
|
pib_board_tsfm_build_info_t tsfm_cfg;
|
||
|
pib_board_user_cfg_t user_cfg;
|
||
|
uint8_t rsv[IOT_PIB_R_BOARD_SIZE - \
|
||
|
sizeof(pib_r_board_info_t) - \
|
||
|
sizeof(pib_r_board_log_t) - \
|
||
|
sizeof(pib_board_fake_build_info_t) - \
|
||
|
sizeof(pib_board_tsfm_build_info_t) - \
|
||
|
sizeof(pib_board_user_cfg_t)];
|
||
|
} iot_pib_r_board_cfg_t;
|
||
|
|
||
|
/* board writable cfg setting */
|
||
|
typedef struct _pib_w_board_log {
|
||
|
uint8_t rsv_part; /* using reserved part or not */
|
||
|
uint32_t pos; /* flash log written position */
|
||
|
} pib_w_board_log_t;
|
||
|
|
||
|
typedef struct _pib_w_board_reset_cnt{
|
||
|
uint32_t pwr_reset;
|
||
|
uint32_t wdt_reset;
|
||
|
uint32_t sft_reset;
|
||
|
} pib_w_board_reset_t;
|
||
|
|
||
|
typedef struct _iot_pib_w_board_cfg {
|
||
|
pib_w_board_log_t log_cfg;
|
||
|
pib_w_board_reset_t rst_cfg;
|
||
|
pib_board_fake_build_info_t build_cfg;
|
||
|
pib_board_vendor_info_t vendor_cfg;
|
||
|
uint8_t rsv[IOT_PIB_W_BOARD_SIZE - \
|
||
|
sizeof(pib_w_board_log_t) - \
|
||
|
sizeof(pib_w_board_reset_t) - \
|
||
|
sizeof(pib_board_fake_build_info_t) - \
|
||
|
sizeof(pib_board_vendor_info_t)];
|
||
|
} iot_pib_w_board_cfg_t;
|
||
|
|
||
|
/* start ----------------------------- cvg read only config setting */
|
||
|
typedef struct _iot_pib_r_cvg_sta_cfg {
|
||
|
/* see PLC_DEV_TYPE_XXX */
|
||
|
uint8_t dev_type;
|
||
|
/* network monitor enable flag */
|
||
|
uint8_t nw_monitor_enable: 1,
|
||
|
/* reserved for future */
|
||
|
rsvd: 7;
|
||
|
/* reserved for future */
|
||
|
uint8_t reserved[6];
|
||
|
} iot_pib_r_cvg_sta_cfg_t;
|
||
|
|
||
|
typedef struct _iot_pib_r_cvg_cco_cfg {
|
||
|
/* see PLC_DEV_TYPE_XXX */
|
||
|
uint8_t dev_type;
|
||
|
/* initial frequency band ID */
|
||
|
uint8_t freq_band_id;
|
||
|
/* allow to use beacon for channel evaluation */
|
||
|
uint8_t allow_chan_eval;
|
||
|
/* initial allowed to cco traffic success ratio, the unit is 1% */
|
||
|
uint8_t allowed_cco_tf_sr;
|
||
|
/* number of full route period sta need to spend on tr_sf calc. the unit
|
||
|
* is 1 route period.
|
||
|
*/
|
||
|
uint8_t proxy_select_dur;
|
||
|
/* sta assoc retry interval after cco reject sta assoc request. the
|
||
|
* unit is 1 ms.
|
||
|
*/
|
||
|
uint32_t assoc_retry_int;
|
||
|
/* delay for each frequency band switch request, uint is 1ms */
|
||
|
uint32_t fb_chg_delay;
|
||
|
/* minimal beacon period, the unit is 1s */
|
||
|
uint8_t min_bc_period;
|
||
|
/* allowed maximum nid value. 0 means no limitation */
|
||
|
uint16_t max_nid;
|
||
|
/* flag to mark if white list notification to STA enabled. 0 means
|
||
|
* disabled.
|
||
|
*/
|
||
|
uint8_t wl_notify_enable;
|
||
|
/* flag to mark if disable freq band detection */
|
||
|
uint8_t fb_detect_disable :1,
|
||
|
/* disable tx 3phase function */
|
||
|
tx_3phase_disable :1,
|
||
|
/* reserved for future */
|
||
|
rsvd :6;
|
||
|
/* delay for each rf channel switch request, unit is 1s */
|
||
|
uint16_t rf_chg_delay;
|
||
|
} iot_pib_r_cvg_cco_cfg_t;
|
||
|
|
||
|
typedef struct _iot_pib_r_cvg_real_cfg {
|
||
|
/* sta role only configuration */
|
||
|
iot_pib_r_cvg_sta_cfg_t sta;
|
||
|
/* cco role only configuration */
|
||
|
iot_pib_r_cvg_cco_cfg_t cco;
|
||
|
} iot_pib_r_cvg_real_cfg_t;
|
||
|
|
||
|
typedef struct _iot_pib_r_cvg_cfg {
|
||
|
/* configuration */
|
||
|
iot_pib_r_cvg_real_cfg_t cfg;
|
||
|
/* dummy data to make it a fixed size */
|
||
|
uint8_t dummy[IOT_PIB_R_CVG_SIZE - sizeof(iot_pib_r_cvg_real_cfg_t)];
|
||
|
} iot_pib_r_cvg_cfg_t;
|
||
|
/* end ----------------------------- cvg read only config setting */
|
||
|
|
||
|
/* start ----------------------------- cvg read/write config setting */
|
||
|
typedef struct _iot_pib_w_cvg_sta_cfg {
|
||
|
/* association random number */
|
||
|
uint32_t assoc_rand_num;
|
||
|
/* preferred cco mac address. big endian */
|
||
|
uint8_t prefer_cco_addr[6];
|
||
|
/* prefered sta mac address. big endian */
|
||
|
uint8_t prefer_sta_addr[6];
|
||
|
/* flag to mark if lock network for tsfm, the locked network addr is
|
||
|
* saved in prefer_cco_addr, the locked sta addr is saved in prefer_sta_addr
|
||
|
*/
|
||
|
uint8_t tsfm_nw_lock :1,
|
||
|
/* role of last joined network, 1 is PCO role, 0 is STA role */
|
||
|
last_role :1,
|
||
|
/* preferred rf option, see RF_OPTION_XXX */
|
||
|
prefer_rf_option :2,
|
||
|
/* 3ps device gpio tx-rx switch phase, see PLC_PHASE_XXX */
|
||
|
gpio_trx_phase :2,
|
||
|
/* reserved for future */
|
||
|
rsvd1 :2;
|
||
|
/* preferred network id */
|
||
|
uint32_t prefer_nid :24,
|
||
|
/* preferred rf channel, see RF_CHANNEL_ID_XXX */
|
||
|
prefer_rf_channel:8;
|
||
|
/* reserved for future */
|
||
|
uint8_t rsvd[11];
|
||
|
} iot_pib_w_cvg_sta_cfg_t;
|
||
|
|
||
|
typedef struct _iot_pib_w_cvg_cco_cfg {
|
||
|
/* current network id */
|
||
|
uint32_t nid;
|
||
|
/* network serial number */
|
||
|
uint8_t network_sn;
|
||
|
/* current frequency band ID */
|
||
|
uint8_t freq_band_id;
|
||
|
/* network hplc tx power cap, unit is 1 dbuv */
|
||
|
uint8_t tx_power_cap;
|
||
|
/* last used mac address */
|
||
|
uint8_t addr[6];
|
||
|
/* rf channel, see RF_CHANNEL_ID_XXX */
|
||
|
uint8_t rf_channel;
|
||
|
/* rf option, see RF_OPTION_XXX */
|
||
|
uint8_t rf_option :2,
|
||
|
/* flag to mark if enable rf channel coordination, default is enabled */
|
||
|
rf_cod_enable :1,
|
||
|
/* flag to mark if rf tx power is valid */
|
||
|
rf_tx_power_valid :1,
|
||
|
/* flag to mark if enable the authorization process */
|
||
|
auth_enable :1,
|
||
|
/* encryption mode, see ENCRYP_MODE_XXX */
|
||
|
encrypt_mode :1,
|
||
|
/* encryption_algorithm, see ENCRYP_ALGO_XXX */
|
||
|
encrypt_algo :1,
|
||
|
/* reserved for future */
|
||
|
rsvd :1;
|
||
|
/* network rf tx power cap, unit is 1 dbm */
|
||
|
int8_t rf_tx_power_cap;
|
||
|
} iot_pib_w_cvg_cco_cfg_t;
|
||
|
|
||
|
typedef struct _iot_pib_w_cvg_real_cfg {
|
||
|
/* special mark to make sure config is valid, see CVG_CFG_RW_MARK */
|
||
|
uint32_t mark;
|
||
|
/* reboot count */
|
||
|
uint8_t reboot_cnt;
|
||
|
/* sta role only configuration */
|
||
|
iot_pib_w_cvg_sta_cfg_t sta;
|
||
|
/* cco role only configuration */
|
||
|
iot_pib_w_cvg_cco_cfg_t cco;
|
||
|
} iot_pib_w_cvg_real_cfg_t;
|
||
|
|
||
|
typedef struct _iot_pib_w_cvg_cfg {
|
||
|
/* configuration */
|
||
|
iot_pib_w_cvg_real_cfg_t cfg;
|
||
|
/* dummy data to make it a fixed size */
|
||
|
uint8_t dummy[IOT_PIB_W_CVG_SIZE - sizeof(iot_pib_w_cvg_real_cfg_t)];
|
||
|
} iot_pib_w_cvg_cfg_t;
|
||
|
/* end ----------------------------- cvg read/write config setting */
|
||
|
|
||
|
/* mac config setting */
|
||
|
typedef struct _iot_pib_r_mac_cfg {
|
||
|
/* power dBuV, see PHY_FULL_PWR_DBUV */
|
||
|
uint32_t pwr_dbuv : 8,
|
||
|
/* 0 - enable auto high power, 1 - disable auto high power */
|
||
|
dis_high_power_req_ena : 1,
|
||
|
/* flag to mark if the "rf_pwr_dbm" field is valid */
|
||
|
rf_pwr_valid : 1,
|
||
|
/* reserved for further use */
|
||
|
rsvd : 14,
|
||
|
/* rf power dbm, see RF_TX_FULL_PWR_DBM */
|
||
|
rf_pwr_dbm : 8;
|
||
|
uint8_t dummy[IOT_PIB_R_MAC_SIZE - sizeof(uint32_t)];
|
||
|
} iot_pib_r_mac_cfg_t;
|
||
|
|
||
|
/* mac config setting */
|
||
|
typedef struct _iot_pib_w_mac_cfg {
|
||
|
uint8_t dummy[IOT_PIB_W_MAC_SIZE];
|
||
|
} iot_pib_w_mac_cfg_t;
|
||
|
|
||
|
/* halphy readonly config setting */
|
||
|
typedef struct _iot_pib_r_halphy_cfg_info {
|
||
|
/* tx power reduce */
|
||
|
uint8_t tx_pwr_reduce_db;
|
||
|
/* psd fix data */
|
||
|
uint8_t tx_pwr_psd_fix_db;
|
||
|
/* tx pwr ctl enable */
|
||
|
bool_t tx_pwr_ctl_ena;
|
||
|
/* start tone */
|
||
|
uint16_t start_tone;
|
||
|
/* end tone */
|
||
|
uint16_t end_tone;
|
||
|
/* inter time */
|
||
|
uint16_t inter_time;
|
||
|
} iot_pib_r_halphy_cfg_info_t;
|
||
|
|
||
|
/* halphy config setting */
|
||
|
typedef struct _iot_pib_r_halphy_cfg {
|
||
|
iot_pib_r_halphy_cfg_info_t cfg;
|
||
|
uint8_t dummy[IOT_PIB_R_HALPHY_SIZE - sizeof(iot_pib_r_halphy_cfg_info_t)];
|
||
|
} iot_pib_r_halphy_cfg_t;
|
||
|
|
||
|
/* halphy config setting */
|
||
|
#define IOI_PHY_GAIN_STEP_NUM (85)
|
||
|
typedef struct _iot_pib_w_halphy_real_cfg {
|
||
|
/* mask */
|
||
|
uint32_t mask;
|
||
|
/* chip id for check valid */
|
||
|
uint32_t chipid_hi;
|
||
|
uint32_t chipid_lo;
|
||
|
/* tx dc cali */
|
||
|
uint16_t tx_dc[4];
|
||
|
/* rx dc cali */
|
||
|
uint16_t rx_dc[IOI_PHY_GAIN_STEP_NUM];
|
||
|
/* bandwidth filter */
|
||
|
uint16_t cap_set[5];
|
||
|
} iot_pib_w_halphy_real_cfg_t;
|
||
|
|
||
|
typedef struct _iot_pib_w_halphy_cfg {
|
||
|
/* configuration */
|
||
|
iot_pib_w_halphy_real_cfg_t cfg;
|
||
|
/* dummy data to make it a fixed size */
|
||
|
uint8_t dummy[IOT_PIB_W_HALPHY_SIZE - sizeof(iot_pib_w_halphy_real_cfg_t)];
|
||
|
} iot_pib_w_halphy_cfg_t;
|
||
|
|
||
|
/* cli config setting */
|
||
|
typedef struct _iot_pib_r_cli_cfg {
|
||
|
uint8_t dummy[IOT_PIB_R_CLI_SIZE];
|
||
|
} iot_pib_r_cli_cfg_t;
|
||
|
|
||
|
/* cli config setting */
|
||
|
typedef struct _iot_pib_w_cli_cfg {
|
||
|
uint8_t dummy[IOT_PIB_W_CLI_SIZE];
|
||
|
} iot_pib_w_cli_cfg_t;
|
||
|
|
||
|
/* upgrage config setting */
|
||
|
typedef struct _iot_pib_w_upgrade_cfg {
|
||
|
uint8_t dummy[IOT_PIB_W_UPGRADE_SIZE];
|
||
|
} iot_pib_w_upgrade_cfg_t;
|
||
|
|
||
|
/* cco app config settings in read only part */
|
||
|
typedef struct _iot_pib_r_cco_app_cfg {
|
||
|
uint8_t dummy[IOT_PIB_R_APP_SIZE];
|
||
|
} iot_pib_r_cco_app_cfg_t;
|
||
|
|
||
|
/* sta app config settings in read only part */
|
||
|
typedef struct _iot_pib_r_sta_app_cfg {
|
||
|
uint8_t dummy[IOT_PIB_R_APP_SIZE];
|
||
|
} iot_pib_r_sta_app_cfg_t;
|
||
|
|
||
|
/* cco app config settings */
|
||
|
typedef struct _iot_pib_w_cco_app_cfg_v0 {
|
||
|
uint8_t dummy[IOT_PIB_W_APP_CCO_SIZE_V0];
|
||
|
} iot_pib_w_cco_app_cfg_v0_t;
|
||
|
|
||
|
typedef struct _iot_pib_w_cco_app_cfg_v1 {
|
||
|
uint8_t dummy[IOT_PIB_W_APP_CCO_SIZE_V1];
|
||
|
} iot_pib_w_cco_app_cfg_v1_t;
|
||
|
|
||
|
/* sta app config settings */
|
||
|
typedef struct _iot_pib_w_sta_app_cfg_v0 {
|
||
|
uint8_t dummy[IOT_PIB_W_APP_STA_SIZE_V0];
|
||
|
} iot_pib_w_sta_app_cfg_v0_t;
|
||
|
|
||
|
typedef struct _iot_pib_w_sta_app_cfg_v1 {
|
||
|
uint8_t dummy[IOT_PIB_W_APP_STA_SIZE_V1];
|
||
|
} iot_pib_w_sta_app_cfg_v1_t;
|
||
|
|
||
|
typedef struct _iot_pib_rw_hdr {
|
||
|
uint32_t crc32;
|
||
|
uint32_t rw_magic;
|
||
|
uint32_t index;
|
||
|
uint32_t rw_len;
|
||
|
uint16_t rw_major;
|
||
|
uint16_t rw_minor;
|
||
|
uint8_t reserved[8];
|
||
|
} iot_pib_w_block_hdr;
|
||
|
|
||
|
typedef struct _iot_pib_r_cco {
|
||
|
iot_pib_hdr_t pibhdr;
|
||
|
iot_pib_r_board_cfg_t board_cfg;
|
||
|
iot_pib_r_cli_cfg_t cli_cfg;
|
||
|
iot_pib_r_mac_cfg_t mac_cfg;
|
||
|
iot_pib_r_halphy_cfg_t halphy_cfg;
|
||
|
iot_pib_r_cvg_cfg_t cvg_cfg;
|
||
|
iot_pib_r_cco_app_cfg_t app_cfg;
|
||
|
} iot_pib_r_cco_t;
|
||
|
|
||
|
typedef struct _iot_pib_w_cco_v0 {
|
||
|
iot_pib_hdr_t pibhdr;
|
||
|
iot_pib_w_board_cfg_t board_cfg;
|
||
|
iot_pib_w_cli_cfg_t cli_cfg;
|
||
|
iot_pib_w_upgrade_cfg_t upgrade_cfg;
|
||
|
iot_pib_w_mac_cfg_t mac_cfg;
|
||
|
iot_pib_w_halphy_cfg_t halphy_cfg;
|
||
|
iot_pib_w_cvg_cfg_t cvg_cfg;
|
||
|
iot_pib_w_cco_app_cfg_v0_t app_cfg;
|
||
|
} iot_pib_w_cco_v0_t;
|
||
|
|
||
|
typedef struct _iot_pib_w_cco_v1 {
|
||
|
iot_pib_w_block_hdr cco_rw_hdr;
|
||
|
iot_pib_hdr_t pibhdr;
|
||
|
iot_pib_w_board_cfg_t board_cfg;
|
||
|
iot_pib_w_cli_cfg_t cli_cfg;
|
||
|
iot_pib_w_upgrade_cfg_t upgrade_cfg;
|
||
|
iot_pib_w_mac_cfg_t mac_cfg;
|
||
|
iot_pib_w_halphy_cfg_t halphy_cfg;
|
||
|
iot_pib_w_cvg_cfg_t cvg_cfg;
|
||
|
iot_pib_w_cco_app_cfg_v1_t app_cfg;
|
||
|
} iot_pib_w_cco_v1_t;
|
||
|
|
||
|
typedef struct _iot_pib_r_sta {
|
||
|
iot_pib_hdr_t pibhdr;
|
||
|
iot_pib_r_board_cfg_t board_cfg;
|
||
|
iot_pib_r_cli_cfg_t cli_cfg;
|
||
|
iot_pib_r_mac_cfg_t mac_cfg;
|
||
|
iot_pib_r_halphy_cfg_t halphy_cfg;
|
||
|
iot_pib_r_cvg_cfg_t cvg_cfg;
|
||
|
iot_pib_r_sta_app_cfg_t app_cfg;
|
||
|
} iot_pib_r_sta_t;
|
||
|
|
||
|
typedef struct _iot_pib_w_sta_v0 {
|
||
|
iot_pib_hdr_t pibhdr;
|
||
|
iot_pib_w_board_cfg_t board_cfg;
|
||
|
iot_pib_w_cli_cfg_t cli_cfg;
|
||
|
iot_pib_w_upgrade_cfg_t upgrade_cfg;
|
||
|
iot_pib_w_mac_cfg_t mac_cfg;
|
||
|
iot_pib_w_halphy_cfg_t halphy_cfg;
|
||
|
iot_pib_w_cvg_cfg_t cvg_cfg;
|
||
|
iot_pib_w_sta_app_cfg_v0_t app_cfg;
|
||
|
} iot_pib_w_sta_v0_t;
|
||
|
|
||
|
typedef struct _iot_pib_w_sta_v1 {
|
||
|
iot_pib_w_block_hdr sta_rw_hdr;
|
||
|
iot_pib_hdr_t pibhdr;
|
||
|
iot_pib_w_board_cfg_t board_cfg;
|
||
|
iot_pib_w_cli_cfg_t cli_cfg;
|
||
|
iot_pib_w_upgrade_cfg_t upgrade_cfg;
|
||
|
iot_pib_w_mac_cfg_t mac_cfg;
|
||
|
iot_pib_w_halphy_cfg_t halphy_cfg;
|
||
|
iot_pib_w_cvg_cfg_t cvg_cfg;
|
||
|
iot_pib_w_sta_app_cfg_v1_t app_cfg;
|
||
|
} iot_pib_w_sta_v1_t;
|
||
|
|
||
|
typedef iot_pib_w_sta_v1_t iot_pib_w_sta_t;
|
||
|
typedef iot_pib_w_cco_v1_t iot_pib_w_cco_t;
|
||
|
|
||
|
typedef struct _iot_pib_cco_mem {
|
||
|
iot_pib_r_cco_t r_ccopib;
|
||
|
iot_pib_w_cco_t w_ccopib;
|
||
|
}iot_pib_cco_mem_t;
|
||
|
|
||
|
typedef struct _iot_pib_sta_mem {
|
||
|
iot_pib_r_sta_t r_stapib;
|
||
|
iot_pib_w_sta_t w_stapib;
|
||
|
}iot_pib_sta_mem_t;
|
||
|
|
||
|
/* pib section size check */
|
||
|
typedef union {
|
||
|
uint8_t iot_pib_r_hdr_chk[IOT_PIB_R_HEAD_SIZE - \
|
||
|
sizeof(iot_pib_hdr_t) + 1];
|
||
|
uint8_t iot_pib_w_hdr_chk[IOT_PIB_W_HEAD_SIZE - \
|
||
|
sizeof(iot_pib_hdr_t) + 1];
|
||
|
uint8_t iot_pib_r_board_cfg_chk[IOT_PIB_R_BOARD_SIZE \
|
||
|
- sizeof(iot_pib_r_board_cfg_t) + 1];
|
||
|
uint8_t iot_pib_w_board_cfg_chk[IOT_PIB_W_BOARD_SIZE \
|
||
|
- sizeof(iot_pib_w_board_cfg_t) + 1];
|
||
|
uint8_t iot_pib_r_cvg_cfg_chk[IOT_PIB_R_CVG_SIZE - \
|
||
|
sizeof (iot_pib_r_cvg_cfg_t) + 1];
|
||
|
uint8_t iot_pib_w_cvg_cfg_chk[IOT_PIB_W_CVG_SIZE - \
|
||
|
sizeof(iot_pib_w_cvg_cfg_t) + 1];
|
||
|
uint8_t iot_pib_r_mac_cfg_chk[IOT_PIB_R_MAC_SIZE -\
|
||
|
sizeof(iot_pib_r_mac_cfg_t) + 1];
|
||
|
uint8_t iot_pib_w_mac_cfg_chk[IOT_PIB_W_MAC_SIZE - \
|
||
|
sizeof(iot_pib_w_mac_cfg_t) + 1];
|
||
|
uint8_t iot_pib_r_halphy_cfg_chk[IOT_PIB_R_HALPHY_SIZE -\
|
||
|
sizeof(iot_pib_r_halphy_cfg_t) + 1];
|
||
|
uint8_t iot_pib_w_halphy_cfg_chk[IOT_PIB_W_HALPHY_SIZE - \
|
||
|
sizeof(iot_pib_w_halphy_cfg_t) + 1];
|
||
|
uint8_t iot_pib_r_cli_cfg_chk[IOT_PIB_R_CLI_SIZE - \
|
||
|
sizeof(iot_pib_r_cli_cfg_t) + 1];
|
||
|
uint8_t iot_pib_w_cli_cfg_chk[IOT_PIB_W_CLI_SIZE - \
|
||
|
sizeof(iot_pib_w_cli_cfg_t) + 1];
|
||
|
uint8_t iot_cco_whtielist_chk[IOT_PIB_W_APP_CCO_SIZE_V1 - \
|
||
|
sizeof(iot_pib_w_cco_app_cfg_v1_t) + 1];
|
||
|
uint8_t iot_sta_meterlist_chk[IOT_PIB_W_APP_STA_SIZE_V1 -\
|
||
|
sizeof(iot_pib_w_sta_app_cfg_v1_t) + 1];
|
||
|
uint8_t iot_pib_w_upgrade_cfg_chk[IOT_PIB_W_UPGRADE_SIZE - \
|
||
|
sizeof(iot_pib_w_upgrade_cfg_t) + 1];
|
||
|
} piblen_audit;
|
||
|
|
||
|
/**
|
||
|
* @brief iot_pib_get_section() - function used to get specific module
|
||
|
* cfg data struct.
|
||
|
* @param module_id: pib module layout index.
|
||
|
* @param psection: return pib section start address.
|
||
|
* @param pibtype: return pib type.
|
||
|
* @param rw: get read only memory or
|
||
|
* writable memory, see IOT_PIB_GET_XXX_SECTION.
|
||
|
* @return 0 - success.
|
||
|
* @return otherwise - error code.
|
||
|
*/
|
||
|
uint32_t iot_pib_get_section(uint8_t module_id, uint8_t **psection,
|
||
|
iot_pib_type_t *pibtype, uint8_t rw);
|
||
|
|
||
|
/**
|
||
|
* @brief iot_pib_get_full_section() - function used to get full cfg data
|
||
|
* struct.
|
||
|
* @param ptr_pib: return pib start address include read only
|
||
|
* memory and writable memory.
|
||
|
* @param pibtype: return pib type.
|
||
|
* @return NULL - error, not find pib.
|
||
|
* @return otherwise - pib memory start address.
|
||
|
*/
|
||
|
uint32_t iot_pib_get_full_section(uint32_t *ptr_pib, iot_pib_type_t *pibtype);
|
||
|
|
||
|
/*
|
||
|
* About PIB framework working model
|
||
|
* PIB framework will load config from flash in RAM at system startup.
|
||
|
* PIB framework owner has direct read/write right for their own space in
|
||
|
* RAM. other module only have direct read access in RAM.
|
||
|
*
|
||
|
* Each module has right to submit commit request. PIB module will handle the
|
||
|
* request in silence way. Since other module may submit commit request while
|
||
|
* module owner change self config in RAM. In order to protect change config
|
||
|
* process not break by other module commit, owner should hold commit ref when
|
||
|
* change begin, and release commit ref as change finished.
|
||
|
* PIB framework will think module change complete when ref cont is zero.
|
||
|
* PIB framework will check every module's ref, and do real write flash only
|
||
|
* when all cont zero.
|
||
|
* Module space write will not be blocked by commit request. PIB framework
|
||
|
* will handle it.
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* @brief iot_pib_acquire_commit_ref() - function to hold pib commit execute
|
||
|
* until free commit reference.
|
||
|
* @param module_id: pib module layout index, indicate which module
|
||
|
* to ask for reference.
|
||
|
* @param cur_refcount: per module currently reference counter.
|
||
|
* @return 0 - success.
|
||
|
* @retval otherwise - error.
|
||
|
*/
|
||
|
uint32_t iot_pib_acquire_commit_ref(uint8_t module_id, uint8_t *cur_refcount);
|
||
|
|
||
|
/**
|
||
|
* @brief iot_pib_release_commit_ref() - function to release pib commit
|
||
|
* reference count.
|
||
|
* @param module_id: pib module layout index, indicate which module
|
||
|
* to release.
|
||
|
* @param cur_refcount: per module currently reference counter.
|
||
|
* @return 0 - success.
|
||
|
* @return otherwise - error.
|
||
|
*/
|
||
|
uint32_t iot_pib_release_commit_ref(uint8_t module_id, uint8_t *cur_refcount);
|
||
|
|
||
|
/**
|
||
|
* @brief iot_pib_load() - function used to read pib out of flash.
|
||
|
* @param upgraded: if boot from upgrade
|
||
|
* @return 0 - success.
|
||
|
* @return otherwise - error case.
|
||
|
*/
|
||
|
uint32_t iot_pib_load(bool_t upgraded);
|
||
|
|
||
|
/**
|
||
|
* @brief iot_pib_init() - function used to init pib resources.
|
||
|
* @return 0 - success.
|
||
|
* @return otherwise - error case.
|
||
|
*/
|
||
|
uint32_t iot_pib_init(void);
|
||
|
|
||
|
/**
|
||
|
* @brief iot_pib_deinit() - function used to release pib resources.
|
||
|
* @return 0 - success.
|
||
|
* @return otherwise - error case.
|
||
|
*/
|
||
|
uint32_t iot_pib_deinit(void);
|
||
|
|
||
|
/**
|
||
|
* @brief iot_pib_commit() - function used by module to trigger write pib
|
||
|
* to flash.
|
||
|
* @param request_module_id: module index which trying to trigger write
|
||
|
action.
|
||
|
* @param commit_type: module apply for write condition.
|
||
|
* @return 0 - error, not find pib.
|
||
|
* @return otherwise - pib memory start address.
|
||
|
*/
|
||
|
uint32_t iot_pib_commit(uint8_t req_module_id,
|
||
|
iot_pib_commit_type_t commit_type, uint16_t* commit_ticket);
|
||
|
|
||
|
/**
|
||
|
* @brief iot_pib_report_commit_status_func_t() - function callback to
|
||
|
* receive pib commit status.
|
||
|
* @param status: pib commit status. see IOT_PIB_STATUS_COMMIT_XXX.
|
||
|
* @param commit_ticket: commit ticket number which already done saving
|
||
|
*/
|
||
|
typedef void(*iot_pib_report_commit_status_func_t)(uint8_t status,
|
||
|
uint16_t commit_ticket);
|
||
|
|
||
|
/**
|
||
|
* @brief iot_pib_register_commit_cb() - register pib commit callback
|
||
|
* function
|
||
|
* @param module_id: pib module id.
|
||
|
* @param cb: callback function.
|
||
|
* @return 0 - success.
|
||
|
* @return otherwise - fail.
|
||
|
*/
|
||
|
uint32_t iot_pib_register_commit_cb(uint32_t module_id,
|
||
|
iot_pib_report_commit_status_func_t cb);
|
||
|
|
||
|
/**
|
||
|
* @brief iot_pib_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_get_crc_status(uint8_t* r_crc, uint8_t* w_crc);
|
||
|
|
||
|
#pragma pack(pop) // restore the pack status
|
||
|
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
#endif /* IOT_PIB_H */
|