Files
kunlun/app/smart_grid/inc/internal/iot_sg_sta_topo.h
2024-09-28 14:24:04 +08:00

235 lines
7.4 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_SG_STA_TOPO_H
#define IOT_SG_STA_TOPO_H
#include "iot_utils_api.h"
/* smart grid internal header files */
#include "iot_sg_fr.h"
#include "iot_sg_cfg.h"
#ifdef __cplusplus
extern "C" {
#endif
/* topo bitmap sn definitions */
#define IOT_SG_STA_TSFM_SN_FIRST (1)
#define IOT_SG_STA_TSFM_SN_LAST (IOT_SG_STA_TSFM_SN_FIRST \
+ IOT_SG_APP_WL_MAX_NUM - 1)
/* define tsfm topo bm length */
#define IOT_SG_STA_TSFM_TOPO_SN_BM_LEN ((IOT_SG_STA_TSFM_SN_LAST / 8) + 1)
/* define topo code data max length, uint is byte. only for zhejiang */
#define IOT_SG_STA_TSFM_TOPO_CODE_LEN_MAX (16)
/* define tsfm topo record max cnt */
#define IOT_SG_STA_TSFM_TOPO_RECORD_CNT_MAX (10)
/* pack for the structures in the whole file */
#pragma pack(push) // save the pack status
#pragma pack(1) // 1 byte align
/* tsfm topo info definition from hw */
typedef struct _iot_sg_sta_tsfm_topo_info {
/* phase recognized */
uint8_t phase;
/* sn */
uint16_t sn;
/* energy */
uint16_t energy;
} iot_sg_sta_tsfm_topo_info_t;
#pragma pack(pop)
/* topo sn descriptor */
typedef struct _iot_sg_sta_tsfm_topo_desc {
/* data block total cnt */
uint8_t block_cnt;
/* curr data block sequence */
uint8_t curr_seq;
/* the tei of the fisrt sn in bitmap */
uint16_t first_sn;
/* length of bitmap, uint is 1 byte */
uint16_t length;
/* energy index */
uint16_t energy_idx;
/* energy cnt */
uint16_t energy_cnt;
} iot_sg_sta_tsfm_topo_desc_t;
/* topo sn bitmap */
typedef struct _iot_sg_sta_tsfm_topo_bm {
/* bitmap of topo sn in all phase */
uint8_t map[IOT_SG_STA_TSFM_TOPO_SN_BM_LEN];
/* bitmap of topo sn in phase a */
uint8_t a_map[IOT_SG_STA_TSFM_TOPO_SN_BM_LEN];
/* bitmap of topo sn in phase b */
uint8_t b_map[IOT_SG_STA_TSFM_TOPO_SN_BM_LEN];
/* bitmap of topo sn in phase c */
uint8_t c_map[IOT_SG_STA_TSFM_TOPO_SN_BM_LEN];
/* energy cnt */
uint16_t energy_cnt[IOT_PLC_PHASE_CNT + 1];
/* energy table */
uint16_t table[IOT_SG_STA_TSFM_TOPO_SN_BM_LEN * 8];
} iot_sg_sta_tsfm_topo_bm_t;
/* sta tsfm topo send record time uint */
typedef struct _iot_sg_sta_tsfm_topo_time_uint {
/* start time stamp */
iot_time_tm_t start_tm;
/* end time stamp */
iot_time_tm_t end_tm;
} iot_sg_sta_tsfm_topo_time_uint_t;
/* sta tsfm topo send record */
typedef struct _iot_sg_sta_tsfm_topo_record_t {
/* record cnt in list */
uint8_t cnt;
/* current index in list */
uint8_t idx;
/* current flash write index, starting from 0 */
uint32_t flash_idx;
/* send record list */
iot_sg_sta_tsfm_topo_time_uint_t list[IOT_SG_STA_TSFM_TOPO_RECORD_CNT_MAX];
} iot_sg_sta_tsfm_topo_record_t;
/* sta tsfm topo info */
typedef struct _iot_sg_sta_topo_info {
/* interval of tsfm topo repeat send, uint is 1s */
uint8_t repeat_interval;
/* cnt of tsfm topo repeat send */
uint8_t repeat_cnt;
/* send mode choose, use to distinguish branch1 and branch2,
* see IOT_PLC_HW_TSFM_SEND_MODE_XXX.
*/
uint8_t send_mode;
/* topo sn bitmap */
iot_sg_sta_tsfm_topo_bm_t *sn_bm;
/* branch1 send info */
struct {
/* ahead interval time of sending data relative to zero-crossing
* point, uint is 1us.
*/
uint16_t ahead;
/* duration of bit data output, uint is 1us */
uint16_t dur_output;
/* topo sn to launch */
uint16_t sn;
} branch1;
/* branch2 send info */
struct {
/* topo sn, used to check message number */
uint16_t sn;
/* save send mode when sn same return. */
uint8_t sn_send_mode;
/* sn is valid, 0: invalid, 1: valid. */
uint16_t sn_is_valid :1,
/* flag of send pending */
send_pend :1,
/* code length */
code_len :6,
/* send encode flag, see IOT_PLC_HW_TSFM_LOAD_ENCODE_XXX */
encode :2,
/* reserve for further */
resv :6;
/* last send time stamp, used to control send interval,
* uint is 1s.
*/
uint32_t last_ts;
/* current sequence */
uint16_t seq;
/* start send time */
iot_time_tm_t start_time;
/* code data */
uint8_t code_data[IOT_SG_STA_TSFM_TOPO_CODE_LEN_MAX];
/* 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;
/* characteristics data per bit duration time, unit: 1us */
uint32_t chara_bit_dur;
} branch2;
/* tsfm topo send record */
iot_sg_sta_tsfm_topo_record_t send_record;
} iot_sg_sta_topo_info_t;
/**
* @brief iot_sg_sta_save_tsfm_info - save hardware transformer topo info
* @param tsfm_info: - hardware transformer topo info for save.
*/
void iot_sg_sta_save_tsfm_topo_info(iot_sg_sta_tsfm_topo_info_t *topo_info);
/**
* @brief clear hardware transformer topo info
*/
void iot_sg_sta_clear_tsfm_topo_info(void);
/**
* @brief get topo bitmap info.
* @param bitmap: pointer to bitmap info cache.
* @param phase_type: phase type, see PROTO_645_2007_EXT_BRM_PHASE_XXX.
* @param block_seq: topo data block sequence.
* @retval: 0 - for success case.
* @retval: otherwise - error code.
*/
uint32_t iot_sg_sta_get_tsfm_topo_bitmap_info(
iot_sg_sta_tsfm_topo_desc_t *bitmap, uint8_t phase_type,
uint8_t block_seq);
/**
* @brief fill topo bitmap info.
* @param map: pointer to bitmap filled.
* @param bitmap_info: pointer to bitmap info cache.
* @param phase_type: phase type, see PROTO_645_2007_EXT_BRM_PHASE_XXX.
*/
void iot_sg_sta_tsfm_topo_fill_bitmap_info(
uint8_t *map, iot_sg_sta_tsfm_topo_desc_t *bitmap_info,
uint8_t phase_type);
/**
* @brief fill topo energy info.
* @param table: pointer to energy table filled.
* @param phase: phase to be filled
* @param start_index: start index to be filled.
* @param fill_cnt: counter to be filled.
*/
void iot_sg_sta_tsfm_topo_fill_energy_info(
uint8_t *table, uint8_t phase, uint16_t start_index, uint16_t fill_cnt);
/**
* @brief topo sn info dump.
*/
void iot_sg_sta_tsfm_topo_bitmap_dump(void);
/**
* @brief topo sn send repeat.
*/
void iot_sg_sta_tsfm_topo_repeat(void);
/**
* @brief topo init.
*/
void iot_sg_sta_hw_topo_init(void);
/**
* @brief topo deinit.
*/
void iot_sg_sta_hw_topo_deinit(void);
#ifdef __cplusplus
}
#endif
#endif /* IOT_SG_STA_TOPO_H */