262 lines
8.3 KiB
C
262 lines
8.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_BRM_NV_H
|
||
|
#define IOT_BRM_NV_H
|
||
|
|
||
|
/* os shim includes */
|
||
|
#include "os_types_api.h"
|
||
|
|
||
|
/* iot common header files */
|
||
|
#include "iot_utils_api.h"
|
||
|
#include "iot_config_api.h"
|
||
|
|
||
|
/* branch management internal header files */
|
||
|
#include "iot_brm_common.h"
|
||
|
#include "iot_brm_evt.h"
|
||
|
|
||
|
/* define the length of the non-volatile region reserved for events*/
|
||
|
#define IOT_BRM_NV_EVT_RSVD_DATA_LEN 499
|
||
|
/* define the length of the non-volatile parameter */
|
||
|
#define IOT_BRM_NV_PARAMS_DATA_LEN 520
|
||
|
|
||
|
/* define branch detect identification code max len */
|
||
|
#define IOT_BRM_BRANCH_ID_CODE_MAX 16
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
extern "C" {
|
||
|
#endif
|
||
|
|
||
|
#if (IOT_BRM_ENABLE && PLC_SUPPORT_STA_ROLE)
|
||
|
|
||
|
/* non-volatile section ID */
|
||
|
typedef enum {
|
||
|
/* node list section */
|
||
|
iot_brm_nv_id_node_list,
|
||
|
/* assembly check info section */
|
||
|
iot_brm_nv_id_ass_chk_info,
|
||
|
/* param section */
|
||
|
iot_brm_nv_id_param,
|
||
|
/* power down info section */
|
||
|
iot_brm_nv_id_pd_info,
|
||
|
/* evt info section */
|
||
|
iot_brm_nv_id_evt_info,
|
||
|
/* max */
|
||
|
iot_brm_nv_id_max,
|
||
|
} iot_brm_nv_id_t;
|
||
|
|
||
|
#pragma pack(push) /* save the pack status */
|
||
|
#pragma pack(1) /* 1 byte align */
|
||
|
|
||
|
/* time parameter setting of freezing on monthly settlement date */
|
||
|
typedef struct {
|
||
|
/* day */
|
||
|
uint8_t day;
|
||
|
/* hour */
|
||
|
uint8_t hour;
|
||
|
} iot_brm_msd_frozen_time_t;
|
||
|
|
||
|
/* branch revceive config info valid mark magic */
|
||
|
#define IOT_BRM_BR_CFG_VALID_MARK 0x5A5A
|
||
|
|
||
|
/* branch revceive confog mark */
|
||
|
typedef struct _iot_brm_br_cfg {
|
||
|
/* load hw tsfm mode encode frequncy. unit: 0.01Hz */
|
||
|
uint32_t fc;
|
||
|
/* characteristics data per bit duration time, unit: 1ms */
|
||
|
uint16_t chara_bit_dur;
|
||
|
/* modulate pulse signal high duration time, unit: 1us */
|
||
|
uint16_t pulse_high_dur;
|
||
|
/* modulate pulse signal low duration time, unit: 1us */
|
||
|
uint16_t pulse_low_dur;
|
||
|
/* non fix code similarity threshold, uint is 0.1% */
|
||
|
uint16_t similarity_thr;
|
||
|
/* fix code similarity threshold, uint is 0.1% */
|
||
|
uint16_t similarity_thr_fix;
|
||
|
/* branch receive identification code len */
|
||
|
uint8_t id_code_len;
|
||
|
/* branch receive identification code */
|
||
|
uint8_t id_code[IOT_BRM_BRANCH_ID_CODE_MAX];
|
||
|
/* reserved for further use */
|
||
|
uint8_t rsvd[7];
|
||
|
/* config info valid mark */
|
||
|
uint16_t valid_mark;
|
||
|
} iot_brm_br_cfg_t;
|
||
|
|
||
|
/* non-volatile parameter layout */
|
||
|
typedef struct _iot_brm_nv_params {
|
||
|
/* longitude */
|
||
|
iot_brm_location_unit_t longitude;
|
||
|
/* latitude */
|
||
|
iot_brm_location_unit_t latitude;
|
||
|
/* threshold data of qiedian event */
|
||
|
iot_brm_evt_qd_thr_t qd_thr;
|
||
|
/* voltage ratio */
|
||
|
uint32_t v_ratio;
|
||
|
/* current ratio*/
|
||
|
uint32_t i_ratio;
|
||
|
/* tsfm addr, little-endian */
|
||
|
uint8_t tsfm_addr[IOT_MAC_ADDR_LEN];
|
||
|
/* terminal information mode check */
|
||
|
uint8_t trans_inf_is_valid :1,
|
||
|
/* terminal communication port number */
|
||
|
trans_port :2,
|
||
|
/* terminal type, if 0: 3761 terminal, 1: 698 terminal */
|
||
|
is_698 :1,
|
||
|
/* not used */
|
||
|
rsvd0 :4;
|
||
|
/* terminal address configuration */
|
||
|
union {
|
||
|
/* terminal address 698, little-endian */
|
||
|
uint8_t trans_698_addr[IOT_MAC_ADDR_LEN];
|
||
|
struct{
|
||
|
/* administrative region code */
|
||
|
uint16_t area_code;
|
||
|
/* terminal address region */
|
||
|
uint16_t dev_addr;
|
||
|
} trans_3761;
|
||
|
} terminal_addr;
|
||
|
/* start time of curve recording */
|
||
|
uint32_t cr_rec_start;
|
||
|
/* curve recording interval, uins is 1s */
|
||
|
uint16_t cr_rec_interval;
|
||
|
/* threshold data of under voltage event */
|
||
|
iot_brm_evt_uv_thr_t uv_thr;
|
||
|
/* threshold data of over voltage event */
|
||
|
iot_brm_evt_ov_thr_t ov_thr;
|
||
|
/* threshold data of over current event */
|
||
|
iot_brm_evt_oi_thr_t oi_thr;
|
||
|
/* threshold data of phase failure event */
|
||
|
iot_brm_evt_pf_thr_t pf_thr;
|
||
|
/* threshold data of voltage unbalance event */
|
||
|
iot_brm_evt_unbalance_thr_t ubv_thr;
|
||
|
/* threshold data of current unbalance event */
|
||
|
iot_brm_evt_unbalance_thr_t ubi_thr;
|
||
|
/* current ratio coefficient, unit: 0.0001 */
|
||
|
uint32_t i_coeff;
|
||
|
/* reserved */
|
||
|
uint8_t rsvd1[27];
|
||
|
/* demand slide interval unit: 1 minute */
|
||
|
uint8_t demand_slide_interval;
|
||
|
/* demand period uint: 1 minute */
|
||
|
uint8_t demand_period;
|
||
|
/* data format = DDhh. */
|
||
|
iot_brm_msd_frozen_time_t sday_time[IOT_BRM_SUPPORT_MSD_NUM];
|
||
|
/* devive asset management code */
|
||
|
uint8_t amc[32];
|
||
|
/* branch revceive parameter */
|
||
|
iot_brm_br_cfg_t br_cfg;
|
||
|
/* reserved for further use */
|
||
|
uint8_t rsvd2[334];
|
||
|
} iot_brm_nv_params_t;
|
||
|
|
||
|
/* node information list layout */
|
||
|
typedef struct _iot_brm_nv_node_list {
|
||
|
/* reserved for further use */
|
||
|
uint8_t rsvd[12];
|
||
|
/* node information list */
|
||
|
iot_brm_nv_node_entry_t entry[IOT_BRM_SUPPORT_NODE_MAX];
|
||
|
} iot_brm_nv_node_list_t;
|
||
|
|
||
|
/* node information list layout */
|
||
|
typedef struct _iot_brm_nv_pd_info {
|
||
|
/* record number */
|
||
|
uint32_t rec_sn;
|
||
|
/* not used. */
|
||
|
uint32_t reason :2,
|
||
|
/* reserved for further use */
|
||
|
rsvd1 :30;
|
||
|
/* reserved for further use */
|
||
|
uint32_t rsvd2;
|
||
|
/* payload */
|
||
|
uint8_t e_data[sizeof(iot_brm_meter_energy_triphase_t) +
|
||
|
sizeof(iot_brm_meter_energy_sigphase_t) * IOT_BRM_PHASE_C];
|
||
|
} iot_brm_nv_pd_info_t;
|
||
|
|
||
|
/* node information list layout */
|
||
|
typedef struct _iot_brm_nv_evt_info {
|
||
|
/* record number */
|
||
|
uint32_t rec_sn;
|
||
|
/* not used. */
|
||
|
uint32_t rsvd[2];
|
||
|
/* payload */
|
||
|
uint8_t payload[IOT_BRM_NV_EVT_RSVD_DATA_LEN];
|
||
|
} iot_brm_nv_evt_info_t;
|
||
|
|
||
|
/* node assembly check info descriptor */
|
||
|
typedef struct _iot_brm_ass_node_nv_entry {
|
||
|
/* node addr, little-endian */
|
||
|
uint8_t addr[IOT_MAC_ADDR_LEN];
|
||
|
/* 1 - assembly ok, 0 assembly fail */
|
||
|
uint8_t ass_ok : 1,
|
||
|
/* node proto type, see IOT_BRM_PROTO_TYPE_XXX */
|
||
|
pid : 3,
|
||
|
/* node baud rate id, see IOT_BRM_BUAD_ID_XXX */
|
||
|
bid : 3,
|
||
|
/* flag mark to the check by PLC link */
|
||
|
is_plc_chk : 1;
|
||
|
} iot_brm_ass_node_nv_entry_t;
|
||
|
|
||
|
/* assembly check info layout */
|
||
|
typedef struct _iot_brm_nv_ass_chk_info {
|
||
|
/* record number */
|
||
|
uint32_t ts;
|
||
|
/* time consuming, uint is 1s */
|
||
|
uint16_t time_cons;
|
||
|
/* phase 1, wiring status, see PROTO_645_EXT_BRM_ASS_WIRE_XXX */
|
||
|
uint8_t phase1_wire_st;
|
||
|
/* phase 2, wiring status, see PROTO_645_EXT_BRM_ASS_WIRE_XXX */
|
||
|
uint8_t phase2_wire_st;
|
||
|
/* phase 3, wiring status, see PROTO_645_EXT_BRM_ASS_WIRE_XXX */
|
||
|
uint8_t phase3_wire_st;
|
||
|
/* not used no.1 */
|
||
|
uint8_t rsvd1[3];
|
||
|
/* not used no.2 */
|
||
|
uint32_t rsvd2[2];
|
||
|
/* node assembly check nv info entry */
|
||
|
iot_brm_ass_node_nv_entry_t ent[IOT_BRM_SUPPORT_NODE_MAX];
|
||
|
} iot_brm_nv_ass_chk_info_t;
|
||
|
|
||
|
#pragma pack(pop) /* 1 byte align */
|
||
|
|
||
|
/**
|
||
|
* @brief iot_brm_nv_init() - initialization of non-volatile regions
|
||
|
* @retval: ERR_OK - successfully, otherwise - error code
|
||
|
*/
|
||
|
uint32_t iot_brm_nv_init(void);
|
||
|
|
||
|
/**
|
||
|
* @brief iot_brm_nv_update_section() - gets the buffer pointer for the
|
||
|
* specified section
|
||
|
* @param id: seticon id, see iot_brm_nv_id_t
|
||
|
* @retval: buffer pointer for the specified section
|
||
|
*/
|
||
|
void *iot_brm_nv_get_section(iot_brm_nv_id_t id);
|
||
|
|
||
|
/**
|
||
|
* @brief iot_brm_nv_update_section() - update the specified seticon to
|
||
|
* non-volatile storage
|
||
|
* @param id: seticon id, see iot_brm_nv_id_t
|
||
|
*/
|
||
|
void iot_brm_nv_update_section(iot_brm_nv_id_t id);
|
||
|
|
||
|
#endif /* IOT_BRM_ENABLE && PLC_SUPPORT_STA_ROLE */
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
#endif /* IOT_BRM_REC_H */
|