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

277 lines
10 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_BWM_INTERNAL_H
#define CVG_BWM_INTERNAL_H
/* os shim includes */
#include "os_types.h"
#include "os_timer_api.h"
/* public api includes */
#include "cvg_api.h"
#include "plc_fr.h"
#include "mac_bcm_api.h"
/* cvg module internal includes */
#include "cvg.h"
#ifdef __cplusplus
extern "C" {
#endif
/* define beacon period region info */
#define CVG_BWM_REG_BC 0 /* beacon region */
#define CVG_BWM_REG_CSMA 1 /* csma region */
#define CVG_BWM_REG_TDMA 2 /* tdma region */
#define CVG_BWM_REG_DCSMA 3 /* dedicated csma region */
#define CVG_BWM_REG_CNT 4 /* max number of region count in one bp */
/* define bandwidth management state, different state may have different
* bandwidth configuration. beacon and csma region are always enabled.
*/
/* invalid state */
#define CVG_BWM_S_INVALID 0
/* network established and only csma region required */
#define CVG_BWM_S_CSMA_ONLY 1
/* network established and tdma region required */
#define CVG_BWM_S_TDMA_EN 2
/* network established and dedicated csma region required */
#define CVG_BWM_S_DCSMA_EN 3
/* network established and both tdma and dedicated csma region required */
#define CVG_BWM_S_TDMA_DCSMA_EN 4
/* max number of state */
#define CVG_BWM_S_CNT 4
typedef struct _cvg_bwm_bw_ratio {
/* ratio of each region. The sum of each region ratio must be 100.
* see CVG_BWM_REG_XXX for the region definition.
*/
uint8_t ratio[CVG_BWM_REG_CNT];
/* minimum ratio of each phase in csma region. if csma region acquired
* 50% of a whole beacon period and the minimum ratio of each phase is
* 10%, then each phase in csma region will have at least 5% of the whole
* beacon period. this is not applicable to dedicated csma region.
*/
uint8_t csma_ratio_per_phase_min;
} cvg_bwm_bw_ratio_t;
typedef struct _cvg_bwm_cco_vdev {
/* ratio table of each state */
cvg_bwm_bw_ratio_t ratio_tab[CVG_BWM_S_CNT];
/* the last update time of the frequency change information */
uint64_t fb_chg_last_ts;
/* time left of frequency band change */
uint32_t fb_chg_left;
/* delay for each frequency band switch request, unit is 1ms */
uint32_t fb_chg_delay;
/* the last update time of the rf channel change information */
uint64_t rf_chg_last_ts;
/* time left of rf channel change */
uint32_t rf_chg_left;
/* delay for each rf channel switch request, unit is 1ms */
uint32_t rf_chg_delay;
/* current beacon period duration */
uint32_t curr_bc_period;
/* next beacon period duration */
uint32_t next_bc_period;
/* current min allowed bc period, uint is 1ms */
uint32_t min_bc_period;
/* protocol max allowed bc period, uint is 1ms */
uint32_t max_bc_period;
/* current bandwidth state */
uint8_t curr_state;
/* next bandwidth state */
uint8_t next_state;
/* current max allowed bc slot count */
uint8_t max_bc_slot;
/* current max allowed beacon region duratio */
uint16_t max_bc_dur;
/* current min required csma regtion duration */
uint16_t min_csma_dur;
/* current min required tdma regtion duration */
uint16_t min_tdma_dur;
/* current min required dedicated csma regtion duration */
uint16_t min_dcsma_dur;
/* next beacon slot duration, unit is 1ms */
uint8_t next_bc_slot_dur;
/* tei start from which to search next discovery beacon sta */
tei_t d_tei;
/* level start from which to search next discovery beacon sta */
uint8_t d_level;
/* number of times stay in current search start point for next discovery
* beacon sta.
*/
uint8_t d_cnt;
/* tei start from which to search next discovery beacon rf sta */
tei_t d_rf_tei;
/* level start from which to search next discovery beacon rf sta */
uint8_t d_rf_level;
/* number of times stay in current search start point for next discovery
* beacon rf sta.
*/
uint8_t d_rf_cnt;
/* link id of the tdma region */
uint8_t tdma_lid;
/* link id of the dedicated csma region */
uint8_t dcsma_lid;
/* current dcsma bind phase */
uint8_t dcsma_phase :2,
/* flag to mark if CCO device uses csma 1ms unit */
csma_1ms :1,
/* flag to mark if CCO device enlarge hplc bc slot duration by payload size
*/
bc_slot_enlarge_by_pld :1,
/* flag to mark if CCO device enlarge hplc bc slot duration by topo level */
bc_slot_enlarge_by_level :1,
/* flag to mark if rf channel change is initiated by internal module */
rf_chg_inner :1,
/* flag to mark if CCO device using minimum beacon payload size */
bc_pld_min :1,
/* reserved for future */
rsvd :1;
/* flag to mark if csma solt average distribution of each phase is enabled
*/
uint8_t csma_slot_average;
/* the ratio of rf beacon slot duration to hplc beacon slot duration */
uint8_t rf_ts_ratio;
/* time stamp of last time CCO device enlarge hplc bc slot, uint is 1s */
uint32_t bc_slot_enlarge_ts;
} cvg_bwm_cco_vdev_t;
/* per vdev bandwidth management descriptor */
typedef struct _cvg_bwm_vdev {
/* pointer of cvg vdev */
cvg_vdev_t *vdev;
/* time slot assignment info */
mac_bc_time_slot_t ts;
/* frequency change notification assignment info */
mac_bc_freq_chg_t fb_chg;
/* timer for frequency change left time */
timer_id_t fb_chg_timer;
/* currently used frequency band ID */
uint8_t fb_id;
/* frequency change target ID */
uint8_t fb_target_id;
/* rf channel change notification assignment info */
mac_bc_rf_channel_chg_t rf_chg;
/* timer for rf channel change left time */
timer_id_t rf_chg_timer;
/* currently used rf channel */
uint8_t rf_channel;
/* rf channel change target ID */
uint8_t rf_target_channel;
/* rf option change target ID, see RF_OPTION_XXX */
uint8_t rf_target_option;
/* currently used rf option, see RF_OPTION_XXX */
uint8_t rf_option;
/* flag to mark if time slot info changed */
uint8_t ts_updated :1,
/* flag to mark if frequency band change info changed */
fb_chg_updated :1,
/* flag to mark if band locked */
fb_lock :1,
/* flag to mark if rf channel and option change info changed */
rf_chg_updated :1,
/* flag to mark if rf channel and option locked */
rf_lock :1,
/* flag to mark if binding csma or tdma lid is updated */
lid_updated :1,
/* reserved for further use */
reserved :2;
/* rf channel changed detection count */
uint8_t rf_chg_cnt;
/* pointer CCO proprietary bwm structure */
cvg_bwm_cco_vdev_t *cco;
} cvg_bwm_vdev_t;
#if (CVG_BWM_DEBUG)
/* debug funtion to dump time slot info */
void cvg_bwm_dump_ts(cvg_vdev_t *vdev, mac_bc_time_slot_t *ts);
#else /* CVG_BWM_DEBUG */
#define cvg_bwm_dump_ts(vdev, ts)
#endif /* CVG_BWM_DEBUG */
/**
* @brief cvg_bwm_restart_fb_chg_timer() - restart freq band change timer.
* @param bwm: pointer to bwm
* @param dur: duration, uint is 1ms.
*/
void cvg_bwm_restart_fb_chg_timer(cvg_bwm_vdev_t *bwm, uint32_t dur);
#if (PLC_SUPPORT_CCO_ROLE)
/*
* cvg_bwm_cco_reset_vdev() - bwm cco vdev reset function
* @bwm: bwm vdev pointer
* @cfg: pointer of vdev configuration
*/
void cvg_bwm_cco_reset_vdev(cvg_bwm_vdev_t *bwm, cvg_vdev_cfg_t *cfg);
/*
* cvg_bwm_cco_init_vdev() - bwm cco vdev init function
* @bwm: bwm vdev pointer
* @cfg: pointer of vdev configuration
*
* return:
* 0 -- for success case
* otherwise -- error code
*/
uint32_t cvg_bwm_cco_init_vdev(cvg_bwm_vdev_t *bwm, cvg_vdev_cfg_t *cfg);
/*
* cvg_bwm_cco_deinit_vdev() - bwm cco vdev deinit function
* @bwm: bwm vdev pointer
*/
void cvg_bwm_cco_deinit_vdev(cvg_bwm_vdev_t *bwm);
/**
* @brief cvg_bwm_cco_set_fb() - set new frequency band ID for CCO.
* @param bwm: pointer to bwm
* @param freq_band_id: new frequency band ID to be set.
* @retval: 0 -- for success case
* @retval: otherwise -- error code
*/
uint32_t cvg_bwm_cco_set_fb(cvg_bwm_vdev_t *bwm, uint8_t freq_band_id);
#else
#define cvg_bwm_cco_reset_vdev(bwm, cfg)
#define cvg_bwm_cco_init_vdev(bwm, cfg) (ERR_NOSUPP)
static inline uint32_t cvg_bwm_cco_set_fb(cvg_bwm_vdev_t *bwm,
uint8_t freq_band_id)
{
(void)bwm;
(void)freq_band_id;
return ERR_NOSUPP;
}
#define cvg_bwm_cco_deinit_vdev(bwm)
#endif /* PLC_SUPPORT_CCO_ROLE */
#ifdef __cplusplus
}
#endif
#endif /* CVG_BWM_INTERNAL_H */