forked from gatsby/df_datalink
feat: 修改聆听逻辑, 增加超时时间判定与下发
This commit is contained in:
@@ -34,7 +34,6 @@
|
|||||||
/************************** Constant Definitions *****************************/
|
/************************** Constant Definitions *****************************/
|
||||||
#define NET_START_TIME_INFTY UINT32_MAX
|
#define NET_START_TIME_INFTY UINT32_MAX
|
||||||
#define LINK_BROCK_THRESHOLD L2_SLOTS_PER_FRAME // 0.5 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 *****************************/
|
/************************** Variable Definitions *****************************/
|
||||||
/***************** Macros (Inline Functions) Definitions *********************/
|
/***************** Macros (Inline Functions) Definitions *********************/
|
||||||
@@ -1313,17 +1312,6 @@ int32_t L2_SetupNextSlot(L2_INST *instPtr, L2_TOR_TYPE txrxMode, L2_FRAME_TYPE f
|
|||||||
L2_RcdShift(&(instPtr->frame), frameType);
|
L2_RcdShift(&(instPtr->frame), frameType);
|
||||||
L2_RcdShift(&(instPtr->tor), txrxMode);
|
L2_RcdShift(&(instPtr->tor), txrxMode);
|
||||||
|
|
||||||
if (L2_isCxn2Net(instPtr) == false)
|
|
||||||
{
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TIME_WORD pollTime = {0, 0};
|
TIME_WORD pollTime = {0, 0};
|
||||||
pollTime.int_part = TimeCtrl_GetIntCnt(instPtr->config.tmcInstPtr) + 1;
|
pollTime.int_part = TimeCtrl_GetIntCnt(instPtr->config.tmcInstPtr) + 1;
|
||||||
Status = Phy_SetTimeWord(phyRef, &pollTime, PHY_TIME_WORD_POLL);
|
Status = Phy_SetTimeWord(phyRef, &pollTime, PHY_TIME_WORD_POLL);
|
||||||
|
|||||||
@@ -213,8 +213,8 @@ typedef struct
|
|||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
bool isAdvRecvd; ///< indicates if advertisement frame done(antenna locked).
|
TIME_WORD timeoutWord; ///< listening timeout word
|
||||||
uint8_t advCnt; ///< adv receive try count
|
uint8_t timeoutCnt; ///< listening timeout count
|
||||||
} L2_SCAN_FSM;
|
} L2_SCAN_FSM;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,7 +31,8 @@
|
|||||||
#include "../phy_layer/phy_layer.h"
|
#include "../phy_layer/phy_layer.h"
|
||||||
|
|
||||||
/************************** Constant Definitions *****************************/
|
/************************** Constant Definitions *****************************/
|
||||||
#define ACK_FRAME_SLOTS 4
|
#define LISTEN_TIMEOUT_INT 2*L2_SLOTS_PER_FRAME // number of 2 ms slots
|
||||||
|
|
||||||
/***************** Macros (In-line Functions) Definitions *********************/
|
/***************** Macros (In-line Functions) Definitions *********************/
|
||||||
|
|
||||||
/**************************** Type Definitions *******************************/
|
/**************************** Type Definitions *******************************/
|
||||||
@@ -39,52 +40,8 @@
|
|||||||
/************************** Variable Definitions *****************************/
|
/************************** Variable Definitions *****************************/
|
||||||
|
|
||||||
/************************** Function Prototypes ******************************/
|
/************************** Function Prototypes ******************************/
|
||||||
static void AdvRecvStateUpdate(L2_SCAN_FSM *scanFsmPtr, bool state);
|
|
||||||
static int32_t Scan_AdvHandler(L2_INST *instPtr);
|
|
||||||
static int32_t ScanMsg_Packing(L2_INST *instPtr, L2_FRAME_TYPE type, uint8_t dstId);
|
static int32_t ScanMsg_Packing(L2_INST *instPtr, L2_FRAME_TYPE type, uint8_t dstId);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Update Base-info Advertisement state.
|
|
||||||
*/
|
|
||||||
static void AdvRecvStateUpdate(L2_SCAN_FSM *scanFsmPtr, bool state)
|
|
||||||
{
|
|
||||||
ASSERT(scanFsmPtr != NULL);
|
|
||||||
DBG_INFO("Update AdvRecvState from [%" PRId8 "] to [%" PRId8 "].\n",
|
|
||||||
scanFsmPtr->isAdvRecvd, state);
|
|
||||||
scanFsmPtr->isAdvRecvd = state;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/**
|
|
||||||
* @brief Member node scan net BmAdvt stage handler.
|
|
||||||
*
|
|
||||||
* @param instPtr Pointer to linklayer layer instance.
|
|
||||||
*
|
|
||||||
* @return used slot (2 ms slot).
|
|
||||||
*
|
|
||||||
******************************************************************************/
|
|
||||||
static int32_t Scan_AdvHandler(L2_INST *instPtr)
|
|
||||||
{
|
|
||||||
ASSERT(instPtr != NULL);
|
|
||||||
L2_SCAN_FSM *scanFsmPtr = instPtr->scanFSM;
|
|
||||||
DBG_INFO("** Net-Setup - Advertisement Procedure (Attempts: %" PRIu8 ") **\n", scanFsmPtr->advCnt);
|
|
||||||
|
|
||||||
// Network status is updated in L2_Scan_PktHandler() if valid ADV frame is received.
|
|
||||||
if (scanFsmPtr->isAdvRecvd == true)
|
|
||||||
{
|
|
||||||
DBG_ERROR("Only unconnected node can execute Scan_AdvHandler().\n");
|
|
||||||
return EUNEXP;
|
|
||||||
}
|
|
||||||
// no valid bm frame was received.
|
|
||||||
else
|
|
||||||
{
|
|
||||||
(void)L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_FRAME_ADV);
|
|
||||||
scanFsmPtr->advCnt++;
|
|
||||||
}
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/**
|
/**
|
||||||
* @brief Packing Scan message to a bit array.
|
* @brief Packing Scan message to a bit array.
|
||||||
@@ -292,8 +249,6 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg)
|
|||||||
memcpy(instPtr->log.rxLog.data, msg, sizeof(L2_MSG_ADV));
|
memcpy(instPtr->log.rxLog.data, msg, sizeof(L2_MSG_ADV));
|
||||||
instPtr->log.rxLog.dataId = dataId;
|
instPtr->log.rxLog.dataId = dataId;
|
||||||
|
|
||||||
// trigger flag
|
|
||||||
AdvRecvStateUpdate(scanFsmPtr, true);
|
|
||||||
Status = SUCCESS;
|
Status = SUCCESS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -408,8 +363,9 @@ int32_t L2_Scan_Init(L2_SCAN_FSM **scanFSMPtr)
|
|||||||
void L2_Scan_Reset(L2_SCAN_FSM *scanFSMPtr)
|
void L2_Scan_Reset(L2_SCAN_FSM *scanFSMPtr)
|
||||||
{
|
{
|
||||||
ASSERT(scanFSMPtr != NULL);
|
ASSERT(scanFSMPtr != NULL);
|
||||||
scanFSMPtr->isAdvRecvd = false;
|
scanFSMPtr->timeoutWord.int_part = 0;
|
||||||
scanFSMPtr->advCnt = 0;
|
scanFSMPtr->timeoutWord.frac_part = 0;
|
||||||
|
scanFSMPtr->timeoutCnt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -428,26 +384,53 @@ void L2_Scan_Destroy(L2_SCAN_FSM *scanFSMPtr)
|
|||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/**
|
/**
|
||||||
* @brief Execute a member node scan net procedure.
|
* @brief Member node listening procedure.
|
||||||
*
|
*
|
||||||
* @param instPtr a pointer to linklayer layer instance
|
* @param instPtr Pointer to linklayer layer instance.
|
||||||
*
|
*
|
||||||
* @return used slot (2 ms slot).
|
* @return used slot (2 ms slot).
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
int32_t L2_Scan_Proc(L2_INST *instPtr)
|
int32_t L2_Scan_Proc(L2_INST *instPtr)
|
||||||
{
|
{
|
||||||
if (L2_GetNodeType(instPtr) == L2_NODE_HEAD)
|
ASSERT(instPtr != NULL);
|
||||||
{
|
PHY_INST *phyRef = instPtr->config.phyInstPtr;
|
||||||
DBG_ERROR("Only member node needs to execute L2_Scan_Proc. \n");
|
L2_SCAN_FSM *scanFsmPtr = instPtr->scanFSM;
|
||||||
return FAILURE;
|
|
||||||
}
|
|
||||||
int32_t Status;
|
int32_t Status;
|
||||||
DBG_INFO("-------- ScanNet Process --------\n");
|
DBG_INFO("** Net-Setup - Listening Procedure (Attempts: %" PRIu8 ") **\n", scanFsmPtr->advCnt);
|
||||||
|
|
||||||
Status = Scan_AdvHandler(instPtr);
|
uint32_t currTimeInt = TimeCtrl_GetIntCnt(instPtr->config.tmcInstPtr);
|
||||||
|
|
||||||
|
if (scanFsmPtr->timeoutWord.int_part < currTimeInt)
|
||||||
|
{
|
||||||
|
// listening timeout: current system time + listening duration
|
||||||
|
TIME_WORD listenTime = {currTimeInt + 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);
|
||||||
|
}
|
||||||
|
scanFsmPtr->timeoutWord = listenTime;
|
||||||
|
|
||||||
|
// physical start time: set to next slot
|
||||||
|
TIME_WORD pollTime = {0, 0};
|
||||||
|
pollTime.int_part = currTimeInt + 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
Status = Phy_SetupNextSlot(phyRef, PHY_TOR_RX, L2_L2frame2L1frame(L2_FRAME_ADV, L2_SVC_NONE),
|
||||||
|
instPtr->sendPktData);
|
||||||
|
|
||||||
|
// record
|
||||||
|
scanFsmPtr->timeoutCnt++;
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|||||||
@@ -649,7 +649,7 @@ static int32_t Service_PktHandler2M(L2_INST *instPtr, uint8_t *msg)
|
|||||||
/**
|
/**
|
||||||
* @brief Initialize service net FSM
|
* @brief Initialize service net FSM
|
||||||
*
|
*
|
||||||
* @param serviceFSM A pointer to service FSM instance.
|
* @param svcFSMPtr A pointer to service FSM instance.
|
||||||
*
|
*
|
||||||
* @return SUCCESS Initialize successfully.
|
* @return SUCCESS Initialize successfully.
|
||||||
* Other Initialize failed.
|
* Other Initialize failed.
|
||||||
@@ -671,7 +671,7 @@ int32_t L2_Service_Init(L2_SVC_FSM **svcFSMPtr)
|
|||||||
/**
|
/**
|
||||||
* @brief Reset ServiceNet FSM
|
* @brief Reset ServiceNet FSM
|
||||||
*
|
*
|
||||||
* @param scanFsmPtr a pointer to service net finite state machine
|
* @param svcFSMPtr a pointer to service net finite state machine
|
||||||
*
|
*
|
||||||
* @return NONE
|
* @return NONE
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user