cleanup and misc update

This commit is contained in:
Gatsby Van
2024-03-16 16:57:21 +08:00
parent c07cd00f2f
commit b7607a7a1b
4 changed files with 45 additions and 30 deletions
@@ -401,7 +401,6 @@ void L2_FrameStateUpdate(L2_INST *instPtr)
int32_t L2_SteerBeam2Node(L2_INST *instPtr, uint8_t nodeId) int32_t L2_SteerBeam2Node(L2_INST *instPtr, uint8_t nodeId)
{ {
ASSERT(instPtr != NULL); ASSERT(instPtr != NULL);
ASSERT(instPtr->config.phyInstPtr != NULL);
int32_t Status; int32_t Status;
COORD myPos, dstPos, beamDir; COORD myPos, dstPos, beamDir;
@@ -948,7 +947,7 @@ int32_t Linklayer_EventHandler(L2_INST *instPtr, const L2_EVENT *l2Event)
case L2_EV_LOST_CXN: case L2_EV_LOST_CXN:
{ {
DBG_INFO("Event L2_EV_LOST_CXN asserted....\n"); DBG_INFO("Event L2_EV_LOST_CXN asserted....\n");
if (instPtr->config.myType == L2_NODE_HEAD) if (L2_GetNodeType(instPtr) == L2_NODE_HEAD)
{ {
DBG_ERROR("Illegal event, only None_Head node can assert L2_EV_LOST_CXN.\n"); DBG_ERROR("Illegal event, only None_Head node can assert L2_EV_LOST_CXN.\n");
break; break;
@@ -1171,6 +1170,8 @@ int32_t Linklayer_Proc(L2_INST *instPtr)
{ {
ASSERT(instPtr != NULL); ASSERT(instPtr != NULL);
int32_t Status; int32_t Status;
PHY_INST *phyRef = instPtr->config.phyInstPtr;
TMC_INST *tmcRef = instPtr->config.tmcInstPtr;
if (instPtr->isEnable == false) if (instPtr->isEnable == false)
{ {
@@ -1179,7 +1180,7 @@ int32_t Linklayer_Proc(L2_INST *instPtr)
} }
// FIXME: Consider time wrapping. // FIXME: Consider time wrapping.
uint32_t nextTimeUnit = (TimeCtrl_GetIntCnt(instPtr->config.tmcInstPtr) + 1) / L2_SLOTS_PER_FRAME; uint32_t nextTimeUnit = (TimeCtrl_GetIntCnt(tmcRef) + 1) / L2_SLOTS_PER_FRAME;
if (nextTimeUnit < instPtr->netStartTime) if (nextTimeUnit < instPtr->netStartTime)
{ {
DBG_WARNING("Linklayer not start yet, next time unit: %" PRIu32 ", start time unit: %" PRIu32 ".\n", DBG_WARNING("Linklayer not start yet, next time unit: %" PRIu32 ", start time unit: %" PRIu32 ".\n",
@@ -1211,19 +1212,19 @@ int32_t Linklayer_Proc(L2_INST *instPtr)
// Run Link layer routine, setup next slot procedure. // Run Link layer routine, setup next slot procedure.
if (L2_GetNodeType(instPtr) == L2_NODE_HEAD) if (L2_GetNodeType(instPtr) == L2_NODE_HEAD)
{ {
Phy_SetMode(instPtr->config.phyInstPtr, PHY_MODE_PULL); Phy_SetMode(phyRef, PHY_MODE_PULL);
Status = Linklayer_Routine(instPtr); Status = Linklayer_Routine(instPtr);
} }
else else
{ // L2_NODE_MEMBER { // L2_NODE_MEMBER
if (L2_isCxn2Net(instPtr)) if (L2_isCxn2Net(instPtr))
{ {
Phy_SetMode(instPtr->config.phyInstPtr, PHY_MODE_PULL); Phy_SetMode(phyRef, PHY_MODE_PULL);
Status = Linklayer_Routine(instPtr); Status = Linklayer_Routine(instPtr);
} }
else else
{ {
Phy_SetMode(instPtr->config.phyInstPtr, PHY_MODE_LISTEN); Phy_SetMode(phyRef, PHY_MODE_LISTEN);
Status = L2_Scan_Proc(instPtr); Status = L2_Scan_Proc(instPtr);
} }
} }
@@ -1241,14 +1242,14 @@ int32_t Linklayer_Proc(L2_INST *instPtr)
instPtr->mainState = instPtr->nextState; instPtr->mainState = instPtr->nextState;
instPtr->linkLog.tuNum = instPtr->frameNum.curr; instPtr->linkLog.tuNum = instPtr->frameNum.curr;
instPtr->linkLog.slotNum = (uint8_t)instPtr->slotNum.curr; instPtr->linkLog.slotNum = (uint8_t)instPtr->slotNum.curr;
instPtr->linkLog.nodeType = (instPtr->config.myType == L2_NODE_HEAD) ? 0xAA : 0xCC; instPtr->linkLog.nodeType = (L2_GetNodeType(instPtr) == L2_NODE_HEAD) ? 0xAA : 0xCC;
instPtr->linkLog.cxnStatus = (instPtr->cxn2Net) ? 0x11 : 0x00; instPtr->linkLog.cxnStatus = (instPtr->cxn2Net) ? 0x11 : 0x00;
instPtr->linkLog.linkStage = (instPtr->mainState == L2_INIT_STATE) ? 0x11 : 0x22; instPtr->linkLog.linkStage = (instPtr->mainState == L2_INIT_STATE) ? 0x11 : 0x22;
instPtr->linkLog.recxnCnt = instPtr->log.reconnectCnt; instPtr->linkLog.recxnCnt = instPtr->log.reconnectCnt;
instPtr->linkLog.beamNo = instPtr->scanFSM->beamNo; instPtr->linkLog.beamNo = instPtr->scanFSM->beamNo;
instPtr->linkLog.beamWidth = instPtr->log.lastBeamWidth; instPtr->linkLog.beamWidth = instPtr->log.lastBeamWidth;
instPtr->linkLog.beamAz = instPtr->config.phyInstPtr->antNrrwPattern[instPtr->scanFSM->beamNo].oaxis; instPtr->linkLog.beamAz = phyRef->antNrrwPattern[instPtr->scanFSM->beamNo].oaxis;
instPtr->linkLog.beamEl = instPtr->config.phyInstPtr->antNrrwPattern[instPtr->scanFSM->beamNo].raxis; instPtr->linkLog.beamEl = phyRef->antNrrwPattern[instPtr->scanFSM->beamNo].raxis;
instPtr->linkLog.advTxCnt = (uint16_t)instPtr->log.advTxCnt; instPtr->linkLog.advTxCnt = (uint16_t)instPtr->log.advTxCnt;
instPtr->linkLog.advRecvCnt = (uint16_t)instPtr->log.advRecvCnt; instPtr->linkLog.advRecvCnt = (uint16_t)instPtr->log.advRecvCnt;
instPtr->linkLog.advCorrectCnt = (uint16_t)instPtr->log.advCorrectCnt; instPtr->linkLog.advCorrectCnt = (uint16_t)instPtr->log.advCorrectCnt;
+31 -17
View File
@@ -206,22 +206,26 @@ static int32_t Scan_InitScanHandler(L2_INST *instPtr)
else if(Phy_IsFrameDetected(phyRef)) else if(Phy_IsFrameDetected(phyRef))
{ {
// last scan beam number // last scan beam number
instPtr->scanFSM->beamNo = Phy_LastScanBeamNo(instPtr->config.phyInstPtr); scanFsmPtr->beamNo = Phy_LastScanBeamNo(phyRef);
// Update scan beam table // Update scan beam table
L2_Scan_RefreashScanTable(instPtr); L2_Scan_RefreashScanTable(instPtr);
} }
if (scanFsmPtr->isLocked == true) if (scanFsmPtr->isLocked == true)
{ {
StageUpdate(scanFsmPtr, L2_SCAN_ADV_STAGE); scanFsmPtr->beamNo = Phy_LastScanBeamNo(phyRef);
/* Antenna setting (reserved.) */ Phy_SetBeamNo(phyRef, scanFsmPtr->beamNo, PHY_ANT_BEAM_16);
L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_ADV_FRAME); L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_ADV_FRAME);
StageUpdate(scanFsmPtr, L2_SCAN_ADV_STAGE);
instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16;
} /* Otherwise remain L2_SCAN_INIT_STAGE */ } /* Otherwise remain L2_SCAN_INIT_STAGE */
else else
{ {
/* Antenna setting (reserved.) */ /* Antenna steering (reserved, automatically accomplished by physical layer) */
Phy_SetBeamNo(phyRef, scanFsmPtr->beamNo, PHY_ANT_BEAM_16);
L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_SCAN_FRAME); L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_SCAN_FRAME);
scanFsmPtr->scanCnt++; scanFsmPtr->scanCnt++;
instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16;
} }
return SUCCESS; return SUCCESS;
} }
@@ -239,19 +243,22 @@ static int32_t Scan_InitScanHandler(L2_INST *instPtr)
******************************************************************************/ ******************************************************************************/
static int32_t Scan_AdvHandler(L2_INST *instPtr) static int32_t Scan_AdvHandler(L2_INST *instPtr)
{ {
ASSERT(instPtr != NULL);
L2_SCAN_FSM *scanFsmPtr = instPtr->scanFSM; L2_SCAN_FSM *scanFsmPtr = instPtr->scanFSM;
PHY_INST *phyRef = instPtr->config.phyInstPtr;
DBG_INFO("** Net-Setup - Advertisement Procedure (Timeout: %" PRIu8 ") **\n", scanFsmPtr->advTimeout); DBG_INFO("** Net-Setup - Advertisement Procedure (Timeout: %" PRIu8 ") **\n", scanFsmPtr->advTimeout);
// if received a valid bm frame. // if received a valid bm frame.
if (scanFsmPtr->isAdvRecvd == true) if (scanFsmPtr->isAdvRecvd == true)
{ {
// last scan beam number // last scan beam number
instPtr->scanFSM->beamNo = Phy_LastScanBeamNo(instPtr->config.phyInstPtr); scanFsmPtr->beamNo = Phy_LastScanBeamNo(phyRef);
// reset listen counter.
scanFsmPtr->advTimeout = 0;
scanFsmPtr->advTimeout = 0; /* reset listen counter. */ // Update scan stage
DBG_INFO("Received Adv frame, skipping 10ms for turn around...\n");
// TODO: check functionality.
StageUpdate(scanFsmPtr, L2_SCAN_CFM_STAGE); StageUpdate(scanFsmPtr, L2_SCAN_CFM_STAGE);
DBG_INFO("Received Adv frame, skipping 10ms for turn around...\n");
return SUCCESS; return SUCCESS;
} }
// no valid bm frame was received. // no valid bm frame was received.
@@ -260,16 +267,20 @@ static int32_t Scan_AdvHandler(L2_INST *instPtr)
/* if time out reached, go back to init scan stage. */ /* if time out reached, go back to init scan stage. */
if (scanFsmPtr->advTimeout > ADV_LISTEN_TIMEOUT) if (scanFsmPtr->advTimeout > ADV_LISTEN_TIMEOUT)
{ {
/* Antenna setting (reserved, automatically accomplished by physical layer) */ /* Antenna steering (reserved, automatically accomplished by physical layer) */
Phy_SetBeamNo(phyRef, scanFsmPtr->beamNo, PHY_ANT_BEAM_16);
L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_SCAN_FRAME); L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_SCAN_FRAME);
DBG_WARNING("Adv timeout, restart net scan from L2_SCAN_INIT_STAGE.\n"); DBG_WARNING("Adv timeout, restart net scan from L2_SCAN_INIT_STAGE.\n");
L2_Scan_Reset(scanFsmPtr); L2_Scan_Reset(scanFsmPtr);
instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16;
} }
else else
{ {
/* Antenna setting (reserved, automatically accomplished by physical layer) */ /* Antenna steering (reserved, automatically accomplished by physical layer) */
Phy_SetBeamNo(phyRef, scanFsmPtr->beamNo, PHY_ANT_BEAM_16);
L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_ADV_FRAME); L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_ADV_FRAME);
scanFsmPtr->advTimeout++; scanFsmPtr->advTimeout++;
instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16;
} }
return SUCCESS; return SUCCESS;
} }
@@ -286,7 +297,9 @@ static int32_t Scan_AdvHandler(L2_INST *instPtr)
******************************************************************************/ ******************************************************************************/
static int32_t Scan_CfmHandler(L2_INST *instPtr) static int32_t Scan_CfmHandler(L2_INST *instPtr)
{ {
ASSERT(instPtr != NULL);
L2_SCAN_FSM *scanFsmPtr = instPtr->scanFSM; L2_SCAN_FSM *scanFsmPtr = instPtr->scanFSM;
PHY_INST *phyRef = instPtr->config.phyInstPtr;
DBG_INFO("** Net-Setup - Confirm Procedure (Timeout: %" PRIu8 ") **\n", scanFsmPtr->cfmTimeout); DBG_INFO("** Net-Setup - Confirm Procedure (Timeout: %" PRIu8 ") **\n", scanFsmPtr->cfmTimeout);
// 2 way acq failed, back to init stage. // 2 way acq failed, back to init stage.
@@ -300,9 +313,9 @@ static int32_t Scan_CfmHandler(L2_INST *instPtr)
{ {
// using pull mode to receive confirm frame // using pull mode to receive confirm frame
// since first time sync procedure is accomplished in ADV stage. // since first time sync procedure is accomplished in ADV stage.
Phy_SetBeamWidth(instPtr->config.phyInstPtr, PHY_ANT_BEAM_16); Phy_SetBeamWidth(phyRef, PHY_ANT_BEAM_16);
Phy_SetBeamNo(instPtr->config.phyInstPtr, scanFsmPtr->beamNo, PHY_ANT_BEAM_16); Phy_SetBeamNo(phyRef, scanFsmPtr->beamNo, PHY_ANT_BEAM_16);
Phy_SetMode(instPtr->config.phyInstPtr, PHY_MODE_PULL); Phy_SetMode(phyRef, PHY_MODE_PULL);
L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_CFM_FRAME); L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_CFM_FRAME);
scanFsmPtr->cfmTimeout++; // increase counter. scanFsmPtr->cfmTimeout++; // increase counter.
instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16; instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16;
@@ -444,7 +457,7 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg)
StageUpdate(scanFsmPtr, L2_SCAN_ADV_STAGE); StageUpdate(scanFsmPtr, L2_SCAN_ADV_STAGE);
case L2_ADV_FRAME: case L2_ADV_FRAME:
{ {
if (instPtr->config.myType == L2_NODE_HEAD) if (L2_GetNodeType(instPtr) == L2_NODE_HEAD)
{ {
DBG_ERROR("Unexpected call from head node, only member Node can handle L2_SCAN_FRAME and L2_ADV_FRAME.\n"); DBG_ERROR("Unexpected call from head node, only member Node can handle L2_SCAN_FRAME and L2_ADV_FRAME.\n");
Status = EUNEXP; Status = EUNEXP;
@@ -762,6 +775,7 @@ int32_t L2_Scan_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry)
L2_TOR_TYPE torState; L2_TOR_TYPE torState;
int32_t Status; int32_t Status;
const NODE_ENTRY* commNode; const NODE_ENTRY* commNode;
PHY_INST *phyRef = instPtr->config.phyInstPtr;
DBG_INFO("-------- Scan Routine --------\n"); DBG_INFO("-------- Scan Routine --------\n");
if (rtneEntry->slotSeq != 0) if (rtneEntry->slotSeq != 0)
@@ -787,11 +801,11 @@ int32_t L2_Scan_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry)
} }
// Setup antenna beam // Setup antenna beam
Phy_SetBeamWidth(instPtr->config.phyInstPtr, PHY_ANT_BEAM_16); Phy_SetBeamWidth(phyRef, PHY_ANT_BEAM_16);
instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16; instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16;
if (commNode != NULL) if (commNode != NULL)
{ {
Phy_SetBeamNo(instPtr->config.phyInstPtr, commNode->nodeInfo.beamNo, PHY_ANT_BEAM_16); Phy_SetBeamNo(phyRef, commNode->nodeInfo.beamNo, PHY_ANT_BEAM_16);
} }
} }
else else
@@ -809,7 +823,7 @@ int32_t L2_Scan_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry)
torState = L2_TOR_SUSPEND; torState = L2_TOR_SUSPEND;
} }
// Setup antenna beam // Setup antenna beam
Phy_SetBeamWidth(instPtr->config.phyInstPtr, PHY_ANT_BEAM_120); Phy_SetBeamWidth(phyRef, PHY_ANT_BEAM_120);
instPtr->log.lastBeamWidth = PHY_ANT_BEAM_120; instPtr->log.lastBeamWidth = PHY_ANT_BEAM_120;
} }
@@ -49,7 +49,8 @@ int32_t L2_GetTimeDeviation(L2_INST *instPtr, uint32_t frameNum, uint32_t slotNu
ASSERT(instPtr != NULL); ASSERT(instPtr != NULL);
ASSERT(timeDev != NULL); ASSERT(timeDev != NULL);
L1_FRAME_TYPE lastRecvdFrame; L1_FRAME_TYPE lastRecvdFrame;
lastRecvdFrame = Phy_GetLastRecvFrameType(instPtr->config.phyInstPtr); PHY_INST *phyRef = instPtr->config.phyInstPtr;
lastRecvdFrame = Phy_GetLastRecvFrameType(phyRef);
if (lastRecvdFrame == L1_NONE_FRAME) if (lastRecvdFrame == L1_NONE_FRAME)
{ {
DBG_ERROR("Invalid TimeAlign operation, no frame was received."); DBG_ERROR("Invalid TimeAlign operation, no frame was received.");
@@ -68,7 +69,7 @@ int32_t L2_GetTimeDeviation(L2_INST *instPtr, uint32_t frameNum, uint32_t slotNu
expectTime += (uint64_t)instPtr->netStartTime * L2_SLOTS_PER_FRAME * TIME_FRAC_MAX; expectTime += (uint64_t)instPtr->netStartTime * L2_SLOTS_PER_FRAME * TIME_FRAC_MAX;
} }
Phy_GetLastReceivedFrameSyncTimeStamp(instPtr->config.phyInstPtr, &timeStamp); Phy_GetLastReceivedFrameSyncTimeStamp(phyRef, &timeStamp);
currTime = (uint64_t)timeStamp.frac_part; currTime = (uint64_t)timeStamp.frac_part;
currTime += ((uint64_t)timeStamp.int_part) * TIME_FRAC_MAX; currTime += ((uint64_t)timeStamp.int_part) * TIME_FRAC_MAX;
@@ -76,7 +77,6 @@ int32_t L2_GetTimeDeviation(L2_INST *instPtr, uint32_t frameNum, uint32_t slotNu
return SUCCESS; return SUCCESS;
} }
/*****************************************************************************/ /*****************************************************************************/
/** /**
* @brief Implement time adjustment by applying time deviation. * @brief Implement time adjustment by applying time deviation.
@@ -493,7 +493,7 @@ int32_t Phy_InstInit(PHY_INST **instPtr, PHY_CONFIG *phyConfig)
} }
else else
{ {
(*instPtr)->antInfoAddr = NULL; (*instPtr)->antInfoAddr = (uintptr_t)NULL;
} }
/* Initialize the XAdc driver. */ /* Initialize the XAdc driver. */