*add calibration setting

This commit is contained in:
bit-cyber-fh
2024-04-02 00:04:21 +08:00
parent 06169451f8
commit bbdaa49d53
5 changed files with 368 additions and 87 deletions
@@ -1,20 +1,16 @@
/*****************************************************************************/
/**
* Description: Antenna configuration functions.
* @file phy_antenna.h
* @author FanHao ([email protected])
* @brief Physical layer control antenna configuration functions.
* @version 0.0
* @date 2023-04-24
*
* Author: Fan Hao
* Date: 2022-06-18 16:37
* LastEditors: Fan Hao
* LastEditTime: 2022-06-18 17:15
* Revisions: Rev 0.0
* History:
* [2024-01-20]: New branch for duifei.
* [2022-06-18]: Initial version.
*
* Copyright(c) 2022 Beijing Institute of Technology.
* Lab of Communication and Networking
* @copyright Copyright(c) 2024 Beijing Institute of Technology.\n
* Lab of Communication and Network
*
******************************************************************************/
/**
* @addtogroup PhysicalLayer
* @{
@@ -71,62 +67,123 @@
// Pair by regex
// Regex: (([0-9]+, ){8})
const uint16_t hopPattern_2KBPS_20MS[L1_FRAME_2KBPS_20MS_HOPS] =
const uint16_t freqTable[L1_FRAME_MAX_HOPS] =
{
1500
1084, 1097, 1110, 1123, 1136, 1149, 1162, 1175,
1188, 1201, 1214, 1227, 1240, 1253, 1266, 1279,
1292, 1305, 1318, 1331, 1344, 1357, 1370, 1383,
1396, 1409, 1422, 1435, 1448, 1461, 1474, 1487,
1500, 1513, 1526, 1539, 1552, 1565, 1578, 1591,
1604, 1617, 1630, 1643, 1656, 1669, 1682, 1695,
1708, 1721, 1734, 1747, 1760, 1773, 1786, 1799,
1812, 1825, 1838, 1851, 1864, 1877, 1890, 1903,
1916, 1929, 1942, 1955, 1968, 1981, 1994, 2007,
2020, 2033, 2046, 2059, 2072, 2085, 2098, 2111,
2124
}
const uint16_t antCalTable[L1_FRAME_MAX_HOPS][L1_ANT_NUM_CH] =
//Antenna-JG01
{
{ 0, 2525, -7533, -6846}, { 0, 12726, -7818, -6860},
{ 0, 2490, -7836, -6907}, { 0, 4479, -7716, -6837},
{ 0, 6409, -7770, -6776}, { 0, 14616, -7977, -6816},
{ 0, -22557, -8002, -6911}, { 0, -22587, -8121, -6918},
{ 0, -1124, -8123, -7030}, { 0, -152, -8219, -7042},
{ 0, 1823, -8209, -7130}, { 0, 1790, -8290, -7214},
{ 0, 1669, -8362, -7283}, { 0, 1634, -8459, -7276},
{ 0, 1615, -8315, -7415}, { 0, 1698, -8168, -7366},
{ 0, 1535, -8285, -7520}, { 0, 1619, -8285, -7532},
{ 0, 1609, -8201, -7693}, { 0, 1671, -8145, -7769},
{ 0, 1676, -8135, -7805}, { 0, 951, -10279, -8871},
{ 0, 976, -10235, -8978}, { 0, 1118, -10127, -9019},
{ 0, 1175, -10003, -9007}, { 0, 1386, -9847, -9039},
{ 0, 1535, -9572, -9058}, { 0, 1729, -9493, -9006},
{ 0, -1158, -9312, -9003}, { 0, 23771, -9147, -8928},
{ 0, 20733, -9074, -8924}, { 0, 2455, -8841, -8886},
{ 0, 2622, -8718, -8735}, { 0, 2791, -8615, -8705},
{ 0, 2861, -8168, -8331}, { 0, 3076, -8091, -8218},
{ 0, 3257, -8046, -8100}, { 0, 3331, -7923, -8073},
{ 0, 3396, -7826, -7994}, { 0, 3478, -7842, -8016},
{ 0, 3518, -7846, -7765}, { 0, 3585, -7753, -7715},
{ 0, 150, -8145, -8591}, { 0, 192, -8090, -8570},
{ 0, 207, -8150, -8597}, { 0, 178, -8142, -8656},
{ 0, 89, -8557, -8688}, { 0, 107, -8614, -8733},
{ 0, 194, -8605, -8782}, { 0, 153, -8655, -8881},
{ 0, 70, -8615, -8952}, { 0, 35, -8596, -9148},
{ 0, 49, -8636, -9286}, { 0, 6, -8587, -9435},
{ 0, -51, -8540, -9549}, { 0, -65, -8588, -9700},
{ 0, -55, -8503, -9820}, { 0, -20, -8414, -9907},
{ 0, -112, -8481, -10031}, { 0, -69, -8535, -10185},
{ 0, 2, -8550, -10052}, { 0, -1, -8493, -10291},
{ 0, -73, -8441, -10380}, { 0, 1958, -6930, -8295},
{ 0, -1148, -6939, -8396}, { 0, 1915, -6784, -8370},
{ 0, 1871, -6970, -8514}, { 0, 1821, -6974, -8387},
{ 0, 1781, -6906, -8431}, { 0, 1736, -6897, -8462},
{ 0, 1664, -7024, -8377}, { 0, 1629, -7127, -8436},
{ 0, 1603, -7148, -8528}, { 0, 1577, -7198, -8500},
{ 0, 1528, -7311, -8512}, { 0, 1577, -7390, -8570},
{ 0, 1616, -7436, -8572}, { 0, 1589, -7597, -8590},
{ 0, 1722, -7550, -8568}, { 0, 1741, -7691, -8449},
{ 0, 1767, -7775, -8328},
};
const uint16_t hopPattern_2KBPS_100MS[L1_FRAME_2KBPS_100MS_HOPS] =
const uint8_t hopPattern_2KBPS_20MS[L1_FRAME_2KBPS_20MS_HOPS] =
{
0, 44, 88, 131, 175, 219, 263, 306,
350, 394, 438, 481, 525, 569, 613, 656,
700, 744, 788, 831, 875, 919, 963, 1006,
1050, 1094, 1138, 1181, 1225, 1269, 1313, 1356,
1400, 1444, 1488, 1531, 1575, 1619, 1663, 1706,
1750, 1794, 1838, 1881, 1925, 1969, 2013, 2056,
2100, 2144, 2188, 2231, 2275, 2319, 2363, 2406,
2450, 2494, 2538, 2581, 2625, 2669, 2713, 2756,
2800, 2844, 2888, 2931, 2975, 3019, 3063, 3106,
3150, 3194, 3238, 3281, 3325, 3369, 3413, 3456,
3500
0
};
const uint16_t hopPattern_10KBPS_10MS[L1_FRAME_10KBPS_10MS_HOPS] =
const uint8_t hopPattern_2KBPS_100MS[L1_FRAME_2KBPS_100MS_HOPS] =
{
1500
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79,
80
};
const uint16_t hopPattern_10KBPS_20MS[L1_FRAME_10KBPS_20MS_HOPS] =
const uint8_t hopPattern_10KBPS_10MS[L1_FRAME_10KBPS_10MS_HOPS] =
{
1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500,
1500, 1500, 1500
0
};
const uint16_t hopPattern_40KBPS_10MS[L1_FRAME_40KBPS_10MS_HOPS] =
const uint8_t hopPattern_10KBPS_20MS[L1_FRAME_10KBPS_20MS_HOPS] =
{
1600, 1650, 1700, 1750, 1800, 1850, 1900, 1550,
1500
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10
};
const uint16_t hopPattern_40KBPS_20MS[L1_FRAME_40KBPS_20MS_HOPS] =
const uint8_t hopPattern_40KBPS_10MS[L1_FRAME_40KBPS_10MS_HOPS] =
{
1700, 1800, 1900, 2000, 1700, 1700, 1700, 1700,
1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700,
1700, 1700, 1700
0, 1, 2, 3, 4, 5, 6, 7,
8,
};
const uint16_t hopPattern_200KBPS_5MS[L1_FRAME_200KBPS_5MS_HOPS] =
const uint8_t hopPattern_40KBPS_20MS[L1_FRAME_40KBPS_20MS_HOPS] =
{
500, 1600, 1700, 1800, 1900, 2000, 1500, 1600,
1700, 1800, 1900, 2000, 1500, 1600, 1700, 1800,
1900, 2000, 1500, 1500
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18
};
const uint16_t hopPattern_1M2BPS_5MS[L1_FRAME_1M2BPS_5MS_HOPS] =
const uint8_t hopPattern_200KBPS_5MS[L1_FRAME_200KBPS_5MS_HOPS] =
{
500, 600, 700, 800, 900, 1000, 500, 600,
700, 800, 900, 1000, 500, 600, 700, 800,
900, 1000, 500, 500
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19
};
const uint8_t hopPattern_1M2BPS_5MS[L1_FRAME_1M2BPS_5MS_HOPS] =
{
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19
};
/** @} PhysicalLayer_AntennaConfig_Constants*/
@@ -228,7 +285,7 @@ void Phy_AntConfigMode(PHY_INST *instPtr, PHY_ANT_MODE mode)
/*****************************************************************************/
/**
* @brief Update antenna beam width setting
* @brief Update antenna beam table
*
* @param instPtr pointer to physical layer instance
* @param table new beam table
@@ -302,7 +359,7 @@ int32_t Phy_SetBeamNo(PHY_INST *instPtr, int32_t beamNo, PHY_ANT_BEAM_WIDTH beam
* @param beamWidth new beam width
*
* @return SUCCESS.
* EPARAM - the direction is exceeds predefined range
* EPARAM
*
******************************************************************************/
int32_t Phy_SetBeamWidth(PHY_INST *instPtr, PHY_ANT_BEAM_WIDTH beamWidth)
@@ -72,14 +72,16 @@
/** @} PhysicalLayer_Private_Constants*/
/************************** Variable Definitions *****************************/
extern const uint16_t hopPattern_2KBPS_20MS[L1_FRAME_2KBPS_20MS_HOPS];
extern const uint16_t hopPattern_2KBPS_100MS[L1_FRAME_2KBPS_100MS_HOPS];
extern const uint16_t hopPattern_10KBPS_10MS[L1_FRAME_10KBPS_10MS_HOPS];
extern const uint16_t hopPattern_10KBPS_20MS[L1_FRAME_10KBPS_20MS_HOPS];
extern const uint16_t hopPattern_40KBPS_10MS[L1_FRAME_40KBPS_10MS_HOPS];
extern const uint16_t hopPattern_40KBPS_20MS[L1_FRAME_40KBPS_20MS_HOPS];
extern const uint16_t hopPattern_200KBPS_5MS[L1_FRAME_200KBPS_5MS_HOPS];
extern const uint16_t hopPattern_1M2BPS_5MS[L1_FRAME_1M2BPS_5MS_HOPS];
extern const uint16_t freqTable[L1_FRAME_MAX_HOPS];
extern const int16_t antCalTable[L1_FRAME_MAX_HOPS][L1_ANT_NUM_CH];
extern const uint8_t hopPattern_2KBPS_20MS[L1_FRAME_2KBPS_20MS_HOPS];
extern const uint8_t hopPattern_2KBPS_100MS[L1_FRAME_2KBPS_100MS_HOPS];
extern const uint8_t hopPattern_10KBPS_10MS[L1_FRAME_10KBPS_10MS_HOPS];
extern const uint8_t hopPattern_10KBPS_20MS[L1_FRAME_10KBPS_20MS_HOPS];
extern const uint8_t hopPattern_40KBPS_10MS[L1_FRAME_40KBPS_10MS_HOPS];
extern const uint8_t hopPattern_40KBPS_20MS[L1_FRAME_40KBPS_20MS_HOPS];
extern const uint8_t hopPattern_200KBPS_5MS[L1_FRAME_200KBPS_5MS_HOPS];
extern const uint8_t hopPattern_1M2BPS_5MS[L1_FRAME_1M2BPS_5MS_HOPS];
/***************** Macros (Inline Functions) Definitions *********************/
/************************** Function Prototypes ******************************/
@@ -423,7 +425,6 @@ int32_t Phy_Init(PHY_INST **instPtr, PHY_CONFIG *phyConfig)
memset(&((*instPtr))->tor, PHY_TOR_SUSPEND, sizeof(PHY_RCD));
memset(&((*instPtr)->frameType), L1_NONE_FRAME, sizeof(PHY_RCD));
memset(&((*instPtr)->antNo), (int32_t)L1_INIT_BEAM_NO, sizeof(PHY_RCD));
memset(&((*instPtr)->beamNo), (int32_t)L1_INIT_ANT_NO, sizeof(PHY_RCD));
memset(&((*instPtr)->beamWd), (int32_t)L1_INIT_ANT_WD, sizeof(PHY_RCD));
memset(&((*instPtr)->hwSate), 0x00, sizeof(HWSTATE));
@@ -655,8 +656,8 @@ void Phy_Halt(PHY_INST *instPtr)
/**
* @brief Set physical layer working mode.
*
* @param instPtr a pointer to physical instance
* @param modeCod intened mode code
* @param instPtr physical instance
* @param modeCod intend mode code
*
* @return SUCCESS
* other
@@ -693,12 +694,12 @@ int32_t Phy_SetMode(PHY_INST *instPtr, PHY_MODE modeCod)
/**
* @brief Setup a specific timer word register in physical controller.
*
* @param instPtr
* @param tmWord
* @param tmType
* @param instPtr physical instance
* @param tmWord time word
* @param tmType time word type
*
* @return SUCCESS
* FAILURE pattern length exceeds maximum length.
* FAILURE
*
******************************************************************************/
int32_t Phy_SetTimeWord(PHY_INST *instPtr, const TIME_WORD *tmWord, PHY_TIME_WORD_TYPE tmType)
@@ -742,7 +743,7 @@ int32_t Phy_SetupNextSlot(PHY_INST *instPtr, PHY_TOR_TYPE txrxMode,
ASSERT(instPtr != NULL);
int32_t Status;
uint32_t phyModeCtrl, hopNum;
const uint16_t *hopPattern;
const uint8_t *hopPattern;
// Implement a ping-pong flow, offset always is 0 or half of buffer depth.
instPtr->antConfigOffset = (L1_ANTCONFIG_MAX_LEN >> 1) - instPtr->antConfigOffset;
uint32_t antConfigAddr = instPtr->antConfigAddr + instPtr->antConfigOffset;
@@ -821,12 +822,37 @@ int32_t Phy_SetupNextSlot(PHY_INST *instPtr, PHY_TOR_TYPE txrxMode,
// TODO: Set antenna stand by, when suspend.
const uint8_t *dataSrcPtr = (uint8_t *)(&(instPtr->antConfig));
size_t hopIdx;
uint16_t hopFreq;
int16_t hopCal;
for (int32_t i = 0; i < hopNum; i++)
{
instPtr->antConfig.antFreq[0] = (uint8_t)(hopPattern[i] >> 8);
instPtr->antConfig.antFreq[1] = (uint8_t)hopPattern[i];
instPtr->antConfig.rfFreq[0] = (uint8_t)(hopPattern[i] >> 8);
instPtr->antConfig.rfFreq[1] = (uint8_t)hopPattern[i];
hopIdx = hopPattern[i];
// Frequency setting
hopFreq = freqTable[hopIdx];
instPtr->antConfig.antFreq[0] = (uint8_t)(hopFreq >> 8);
instPtr->antConfig.antFreq[1] = (uint8_t)hopFreq;
instPtr->antConfig.rfFreq[0] = (uint8_t)(hopFreq >> 8);
instPtr->antConfig.rfFreq[1] = (uint8_t)hopFreq;
// Calibration setting
// -- CH0
hopCal = antCalTable[hopIdx][0];
instPtr->antConfig.ch0Cal[0] = (uint8_t)(hopCal >> 8);
instPtr->antConfig.ch0Cal[1] = (uint8_t)hopCal;
// -- CH1
hopCal = antCalTable[hopIdx][1];
instPtr->antConfig.ch1Cal[0] = (uint8_t)(hopCal >> 8);
instPtr->antConfig.ch1Cal[1] = (uint8_t)hopCal;
// -- CH2
hopCal = antCalTable[hopIdx][2];
instPtr->antConfig.ch2Cal[0] = (uint8_t)(hopCal >> 8);
instPtr->antConfig.ch2Cal[1] = (uint8_t)hopCal;
// -- CH3
hopCal = antCalTable[hopIdx][3];
instPtr->antConfig.ch3Cal[0] = (uint8_t)(hopCal >> 8);
instPtr->antConfig.ch3Cal[1] = (uint8_t)hopCal;
memcpy((uint8_t *)(antConfigAddr + i * ANT_COINFO_LEN),
dataSrcPtr, sizeof(PHY_ANT_CONFIG));
}
@@ -834,13 +860,6 @@ int32_t Phy_SetupNextSlot(PHY_INST *instPtr, PHY_TOR_TYPE txrxMode,
| ((hopNum << ANT_CONFIG_NUM_SHIFT) & ANT_CONFIG_NUM_MASK)
| ((ANT_COINFO_LEN << ANT_CONFIG_LEN_SHIFT) & ANT_CONFIG_LEN_MASK);
/*
memcpy((uint8_t*)antConfigDataAddr, hopPattern, hopNum*sizeof(uint16_t));
uint32_t antCtrl = (instPtr->antCoinfigOffset & ANT_CONFIG_OFFSET_MASK)
| ((hopNum << ANT_CONFIG_NUM_SHIFT) & ANT_CONFIG_NUM_MASK)
| ((sizeof(uint16_t) << ANT_CONFIG_LEN_SHIFT) & ANT_CONFIG_LEN_MASK);
*/
// Set antenna configs
PhyWrite(instPtr, ANT_CONFIG, antCtrl);
@@ -862,7 +881,6 @@ int32_t Phy_SetupNextSlot(PHY_INST *instPtr, PHY_TOR_TYPE txrxMode,
Phy_RcdShift(&(instPtr->tor), txrxMode);
Phy_RcdShift(&(instPtr->frameType), frameType);
// TODO:
Phy_RcdShift(&(instPtr->antNo), L1_INIT_ANT_NO);
Phy_RcdShift(&(instPtr->beamNo), L1_INIT_BEAM_NO);
Phy_RcdShift(&(instPtr->beamWd), L1_INIT_ANT_WD);
return SUCCESS;
@@ -872,7 +890,7 @@ int32_t Phy_SetupNextSlot(PHY_INST *instPtr, PHY_TOR_TYPE txrxMode,
/**
* @brief Update physical layer status cache.
*
* @param instPtr A pointer to physical layer control instance.
* @param instPtr physical layer control instance.
*
* @return NONE.
*
@@ -905,7 +923,8 @@ void Phy_UpdateState(PHY_INST *instPtr)
/**
* @brief Copy ans store the received data, if received data valid.
*
* @param instPtr a pointer to physical layer control instance.
* @param instPtr to physical layer control instance.
* @param dataBuff data buffer.
*
* @return NONE
*
@@ -931,7 +950,8 @@ void Phy_PeekRecvData(PHY_INST *instPtr, uint8_t *dataBuff)
* @brief Get the received data (if valid), store it to data buffer.
* and clear data valid flag.
*
* @param instPtr a pointer to physical layer control instance.
* @param instPtr to physical layer control instance.
* @param dataBuff data buffer.
*
* @return NONE
*
@@ -995,10 +1015,9 @@ void Phy_UpdateLogging(PHY_INST *instPtr)
/*****************************************************************************/
/**
* @brief Setup a specific timer word register in physical controller.
* @brief Refresh hardware status.
*
* @param instPtr a pointer to hopping pattern buffer
* @param patternLen a integer indicate the length of hopping pattern.
*
* @return NONE
*
@@ -1133,6 +1152,8 @@ void Phy_RefreshHwSate(PHY_INST *instPtr)
instPtr->hwSate.isAntOk = (instPtr->hwSate.antVolt == (VOLT_ANT_PROC_OK | VOLT_ANT_RF_OK | VOLT_ANT_NIL_OK | ANT_STATE_OK))
&& (instPtr->hwSate.antPll == (CLK_ANT_BBPLL_LOCK | CLK_ANT_RFPLL0_LOCK | CLK_ANT_RFPLL1_LOCK));
instPtr->hwSate.phyId = instPtr.phyCofig.devId;
memset(instPtr->hwSate.reserve, 0x00, sizeof(instPtr->hwSate.reserve));
SysMonitor_UpdateHardwareStatus(&(instPtr->hwSate));
@@ -37,7 +37,7 @@
#define L1_NUM_ANT_NRRW_PATTERN 37
#define L1_INIT_BEAM_NO 0
#define L1_INIT_ANT_WD PHY_ANT_BEAM_120
#define L1_INIT_ANT_NO 0
#define L1_ANT_NUM_CH 4
#define L1_FRAME_NONE_LEN UINT32_MAX // byte
#define L1_FRAME_NONE_COMP UINT32_MAX // *10ns(Timer_L)
@@ -111,6 +111,10 @@ typedef struct
uint8_t rfMonitor; ///< Receive monitor, 0-normal, 1-switch to monitor port
uint8_t rfReserved0; ///< reserved for further use
uint8_t rfReserved1; ///< reserved for further use
uint8_t ch0Cal[2];
uint8_t ch1Cal[2];
uint8_t ch2Cal[2];
uint8_t ch3Cal[2];
} PHY_ANT_CONFIG;
/**
@@ -229,7 +233,6 @@ typedef struct
bool isValid; ///< indicates if last reception frame data valid (crc check pass)
TIME_WORD recvSlotTime; ///< last slot start time stamp
TIME_WORD recvFsTime; ///< last frame sync time stamp
PHY_RCD antNo; ///< antenna number record
PHY_RCD beamNo; ///< beam number record
PHY_RCD beamWd; ///< beam width record
PHY_RCD tor; ///< tx rx state record