Files
kunlun/plc/cvg/nwm/inc/cvg_nwm_sta_zc.h
2024-09-28 14:24:04 +08:00

174 lines
6.8 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 CVG_NWM_STA_ZC_H
#define CVG_NWM_STA_ZC_H
/* public includes */
#include "plc_mme_zero_cross.h"
#include "plc_cert_test.h"
#include "mac_zc_api.h"
/* cvg module internal includes */
#include "cvg_nwm_sta_common.h"
#ifdef __cplusplus
extern "C" {
#endif
/* zc ntb data */
typedef struct cvg_nwm_sta_zc_data {
uint32_t ntb[PLC_PHASE_CNT];
float period[PLC_PHASE_CNT];
uint8_t phase_cnt;
} cvg_nwm_sta_zc_data_t;
#if (PLC_SUPPORT_STA_ROLE && PLC_SUPPORT_PHY_PHASE_IDENT)
/*
* @brief cvg_nwm_sta_get_zc_ntb() - get sta local zc ntb data.
* @param nwm: pointer to nwm
* @param zc_data: zc ntb data
*/
uint32_t cvg_nwm_sta_get_zc_ntb(cvg_nwm_vdev_t *nwm,
cvg_nwm_sta_zc_data_t *zc_data);
/*
* @brief cvg_nwm_sta_zc_3p_check() - local 3p device zc check.
* @param nwm: pointer to nwm
*/
void cvg_nwm_sta_zc_3p_check(cvg_nwm_vdev_t *nwm);
/*
* @brief cvg_nwm_sta_fill_ntb_diff_val() - fill ntb diff value from mac report.
* @param nwm: pointer to nwm
* @param std_ntb: returns the standard NTB of the zero-crossing
* difference sequence, uint is 256 NTB.
* @param ntb_diff_val: pointer to the buffer to fill in ntb diff value
* @param mac_rpt: point to the mac report zero-cross ntb values
* @param phase_cnt if needed, get every phase zero-cross ntb value count
* @param real_ntb_size calculated real zero-cross ntb size
* @param max_phase how many phase ntb values need to fill to ntb_diff_val
* @param ntb_diff_cnt point to the ntb diff value count, it will be the
* output param and return the ntb diff value count
* @param phase_mask: phase to be masked off, bit 0~2 corresponds to
* phase 1/2/3 of device.
*/
uint32_t cvg_nwm_sta_fill_ntb_diff_val(cvg_nwm_vdev_t *nwm, uint32_t *std_ntb,
ntb_diff_value_t *ntb_diff_val, mac_zc_ntb_rpt_t *mac_rpt,
uint8_t *phase_cnt, uint16_t *real_ntb_size,
uint8_t max_phase, uint8_t *ntb_diff_cnt, uint8_t phase_mask);
/*
* @brief cvg_nwm_sta_fill_ntb_diff_val_gd() - fill ntb diff value, apply to
* guangdong protocol
* @param nwm: pointer to nwm
* @param std_ntb: returns the standard NTB of the zero-crossing
* difference sequence, uint is 1 NTB.
* @param ntb_diff_val: pointer to the buffer to fill in ntb diff value
* @param mac_rpt: point to the mac report zero-cross ntb values
* @param phase_cnt if needed, get every phase zero-cross ntb value count
* @param real_ntb_size calculated real zero-cross ntb size
* @param max_phase how many phase ntb values need to fill to ntb_diff_val
* @param ntb_diff_cnt point to the ntb diff value count, it will be the
* output param and return the ntb diff value count
* @param phase_mask: phase to be masked off, bit 0~2 corresponds to
* phase 1/2/3 of device.
*/
uint32_t cvg_nwm_sta_fill_ntb_diff_val_gd(cvg_nwm_vdev_t *nwm, uint32_t *std_ntb,
uint16_t *ntb_diff_val, mac_zc_ntb_rpt_t *mac_rpt,
uint8_t *phase_cnt, uint16_t *real_ntb_size,
uint8_t max_phase, uint8_t *ntb_diff_cnt, uint8_t phase_mask);
#if PLC_SUPPORT_TSFM_ZC_NTB
/*
* @brief cvg_nwm_sta_area_notify_ntb_rpt_calc() - calculate the local device
* physical phase and zc ntb info by the area notify zc ntb report of the CCO
* sent.
* @param nwm: pointer to nwm
* @param nw_info: pointer to network info
* @param zc_ntb_rpt: area notify zc ntb report
*/
void cvg_nwm_sta_area_notify_ntb_rpt_calc(cvg_nwm_vdev_t *nwm,
cvg_nwm_sta_nw_info_t *nw_info,
mme_area_notify_zc_ntb_report_header_t *zc_ntb_rpt);
/*
* @brief cvg_nwm_sta_calc_nw_zc_ntb() - calculate zc ntb info in the current
* statistics period.
* @param nw_info: pointer to network info
*/
void cvg_nwm_sta_calc_nw_zc_ntb(cvg_nwm_sta_nw_info_t *nw_info);
/*
* @brief cvg_nwm_sta_calc_all_nw_zc_ntb() - calculate all network zc ntb info
* in the current statistics period.
* @param nwm: pointer to nwm
*/
void cvg_nwm_sta_calc_all_nw_zc_ntb(cvg_nwm_vdev_t *nwm);
/*
* @brief cvg_nwm_sta_clear_zc_ntb() - clear zc ntb info.
* @param nw_info: pointer to network info
*/
void cvg_nwm_sta_clear_zc_ntb(cvg_nwm_sta_nw_info_t *nw_info);
/*
* @brief cvg_nwm_sta_zc_check_sn_rec() - check if this is a duplicate zc ntb
* tsfm report frame.
* @param nw_info: pointer to network info
* @param sn: zc ntb collection sn
* @param edge: zc edge type
* @param from_app: from app call
*
* @retval: return non-zero if it is a duplicate frame.
*/
uint8_t cvg_nwm_sta_zc_check_sn_rec(cvg_nwm_sta_nw_info_t *nw_info, uint8_t sn,
uint8_t edge, uint8_t from_app);
#else /* PLC_SUPPORT_TSFM_ZC_NTB */
#define cvg_nwm_sta_area_notify_ntb_rpt_calc(nwm, nw_info, zc_ntb_rpt)
#define cvg_nwm_sta_calc_nw_zc_ntb(nw_info)
#define cvg_nwm_sta_calc_all_nw_zc_ntb(nwm)
#define cvg_nwm_sta_clear_zc_ntb(nw_info)
#define cvg_nwm_sta_zc_check_sn_rec(nw_info, sn, edge, from_app) (0)
#endif /* PLC_SUPPORT_TSFM_ZC_NTB */
#else /* PLC_SUPPORT_STA_ROLE && PLC_SUPPORT_PHY_PHASE_IDENT */
#define cvg_nwm_sta_get_zc_ntb(nwm, zc_data) (ERR_NOSUPP)
#define cvg_nwm_sta_fill_ntb_diff_val(nwm, std_ntb, ntb_diff_val, mac_rpt, \
phase_cnt, real_ntb_size, max_phase, ntb_diff_cnt, phase_mask) (ERR_NOSUPP)
#define cvg_nwm_sta_fill_ntb_diff_val_gd(nwm, std_ntb, ntb_diff_val, mac_rpt, \
phase_cnt, real_ntb_size, max_phase, ntb_diff_cnt, phase_mask) (ERR_NOSUPP)
#define cvg_nwm_sta_area_notify_ntb_rpt_calc(nwm, nw_info, zc_ntb_rpt)
#define cvg_nwm_sta_calc_nw_zc_ntb(nw_info)
#define cvg_nwm_sta_calc_all_nw_zc_ntb(nwm)
#define cvg_nwm_sta_clear_zc_ntb(nw_info)
#define cvg_nwm_sta_zc_3p_check(nwm)
#define cvg_nwm_sta_zc_check_sn_rec(nw_info, sn, edge, from_app) (0)
#endif /* PLC_SUPPORT_STA_ROLE && PLC_SUPPORT_PHY_PHASE_IDENT */
#ifdef __cplusplus
}
#endif
#endif /* CVG_NWM_STA_ZC_H */