346 lines
11 KiB
C
346 lines
11 KiB
C
/*****************************************************************************/
|
|
/**
|
|
* Description: Antenna configuration functions.
|
|
*
|
|
* Author: Fan Hao
|
|
* Date: 2022-06-18 16:37
|
|
* LastEditors: Fan Hao
|
|
* LastEditTime: 2022-06-18 17:15
|
|
* Revisions: Rev 0.0
|
|
* History:
|
|
* [2022-06-18]: Initial version.
|
|
*
|
|
* Copyright(c) 2022 Beijing Institute of Technology.
|
|
* Lab of Communication and Networking
|
|
*
|
|
******************************************************************************/
|
|
#include <string.h>
|
|
#include <stdint.h>
|
|
#include <math.h>
|
|
#include "phy_ctrl.h"
|
|
#include "../error.h"
|
|
|
|
#define ANT_PI 3.14159265358979323846
|
|
|
|
#define ANT_COINFO_HEAD 0xAA
|
|
#define ANT_COINFO_TAIL 0xCC
|
|
|
|
#define CTRL_WORD_DEFAULT 0x00
|
|
|
|
#define ANT_MODE_BEAM_MASK 0xF0
|
|
#define ANT_BEAM_NARROR 0x00 // 8
|
|
#define ANT_BEAM_SUBNARROR_0 0x10 // 25
|
|
#define ANT_BEAM_SUBNARROR_1 0x20 // 60
|
|
#define ANT_BEAM_WIDE 0x30 // 120
|
|
|
|
#define ANT_MODE_POWER_MASK 0x0F
|
|
#define ANT_POWER_FULL 0x00
|
|
#define ANT_POWER_LOW 0x04
|
|
#define ANT_POWER_STANDBY 0x0F
|
|
#define ATN_MODE_SILENT (ANT_BEAM_SUBNARROR_0 | ANT_POWER_STANDBY)
|
|
#define ATN_MODE_LOWPOWER (ANT_BEAM_SUBNARROR_0 | ANT_POWER_LOW)
|
|
#define ATN_MODE_FULLPOWER (ANT_BEAM_SUBNARROR_0 | ANT_POWER_FULL)
|
|
#define ATN_MODE_DEFAULT ATN_MODE_SILENT
|
|
|
|
#define DEFAULT_CENTRTAL_FREQ 0x06D7 // 26.25GHz
|
|
|
|
#define RXTXMODE_RX 0x00
|
|
#define RXTXMODE_TX 0x01
|
|
|
|
#define RXTXMODE_DEFAULT 0x00
|
|
|
|
#define CALIBRMODE_NORMAL 0x00
|
|
#define CALIBRMODE_SINGLE_TR_CAL 0x01
|
|
|
|
#define RF_CTRL_DEFAULT 0x00
|
|
|
|
// Pair by regex
|
|
// Regex: (([0-9]+, ){8})
|
|
uint16_t hopPattern_Config[L1_FRAME_MAX_HOPS] =
|
|
{
|
|
0
|
|
};
|
|
|
|
uint16_t hopPattern_2KBPS_20MS[L1_FRAME_2KBPS_20MS_HOPS] =
|
|
{
|
|
1500
|
|
};
|
|
|
|
uint16_t hopPattern_2KBPS_100MS[L1_FRAME_2KBPS_100MS_HOPS] =
|
|
{
|
|
2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400,
|
|
2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400,
|
|
2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400,
|
|
2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400,
|
|
2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400,
|
|
2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400,
|
|
2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400,
|
|
2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400,
|
|
2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400,
|
|
2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400,
|
|
2400
|
|
};
|
|
|
|
uint16_t hopPattern_10KBPS_10MS[L1_FRAME_10KBPS_10MS_HOPS] =
|
|
{
|
|
1500
|
|
};
|
|
|
|
uint16_t hopPattern_10KBPS_20MS[L1_FRAME_10KBPS_20MS_HOPS] =
|
|
{
|
|
1500, 1600, 1700, 1800, 1900, 2000, 1500, 1600,
|
|
1700, 1800, 1900
|
|
};
|
|
|
|
uint16_t hopPattern_40KBPS_10MS[L1_FRAME_40KBPS_10MS_HOPS] =
|
|
{
|
|
2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400,
|
|
2400
|
|
};
|
|
|
|
uint16_t hopPattern_40KBPS_20MS[L1_FRAME_40KBPS_20MS_HOPS] =
|
|
{
|
|
2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400,
|
|
2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400,
|
|
2400, 2400, 2400
|
|
};
|
|
|
|
uint16_t hopPattern_200KBPS_5MS[L1_FRAME_200KBPS_5MS_HOPS] =
|
|
{
|
|
1500, 1600, 1700, 1800, 1900, 2000, 1500, 1600,
|
|
1700, 1800, 1900, 2000, 1500, 1600, 1700, 1800,
|
|
1900, 2000, 1500, 1500
|
|
};
|
|
|
|
uint16_t hopPattern_1M2BPS_5MS[L1_FRAME_1M2BPS_5MS_HOPS] =
|
|
{
|
|
500 , 600 , 700 , 800 , 900 , 1000, 500 , 600 ,
|
|
700 , 800 , 900 , 1000, 500 , 600 , 700 , 800 ,
|
|
900 , 1000, 500 , 500
|
|
};
|
|
|
|
// Pair by regex
|
|
// Regex: ((\{\.oaxis = [0-9]+[ ,]+\.raxis = [0-9]+[ ]*\}, ){2})
|
|
#if defined(PHY_BEAM_SET_PRESET)
|
|
ANT_ANGLE antSubnrrwPattern[L1_NUM_ANT_SUBNRRW_PATTERN] = {
|
|
{.oaxis = 0 , .raxis =2225},{.oaxis = 96 , .raxis =850 },
|
|
{.oaxis = 135, .raxis =3075},{.oaxis = 166, .raxis =1700},
|
|
{.oaxis = 192, .raxis =325 },{.oaxis = 215, .raxis =2550},
|
|
{.oaxis = 236, .raxis =1174},{.oaxis = 255, .raxis =3399},
|
|
{.oaxis = 273, .raxis =2024},{.oaxis = 290, .raxis =649 },
|
|
{.oaxis = 306, .raxis =2874},{.oaxis = 321, .raxis =1499},
|
|
{.oaxis = 336, .raxis =124 },{.oaxis = 350, .raxis =2349},
|
|
{.oaxis = 363, .raxis =974 },{.oaxis = 377, .raxis =3199},
|
|
{.oaxis = 389, .raxis =1824},{.oaxis = 402, .raxis =449 },
|
|
{.oaxis = 414, .raxis =2674},{.oaxis = 426, .raxis =1298},
|
|
{.oaxis = 438, .raxis =3523},{.oaxis = 449, .raxis =2148},
|
|
{.oaxis = 460, .raxis =773 },{.oaxis = 471, .raxis =2998},
|
|
{.oaxis = 482, .raxis =1623},{.oaxis = 492, .raxis =248 },
|
|
{.oaxis = 503, .raxis =2473},{.oaxis = 513, .raxis =1098},
|
|
{.oaxis = 523, .raxis =3323},{.oaxis = 533, .raxis =1948},
|
|
{.oaxis = 543, .raxis =573 },{.oaxis = 553, .raxis =2798},
|
|
{.oaxis = 563, .raxis =1422},{.oaxis = 572, .raxis =47 },
|
|
{.oaxis = 581, .raxis =2272},{.oaxis = 591, .raxis =897 },
|
|
{.oaxis = 600, .raxis =3122}
|
|
};
|
|
ANT_ANGLE antNrrwPattern[L1_NUM_ANT_NRRW_PATTERN] = {
|
|
{.oaxis = 0 , .raxis =2225},{.oaxis = 74 , .raxis =850 },
|
|
{.oaxis = 105, .raxis =3075},{.oaxis = 128, .raxis =1700},
|
|
{.oaxis = 148, .raxis =325 },{.oaxis = 166, .raxis =2550},
|
|
{.oaxis = 182, .raxis =1174},{.oaxis = 197, .raxis =3399},
|
|
{.oaxis = 210, .raxis =2024},{.oaxis = 223, .raxis =649 },
|
|
{.oaxis = 236, .raxis =2874},{.oaxis = 247, .raxis =1499},
|
|
{.oaxis = 258, .raxis =124 },{.oaxis = 269, .raxis =2349},
|
|
{.oaxis = 280, .raxis =974 },{.oaxis = 290, .raxis =3199},
|
|
{.oaxis = 299, .raxis =1824},{.oaxis = 309, .raxis =449 },
|
|
{.oaxis = 318, .raxis =2674},{.oaxis = 327, .raxis =1298},
|
|
{.oaxis = 336, .raxis =3523},{.oaxis = 344, .raxis =2148},
|
|
{.oaxis = 352, .raxis =773 },{.oaxis = 361, .raxis =2998},
|
|
{.oaxis = 369, .raxis =1623},{.oaxis = 377, .raxis =248 },
|
|
{.oaxis = 384, .raxis =2473},{.oaxis = 392, .raxis =1098},
|
|
{.oaxis = 399, .raxis =3323},{.oaxis = 407, .raxis =1948},
|
|
{.oaxis = 414, .raxis =573 },{.oaxis = 421, .raxis =2798},
|
|
{.oaxis = 428, .raxis =1422},{.oaxis = 435, .raxis =47 },
|
|
{.oaxis = 442, .raxis =2272},{.oaxis = 449, .raxis =897 },
|
|
{.oaxis = 456, .raxis =3122},{.oaxis = 462, .raxis =1747},
|
|
{.oaxis = 469, .raxis =372 },{.oaxis = 475, .raxis =2597},
|
|
{.oaxis = 482, .raxis =1222},{.oaxis = 488, .raxis =3447},
|
|
{.oaxis = 495, .raxis =2072},{.oaxis = 501, .raxis =697 },
|
|
{.oaxis = 507, .raxis =2922},{.oaxis = 513, .raxis =1546},
|
|
{.oaxis = 519, .raxis =171 },{.oaxis = 525, .raxis =2396},
|
|
{.oaxis = 531, .raxis =1021},{.oaxis = 537, .raxis =3246},
|
|
{.oaxis = 543, .raxis =1871},{.oaxis = 549, .raxis =496 },
|
|
{.oaxis = 555, .raxis =2721},{.oaxis = 561, .raxis =1346},
|
|
{.oaxis = 566, .raxis =3571},{.oaxis = 572, .raxis =2196},
|
|
{.oaxis = 578, .raxis =821 },{.oaxis = 583, .raxis =3045},
|
|
{.oaxis = 589, .raxis =1670},{.oaxis = 594, .raxis =295 },
|
|
{.oaxis = 600, .raxis =2520}
|
|
};
|
|
#else
|
|
PHY_ANT_ANGLE antSubnrrwPattern[L1_NUM_ANT_SUBNRRW_PATTERN] =
|
|
{
|
|
0
|
|
};
|
|
PHY_ANT_ANGLE antNrrwPattern[L1_NUM_ANT_NRRW_PATTERN] =
|
|
{
|
|
0
|
|
};
|
|
#endif
|
|
/*****************************************************************************/
|
|
/**
|
|
* @brief
|
|
*
|
|
* @param antConfig
|
|
*
|
|
* @return
|
|
*
|
|
******************************************************************************/
|
|
void Phy_AntConfigInit(PHY_ANT_CONFIG *antConfig)
|
|
{
|
|
ASSERT(antConfig != NULL);
|
|
antConfig->ctrlWord = CTRL_WORD_DEFAULT;
|
|
antConfig->antMode = ATN_MODE_DEFAULT;
|
|
|
|
// FIXME: Dummy default value.
|
|
// off axis angle setting
|
|
antConfig->oaxis[0] = 0;
|
|
antConfig->oaxis[1] = 0;
|
|
// round axis angle setting
|
|
antConfig->raxis[0] = 0;
|
|
antConfig->raxis[1] = 0;
|
|
|
|
antConfig->antFreq[0] = (uint8_t)(DEFAULT_CENTRTAL_FREQ);
|
|
antConfig->antFreq[1] = (uint8_t)(DEFAULT_CENTRTAL_FREQ >> 8);
|
|
|
|
// FIXME: Dummy default value.
|
|
// trSelect
|
|
antConfig->trSlect = 0;
|
|
// Antenna attenuation setting
|
|
antConfig->antAtt = 20;
|
|
// phase setting
|
|
antConfig->phase = 0;
|
|
|
|
antConfig->rxtxMode = RXTXMODE_DEFAULT;
|
|
antConfig->calibrMode = CALIBRMODE_NORMAL;
|
|
antConfig->antReserved = 0x00;
|
|
// ***********************
|
|
|
|
// FIXME: Dummy default value.
|
|
// RF mode control
|
|
antConfig->rfCtrl = RF_CTRL_DEFAULT;
|
|
// RF frequency
|
|
antConfig->rfFreq[0] = (uint8_t)(DEFAULT_CENTRTAL_FREQ);
|
|
antConfig->rfFreq[1] = (uint8_t)(DEFAULT_CENTRTAL_FREQ >> 8);
|
|
// RF MGC control
|
|
antConfig->rfTxMgc = 0;
|
|
// RF channel 1&2 calibration mgc
|
|
antConfig->rf12CalMgc = 0;
|
|
// RF channel 2&3 calibration mgc
|
|
antConfig->rf34CalMgc = 0;
|
|
// Receive channel 1-4 MGC
|
|
antConfig->rcvMgc = 0;
|
|
antConfig->rfReserved0 = 0x00;
|
|
antConfig->rfReserved1 = 0x00;
|
|
}
|
|
|
|
int32_t Phy_SetBeamNo(PHY_INST *instPtr, int32_t beamNo, PHY_ANT_BEAM_WIDTH beamWidth)
|
|
{
|
|
if (beamWidth == PHY_ANT_BEAM_16)
|
|
{
|
|
if (beamNo >= L1_NUM_ANT_NRRW_PATTERN)
|
|
{
|
|
return FAILURE;
|
|
}
|
|
else
|
|
{
|
|
instPtr->beamNo.next = beamNo;
|
|
instPtr->antConfig.oaxis[1] = (uint8_t)(antNrrwPattern[beamNo].oaxis);
|
|
instPtr->antConfig.oaxis[0] = (uint8_t)((antNrrwPattern[beamNo].oaxis) >> 8);
|
|
instPtr->antConfig.raxis[1] = (uint8_t)(antNrrwPattern[beamNo].raxis);
|
|
instPtr->antConfig.raxis[0] = (uint8_t)((antNrrwPattern[beamNo].raxis) >> 8);
|
|
return SUCCESS;
|
|
}
|
|
}
|
|
else if (beamWidth == PHY_ANT_BEAM_25)
|
|
{
|
|
if (beamNo >= L1_NUM_ANT_SUBNRRW_PATTERN)
|
|
{
|
|
return FAILURE;
|
|
}
|
|
else
|
|
{
|
|
instPtr->beamNo.next = beamNo;
|
|
instPtr->antConfig.oaxis[1] = (uint8_t)(antSubnrrwPattern[beamNo].oaxis);
|
|
instPtr->antConfig.oaxis[0] = (uint8_t)((antSubnrrwPattern[beamNo].oaxis) >> 8);
|
|
instPtr->antConfig.raxis[1] = (uint8_t)(antSubnrrwPattern[beamNo].raxis);
|
|
instPtr->antConfig.raxis[0] = (uint8_t)((antSubnrrwPattern[beamNo].raxis) >> 8);
|
|
return SUCCESS;
|
|
}
|
|
}
|
|
else if(beamWidth == PHY_ANT_BEAM_120)
|
|
{
|
|
// Beam number assign not support.
|
|
// Assign default angle (0,0)
|
|
instPtr->beamNo.next = 0;
|
|
instPtr->antConfig.oaxis[1] = 0;
|
|
instPtr->antConfig.oaxis[0] = 0;
|
|
instPtr->antConfig.raxis[1] = 0;
|
|
instPtr->antConfig.raxis[0] = 0;
|
|
DBG_WARNING("Using default beam number...\n");
|
|
return SUCCESS;
|
|
}
|
|
else
|
|
{
|
|
return FAILURE;
|
|
}
|
|
}
|
|
|
|
int32_t Phy_SetBeamWidth(PHY_INST *instPtr, PHY_ANT_BEAM_WIDTH beamWidth)
|
|
{
|
|
uint8_t beamConfig = instPtr->antConfig.antMode & (~ANT_MODE_BEAM_MASK);
|
|
switch (beamWidth)
|
|
{
|
|
case PHY_ANT_BEAM_120:
|
|
beamConfig |= ANT_BEAM_WIDE;
|
|
break;
|
|
case PHY_ANT_BEAM_60:
|
|
beamConfig |= ANT_BEAM_SUBNARROR_1;
|
|
break;
|
|
case PHY_ANT_BEAM_25:
|
|
beamConfig |= ANT_BEAM_SUBNARROR_0;
|
|
break;
|
|
case PHY_ANT_BEAM_16:
|
|
beamConfig |= ANT_BEAM_NARROR;
|
|
break;
|
|
default:
|
|
DBG_ERROR("Beam width code: 0x%08X is illegal.\n", beamWidth);
|
|
return EPARAM;
|
|
break;
|
|
}
|
|
instPtr->antConfig.antMode = beamConfig;
|
|
instPtr->beamWd.next = beamWidth;
|
|
return SUCCESS;
|
|
}
|
|
|
|
// Common version radius double input
|
|
int32_t Phy_SetBeamAngle(PHY_INST *instPtr, double offAx, double rndAx)
|
|
{
|
|
uint16_t offAxDeg = 0;
|
|
uint16_t rndAxDeg = 0;
|
|
offAxDeg = (offAx >= 0) ? (((int32_t)(offAx * 180 / ANT_PI)) % 360) : (((int32_t)(offAx * 180 / ANT_PI)) % 360 + 360);
|
|
rndAxDeg = (rndAx >= 0) ? (((int32_t)(rndAx * 180 / ANT_PI)) % 360) : (((int32_t)(rndAx * 180 / ANT_PI)) % 360 + 360);
|
|
if (offAxDeg > 60)
|
|
{
|
|
DBG_ERROR("Angle out of range, off axis angle: %u (should be 0~60), round axis angle: %u (should be 0~360).\n",
|
|
offAxDeg, rndAxDeg);
|
|
return EPARAM;
|
|
}
|
|
offAxDeg = offAxDeg * 10;
|
|
rndAxDeg = rndAxDeg * 10;
|
|
instPtr->antConfig.oaxis[1] = (uint8_t)offAxDeg;
|
|
instPtr->antConfig.oaxis[0] = (uint8_t)(offAxDeg >> 8);
|
|
instPtr->antConfig.raxis[1] = (uint8_t)rndAxDeg;
|
|
instPtr->antConfig.raxis[0] = (uint8_t)(rndAxDeg >> 8);
|
|
return SUCCESS;
|
|
}
|