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

213 lines
7.1 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 _MAC_ZC_H_
#define _MAC_ZC_H_
/* common */
#include "os_types.h"
#include "iot_pkt.h"
#include "os_timer.h"
#include "plc_protocol.h"
#include "iot_config.h"
/* mac layer */
#include "plc_mac_cfg.h"
#include "mac_dsr.h"
#include "mac.h"
#include "mac_vdev.h"
#include "mac_zc_api.h"
#ifdef __cplusplus
extern "C" {
#endif
/* enable/disbale mac zc start follow vdev (for sta) */
#define MAC_ZC_START_FOLLOW_VDEV \
(0 && (TARGET_VERSION >= TARGET_KUNLUN3))
/* mac zc support max num, same as mac pdev num */
#define MAC_ZC_NUM_MAX MAX_PDEV_NUM
/* mac zc support phase line */
#define MAC_ZC_PHASE_A 0
#define MAC_ZC_PHASE_B 1
#define MAC_ZC_PHASE_C 2
#define MAC_ZC_PHASE_ALL 3
#define MAC_ZC_PHASE_CNT 3
/* mac zc ntb get pkt distribution
* GET_RESV + RPT_HEAD + RPT_NTB_DATA
*/
/* mac zc ntb get pkt reserve length */
#define MAC_ZC_NTB_GET_RESV_SIZE sizeof(mac_zc_ntb_get_para_t)
/* mac zc ntb get reserve + rpt_header length */
#define MAC_ZC_NTB_RESV_HEAD_SIZE \
(sizeof(mac_zc_ntb_get_para_t) + sizeof(mac_zc_ntb_rpt_t))
#define MAC_ZC_RPT_PKT_GET(pkt, ntb_cnt, mid) \
IOT_PKT_GET(pkt, MAC_ZC_NTB_RESV_HEAD_SIZE + ((ntb_cnt) \
* sizeof(uint32_t)), MAC_ZC_NTB_GET_RESV_SIZE, mid)
/* set mac zc function command id */
typedef enum _mac_zc_func_cmd_id {
/* indicate mac zc reset hw, then re-training */
MAC_ZC_FUNC_CMD_RESET_HW = 0,
/* indicate mac zc stop collect */
MAC_ZC_FUNC_CMD_COLLECT_STOP,
/* indicate mac zc delay reset hw */
MAC_ZC_FUNC_CMD_DELAY_RESET_HW,
/* notification ntb stabilization */
MAC_ZC_FUNC_CMD_NTB_STABLE_NOTIF,
/* mac zc set command id max */
MAC_ZC_FUNC_CMD_ID_MAX,
} mac_zc_func_cmd_id_t;
/* mac dsr set entry function address */
typedef void (*mac_zc_dsr_set_entry_fn_t)(void *table, \
uint8_t dsr_id, void *entry);
/* mac dsr clean function address */
typedef void (*mac_zc_dsr_clr_fn_t)(uint32_t dsr_id);
/* zero-cross ntb get api parameter */
typedef struct _mac_zc_ntb_get_para {
/* get ntb count */
uint32_t count :16,
/* indicate get zc ntb is full period or half period.
* 1: full period; 0: half period
*/
is_full_period :1,
/* indicate get zc ntb is history or current ntb.
* 1: history ntb; 0: current ntb
*/
is_get_history :1,
rsvd0 :14;
/* indicate get targe network id, if the value is INVALID_NID, it is
* represented as current network
*/
uint32_t nid :24,
rsvd1 :8;
/* indicate get target history ntb. if is_get_history is false, then not
* care this parameter
*/
uint32_t ntb;
} mac_zc_ntb_get_para_t;
#if !MAC_ZC_ENABLE
#define mac_zc_systic_trig()
#define mac_zc_train_hw_timeout_internal(id, arg)
#define mac_start_zc_ntb_collect_internal(pdev_id, vdev_id, pkt) \
(ERR_NOSUPP); \
do { \
(void)pdev_id; \
(void)vdev_id; \
(void)pkt; \
} while(0)
#define mac_zc_set_func_cmd_internal(zc_id, cmd, arg)
#define mac_zc_set_func_cmd(zc_id, cmd, arg)
#else //!MAC_ZC_ENABLE
/*
* @brief get mac zero-cross ntb data
* @param id: which pdev to be collected
* @param rpt: report mac zc data parameter
* @param count: number of consecutive zero-cross ntb to be collected
* @param is_full_period: flag to mark if it is collecting full period.
* @param is_history_ntb: flag to mark if it is collecting history ntb.
* @param nid: target network id, 0: means local network id
* @param ntb: target historical zc ntb that needs to be collected
*
* @retval: error code,see ERR_XXX
*/
uint32_t mac_zc_get_ntb(uint8_t id, mac_zc_ntb_rpt_t *rpt,
uint16_t count, uint8_t is_full_period, uint8_t is_history_ntb,
uint32_t nid, uint32_t ntb);
/**
* @brief triger mac zc by system timer
* @retval: none
*/
void mac_zc_systic_trig(void);
/**
* @brief mac_zc_train_hw_timeout_internal
* @param id: timer id
* @param arg: timer callback fn arg(zc ptr)
* @retval: none
*/
void mac_zc_train_hw_timeout_internal(uint32_t id, void *arg);
/*
* @brief start mac layer zero-cross ntb collection. this
* function is similar to mac_start_zc_ntb_collect
* but can only be called inside mac context.
* @param pdev_id: which pdev to be collected
* @param vdev_id: which vdev to be collected
* @param pkt: get zc parameter in the reserve block, and the
* result will fill data block.
*
* @retval: 0 - for success case
* @retval: othersie - error code
*/
uint32_t mac_start_zc_ntb_collect_internal(uint8_t pdev_id, uint8_t vdev_id,
iot_pkt_t *pkt);
/*
* @brief set zc function cmd message
* @param zc_id: which pdev's zc to set
* @param cmd: set command, see mac_zc_func_cmd_id_t.
* @param arg: command parameter.
* @retval: none
*/
void mac_zc_set_func_cmd_internal(uint8_t zc_id, uint8_t cmd, void *arg);
/*
* @brief set zc function cmd message
* @param zc_id: which pdev's zc to set
* @param cmd: set command, see mac_zc_func_cmd_id_t.
* @param arg: command parameter.
* @retval: none
*/
void mac_zc_set_func_cmd(uint8_t zc_id, mac_zc_func_cmd_id_t cmd, void *arg);
#endif //!MAC_ZC_ENABLE
/*
* @brief initialize mac zc system
*
* @param id: mac zc pdev id
* @param task_hdl: current task handle ctxt
* @param dsr_tbl: current task dsr function table entry address
* @param dsr_set_fn: current taks set dsr function address
* @param dsr_clr_fn: current taks clear dsr function address
*
* @retval 0: for success case
* othersie: error code
*/
uint32_t mac_zc_system_init(uint8_t id, void *task_hdl, void *dsr_tbl,
void *dsr_set_fn, void *dsr_clr_fn);
#ifdef __cplusplus
}
#endif
#endif //_MAC_ZC_H_