|
|
|
@@ -31,7 +31,8 @@
|
|
|
|
|
#include "../phy_layer/phy_layer.h"
|
|
|
|
|
|
|
|
|
|
/************************** 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 *********************/
|
|
|
|
|
|
|
|
|
|
/**************************** Type Definitions *******************************/
|
|
|
|
@@ -39,52 +40,8 @@
|
|
|
|
|
/************************** Variable Definitions *****************************/
|
|
|
|
|
|
|
|
|
|
/************************** 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);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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.
|
|
|
|
@@ -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));
|
|
|
|
|
instPtr->log.rxLog.dataId = dataId;
|
|
|
|
|
|
|
|
|
|
// trigger flag
|
|
|
|
|
AdvRecvStateUpdate(scanFsmPtr, true);
|
|
|
|
|
Status = SUCCESS;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@@ -408,8 +363,9 @@ int32_t L2_Scan_Init(L2_SCAN_FSM **scanFSMPtr)
|
|
|
|
|
void L2_Scan_Reset(L2_SCAN_FSM *scanFSMPtr)
|
|
|
|
|
{
|
|
|
|
|
ASSERT(scanFSMPtr != NULL);
|
|
|
|
|
scanFSMPtr->isAdvRecvd = false;
|
|
|
|
|
scanFSMPtr->advCnt = 0;
|
|
|
|
|
scanFSMPtr->timeoutWord.int_part = 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)
|
|
|
|
|
{
|
|
|
|
|
if (L2_GetNodeType(instPtr) == L2_NODE_HEAD)
|
|
|
|
|
{
|
|
|
|
|
DBG_ERROR("Only member node needs to execute L2_Scan_Proc. \n");
|
|
|
|
|
return FAILURE;
|
|
|
|
|
}
|
|
|
|
|
ASSERT(instPtr != NULL);
|
|
|
|
|
PHY_INST *phyRef = instPtr->config.phyInstPtr;
|
|
|
|
|
L2_SCAN_FSM *scanFsmPtr = instPtr->scanFSM;
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
|
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 SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|