From b7607a7a1b3080818955ffeb886a202692c132ee Mon Sep 17 00:00:00 2001 From: Gatsby Van Date: Sat, 16 Mar 2024 16:57:21 +0800 Subject: [PATCH] cleanup and misc update --- .../src/networking/link_layer/link_layer.c | 19 ++++---- .../src/networking/link_layer/scan.c | 48 ++++++++++++------- .../src/networking/link_layer/time_sync.c | 6 +-- .../src/networking/phy_layer/phy_layer.c | 2 +- 4 files changed, 45 insertions(+), 30 deletions(-) diff --git a/df_datalink_sp/src/networking/link_layer/link_layer.c b/df_datalink_sp/src/networking/link_layer/link_layer.c index 6dccf62..dfcdd22 100644 --- a/df_datalink_sp/src/networking/link_layer/link_layer.c +++ b/df_datalink_sp/src/networking/link_layer/link_layer.c @@ -401,7 +401,6 @@ void L2_FrameStateUpdate(L2_INST *instPtr) int32_t L2_SteerBeam2Node(L2_INST *instPtr, uint8_t nodeId) { ASSERT(instPtr != NULL); - ASSERT(instPtr->config.phyInstPtr != NULL); int32_t Status; COORD myPos, dstPos, beamDir; @@ -948,7 +947,7 @@ int32_t Linklayer_EventHandler(L2_INST *instPtr, const L2_EVENT *l2Event) case L2_EV_LOST_CXN: { 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"); break; @@ -1171,6 +1170,8 @@ int32_t Linklayer_Proc(L2_INST *instPtr) { ASSERT(instPtr != NULL); int32_t Status; + PHY_INST *phyRef = instPtr->config.phyInstPtr; + TMC_INST *tmcRef = instPtr->config.tmcInstPtr; if (instPtr->isEnable == false) { @@ -1179,7 +1180,7 @@ int32_t Linklayer_Proc(L2_INST *instPtr) } // 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) { 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. 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); } else { // L2_NODE_MEMBER if (L2_isCxn2Net(instPtr)) { - Phy_SetMode(instPtr->config.phyInstPtr, PHY_MODE_PULL); + Phy_SetMode(phyRef, PHY_MODE_PULL); Status = Linklayer_Routine(instPtr); } else { - Phy_SetMode(instPtr->config.phyInstPtr, PHY_MODE_LISTEN); + Phy_SetMode(phyRef, PHY_MODE_LISTEN); Status = L2_Scan_Proc(instPtr); } } @@ -1241,14 +1242,14 @@ int32_t Linklayer_Proc(L2_INST *instPtr) instPtr->mainState = instPtr->nextState; instPtr->linkLog.tuNum = instPtr->frameNum.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.linkStage = (instPtr->mainState == L2_INIT_STATE) ? 0x11 : 0x22; instPtr->linkLog.recxnCnt = instPtr->log.reconnectCnt; instPtr->linkLog.beamNo = instPtr->scanFSM->beamNo; instPtr->linkLog.beamWidth = instPtr->log.lastBeamWidth; - instPtr->linkLog.beamAz = instPtr->config.phyInstPtr->antNrrwPattern[instPtr->scanFSM->beamNo].oaxis; - instPtr->linkLog.beamEl = instPtr->config.phyInstPtr->antNrrwPattern[instPtr->scanFSM->beamNo].raxis; + instPtr->linkLog.beamAz = phyRef->antNrrwPattern[instPtr->scanFSM->beamNo].oaxis; + instPtr->linkLog.beamEl = phyRef->antNrrwPattern[instPtr->scanFSM->beamNo].raxis; instPtr->linkLog.advTxCnt = (uint16_t)instPtr->log.advTxCnt; instPtr->linkLog.advRecvCnt = (uint16_t)instPtr->log.advRecvCnt; instPtr->linkLog.advCorrectCnt = (uint16_t)instPtr->log.advCorrectCnt; diff --git a/df_datalink_sp/src/networking/link_layer/scan.c b/df_datalink_sp/src/networking/link_layer/scan.c index ce8fa7a..1bfa870 100644 --- a/df_datalink_sp/src/networking/link_layer/scan.c +++ b/df_datalink_sp/src/networking/link_layer/scan.c @@ -206,22 +206,26 @@ static int32_t Scan_InitScanHandler(L2_INST *instPtr) else if(Phy_IsFrameDetected(phyRef)) { // last scan beam number - instPtr->scanFSM->beamNo = Phy_LastScanBeamNo(instPtr->config.phyInstPtr); + scanFsmPtr->beamNo = Phy_LastScanBeamNo(phyRef); // Update scan beam table L2_Scan_RefreashScanTable(instPtr); } if (scanFsmPtr->isLocked == true) { - StageUpdate(scanFsmPtr, L2_SCAN_ADV_STAGE); - /* Antenna setting (reserved.) */ + scanFsmPtr->beamNo = Phy_LastScanBeamNo(phyRef); + Phy_SetBeamNo(phyRef, scanFsmPtr->beamNo, PHY_ANT_BEAM_16); 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 */ 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); scanFsmPtr->scanCnt++; + instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16; } return SUCCESS; } @@ -239,19 +243,22 @@ static int32_t Scan_InitScanHandler(L2_INST *instPtr) ******************************************************************************/ static int32_t Scan_AdvHandler(L2_INST *instPtr) { + ASSERT(instPtr != NULL); L2_SCAN_FSM *scanFsmPtr = instPtr->scanFSM; + PHY_INST *phyRef = instPtr->config.phyInstPtr; DBG_INFO("** Net-Setup - Advertisement Procedure (Timeout: %" PRIu8 ") **\n", scanFsmPtr->advTimeout); // if received a valid bm frame. if (scanFsmPtr->isAdvRecvd == true) { // 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. */ - DBG_INFO("Received Adv frame, skipping 10ms for turn around...\n"); - // TODO: check functionality. + // Update scan stage StageUpdate(scanFsmPtr, L2_SCAN_CFM_STAGE); + DBG_INFO("Received Adv frame, skipping 10ms for turn around...\n"); return SUCCESS; } // 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 (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); DBG_WARNING("Adv timeout, restart net scan from L2_SCAN_INIT_STAGE.\n"); L2_Scan_Reset(scanFsmPtr); + instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16; } 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); scanFsmPtr->advTimeout++; + instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16; } return SUCCESS; } @@ -286,7 +297,9 @@ static int32_t Scan_AdvHandler(L2_INST *instPtr) ******************************************************************************/ static int32_t Scan_CfmHandler(L2_INST *instPtr) { + ASSERT(instPtr != NULL); L2_SCAN_FSM *scanFsmPtr = instPtr->scanFSM; + PHY_INST *phyRef = instPtr->config.phyInstPtr; DBG_INFO("** Net-Setup - Confirm Procedure (Timeout: %" PRIu8 ") **\n", scanFsmPtr->cfmTimeout); // 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 // since first time sync procedure is accomplished in ADV stage. - Phy_SetBeamWidth(instPtr->config.phyInstPtr, PHY_ANT_BEAM_16); - Phy_SetBeamNo(instPtr->config.phyInstPtr, scanFsmPtr->beamNo, PHY_ANT_BEAM_16); - Phy_SetMode(instPtr->config.phyInstPtr, PHY_MODE_PULL); + Phy_SetBeamWidth(phyRef, PHY_ANT_BEAM_16); + Phy_SetBeamNo(phyRef, scanFsmPtr->beamNo, PHY_ANT_BEAM_16); + Phy_SetMode(phyRef, PHY_MODE_PULL); L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_CFM_FRAME); scanFsmPtr->cfmTimeout++; // increase counter. 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); 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"); Status = EUNEXP; @@ -762,6 +775,7 @@ int32_t L2_Scan_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry) L2_TOR_TYPE torState; int32_t Status; const NODE_ENTRY* commNode; + PHY_INST *phyRef = instPtr->config.phyInstPtr; DBG_INFO("-------- Scan Routine --------\n"); 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 - Phy_SetBeamWidth(instPtr->config.phyInstPtr, PHY_ANT_BEAM_16); + Phy_SetBeamWidth(phyRef, PHY_ANT_BEAM_16); instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16; 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 @@ -809,7 +823,7 @@ int32_t L2_Scan_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry) torState = L2_TOR_SUSPEND; } // 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; } diff --git a/df_datalink_sp/src/networking/link_layer/time_sync.c b/df_datalink_sp/src/networking/link_layer/time_sync.c index 3fc703b..6bfd7ea 100644 --- a/df_datalink_sp/src/networking/link_layer/time_sync.c +++ b/df_datalink_sp/src/networking/link_layer/time_sync.c @@ -49,7 +49,8 @@ int32_t L2_GetTimeDeviation(L2_INST *instPtr, uint32_t frameNum, uint32_t slotNu ASSERT(instPtr != NULL); ASSERT(timeDev != NULL); 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) { 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; } - Phy_GetLastReceivedFrameSyncTimeStamp(instPtr->config.phyInstPtr, &timeStamp); + Phy_GetLastReceivedFrameSyncTimeStamp(phyRef, &timeStamp); currTime = (uint64_t)timeStamp.frac_part; 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; } - /*****************************************************************************/ /** * @brief Implement time adjustment by applying time deviation. diff --git a/df_datalink_sp/src/networking/phy_layer/phy_layer.c b/df_datalink_sp/src/networking/phy_layer/phy_layer.c index 3868835..6c8ab0a 100644 --- a/df_datalink_sp/src/networking/phy_layer/phy_layer.c +++ b/df_datalink_sp/src/networking/phy_layer/phy_layer.c @@ -493,7 +493,7 @@ int32_t Phy_InstInit(PHY_INST **instPtr, PHY_CONFIG *phyConfig) } else { - (*instPtr)->antInfoAddr = NULL; + (*instPtr)->antInfoAddr = (uintptr_t)NULL; } /* Initialize the XAdc driver. */