forked from gatsby/df_datalink
feat: 修改聆听建网逻辑, 增加建网帧接收控制
This commit is contained in:
@@ -33,7 +33,8 @@
|
||||
#endif
|
||||
/************************** Constant Definitions *****************************/
|
||||
#define NET_START_TIME_INFTY UINT32_MAX
|
||||
#define LINK_BROCK_THRESHOLD L2_SLOTS_PER_FRAME // 1 seconds
|
||||
#define LINK_BROCK_THRESHOLD L2_SLOTS_PER_FRAME // 0.5 seconds
|
||||
#define LISTEN_TIMEOUT_INT L2_SLOTS_PER_FRAME // number of 2 ms slots
|
||||
|
||||
/************************** Variable Definitions *****************************/
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
@@ -562,6 +563,7 @@ int32_t Linklayer_Init(L2_INST **instPtr, const L2_CONFIG *config)
|
||||
(*instPtr)->recvPktData = NULL;
|
||||
(*instPtr)->schdEventPool = NULL;
|
||||
(*instPtr)->nodeList = NULL;
|
||||
(*instPtr)->scanFSM = NULL;
|
||||
(*instPtr)->serviceFSM = NULL;
|
||||
memcpy(&((*instPtr)->config), config, sizeof(L2_CONFIG));
|
||||
|
||||
@@ -633,6 +635,13 @@ int32_t Linklayer_Init(L2_INST **instPtr, const L2_CONFIG *config)
|
||||
return Status;
|
||||
}
|
||||
|
||||
Status = L2_Scan_Init(&((*instPtr)->scanFSM));
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
Linklayer_Destroy(*instPtr);
|
||||
return Status;
|
||||
}
|
||||
|
||||
Status = L2_Service_Init(&((*instPtr)->serviceFSM));
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
@@ -708,6 +717,7 @@ int32_t Linklayer_Reconfig(L2_INST *instPtr, const L2_CONFIG *config)
|
||||
// Reset according instance
|
||||
L2_ClearSchedEventPool(instPtr->schdEventPool);
|
||||
L2_NodeList_Clear(instPtr->nodeList);
|
||||
L2_Scan_Reset(instPtr->scanFSM);
|
||||
L2_Service_Reset(instPtr->serviceFSM);
|
||||
return SUCCESS;
|
||||
}
|
||||
@@ -732,6 +742,7 @@ void Linklayer_Destroy(L2_INST *instPtr)
|
||||
// Destroy FSMs and nodeList
|
||||
L2_DestroySchedEventPool(instPtr->schdEventPool);
|
||||
L2_NodeList_Destroy(instPtr->nodeList);
|
||||
L2_Scan_Destroy(instPtr->scanFSM);
|
||||
L2_Service_Destroy(instPtr->serviceFSM);
|
||||
free(instPtr);
|
||||
}
|
||||
@@ -848,6 +859,7 @@ int32_t Linklayer_EventHandler(L2_INST *instPtr, const L2_EVENT *l2Event)
|
||||
break;
|
||||
}
|
||||
DBG_WARNING("Lost connection with head node [%" PRId8 "].\n", L2_GetHeadId(instPtr));
|
||||
L2_Scan_Reset(instPtr->scanFSM);
|
||||
L2_Service_Reset(instPtr->serviceFSM);
|
||||
instPtr->cxn2Net = false;
|
||||
UpdateMainSate(instPtr, L2_INIT_STATE);
|
||||
@@ -857,6 +869,7 @@ int32_t Linklayer_EventHandler(L2_INST *instPtr, const L2_EVENT *l2Event)
|
||||
case L2_EV_LOST_NODE:
|
||||
{
|
||||
DBG_INFO("Event L2_EV_LOST_NODE asserted....\n");
|
||||
L2_Scan_Reset(instPtr->scanFSM);
|
||||
L2_Service_Reset(instPtr->serviceFSM);
|
||||
UpdateMainSate(instPtr, L2_INIT_STATE);
|
||||
// Log reconnect
|
||||
@@ -869,6 +882,7 @@ int32_t Linklayer_EventHandler(L2_INST *instPtr, const L2_EVENT *l2Event)
|
||||
if (instPtr->nextState == L2_INIT_STATE)
|
||||
{
|
||||
// Reset scan net FMS for next scan process.
|
||||
L2_Scan_Reset(instPtr->scanFSM);
|
||||
UpdateMainSate(instPtr, L2_INIT_STATE);
|
||||
instPtr->rtneConfig.rtneTable = initTable;
|
||||
instPtr->rtneConfig.rtnePrd = ARRAY_SIZE(initTable);
|
||||
@@ -1122,10 +1136,7 @@ int32_t Linklayer_Proc(L2_INST *instPtr)
|
||||
else
|
||||
{
|
||||
Phy_SetMode(phyRef, PHY_MODE_LISTEN);
|
||||
|
||||
// Trigger physical configuration.
|
||||
// Indicate physical layer that all the configurations were done.
|
||||
PhyWrite(phyRef, SLOT_CMD, SLOT_CMD_KEY);
|
||||
Status = L2_Scan_Proc(instPtr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1146,6 +1157,7 @@ int32_t Linklayer_Proc(L2_INST *instPtr)
|
||||
instPtr->linkLog.cxnStatus = (L2_isCxn2Net(instPtr)) ? 0x11 : 0x00;
|
||||
instPtr->linkLog.linkStage = (instPtr->mainState == L2_INIT_STATE) ? 0x11 : 0x22;
|
||||
instPtr->linkLog.recxnCnt = instPtr->log.reconnectCnt;
|
||||
instPtr->linkLog.antIndex = instPtr->config.phyInstPtr->antIndex.curr;
|
||||
instPtr->linkLog.advTxCnt = (uint16_t)instPtr->log.advTxCnt;
|
||||
instPtr->linkLog.advRecvCnt = (uint16_t)instPtr->log.advRecvCnt;
|
||||
instPtr->linkLog.advCorrectCnt = (uint16_t)instPtr->log.advCorrectCnt;
|
||||
@@ -1301,12 +1313,25 @@ int32_t L2_SetupNextSlot(L2_INST *instPtr, L2_TOR_TYPE txrxMode, L2_FRAME_TYPE f
|
||||
L2_RcdShift(&(instPtr->frame), frameType);
|
||||
L2_RcdShift(&(instPtr->tor), txrxMode);
|
||||
|
||||
TIME_WORD pullTime = {0, 0};
|
||||
pullTime.int_part = TimeCtrl_GetIntCnt(instPtr->config.tmcInstPtr) + 1;
|
||||
Status = Phy_SetTimeWord(phyRef, &pullTime, PHY_TIME_WORD_POLL);
|
||||
if (Status != SUCCESS)
|
||||
if (L2_isCxn2Net(instPtr) == false)
|
||||
{
|
||||
DBG_ERROR("Physical set pull time failed, with error code: %" PRId32 "\n", Status);
|
||||
// NOTE: LISTENING mode is assumed.
|
||||
TIME_WORD listenTime = {LISTEN_TIMEOUT_INT, 0};
|
||||
Status = Phy_SetTimeWord(phyRef, &listenTime, PHY_TIME_WORD_LISTEN_TIMEOUT);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Physical set listening timeout failed, with error code: %" PRId32 "\n", Status);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TIME_WORD pollTime = {0, 0};
|
||||
pollTime.int_part = TimeCtrl_GetIntCnt(instPtr->config.tmcInstPtr) + 1;
|
||||
Status = Phy_SetTimeWord(phyRef, &pollTime, PHY_TIME_WORD_POLL);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Physical set poll time failed, with error code: %" PRId32 "\n", Status);
|
||||
}
|
||||
}
|
||||
|
||||
PHY_TOR_TYPE tor;
|
||||
|
||||
Reference in New Issue
Block a user