Files
kunlun/plc/halmac/inc/multi_nid_sync.h
2024-09-28 14:24:04 +08:00

194 lines
7.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 MULTI_NID_SYNC_H
#define MULTI_NID_SYNC_H
#include "os_types.h"
#include "mac_ppm_scan.h"
#include "plc_utils.h"
#include "phy_bb.h"
#include "phy_multi_ppm.h"
#include "hw_war.h"
#include "mac_uni_cfg_api.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ppm cal period between two bcn rx */
#define DEF_MULTI_SYNC_PERIOD (1000)
/* 120s to NTB */
#define MAX_BCN_RX_TIMEOUT_NTB (120UL * 1000 * 1000 * 25)
/* mac multi ppm update timeout, unit: 1ntb */
#define MAC_MULTI_UPDATE_TIMEOUT_NTB (MAX_BCN_RX_TIMEOUT_NTB >> 2)
/* calculation struct:
* used for storing tmp result of ppm
* calculation for each nid
* the calculation process is performed
* on the cpu0, and placed under pdev struct
*/
typedef struct _m_ppm_cal {
uint32_t nid : 24,
rsv : 8;
mac_ntb_record_ctxt_t ntb_record;
} m_ppm_cal_t;
typedef struct _m_ppm_cal_ctxt{
void *phy_ppm_ctxt;
uint64_t last_clear_ntb;
m_ppm_cal_t ppm_cal[MAX_SYNC_CCO_CNT];
} m_ppm_cal_ctxt_t;
/**
*@brief mac_multi_sync_get_ppm_tbl get ppm table
*@param pdev_id pdev id
*@param ppm_tbl point to ppm table
*@exception none
*@return uint8_t vaild nid cnt.
*/
uint8_t mac_multi_sync_get_ppm_tbl(pdevid_t pdev_id, plc_ppm_status_t *ppm_tbl);
#if ENA_SYNC_DIFF_CCO_PPM
/**
*@brief mac_multi_sync_init init
*@param pdev_id init pdev id
*@exception none
*@return none
*/
void mac_multi_sync_init(uint8_t pdev_id);
/**
*@brief mac_multi_ppm_record update ppm and record
*@param pdev_id indicate pdev id
*@param nid rx buf nid
*@param my_nid my nid
*@param r_ts remote timestamp
*@param l_ts local timestamp
*@param l_ntb local ntb
*@min_update_period min period for ppm update
*@ppm_err input my ppm err,
* unit: see PLC_NTB_PPM_SHIFT
*@exception none
*@return ERR_OK:ok
* ERR_FAIL:nid recorde full
* ERR_BUSY:period is small than min_period
*/
uint32_t mac_multi_ppm_record(uint8_t pdev_id, nid_t nid, nid_t my_nid,
uint32_t rate_mode, uint32_t r_ts, uint32_t l_ts, uint32_t l_ntb,
uint32_t min_update_period, int16_t ppm_err);
/**
*@brief mac_multi_sync_nid_timeout_clear clear timeout cco
*@param pdev_id indicate pdev id
*@return none
*/
void mac_multi_sync_nid_timeout_clear(uint8_t pdev_id);
/**
*@brief mac_myntb_to_other_ntb mac_myntb_to_other_ntb
*@param pdev_id indicate pdev id
*@param nid cur nid
*@array array local ntb array
*@array len array len
*@exception none
*@return ERR_OK:ok
* ERR_FAIL:nid = my_nid or nid not found
*/
uint32_t mac_myntb_to_other_ntb(uint8_t pdev_id, nid_t nid, uint32_t *array,
uint32_t len);
/**
*@brief mac_myntb_to_other_ntb mac_other_ntb_to_myntb
*@param pdev_id indicate pdev id
*@param nid cur nid
*@array array remote ntb array
*@array len array len
*@exception none
*@return ERR_OK:ok
* ERR_FAIL:nid = my_nid or nid not found
*/
uint32_t mac_other_ntb_to_myntb(uint8_t pdev_id, nid_t nid, uint32_t *array,
uint32_t len);
/**
*@brief mac_multi_sync_get_ena get cur enable status
*@param pdev_id indicate pdev id
*@exception none
*@return 0:disable, 1:enable
*/
uint8_t mac_multi_sync_get_ena(uint8_t pdev_id);
/**
*@brief mac_multi_sync_ena enable/disable multi sync
*@param pdev_id indicate pdev id
*@param enable_flag set enable/disable
*@exception none
*@return none
*/
void mac_multi_sync_set_ena(uint8_t pdev_id, uint8_t enable);
/**
*@brief mac_multi_sync_get_ppm get mac sync nid ppm
*@param pdev_id indicate pdev id
*@param nid target nid
*@exception none
*@return nid ppm
*/
int32_t mac_multi_sync_get_ppm(uint8_t pdev_id, nid_t nid);
/**
*@brief mac_multi_sync_apply_new_ppm_step apply new ppm step
*@param pdev_id indicate pdev id
*@param nid which nid we choose to apply
*@param ppm_step ppm adjust step
*@exception none
*@return none
*/
void mac_multi_sync_apply_new_ppm_step(uint8_t pdev_id, nid_t nid,
int8_t ppm_step);
#else /* ENA_SYNC_DIFF_CCO_PPM */
#define mac_multi_sync_init(pdev_id)
#define mac_multi_ppm_record(pdev_id, nid, my_nid, rate_mode, \
r_ts, l_ts, l_ntb, min_update_period, ppm_err) (ERR_FAIL)
#define mac_multi_sync_nid_timeout_clear(pdev_id)
#define mac_myntb_to_other_ntb(pdev_id, nid, array, len) (ERR_FAIL)
#define mac_other_ntb_to_myntb(pdev_id, nid, array, len) (ERR_FAIL)
#define mac_multi_sync_get_ena(pdev_id) (0)
#define mac_multi_sync_set_ena(pdev_id, enable)
#define mac_multi_sync_get_ppm(pdev_id, nid) (PLC_MAX_MAC_NTB_PPM)
#define mac_multi_sync_apply_new_ppm_step(pdev_id, nid, ppm_step)
#endif
#ifdef __cplusplus
}
#endif
#endif