forked from gatsby/datalink_repo
enhance coherence.
This commit is contained in:
@@ -152,13 +152,11 @@ static int32_t ScanMsg_Packing(L2_INST* instPtr, BIT_ARRAY* bitarr, L2_MSG_TYPE
|
||||
FrameInsertChunk(bitarr, BM_MSG_TYPE_OFFSET, BM_MSG_TYPE_LEN, dataChunk);
|
||||
|
||||
/* source node id */
|
||||
dataChunk = (instPtr->myInfo.nodeId & 0x1F)
|
||||
| (((uint16_t)(instPtr->myInfo.clustId & 0x1F)) << 5);
|
||||
dataChunk = (L2_GetNodeId(instPtr) & 0x1F) | (((uint16_t)(L2_GetClusterId(instPtr) & 0x1F)) << 5);
|
||||
FrameInsertChunk(bitarr, BM_MSG_SRC_ADDR_OFFSET, BM_MSG_SRC_ADDR_LEN, dataChunk);
|
||||
|
||||
/* net management node id */
|
||||
dataChunk = (instPtr->config.headId & 0x1F)
|
||||
| (((uint16_t)(instPtr->myInfo.clustId & 0x1F)) << 5);
|
||||
dataChunk = (L2_GetHeadId(instPtr) & 0x1F) | (((uint16_t)(L2_GetClusterId(instPtr) & 0x1F)) << 5);
|
||||
FrameInsertChunk(bitarr, BM_MSG_NETMG_ADDR_OFFSET, BM_MSG_NETMG_ADDR_LEN, dataChunk);
|
||||
|
||||
/* time unit number */
|
||||
@@ -227,20 +225,20 @@ static int32_t ScanMsg_Packing(L2_INST* instPtr, BIT_ARRAY* bitarr, L2_MSG_TYPE
|
||||
FrameInsertChunk(bitarr, NS_MSG_INI_LEN_OFFSET, NS_MSG_INI_LEN_LEN, dataChunk);
|
||||
|
||||
/* message type */
|
||||
dataChunk = (instPtr->myInfo.nodeId == HEAD_NODE) ? 0 : 1;
|
||||
dataChunk = (L2_GetNodeId(instPtr) == HEAD_NODE) ? 0 : 1;
|
||||
FrameInsertChunk(bitarr, NS_MSG_INI_TYPE_OFFSET, NS_MSG_INI_TYPE_LEN, dataChunk);
|
||||
|
||||
/* source node id */
|
||||
dataChunk = (instPtr->myInfo.nodeId & 0x1F)
|
||||
| (((uint16_t)(instPtr->myInfo.clustId & 0x1F)) << 5);
|
||||
dataChunk = (L2_GetNodeId(instPtr) & 0x1F)
|
||||
| (((uint16_t)(L2_GetClusterId(instPtr) & 0x1F)) << 5);
|
||||
FrameInsertChunk(bitarr, NS_MSG_INI_SRC_ADDR_OFFSET, NS_MSG_INI_SRC_ADDR_LEN, dataChunk);
|
||||
|
||||
/* destination node id */
|
||||
dataChunk = (instPtr->myInfo.nodeId == HEAD_NODE) ?
|
||||
(0x3F | (0x3F << 5)) :
|
||||
(instPtr->config.headId & 0x1F) | (((uint16_t)(instPtr->myInfo.clustId & 0x1F)) << 5);
|
||||
dataChunk = (L2_GetNodeId(instPtr) == HEAD_NODE) ?
|
||||
(BROADCAST_ID | (BROADCAST_ID << 5))
|
||||
: (L2_GetHeadId(instPtr) & 0x1F) | (((uint16_t)(L2_GetClusterId(instPtr) & 0x1F)) << 5);
|
||||
FrameInsertChunk(bitarr, NS_MSG_INI_LEN_OFFSET, NS_MSG_INI_LEN_LEN, dataChunk);
|
||||
if (instPtr->myInfo.nodeType == HEAD_NODE) {
|
||||
if (L2_GetNodeType(instPtr) == HEAD_NODE) {
|
||||
/* current net stage */
|
||||
switch (instPtr->mainState) {
|
||||
case INIT_STATE:
|
||||
@@ -426,25 +424,13 @@ failed:
|
||||
static int32_t Scan_InitScanHandler(L2_INST* instPtr) {
|
||||
ASSERT(instPtr != NULL);
|
||||
L2_SCAN_FSM* scanFsmPtr = instPtr->scanNetFSM;
|
||||
PHY_INST* phyRef = instPtr->config.phyInstPtr;
|
||||
static uint32_t scanCnt = 0;
|
||||
DBG_INFO("** Netsetup - InitScan Procedure--**\n");
|
||||
/* clear ack state and lock state in a new scan procedure. */
|
||||
if(scanCnt == 0){
|
||||
LockStateUpdate(scanFsmPtr, false);
|
||||
BmrecvStateUpdate(scanFsmPtr, false);
|
||||
W2ackStateUpdate(scanFsmPtr, false);
|
||||
}
|
||||
if(Phy_IsFrameDetected(phyRef)){
|
||||
LockStateUpdate(scanFsmPtr, true);
|
||||
}
|
||||
DBG_INFO("** Netsetup - InitScan Procedure (Attempts: %u)**\n", scanFsmPtr->scanCnt);
|
||||
|
||||
if(scanFsmPtr->scanMode == INTRA_CLUSTER_MODE){
|
||||
if (scanFsmPtr->isLocked == true) {
|
||||
StageUpdate(scanFsmPtr, BM_ADVT_STAGE);
|
||||
/* Antenna setting (reserved.) */
|
||||
L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_INTRA_BM_FRAME);
|
||||
scanCnt = 0;
|
||||
} /* Otherwise remain INIT_SCAN_STAGE */
|
||||
else {
|
||||
/* Antenna setting (reserved.) */
|
||||
@@ -484,18 +470,13 @@ static int32_t Scan_InitScanHandler(L2_INST* instPtr) {
|
||||
******************************************************************************/
|
||||
static int32_t Scan_BmAdvtHandler(L2_INST* instPtr) {
|
||||
L2_SCAN_FSM* scanFsmPtr = instPtr->scanNetFSM;
|
||||
DBG_INFO("** Netsetup - BmAdvt Procedure--**\n");
|
||||
DBG_INFO("BM Timeout: %u.\n", scanFsmPtr->bmTimeout);
|
||||
DBG_INFO("** Netsetup - BmAdvt Procedure (Timeout: %u) **\n", scanFsmPtr->bmTimeout);
|
||||
|
||||
// if received a valid bm frame.
|
||||
if (scanFsmPtr->isBmRcved == true) {
|
||||
scanFsmPtr->bmTimeout = 0; /* reset listen counter. */
|
||||
/* First BM Advt Frame. */
|
||||
DBG_INFO("Received Bm frame.\n");
|
||||
DBG_INFO("Skipping 10ms for turn around.\n");
|
||||
/* Antenna setting (reserved.) */
|
||||
// FIXME: SUSPEND how many slots in inter net setup mode?
|
||||
L2_SetupNextSlot(instPtr, L2_TOR_SUSPEND, L2_INTRA_W2_ACQ_FRAME);
|
||||
DBG_INFO("Received Bm frame, skipping 10ms for turn around...\n");
|
||||
// TODO: check functionality.
|
||||
StageUpdate(scanFsmPtr, WAY2_ACQ_STAGE);
|
||||
return NUM_SLOTS_10MS;
|
||||
}
|
||||
@@ -515,8 +496,9 @@ static int32_t Scan_BmAdvtHandler(L2_INST* instPtr) {
|
||||
DBG_ERROR("UNKNOWN Scan Mode: %d.\n", scanFsmPtr->scanMode);
|
||||
return NUM_SLOTS_NONE;
|
||||
}
|
||||
StageUpdate(scanFsmPtr, INIT_SCAN_STAGE);
|
||||
DBG_WARNING("BM timeout, restart net scan from INIT_SCAN_STAGE.\n");
|
||||
scanFsmPtr->bmTimeout = 0; /* reset listen counter. */
|
||||
StageUpdate(scanFsmPtr, INIT_SCAN_STAGE);
|
||||
}
|
||||
else {
|
||||
if(scanFsmPtr->scanMode == INTRA_CLUSTER_MODE){
|
||||
@@ -548,8 +530,7 @@ static int32_t Scan_BmAdvtHandler(L2_INST* instPtr) {
|
||||
******************************************************************************/
|
||||
static int32_t Scan_2WAcqHandler (L2_INST* instPtr){
|
||||
L2_SCAN_FSM* scanFsmPtr = instPtr->scanNetFSM;
|
||||
DBG_INFO("** Netsetup - 2WAcq Procedure--**\n");
|
||||
DBG_INFO("2WAcq Timeout: %u.\n", scanFsmPtr->w2acqTimeout);
|
||||
DBG_INFO("** Netsetup - 2WAcq Procedure (Timeout: %u) **\n", scanFsmPtr->w2acqTimeout);
|
||||
L2_FRAME_TYPE frameType = L2_NONE_FRAME;
|
||||
|
||||
if(scanFsmPtr->scanMode == INTRA_CLUSTER_MODE){
|
||||
@@ -565,6 +546,7 @@ static int32_t Scan_2WAcqHandler (L2_INST* instPtr){
|
||||
|
||||
// 2 way acq failed, back to init stage.
|
||||
if (scanFsmPtr->w2acqTimeout >= WAY2_ACQ_SLOT_MAX) {
|
||||
DBG_WARNING("2WAcq timeout, restart net scan from INIT_SCAN_STAGE.\n");
|
||||
scanFsmPtr->w2acqTimeout = 0; // reset counter for next scan.
|
||||
StageUpdate(scanFsmPtr, INIT_SCAN_STAGE);
|
||||
}
|
||||
@@ -596,7 +578,7 @@ int32_t ScanNet_PktHandler(L2_INST* instPtr) {
|
||||
free(scanMsg);
|
||||
return EALLOC;
|
||||
}
|
||||
switch (L2_GetLastRcvFrameType(instPtr)) {
|
||||
switch (L2_GetLastFrameType(instPtr)) {
|
||||
case L2_INTER_SCAN_FRAME:
|
||||
case L2_INTRA_SCAN_FRAME:
|
||||
// refer to "linklayer814.c/L2_FrameStateUpdate"
|
||||
@@ -649,7 +631,7 @@ int32_t ScanNet_PktHandler(L2_INST* instPtr) {
|
||||
goto failed;
|
||||
}
|
||||
}
|
||||
if(instPtr->myInfo.nodeType != HEAD_NODE){
|
||||
if(L2_GetNodeType(instPtr) != HEAD_NODE){
|
||||
if (IsNodeInList(instPtr->nodeList, scanFsmPtr->BMrcvLog.NodeId) == false) {
|
||||
AppendNode(instPtr->nodeList, scanFsmPtr->BMrcvLog.NodeId, (uint8_t) MEMBER_NODE);
|
||||
}
|
||||
@@ -663,7 +645,7 @@ int32_t ScanNet_PktHandler(L2_INST* instPtr) {
|
||||
BmrecvStateUpdate(scanFsmPtr, true);
|
||||
}
|
||||
else{
|
||||
DBG_ERROR("Node type [%d] is not supposed to receive BM frame", instPtr->myInfo.nodeType);
|
||||
DBG_ERROR("Node type [%d] is not supposed to receive BM frame", L2_GetNodeType(instPtr));
|
||||
Status = EUNEXP;
|
||||
goto failed;
|
||||
}
|
||||
@@ -739,18 +721,18 @@ int32_t ScanNet_PktHandler(L2_INST* instPtr) {
|
||||
}
|
||||
}
|
||||
// Update net start time
|
||||
if(instPtr->myInfo.nodeType != HEAD_NODE){
|
||||
if(L2_GetNodeType(instPtr) != HEAD_NODE){
|
||||
instPtr->netStartTime = scanFsmPtr->W2ACQrcvLog.NetScanTime;
|
||||
}
|
||||
|
||||
if(instPtr->myInfo.nodeType == HEAD_NODE){
|
||||
if(L2_GetNodeType(instPtr) == HEAD_NODE){
|
||||
if (IsNodeInList(instPtr->nodeList, scanFsmPtr->W2ACQrcvLog.NodeId) == false) {
|
||||
AppendNode(instPtr->nodeList, scanFsmPtr->W2ACQrcvLog.NodeId, (uint8_t) MEMBER_NODE);
|
||||
}
|
||||
// TODO: Update Node Info
|
||||
}
|
||||
|
||||
if(instPtr->myInfo.nodeType != HEAD_NODE && scanFsmPtr->W2ACQrcvLog.NetStage != NONE_STATE){
|
||||
if(L2_GetNodeType(instPtr) != HEAD_NODE && scanFsmPtr->W2ACQrcvLog.NetStage != NONE_STATE){
|
||||
// sync state with head node
|
||||
L2_NODE_STATE newState = scanFsmPtr->W2ACQrcvLog.NetStage;
|
||||
L2_EVENT stateUpEvent = {
|
||||
@@ -786,8 +768,7 @@ int32_t ScanNet_PktHandler(L2_INST* instPtr) {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
DBG_ERROR("Cannot handler message type [%d] properly.\n",
|
||||
L2_GetLastRcvFrameType(instPtr));
|
||||
DBG_ERROR("Cannot handler message type [%d] properly.\n", L2_GetLastFrameType(instPtr));
|
||||
Status = EIGNORE;
|
||||
goto failed;
|
||||
}
|
||||
@@ -834,6 +815,9 @@ void ScanNet_Reset(L2_SCAN_FSM* scanFSMPtr) {
|
||||
scanFSMPtr->isLocked = false;
|
||||
scanFSMPtr->isBmRcved = false;
|
||||
scanFSMPtr->isAcked = false;
|
||||
scanFSMPtr->scanCnt = 0;
|
||||
scanFSMPtr->bmTimeout = 0;
|
||||
scanFSMPtr->w2acqTimeout = 0;
|
||||
scanFSMPtr->scanStage = NONE_STAGE;
|
||||
scanFSMPtr->scanMode = INTRA_CLUSTER_MODE;
|
||||
// FIXME: Only for test
|
||||
@@ -879,7 +863,7 @@ void ScanNet_Destroy(L2_SCAN_FSM* scanFSMPtr) {
|
||||
******************************************************************************/
|
||||
int32_t ScanNet_Proc(L2_INST* instPtr) {
|
||||
L2_SCAN_FSM* scanFsmPtr = instPtr->scanNetFSM;
|
||||
if (instPtr->myInfo.nodeType == HEAD_NODE) {
|
||||
if (L2_GetNodeType(instPtr) == HEAD_NODE) {
|
||||
DBG_ERROR("Only member node needs to execute ScanNet_Proc. \n");
|
||||
return NUM_SLOTS_NONE;
|
||||
}
|
||||
@@ -929,11 +913,11 @@ int32_t ScanNet_Routine(L2_INST* instPtr, const L2_RTNE_TABLE_ENTRY* rtneEntry)
|
||||
return SQUENCE_SCAN_SLOTS;
|
||||
}
|
||||
|
||||
if(instPtr->myInfo.nodeType != HEAD_NODE){
|
||||
if (rtneEntry->dst0 == instPtr->myInfo.nodeId || rtneEntry->dst0 == BROADCAST_ID){
|
||||
if(L2_GetNodeType(instPtr) != HEAD_NODE){
|
||||
if (rtneEntry->dst0 == L2_GetNodeId(instPtr) || rtneEntry->dst0 == BROADCAST_ID){
|
||||
torState = L2_TOR_RX;
|
||||
}
|
||||
else if (rtneEntry->src0 == instPtr->myInfo.nodeId || rtneEntry->src0 == BROADCAST_ID){
|
||||
else if (rtneEntry->src0 == L2_GetNodeId(instPtr) || rtneEntry->src0 == BROADCAST_ID){
|
||||
torState = L2_TOR_TX;
|
||||
}
|
||||
else {
|
||||
@@ -941,10 +925,10 @@ int32_t ScanNet_Routine(L2_INST* instPtr, const L2_RTNE_TABLE_ENTRY* rtneEntry)
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (rtneEntry->dst0 == instPtr->myInfo.nodeId){
|
||||
if (rtneEntry->dst0 == L2_GetNodeId(instPtr)){
|
||||
torState = L2_TOR_RX;
|
||||
}
|
||||
else if (rtneEntry->src0 == instPtr->myInfo.nodeId){
|
||||
else if (rtneEntry->src0 == L2_GetNodeId(instPtr)){
|
||||
torState = L2_TOR_TX;
|
||||
}
|
||||
else {
|
||||
@@ -959,7 +943,7 @@ int32_t ScanNet_Routine(L2_INST* instPtr, const L2_RTNE_TABLE_ENTRY* rtneEntry)
|
||||
break;
|
||||
|
||||
case SLOT_INTRA_SCAN_ACQ:
|
||||
if (instPtr->myInfo.nodeType != HEAD_NODE && torState == L2_TOR_TX) {
|
||||
if (L2_GetNodeType(instPtr) != HEAD_NODE && torState == L2_TOR_TX) {
|
||||
DBG_ERROR("Only head node can send init-scan Frame.\n");
|
||||
Status = FAILURE;
|
||||
goto routine_err;
|
||||
@@ -974,7 +958,7 @@ int32_t ScanNet_Routine(L2_INST* instPtr, const L2_RTNE_TABLE_ENTRY* rtneEntry)
|
||||
|
||||
case SLOT_INTRA_SCAN_BM:
|
||||
if (torState == L2_TOR_TX) {
|
||||
if (instPtr->myInfo.nodeType != HEAD_NODE) {
|
||||
if (L2_GetNodeType(instPtr) != HEAD_NODE) {
|
||||
DBG_ERROR("Only head node can send BM Frame.\n");
|
||||
Status = FAILURE;
|
||||
goto routine_err;
|
||||
@@ -990,12 +974,11 @@ int32_t ScanNet_Routine(L2_INST* instPtr, const L2_RTNE_TABLE_ENTRY* rtneEntry)
|
||||
break;
|
||||
case SLOT_INTER_SCAN_2W:
|
||||
// TODO:
|
||||
DBG_INFO("#Routine# [Inter Scan-W2_ACQ SUSPEND].\n");
|
||||
L2_SetupNextSlot(instPtr, L2_TOR_SUSPEND, L2_INTER_W2_ACQ_FRAME);
|
||||
break;
|
||||
case SLOT_INTRA_SCAN_2W:
|
||||
if (torState == L2_TOR_TX) {
|
||||
if(instPtr->myInfo.nodeType != HEAD_NODE && L2_isDataAvail(instPtr) == false) {
|
||||
if(L2_GetNodeType(instPtr) != HEAD_NODE && L2_isDataAvail(instPtr) == false) {
|
||||
/* Antenna setting (reserved.) */
|
||||
L2_SetupNextSlot(instPtr, L2_TOR_SUSPEND, L2_INTRA_W2_ACQ_FRAME);
|
||||
break;
|
||||
@@ -1007,6 +990,7 @@ int32_t ScanNet_Routine(L2_INST* instPtr, const L2_RTNE_TABLE_ENTRY* rtneEntry)
|
||||
Status = FAILURE;
|
||||
goto routine_err;
|
||||
}
|
||||
W2ackStateUpdate(instPtr->scanNetFSM, true);
|
||||
acqSend ++;
|
||||
}
|
||||
/* Antenna setting (reserved.) */
|
||||
|
||||
Reference in New Issue
Block a user