390 lines
12 KiB
C
390 lines
12 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 HW_TONEMAP_H
|
|
#define HW_TONEMAP_H
|
|
|
|
#include "os_types.h"
|
|
#include "iot_config.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/*expression:
|
|
* carrier_num : band0, 411. band1, 131.
|
|
* valid_carrier_num = floor(carrier_num/internum,1)*internum
|
|
* symbol_num =
|
|
* (pbsize * 8 * copy_num)/modulation_bits/turborate/valid_carrier_num
|
|
*/
|
|
#define OFDM_SYMBOL_PER_PB( \
|
|
PB_SIZE, ROBO, TurboRate, Modulation, valid_tone_num, InterNum) \
|
|
iot_ceil(((PB_SIZE) * 8 * (ROBO)), \
|
|
((TurboRate) * (Modulation) * \
|
|
(((valid_tone_num/InterNum*InterNum)!=0)? \
|
|
(valid_tone_num/InterNum*InterNum):valid_tone_num)))
|
|
|
|
#define GI_MINI_ROBO 567
|
|
#define GI_HS_ROBO 417
|
|
#define GI_STD_ROBO 417
|
|
#define GI_SG_ROBO_LONG 458
|
|
#define GI_SG_ROBO_SHORT 264
|
|
|
|
#define FRAME_LENGTH_PER_PB_GP(OFDM_SYMBOL_PER_PB_VAL, GI) \
|
|
(((OFDM_SYMBOL_PER_PB_VAL) * 3072 \
|
|
+ GI * ((OFDM_SYMBOL_PER_PB_VAL) - 2) \
|
|
+ 2 * GI_MINI_ROBO) \
|
|
/ (75))
|
|
|
|
/*expression:
|
|
* fl = (symnum * 1024 + GI * (symnum - 2) + 2*458)/25
|
|
*/
|
|
#define FRAME_LENGTH_PER_PB_GW(OFDM_SYMBOL_PER_PB_VAL, GI) \
|
|
(((OFDM_SYMBOL_PER_PB_VAL) * 1024 \
|
|
+ GI * ((OFDM_SYMBOL_PER_PB_VAL) - 2) \
|
|
+ 2 * GI_SG_ROBO_LONG) \
|
|
/ (25))
|
|
|
|
#define DELIMITER_LENGTH_AV(AV_FC_SYMBOL_num, HP101_num, Preamble_sample) \
|
|
(((AV_FC_SYMBOL_num) * (3072 + 1374) + \
|
|
(HP101_num) * 2892 + (Preamble_sample)))
|
|
|
|
#define PREAMBLE_NUM 13
|
|
|
|
/*expression:
|
|
* preamble = (preamble_num * 40.96 + (FC_num * (3072 + 1374) / 75))
|
|
*/
|
|
#define DELIMITER_LENGTH_SG(FC_num) \
|
|
(PREAMBLE_NUM * 40.96 + (FC_num * (3072 + 1374) / 75))
|
|
|
|
#define PB_SIZE_16 16
|
|
#define PB_SIZE_40 40
|
|
#define PB_SIZE_72 72
|
|
#define PB_SIZE_136 136
|
|
#define PB_SIZE_264 264
|
|
#define PB_SIZE_520 520
|
|
#define PB_SIZE_INV 0
|
|
|
|
#define ROBO_COPY_1 1
|
|
#define ROBO_COPY_2 2
|
|
#define ROBO_COPY_3 3
|
|
#define ROBO_COPY_4 4
|
|
#define ROBO_COPY_5 5
|
|
#define ROBO_COPY_6 6
|
|
#define ROBO_COPY_7 7
|
|
#define ROBO_COPY_11 11
|
|
|
|
|
|
/* Modulation has a relation to BPC
|
|
* Mapping for BPSK, QPSK, 8-QAM, 16-QAM,
|
|
* 64-QAM, 256-QAM, 1024-QAM, The Mapper
|
|
* takes 1, 2, 3, 4, 6, 8, or 10 bits
|
|
*/
|
|
#define MODULATION_BPSK 1
|
|
#define MODULATION_QPSK 2
|
|
#define MODULATION_8QAM 3
|
|
#define MODULATION_16QAM 4
|
|
|
|
#define CODING_RATE_1_2 0
|
|
#define CODING_RATE_16_18 1
|
|
#define CODING_RATE_4_5 2
|
|
|
|
#define MAX_PB_NUM_1 1
|
|
#define MAX_PB_NUM_2 2
|
|
#define MAX_PB_NUM_3 3
|
|
#define MAX_PB_NUM_4 4
|
|
|
|
#define SG_TMI_MAX 15
|
|
#define SG_EXT_TMI_MAX 15 // start from 1, id:{0,7,8,9} is not used
|
|
|
|
#define SPG_TMI_MAX 13 // start from 0, id:{2,11,12} is not used
|
|
#define SPG_EXT_TMI_MAX 15 // start from 1, id:{0,7,8,9} is not used
|
|
|
|
#define GP_TMI_MAX 3 // start from 0
|
|
|
|
#define I1901_TMI_MAX 13 //start from 0
|
|
#define I1901_EXT_TMI_MAX 11 //start from 0
|
|
#define I1901_IS_EXT_TMI_MODE 1
|
|
|
|
/* max tmi and max band in all proto */
|
|
#define SG_OFDM_MAX (SG_TMI_MAX + SG_EXT_TMI_MAX) //tmi + ext_tmi
|
|
#define SPG_OFDM_MAX (SPG_TMI_MAX + SPG_EXT_TMI_MAX)
|
|
#define GP_OPDM_MAX (GP_TMI_MAX)
|
|
|
|
#define INTER_1 1
|
|
#define INTER_2 2
|
|
#define INTER_4 4
|
|
#define INTER_6 6
|
|
#define INTER_8 8
|
|
#define INTER_10 10
|
|
#define INTER_11 11
|
|
#define INTER_14 14
|
|
|
|
/* rate table related */
|
|
#define INV_IDX 0x1F /* 5bit */
|
|
#define INV_TMI INV_IDX
|
|
#define INV_ETMI INV_TMI
|
|
#define INV_KBPS 0
|
|
#define MAX_RATE_IDX 0x1ff /* 9bits long */
|
|
|
|
#define TMI2IDX(tmi, etmi, maxtmi) \
|
|
((tmi>=0&&tmi<=(maxtmi))?((tmi<(maxtmi))?tmi:((maxtmi)+etmi)):INV_IDX)
|
|
#define SGTMI2IDX(tmi, etmi) TMI2IDX(tmi, etmi, SG_TMI_MAX)
|
|
#define NWTMI2IDX(tmi, etmi) TMI2IDX(tmi, etmi, SPG_TMI_MAX)
|
|
#define I1901TMI2IDX(tmi, etmi) SGTMI2IDX(tmi, etmi)
|
|
|
|
#define IDX2TMI(IDX,maxtmi) \
|
|
((IDX>=0&&IDX<=31)?((IDX<(maxtmi))?IDX:(maxtmi)):INV_TMI)
|
|
#define SGIDX2TMI(IDX) IDX2TMI(IDX,SG_TMI_MAX)
|
|
#define NWIDX2TMI(IDX) IDX2TMI(IDX,SPG_TMI_MAX)
|
|
|
|
#define IDX2ETMI(IDX,maxtmi) \
|
|
((IDX>=0&&IDX<=31)?((IDX<(maxtmi))?0:IDX-(maxtmi)):INV_ETMI)
|
|
#define SGIDX2ETMI(IDX) IDX2ETMI(IDX,SG_TMI_MAX)
|
|
#define NWIDX2ETMI(IDX) IDX2ETMI(IDX,SPG_TMI_MAX)
|
|
|
|
#define RAGET4(_TBL,IDX,_TBLITEM) _TBL[IDX]._TBLITEM
|
|
#define RAGET_THRE(IDX) RAGET4(g_ra_tbl,IDX,snr_thre)
|
|
#define RAGET_PRID(_PRO,IDX) \
|
|
((_PRO == PLC_PROTO_TYPE_SG) ? (SUPPORT_IEEE_1901 ? \
|
|
RAGET4(g_ra_tbl, IDX, i1901_idx) : \
|
|
RAGET4(g_ra_tbl, IDX, sg_idx)): \
|
|
(_PRO == PLC_PROTO_TYPE_SPG) ? RAGET4(g_ra_tbl, IDX, nw_idx) : 0)
|
|
#define RAGET_TP(IDX) RAGET4(g_ra_tbl,IDX,kbps)
|
|
#define RAGET_ENA(IDX) RAGET4(g_ra_tbl,IDX,enabled)
|
|
#define RAGET_BAND(IDX) RAGET4(g_ra_tbl,IDX,band_id)
|
|
/*
|
|
* tonemap table entry
|
|
*/
|
|
typedef struct _tonemap_table_entry {
|
|
uint32_t pb_size : 10,
|
|
robo_cnt : 4,
|
|
modulation : 3,
|
|
coding_rate_idx : 1,
|
|
max_pb_num : 3;
|
|
} tonemap_table_entry;
|
|
|
|
/* for SG/NW used only */
|
|
typedef struct _robo_inter_table_entry {
|
|
uint32_t robo_cpy : 16,
|
|
inter_num : 16;
|
|
} robo_inter_table_entry;
|
|
|
|
/*
|
|
* universal rate table start
|
|
*/
|
|
typedef struct _rate_tbl_entry {
|
|
uint32_t
|
|
sg_idx : 5,
|
|
nw_idx : 5,
|
|
i1901_idx : 5,
|
|
kbps : 17; /* 262Mbps max */
|
|
int8_t snr_thre; /* snr threshold required for this rate */
|
|
uint8_t
|
|
band_id : 5, /* band id bitmap,band0 is 1,band1 is 2,... */
|
|
enabled : 3;
|
|
} rate_tbl_entry_t;
|
|
|
|
typedef struct _fix_rate_tbl_entry {
|
|
uint8_t bcn_136_idx;
|
|
uint8_t bcn_520_idx;
|
|
uint8_t sof_72_idx;
|
|
uint8_t sof_136_idx;
|
|
uint8_t sof_264_idx;
|
|
uint8_t sof_520_idx;
|
|
uint8_t sof_1040_idx;
|
|
uint8_t sof_1560_idx;
|
|
uint8_t sof_2080_idx;
|
|
} fix_rate_tbl_entry_t;
|
|
|
|
typedef struct _rate_table {
|
|
rate_tbl_entry_t *tmi_pb_kbps;
|
|
uint32_t rate_num;
|
|
} rate_table_t;
|
|
|
|
extern const rate_tbl_entry_t g_ra_tbl[];
|
|
extern const fix_rate_tbl_entry_t g_fix_ra_tbl[];
|
|
extern const fix_rate_tbl_entry_t g_fix_mid_ra_tbl[];
|
|
extern const fix_rate_tbl_entry_t g_fix_high_ra_tbl[];
|
|
|
|
/*
|
|
* universal rate table end
|
|
*/
|
|
|
|
/* get the pb_size - 72, 136, 264, 520
|
|
* if tmi = 15, then use ext_tmi
|
|
* @tmi (IN) - tmi in FC
|
|
* @ext_tmi (IN) - tmi in FC
|
|
* @pb_size (OUT) - output the pb_size
|
|
* return 0 if successful
|
|
*/
|
|
uint32_t phy_get_pb_size(uint32_t proto, uint32_t tmi, uint32_t ext_tmi, \
|
|
uint32_t *pb_size);
|
|
|
|
/**
|
|
*@brief phy_get_pss_id get phy pilot symbols index.
|
|
*@param proto 0:sg, 1:gp, 3:spg.
|
|
*@param tmi tmi in FC 0-14.
|
|
*@param ext_tmi ext tmi in FC 1-6 10-14.
|
|
*@return pilot symbols index id.
|
|
*/
|
|
uint8_t phy_get_pss_id(uint32_t proto, uint32_t tmi, uint32_t ext_tmi);
|
|
|
|
/**
|
|
*@brief phy_get_sym_per_pb get sym num per pb.
|
|
*@param proto 0:sg, 1:gp, 3:spg.
|
|
*@param hw_band_id band id 0-1-2.
|
|
*@param tmi tmi in FC 0-14.
|
|
*@param ext_tmi ext tmi in FC 1-6 10-14.
|
|
*@param pss pilot symbols index id
|
|
*@return sym num per pb.
|
|
*/
|
|
uint32_t phy_get_sym_per_pb(uint32_t proto, uint32_t hw_band_id,
|
|
uint32_t tmi, uint32_t ext_tmi, uint8_t pss);
|
|
|
|
/**
|
|
*@brief phy_get_fl_per_pb get frame len us.
|
|
*@param proto 0:sg, 1:gp, 3:spg.
|
|
*@param hw_band_id band id 0-1-2.
|
|
*@param tmi tmi in FC 0-14.
|
|
*@param ext_tmi ext tmi in FC 1-6 10-14.
|
|
*@return frame len per pb.
|
|
*/
|
|
uint32_t phy_get_fl_per_pb(uint32_t proto, uint32_t hw_band_id, \
|
|
uint32_t tmi, uint32_t ext_tmi);
|
|
|
|
/* get modulation from TMI */
|
|
uint32_t phy_get_pb_mod(uint32_t proto, uint32_t tmi, uint32_t ext_tmi, \
|
|
uint32_t *pb_mod);
|
|
|
|
/* get inter num for each robo cpy */
|
|
uint32_t phy_get_robo_inter(uint32_t robo_cnt, uint32_t *robo_inter);
|
|
|
|
/**
|
|
*@brief get max tmi idx for different proto
|
|
* currently, only SG and NW/PSG has
|
|
* tmi and ext tmi format, GP has
|
|
* only one table, so just return the table's
|
|
* size
|
|
*
|
|
*@param proto [plc protocol]
|
|
*@exception [none]
|
|
*@return [max tmi value or 0 if not supported proto]
|
|
*/
|
|
uint32_t phy_get_max_tmi(uint32_t proto);
|
|
|
|
/**
|
|
*@brief get max estmi idx for different proto
|
|
* currently, only SG and NW/PSG has
|
|
* tmi and ext tmi format, GP has
|
|
* only one table, so just return the table's
|
|
* size
|
|
*
|
|
*@param proto [plc protocol]
|
|
*@exception [none]
|
|
*@return [max etmi value or 0 if not supported proto]
|
|
*/
|
|
uint32_t phy_get_max_etmi(uint32_t proto);
|
|
|
|
uint8_t phy_get_rt_sz();
|
|
|
|
/**
|
|
*@brief get tmi ext tmi from idx for different proto
|
|
* currently, only SG and NW/PSG has
|
|
* tmi and ext tmi format, GP has
|
|
* only one table, so return tmi for it's index
|
|
*
|
|
*@param proto [plc protocol]
|
|
*@param rid [rate tbl index]
|
|
*@param tmi [tmi for return]
|
|
*@param etmi [ext tmi for return]
|
|
*@exception [none]
|
|
*@return [max tmi value or 0 if not supported proto]
|
|
*/
|
|
uint32_t phy_get_tmi_by_rid(uint32_t proto, uint8_t rid, uint32_t *tmi, \
|
|
uint32_t *etmi);
|
|
|
|
uint32_t phy_get_rt_pbsz(uint32_t proto, uint8_t rid, uint32_t *pbsz);
|
|
|
|
/**
|
|
*@brief phy_find_rid_by_tmi. get rate id by tmi and ext_tmi
|
|
*
|
|
*@param proto [plc protocol]
|
|
*@param band_id [proto_bandid]
|
|
*@param rid [rate tbl index]
|
|
*@param tmi [tmi for return]
|
|
*@param etmi [ext tmi for return]
|
|
*@exception [none]
|
|
*@return [0 ok or 1 if not supported proto ]
|
|
*/
|
|
uint32_t phy_find_rid_by_tmi(uint32_t proto, uint32_t band_id,\
|
|
uint32_t *rid, uint32_t tmi, uint32_t etmi);
|
|
|
|
|
|
/**
|
|
*@brief phy_symppb_flppb_init initial symppb and flppb.
|
|
*@param proto proto: 0:sg
|
|
*@return 0: ok
|
|
*/
|
|
uint32_t phy_symppb_flppb_init(uint32_t proto);
|
|
|
|
/**
|
|
*@brief phy_get_symppb_from_table get symppb.
|
|
*@param hw_band_id band id 0-1-2
|
|
*@param tmi tmi 0-14 ext_tmi 1-6 10-14
|
|
*@param etmi etmi 1-6 10-14
|
|
*@return 0: ok
|
|
*/
|
|
uint32_t phy_get_symppb_from_table(uint32_t hw_band_id, \
|
|
uint32_t tmi, uint32_t etmi);
|
|
|
|
/**
|
|
*@brief phy_get_flppb_from_table get flppb.
|
|
*@param hw_band_id band id 0-1-2
|
|
*@param tmi tmi 0-14 ext_tmi 1-6 10-14
|
|
*@param etmi etmi 1-6 10-14
|
|
*@return 0: ok
|
|
*/
|
|
uint32_t phy_get_flppb_from_table(uint32_t hw_band_id, \
|
|
uint32_t tmi, uint32_t etmi);
|
|
|
|
/**
|
|
*@brief phy_tmi_i1901_to_sg convert tmi ieee1901 to sg
|
|
*@param i1901_tmi ieee1901 tmi value, 0~12
|
|
*@param i1901_tmi_ext ieee1901 tmi ext value, 0 or 1
|
|
*@param sg_tmi sg tmi value, 0~14
|
|
*@param sg_tmi_ext sg tmi ext value, 1-6 10-14
|
|
*@return error code, see ERR_XXX
|
|
*/
|
|
uint32_t phy_tmi_i1901_to_sg(uint32_t i1901_tmi, uint32_t i1901_tmi_ext,
|
|
uint32_t *sg_tmi, uint32_t *sg_tmi_ext);
|
|
|
|
/**
|
|
*@brief phy_tmi_sg_to_i1901 convert tmi ieee1901 to sg
|
|
*@param sg_tmi sg tmi value, 0~14
|
|
*@param sg_tmi_ext sg tmi ext value, 1-6 10-14
|
|
*@param i1901_tmi ieee1901 tmi value, 0~12
|
|
*@param i1901_tmi_ext ieee1901 tmi ext value, 0 or 1
|
|
*@return error code, see ERR_XXX
|
|
*/
|
|
uint32_t phy_tmi_sg_to_i1901(uint32_t sg_tmi, uint32_t sg_tmi_ext,
|
|
uint32_t *i1901_tmi, uint32_t *i1901_tmi_ext);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // !HW_TONEMAP_H
|