Compare commits
34
Commits
709619d5bf
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07795a2b20 | ||
|
|
21d3baec98 | ||
|
|
ad0d589141 | ||
|
|
247700fee2 | ||
|
|
31ec331464 | ||
|
|
297cd0d0da | ||
|
|
452df8ad81 | ||
|
|
966148ebef | ||
|
|
693a63a800 | ||
|
|
5745fef452 | ||
|
|
f4af6a1522 | ||
|
|
0f5526736d | ||
|
|
417e566e3d | ||
|
|
12fc651673 | ||
|
|
cb1e368b58 | ||
|
|
c9058b2c63 | ||
|
|
c722ba4277 | ||
|
|
6167475307 | ||
|
|
e55c135229 | ||
|
|
29243b9656 | ||
|
|
de3ae1c3bc | ||
|
|
a0874d55c7 | ||
|
|
26d22b67fb | ||
|
|
35df4d059a | ||
|
|
3fb8b7622c | ||
|
|
deb7433735 | ||
|
|
9c335b0ff2 | ||
|
|
b76f7bedb4 | ||
|
|
2bf10f25b0 | ||
|
|
3f38659af0 | ||
|
|
1e0ad014de | ||
|
|
61a3c49ce8 | ||
|
|
162e291533 | ||
|
|
726d52c674 |
@@ -20,26 +20,25 @@
|
||||
#include <string.h>
|
||||
#include "linklayer814.h"
|
||||
#include "linklayer814_types.h"
|
||||
#include "node_list.h"
|
||||
#include "msg_def.h"
|
||||
#include "../error.h"
|
||||
#include "../time_ctrl/time_ctrl.h"
|
||||
#include "../util/util.h"
|
||||
#include "../common.h"
|
||||
#include "../util/util.h"
|
||||
#include "../time_ctrl/time_ctrl.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
#define NET_START_TIME_INFTY UINT32_MAX
|
||||
/************************** Variable Definitions *****************************/
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
/************************** Function Prototypes ******************************/
|
||||
static void L2_RcdShift(L2_RCD *rcd, int32_t netxVal);
|
||||
static void UpdateMainSate(L2_INST *instPtr, L2_NODE_STATE newSate);
|
||||
static void L2_SetSlotNum(L2_INST *instPtr, uint32_t newSlotNum);
|
||||
static void L2_SetFrameNum(L2_INST *instPtr, uint32_t newFrameNum);
|
||||
static void L2_UpdateSlotNum(L2_INST *instPtr);
|
||||
static void L2_DataAvailUpdate(L2_INST *instPtr, bool status);
|
||||
static L2_FRAME_TYPE L2_GetReceiveFrameType(L2_INST *instPtr);
|
||||
|
||||
/**
|
||||
* @brief helper function to update linkelayer state
|
||||
@@ -305,14 +304,14 @@ inline void L2_RcdShift(L2_RCD *rcd, int32_t netxVal)
|
||||
* @return L2_FRAME_TYPE.
|
||||
*
|
||||
******************************************************************************/
|
||||
static L2_FRAME_TYPE L2_GetReceiveFrameType(L2_INST *instPtr)
|
||||
L2_FRAME_TYPE L2_GetLastOptFrameType(L2_INST *instPtr)
|
||||
{
|
||||
if (instPtr->myInfo.nodeType == L2_NODE_HEAD || L2_isCxn2Net(instPtr))
|
||||
{
|
||||
return instPtr->frame.curr;
|
||||
}
|
||||
|
||||
switch (instPtr->scanNetFSM->scanStage)
|
||||
switch (instPtr->scanFSM->scanStage)
|
||||
{
|
||||
case L2_SCAN_INIT_STAGE:
|
||||
case L2_SCAN_BMADVT_STAGE:
|
||||
@@ -350,7 +349,8 @@ void L2_FrameStateUpdate(L2_INST *instPtr)
|
||||
Phy_RetrieveRecvData(phyRef, instPtr->recvPktData);
|
||||
instPtr->log.frameRecv++;
|
||||
|
||||
switch (L2_GetReceiveFrameType(instPtr))
|
||||
// Update frame state.
|
||||
switch (L2_GetLastOptFrameType(instPtr))
|
||||
{
|
||||
case L2_INTRA_SCAN_FRAME:
|
||||
// INTRA_BM_FRAME could be received if current frame type is INTRA_BM_FRAME
|
||||
@@ -606,7 +606,7 @@ uint32_t L2_GetFrameLen(L2_FRAME_TYPE l2FrameType)
|
||||
/**
|
||||
* @brief Convert L2 frame type to L1 frame type
|
||||
*
|
||||
* @param phyInstPtr A pointer to physical layer control instance.
|
||||
* @param l2Frame
|
||||
*
|
||||
* @return L1 frame type.
|
||||
*
|
||||
@@ -818,24 +818,24 @@ int32_t Linklayer_Init(L2_INST **instPtr, const L2_CONFIG *config)
|
||||
goto error;
|
||||
}
|
||||
|
||||
Status = ScanNet_Init(&((*instPtr)->scanNetFSM));
|
||||
Status = L2_Scan_Init(&((*instPtr)->scanFSM));
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("ScanNet_Init runs failed, with error code: %d.\n", Status);
|
||||
DBG_ERROR("L2_Scan_Init runs failed, with error code: %d.\n", Status);
|
||||
goto error;
|
||||
}
|
||||
|
||||
Status = MgmtNet_Init(&((*instPtr)->mgmtNetFSM));
|
||||
Status = L2_Mgmt_Init(&((*instPtr)->mgmtFSM));
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("MgmtNet_Init runs failed, with error code: %d.\n", Status);
|
||||
DBG_ERROR("L2_Mgmt_Init runs failed, with error code: %d.\n", Status);
|
||||
goto error;
|
||||
}
|
||||
|
||||
Status = ServiceNet_Init(&((*instPtr)->serviceNetFSM));
|
||||
Status = L2_Service_Init(&((*instPtr)->serviceFSM));
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("ServiceNet_Init runs failed, with error code: %d.\n", Status);
|
||||
DBG_ERROR("L2_Service_Init runs failed, with error code: %d.\n", Status);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -923,9 +923,9 @@ int32_t Linklayer_Reconfig(L2_INST *instPtr, const L2_CONFIG *config)
|
||||
// Reset according instance
|
||||
L2_ClearSchedEventPool(instPtr->schdEventPool);
|
||||
L2_NodeList_Clear(instPtr->nodeList);
|
||||
ScanNet_Reset(instPtr->scanNetFSM);
|
||||
MgmtNet_Reset(instPtr->mgmtNetFSM);
|
||||
ServiceNet_Reset(instPtr->serviceNetFSM);
|
||||
L2_Scan_Reset(instPtr->scanFSM);
|
||||
L2_Mgmt_Reset(instPtr->mgmtFSM);
|
||||
L2_Service_Reset(instPtr->serviceFSM);
|
||||
RTT_Reset(instPtr->rttFSM);
|
||||
return SUCCESS;
|
||||
}
|
||||
@@ -951,9 +951,9 @@ void Linklayer_Destroy(L2_INST *instPtr)
|
||||
// Destroy FSMs and nodeList
|
||||
L2_DestroySchedEventPool(instPtr->schdEventPool);
|
||||
L2_NodeList_Destroy(instPtr->nodeList);
|
||||
ScanNet_Destroy(instPtr->scanNetFSM);
|
||||
MgmtNet_Destroy(instPtr->mgmtNetFSM);
|
||||
ServiceNet_Destroy(instPtr->serviceNetFSM);
|
||||
L2_Scan_Destroy(instPtr->scanFSM);
|
||||
L2_Mgmt_Destroy(instPtr->mgmtFSM);
|
||||
L2_Service_Destroy(instPtr->serviceFSM);
|
||||
RTT_Destroy(instPtr->rttFSM);
|
||||
free(instPtr);
|
||||
}
|
||||
@@ -1030,11 +1030,6 @@ int32_t Linklayer_EventHandler(L2_INST *instPtr, const L2_EVENT *l2Event)
|
||||
// TODO: Clear ACK
|
||||
break;
|
||||
}
|
||||
case L2_EV_MGMT_PROC_DONE:
|
||||
{
|
||||
DBG_INFO("Event L2_EV_MGMT_PROC_DONE asserted....\n");
|
||||
break;
|
||||
}
|
||||
case L2_EV_NET_SETUP_DONE:
|
||||
{
|
||||
DBG_INFO("Event L2_EV_NETSETUP_DONE asserted....\n");
|
||||
@@ -1066,8 +1061,17 @@ 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)
|
||||
{
|
||||
DBG_ERROR("Illegal event, only None_Head node can assert L2_EV_LOST_CXN.\n");
|
||||
break;
|
||||
}
|
||||
DBG_WARNING("Lost connection with head node [%d].\n", L2_GetHeadId(instPtr));
|
||||
L2_Scan_Reset(instPtr->scanFSM);
|
||||
L2_Mgmt_Reset(instPtr->mgmtFSM);
|
||||
L2_Service_Reset(instPtr->serviceFSM);
|
||||
instPtr->cxn2Net = false;
|
||||
UpdateMainSate(instPtr, L2_INIT_STATE);
|
||||
break;
|
||||
}
|
||||
case L2_EV_LOST_NODE:
|
||||
@@ -1081,8 +1085,8 @@ 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.
|
||||
ScanNet_Reset(instPtr->scanNetFSM);
|
||||
UpdateMainSate(instPtr, L2_NORMAL_STATE);
|
||||
L2_Scan_Reset(instPtr->scanFSM);
|
||||
UpdateMainSate(instPtr, L2_INIT_STATE);
|
||||
instPtr->rtneConfig.rtneTable = normalTable;
|
||||
instPtr->rtneConfig.rtnePrd = ARRAY_SIZE(normalTable);
|
||||
}
|
||||
@@ -1106,6 +1110,10 @@ int32_t Linklayer_EventHandler(L2_INST *instPtr, const L2_EVENT *l2Event)
|
||||
instPtr->rtneConfig.rtneTable = interSeekTable;
|
||||
instPtr->rtneConfig.rtnePrd = ARRAY_SIZE(interSeekTable);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_WARNING("Unsupported routine state [%d], Continue withe previous routine table.\n", instPtr->nextState);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case L2_ROUTINE_UPDATE:
|
||||
@@ -1135,12 +1143,10 @@ int32_t Linklayer_EventHandler(L2_INST *instPtr, const L2_EVENT *l2Event)
|
||||
* @return Status code.
|
||||
*
|
||||
******************************************************************************/
|
||||
int mgmtFrameRecv = 0;
|
||||
int svcFrameRecv = 0;
|
||||
int32_t Linklayer_PktHandler(L2_INST *instPtr, L2_FRAME_TYPE frameType)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
int32_t Status = SUCCESS;
|
||||
int32_t Status;
|
||||
|
||||
if (instPtr->dataAvail == false)
|
||||
{
|
||||
@@ -1155,7 +1161,7 @@ int32_t Linklayer_PktHandler(L2_INST *instPtr, L2_FRAME_TYPE frameType)
|
||||
case L2_INTRA_BM_FRAME:
|
||||
case L2_INTER_W2_ACQ_FRAME:
|
||||
case L2_INTRA_W2_ACQ_FRAME:
|
||||
Status = ScanNet_PktHandler(instPtr);
|
||||
Status = L2_Scan_PktHandler(instPtr);
|
||||
break;
|
||||
case L2_INTER_MGMT_FRAME:
|
||||
case L2_INTRA_MGMT_FRAME:
|
||||
@@ -1176,8 +1182,7 @@ int32_t Linklayer_PktHandler(L2_INST *instPtr, L2_FRAME_TYPE frameType)
|
||||
instPtr->mgmtMsgRecvCnt1++;
|
||||
}
|
||||
}
|
||||
mgmtFrameRecv++;
|
||||
Status = MgmtNet_PktHandler(instPtr);
|
||||
Status = L2_Mgmt_PktHandler(instPtr);
|
||||
break;
|
||||
case L2_INTER_SVC_FRAME:
|
||||
case L2_INTRA_SVC_FRAME:
|
||||
@@ -1196,8 +1201,7 @@ int32_t Linklayer_PktHandler(L2_INST *instPtr, L2_FRAME_TYPE frameType)
|
||||
instPtr->svcMsgRecvCnt1++;
|
||||
}
|
||||
}
|
||||
svcFrameRecv++;
|
||||
Status = ServiceNet_PktHandler(instPtr);
|
||||
Status = L2_Service_PktHandler(instPtr);
|
||||
break;
|
||||
default:
|
||||
DBG_WARNING("L2FrameHandler: UNKNOWN L2-FrameType %d\n", frameType);
|
||||
@@ -1223,15 +1227,6 @@ static int32_t Linklayer_Routine(L2_INST *instPtr)
|
||||
int32_t Status;
|
||||
uint32_t tableIndx, entryIndx;
|
||||
|
||||
// FIXME: Consider time wrapping.
|
||||
uint32_t nextTimeUnit = (TimeCtrl_GetIntCnt(instPtr->config.tmcInstPtr) + 1) / L2_SLOTS_PER_FRAME;
|
||||
if (nextTimeUnit < instPtr->netStartTime)
|
||||
{
|
||||
DBG_WARNING("Linklayer not start yet, next time unit: %u, start time unit: %u.\n",
|
||||
nextTimeUnit, instPtr->netStartTime);
|
||||
return EIGNORE;
|
||||
}
|
||||
|
||||
// Determine which routine entry is going to be performed.
|
||||
tableIndx = L2_GetNextFrameNum(instPtr) % instPtr->rtneConfig.rtnePrd;
|
||||
entryIndx = L2_GetNextSlotNum(instPtr);
|
||||
@@ -1257,17 +1252,17 @@ static int32_t Linklayer_Routine(L2_INST *instPtr)
|
||||
case L2_SLOT_INTRA_SCAN_BM:
|
||||
case L2_SLOT_INTER_SCAN_2W:
|
||||
case L2_SLOT_INTRA_SCAN_2W:
|
||||
Status = ScanNet_Routine(instPtr, &rtneEntry);
|
||||
Status = L2_Scan_Routine(instPtr, &rtneEntry);
|
||||
break;
|
||||
case L2_SLOT_INTER_SVC:
|
||||
case L2_SLOT_INTRA_SVC:
|
||||
Status = ServiceNet_Routine(instPtr, &rtneEntry);
|
||||
Status = L2_Service_Routine(instPtr, &rtneEntry);
|
||||
break;
|
||||
case L2_SLOT_INTER_MGMT:
|
||||
case L2_SLOT_INTRA_MGMT:
|
||||
case L2_SLOT_INTER_TSYNC:
|
||||
case L2_SLOT_INTRA_TSYNC:
|
||||
Status = MgmtNet_Routine(instPtr, &rtneEntry);
|
||||
Status = L2_Mgmt_Routine(instPtr, &rtneEntry);
|
||||
break;
|
||||
default:
|
||||
DBG_ERROR("UNKNOWN slot type [%d].\n", rtneEntry.slotType);
|
||||
@@ -1313,6 +1308,15 @@ int32_t Linklayer_Proc(L2_INST *instPtr)
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
// FIXME: Consider time wrapping.
|
||||
uint32_t nextTimeUnit = (TimeCtrl_GetIntCnt(instPtr->config.tmcInstPtr) + 1) / L2_SLOTS_PER_FRAME;
|
||||
if (nextTimeUnit < instPtr->netStartTime)
|
||||
{
|
||||
DBG_WARNING("Linklayer not start yet, next time unit: %u, start time unit: %u.\n",
|
||||
nextTimeUnit, instPtr->netStartTime);
|
||||
return EIGNORE;
|
||||
}
|
||||
|
||||
// Update slot number.
|
||||
L2_UpdateSlotNum(instPtr);
|
||||
|
||||
@@ -1325,7 +1329,10 @@ int32_t Linklayer_Proc(L2_INST *instPtr)
|
||||
// Handle frame received in last slot.
|
||||
if (L2_isDataAvail(instPtr) == true)
|
||||
{
|
||||
Linklayer_PktHandler(instPtr, L2_GetLastFrameType(instPtr));
|
||||
if (Linklayer_PktHandler(instPtr, L2_GetLastOptFrameType(instPtr)) != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Failed to handle last received frame: %d.\n", instPtr->frame.last);
|
||||
}
|
||||
}
|
||||
|
||||
// Run Link layer routine, setup next slot procedure.
|
||||
@@ -1344,9 +1351,10 @@ int32_t Linklayer_Proc(L2_INST *instPtr)
|
||||
else
|
||||
{
|
||||
Phy_SetMode(instPtr->config.phyInstPtr, PHY_MODE_LISTEN);
|
||||
Status = ScanNet_Proc(instPtr);
|
||||
Status = L2_Scan_Proc(instPtr);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if previous runs has error occurred.
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
|
||||
@@ -53,7 +53,7 @@ typedef struct
|
||||
uint8_t bkpHeadId;
|
||||
uint8_t netScale;
|
||||
PHY_INST *phyInstPtr;
|
||||
TIMECTRL_INST *tmcInstPtr;
|
||||
TMC_INST *tmcInstPtr;
|
||||
} L2_CONFIG;
|
||||
|
||||
typedef struct
|
||||
@@ -106,9 +106,9 @@ typedef struct
|
||||
L2_NODE_STATE mainState; // the main state of link layer state
|
||||
L2_NODE_STATE nextState; // next state of link layer state, which will be applied to mainState every second.
|
||||
L2_RTNE_CONFIG rtneConfig; // current routine table configuration and status.
|
||||
L2_SCAN_FSM *scanNetFSM; // FSM of scan net (link set up)
|
||||
L2_MGMT_FSM *mgmtNetFSM; // FSM of management net (link management and time sync)
|
||||
L2_SVC_FSM *serviceNetFSM; // FSM of service net (data service)
|
||||
L2_SCAN_FSM *scanFSM; // FSM of scan net (link set up)
|
||||
L2_MGMT_FSM *mgmtFSM; // FSM of management net (link management and time sync)
|
||||
L2_SVC_FSM *serviceFSM; // FSM of service net (data service)
|
||||
L2_RTT_FSM *rttFSM; // FSM for RTT (time sync algorithm)
|
||||
uint8_t *sendPktData;
|
||||
uint8_t *recvPktData;
|
||||
@@ -152,7 +152,7 @@ int32_t L2_RescheduleEventAfter(L2_INST *instPtr, L2_SCHD_EVENT *schdEvent, uint
|
||||
|
||||
// Framing
|
||||
void L2_FrameStateUpdate(L2_INST *instPtr);
|
||||
L2_FRAME_TYPE L2_GetLastRcvFrameType(L2_INST *instPtr);
|
||||
L2_FRAME_TYPE L2_GetLastOptFrameType(L2_INST *instPtr);
|
||||
L1_FRAME_TYPE L2_L2frame2L1frame(L2_FRAME_TYPE l2Frame);
|
||||
void FrameGetChunk(BIT_ARRAY *bitarr, uint32_t offset, uint32_t numBit, uint64_t *chunk);
|
||||
void FrameInsertChunk(BIT_ARRAY *bitarr, uint32_t offset, uint32_t numBit, uint64_t chunck);
|
||||
@@ -160,26 +160,26 @@ int32_t L2_CrcAppend(uint8_t *dataBuff, uint32_t dataLen, uint32_t crcPos, L2_CR
|
||||
bool L2_CrcCheck(uint8_t *dataBuff, uint32_t dataLen, uint32_t crcPos, L2_CRC_TYPE crcType);
|
||||
|
||||
// Scan Net
|
||||
int32_t ScanNet_Init(L2_SCAN_FSM **scanFSMPtr);
|
||||
void ScanNet_Reset(L2_SCAN_FSM *scanFSMPtr);
|
||||
void ScanNet_Destroy(L2_SCAN_FSM *scanFSMPtr);
|
||||
int32_t ScanNet_Proc(L2_INST *instPtr);
|
||||
int32_t ScanNet_PktHandler(L2_INST *instPtr);
|
||||
int32_t ScanNet_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry);
|
||||
int32_t L2_Scan_Init(L2_SCAN_FSM **scanFSMPtr);
|
||||
void L2_Scan_Reset(L2_SCAN_FSM *scanFSMPtr);
|
||||
void L2_Scan_Destroy(L2_SCAN_FSM *scanFSMPtr);
|
||||
int32_t L2_Scan_Proc(L2_INST *instPtr);
|
||||
int32_t L2_Scan_PktHandler(L2_INST *instPtr);
|
||||
int32_t L2_Scan_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry);
|
||||
|
||||
// Management Net
|
||||
int32_t MgmtNet_Init(L2_MGMT_FSM **mgmtFSM);
|
||||
void MgmtNet_Reset(L2_MGMT_FSM *mgmtFSM);
|
||||
void MgmtNet_Destroy(L2_MGMT_FSM *mgmtFSM);
|
||||
int32_t MgmtNet_PktHandler(L2_INST *instPtr);
|
||||
int32_t MgmtNet_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry);
|
||||
int32_t L2_Mgmt_Init(L2_MGMT_FSM **mgmtFSM);
|
||||
void L2_Mgmt_Reset(L2_MGMT_FSM *mgmtFSM);
|
||||
void L2_Mgmt_Destroy(L2_MGMT_FSM *mgmtFSM);
|
||||
int32_t L2_Mgmt_PktHandler(L2_INST *instPtr);
|
||||
int32_t L2_Mgmt_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry);
|
||||
|
||||
// Service net
|
||||
int32_t ServiceNet_Init(L2_SVC_FSM **serviceFSM);
|
||||
void ServiceNet_Reset(L2_SVC_FSM *serviceFSM);
|
||||
void ServiceNet_Destroy(L2_SVC_FSM *serviceFSM);
|
||||
int32_t ServiceNet_PktHandler(L2_INST *instPtr);
|
||||
int32_t ServiceNet_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *schedEntry);
|
||||
int32_t L2_Service_Init(L2_SVC_FSM **serviceFSM);
|
||||
void L2_Service_Reset(L2_SVC_FSM *serviceFSM);
|
||||
void L2_Service_Destroy(L2_SVC_FSM *serviceFSM);
|
||||
int32_t L2_Service_PktHandler(L2_INST *instPtr);
|
||||
int32_t L2_Service_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *schedEntry);
|
||||
|
||||
// Miscellaneous
|
||||
uint8_t L2_GetNodeId(L2_INST *instPtr);
|
||||
@@ -190,7 +190,6 @@ L2_NODE_STATE L2_GetMainState(L2_INST *instPtr);
|
||||
L2_RTT_FSM *L2_GetRttFsm(L2_INST *instPtr);
|
||||
bool L2_isDataAvail(L2_INST *instPtr);
|
||||
bool L2_isCxn2Net(L2_INST *instPtr);
|
||||
void L2_RcdShift(L2_RCD *rcd, int32_t netxVal);
|
||||
uint32_t L2_GetFrameLen(L2_FRAME_TYPE l2FrameType);
|
||||
uint32_t L2_GetLastFrameNum(L2_INST *instPtr);
|
||||
uint32_t L2_GetLastSlotNum(L2_INST *instPtr);
|
||||
|
||||
@@ -19,8 +19,9 @@
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
#include <stdbool.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include "geometry/coord.h"
|
||||
#include "geometry/quaternion.h"
|
||||
#include "../phy_ctrl/phy_ctrl.h"
|
||||
/************************** Constant Definitions *****************************/
|
||||
// Common node ID definition
|
||||
@@ -46,6 +47,7 @@
|
||||
#define L2_SLOTS_PER_SUBFRAME 20
|
||||
|
||||
#define L2_NUM_SLOTS_NONE UINT32_MAX
|
||||
#define L2_NUM_SLOTS_100MS 20
|
||||
#define L2_NUM_SLOTS_20MS 4
|
||||
#define L2_NUM_SLOTS_10MS 2
|
||||
#define L2_NUM_SLOTS_5MS 1
|
||||
@@ -91,6 +93,9 @@ typedef enum
|
||||
L2_SEEK_STATE = 5
|
||||
} L2_NODE_STATE;
|
||||
|
||||
/** @name Node information type definition
|
||||
* The following types define the detail node info which needed by the link layer.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t nodeId;
|
||||
@@ -100,6 +105,7 @@ typedef struct
|
||||
uint8_t beamNo;
|
||||
COORD pos;
|
||||
COORD speed;
|
||||
QUATERNION attitude;
|
||||
} L2_NODE_INFO;
|
||||
|
||||
/** @name L2 event enum
|
||||
@@ -109,18 +115,17 @@ typedef enum
|
||||
{
|
||||
L2_EV_NONE = 0,
|
||||
L2_EV_SCAN_PROC_DONE = 1,
|
||||
L2_EV_MGMT_PROC_DONE = 2,
|
||||
L2_EV_NET_SETUP_DONE = 3,
|
||||
L2_EV_TIME_SYNC = 4,
|
||||
L2_EV_RTT_RECV_UPDATE = 5,
|
||||
L2_EV_LINK_SET_REQ = 6,
|
||||
L2_EV_LOST_CXN = 7,
|
||||
L2_EV_LOST_NODE = 8,
|
||||
L2_EV_SET_FRAME_NUM = 9,
|
||||
L2_EV_SET_SLOT_NUM = 10,
|
||||
L2_EV_MAIN_STATE_UPDATE = 11,
|
||||
L2_ROUTINE_FINISH = 12,
|
||||
L2_ROUTINE_UPDATE = 13
|
||||
L2_EV_NET_SETUP_DONE = 2,
|
||||
L2_EV_TIME_SYNC = 3,
|
||||
L2_EV_RTT_RECV_UPDATE = 4,
|
||||
L2_EV_LINK_SET_REQ = 5,
|
||||
L2_EV_LOST_CXN = 6,
|
||||
L2_EV_LOST_NODE = 7,
|
||||
L2_EV_SET_FRAME_NUM = 8,
|
||||
L2_EV_SET_SLOT_NUM = 9,
|
||||
L2_EV_MAIN_STATE_UPDATE = 10,
|
||||
L2_ROUTINE_FINISH = 11,
|
||||
L2_ROUTINE_UPDATE = 12
|
||||
} L2_EVENT_TYPE;
|
||||
|
||||
/** @name L2 event
|
||||
@@ -153,17 +158,6 @@ typedef enum
|
||||
L2_SLOT_INTRA_TSYNC = 13,
|
||||
} L2_SLOT_TYPE;
|
||||
|
||||
/** @name Frame types
|
||||
* A definition of different frame types.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
L2_CRC_NONE = 0,
|
||||
L2_CRC16_1021 = 1,
|
||||
L2_CRC16_8005 = 2,
|
||||
L2_CRC8_31 = 3
|
||||
} L2_CRC_TYPE;
|
||||
|
||||
/** @name Frame types
|
||||
* A definition of different frame types.
|
||||
*/
|
||||
@@ -184,6 +178,17 @@ typedef enum
|
||||
L2_INTRA_SVC_FRAME = 12
|
||||
} L2_FRAME_TYPE;
|
||||
|
||||
/** @name Frame types
|
||||
* A definition of different frame types.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
L2_CRC_NONE = 0,
|
||||
L2_CRC16_1021 = 1,
|
||||
L2_CRC16_8005 = 2,
|
||||
L2_CRC8_31 = 3
|
||||
} L2_CRC_TYPE;
|
||||
|
||||
/** @name Schedule subtable entry
|
||||
* A definition of Schedule subtable entry.
|
||||
*/
|
||||
@@ -244,7 +249,7 @@ typedef enum
|
||||
typedef struct
|
||||
{
|
||||
bool isLocked; // init acq done.
|
||||
bool isBmRcved; // bm received.
|
||||
bool isBmRecvd; // bm received.
|
||||
bool isAcked; // 2way acq done.
|
||||
uint32_t scanCnt;
|
||||
uint32_t bmTimeout;
|
||||
|
||||
@@ -550,14 +550,14 @@ failed:
|
||||
* EALLOC Memory allocation error.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t MgmtNet_Init(L2_MGMT_FSM **mgmtFSM)
|
||||
int32_t L2_Mgmt_Init(L2_MGMT_FSM **mgmtFSM)
|
||||
{
|
||||
(*mgmtFSM) = (L2_MGMT_FSM *)malloc(sizeof(L2_MGMT_FSM));
|
||||
if (*mgmtFSM == NULL)
|
||||
{
|
||||
return EALLOC;
|
||||
}
|
||||
MgmtNet_Reset(*mgmtFSM);
|
||||
L2_Mgmt_Reset(*mgmtFSM);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -570,7 +570,7 @@ int32_t MgmtNet_Init(L2_MGMT_FSM **mgmtFSM)
|
||||
* @return NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
void MgmtNet_Reset(L2_MGMT_FSM *mgmtFSM)
|
||||
void L2_Mgmt_Reset(L2_MGMT_FSM *mgmtFSM)
|
||||
{
|
||||
mgmtFSM->isBisarProc = false;
|
||||
mgmtFSM->isPendSlotAlloc = false;
|
||||
@@ -607,7 +607,7 @@ void MgmtNet_Reset(L2_MGMT_FSM *mgmtFSM)
|
||||
* @return NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
void MgmtNet_Destroy(L2_MGMT_FSM *mgmtFSM)
|
||||
void L2_Mgmt_Destroy(L2_MGMT_FSM *mgmtFSM)
|
||||
{
|
||||
free(mgmtFSM);
|
||||
}
|
||||
@@ -623,15 +623,15 @@ void MgmtNet_Destroy(L2_MGMT_FSM *mgmtFSM)
|
||||
* Other Packed was dumped(not addressed to me, unrecognized frame type)
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t MgmtNet_PktHandler(L2_INST *instPtr)
|
||||
int32_t L2_Mgmt_PktHandler(L2_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
int32_t Status;
|
||||
uint32_t filedSize = 0;
|
||||
uint64_t dataChunk = 0;
|
||||
L2_MGMT_MSG_RECORD *mgmtMsgLog = &(instPtr->mgmtNetFSM->mgmtMsgLog);
|
||||
L2_RTT_MSG_RECORD *rttMsgRspLog = &(instPtr->mgmtNetFSM->rttMsgRspLog);
|
||||
L2_RTT_MSG_RECORD *rttMsgReqLog = &(instPtr->mgmtNetFSM->rttMsgReqLog);
|
||||
L2_MGMT_MSG_RECORD *mgmtMsgLog = &(instPtr->mgmtFSM->mgmtMsgLog);
|
||||
L2_RTT_MSG_RECORD *rttMsgRspLog = &(instPtr->mgmtFSM->rttMsgRspLog);
|
||||
L2_RTT_MSG_RECORD *rttMsgReqLog = &(instPtr->mgmtFSM->rttMsgReqLog);
|
||||
|
||||
DBG_INFO("Management net handling packet...\n");
|
||||
|
||||
@@ -641,7 +641,7 @@ int32_t MgmtNet_PktHandler(L2_INST *instPtr)
|
||||
DBG_INFO("Failed to start handling process...\n");
|
||||
return EALLOC;
|
||||
}
|
||||
switch (L2_GetLastFrameType(instPtr))
|
||||
switch (L2_GetLastOptFrameType(instPtr))
|
||||
{
|
||||
case L2_INTER_MGMT_FRAME:
|
||||
case L2_INTRA_MGMT_FRAME:
|
||||
@@ -936,7 +936,7 @@ static bool IsTTLValid(NODE_ENTRY *entry)
|
||||
* @return Slot has be used.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t MgmtNet_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry)
|
||||
int32_t L2_Mgmt_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
int32_t Status;
|
||||
|
||||
@@ -27,12 +27,7 @@
|
||||
#include "../bit_array/bit_macros.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
#define INIT_BEAM_NO 0
|
||||
#define BEAM_PER_ANT 37
|
||||
#define INIT_ANT_NO 0
|
||||
#define ANT_NUM 6
|
||||
|
||||
#define BM_LSTEN_TIMEOUT 40
|
||||
#define BM_LISTEN_TIMEOUT 40
|
||||
|
||||
#define SQUENCE_SCAN_SLOTS 0
|
||||
|
||||
@@ -93,8 +88,8 @@ static void BmrecvStateUpdate(L2_SCAN_FSM *scanFsmPtr, bool state)
|
||||
{
|
||||
ASSERT(scanFsmPtr != NULL);
|
||||
DBG_INFO("Update BmRecvState from [%d] to [%d].\n",
|
||||
scanFsmPtr->isBmRcved, state);
|
||||
scanFsmPtr->isBmRcved = state;
|
||||
scanFsmPtr->isBmRecvd, state);
|
||||
scanFsmPtr->isBmRecvd = state;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -445,7 +440,7 @@ failed:
|
||||
static int32_t Scan_InitScanHandler(L2_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
L2_SCAN_FSM *scanFsmPtr = instPtr->scanNetFSM;
|
||||
L2_SCAN_FSM *scanFsmPtr = instPtr->scanFSM;
|
||||
DBG_INFO("** Netsetup - InitScan Procedure (Attempts: %u)**\n", scanFsmPtr->scanCnt);
|
||||
|
||||
if (scanFsmPtr->scanMode == L2_SCAN_INTRA_MODE)
|
||||
@@ -499,11 +494,11 @@ static int32_t Scan_InitScanHandler(L2_INST *instPtr)
|
||||
******************************************************************************/
|
||||
static int32_t Scan_BmAdvtHandler(L2_INST *instPtr)
|
||||
{
|
||||
L2_SCAN_FSM *scanFsmPtr = instPtr->scanNetFSM;
|
||||
L2_SCAN_FSM *scanFsmPtr = instPtr->scanFSM;
|
||||
DBG_INFO("** Netsetup - BmAdvt Procedure (Timeout: %u) **\n", scanFsmPtr->bmTimeout);
|
||||
|
||||
// if received a valid bm frame.
|
||||
if (scanFsmPtr->isBmRcved == true)
|
||||
if (scanFsmPtr->isBmRecvd == true)
|
||||
{
|
||||
scanFsmPtr->bmTimeout = 0; /* reset listen counter. */
|
||||
DBG_INFO("Received Bm frame, skipping 10ms for turn around...\n");
|
||||
@@ -515,7 +510,7 @@ static int32_t Scan_BmAdvtHandler(L2_INST *instPtr)
|
||||
else
|
||||
{
|
||||
/* if time out reached, go back to init scan stage. */
|
||||
if (scanFsmPtr->bmTimeout > BM_LSTEN_TIMEOUT)
|
||||
if (scanFsmPtr->bmTimeout > BM_LISTEN_TIMEOUT)
|
||||
{
|
||||
if (scanFsmPtr->scanMode == L2_SCAN_INTRA_MODE)
|
||||
{
|
||||
@@ -533,7 +528,7 @@ static int32_t Scan_BmAdvtHandler(L2_INST *instPtr)
|
||||
return FAILURE;
|
||||
}
|
||||
DBG_WARNING("BM timeout, restart net scan from L2_SCAN_INIT_STAGE.\n");
|
||||
ScanNet_Reset(scanFsmPtr);
|
||||
L2_Scan_Reset(scanFsmPtr);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -569,7 +564,7 @@ static int32_t Scan_BmAdvtHandler(L2_INST *instPtr)
|
||||
******************************************************************************/
|
||||
static int32_t Scan_2WAcqHandler(L2_INST *instPtr)
|
||||
{
|
||||
L2_SCAN_FSM *scanFsmPtr = instPtr->scanNetFSM;
|
||||
L2_SCAN_FSM *scanFsmPtr = instPtr->scanFSM;
|
||||
DBG_INFO("** Netsetup - 2WAcq Procedure (Timeout: %u) **\n", scanFsmPtr->w2acqTimeout);
|
||||
L2_FRAME_TYPE frameType = L2_NONE_FRAME;
|
||||
|
||||
@@ -591,7 +586,7 @@ static int32_t Scan_2WAcqHandler(L2_INST *instPtr)
|
||||
if (scanFsmPtr->w2acqTimeout >= WAY2_ACQ_SLOT_MAX)
|
||||
{
|
||||
DBG_WARNING("2WAcq timeout, restart net scan from L2_SCAN_INIT_STAGE.\n");
|
||||
ScanNet_Reset(scanFsmPtr);
|
||||
L2_Scan_Reset(scanFsmPtr);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -615,11 +610,11 @@ static int32_t Scan_2WAcqHandler(L2_INST *instPtr)
|
||||
* error code
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t ScanNet_PktHandler(L2_INST *instPtr)
|
||||
int32_t L2_Scan_PktHandler(L2_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
uint32_t Status;
|
||||
L2_SCAN_FSM *scanFsmPtr = instPtr->scanNetFSM;
|
||||
L2_SCAN_FSM *scanFsmPtr = instPtr->scanFSM;
|
||||
uint64_t dataChunk;
|
||||
|
||||
DBG_INFO("Scan net handling packet...\n");
|
||||
@@ -630,7 +625,7 @@ int32_t ScanNet_PktHandler(L2_INST *instPtr)
|
||||
DBG_INFO("Failed to start handling process...\n");
|
||||
return EALLOC;
|
||||
}
|
||||
switch (L2_GetLastFrameType(instPtr))
|
||||
switch (L2_GetLastOptFrameType(instPtr))
|
||||
{
|
||||
case L2_INTER_SCAN_FRAME:
|
||||
case L2_INTRA_SCAN_FRAME:
|
||||
@@ -870,7 +865,7 @@ failed:
|
||||
* EMAC_MEMORY_ALLOC_ERROR Memory allocate error.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t ScanNet_Init(L2_SCAN_FSM **scanFSMPtr)
|
||||
int32_t L2_Scan_Init(L2_SCAN_FSM **scanFSMPtr)
|
||||
{
|
||||
*scanFSMPtr = (L2_SCAN_FSM *)malloc(sizeof(L2_SCAN_FSM));
|
||||
if (*scanFSMPtr == NULL)
|
||||
@@ -878,7 +873,7 @@ int32_t ScanNet_Init(L2_SCAN_FSM **scanFSMPtr)
|
||||
DBG_ERROR("Failed to allocate memory for scanFsmPtr.\n");
|
||||
return EALLOC;
|
||||
}
|
||||
ScanNet_Reset(*scanFSMPtr);
|
||||
L2_Scan_Reset(*scanFSMPtr);
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
@@ -891,11 +886,11 @@ int32_t ScanNet_Init(L2_SCAN_FSM **scanFSMPtr)
|
||||
* @return NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
void ScanNet_Reset(L2_SCAN_FSM *scanFSMPtr)
|
||||
void L2_Scan_Reset(L2_SCAN_FSM *scanFSMPtr)
|
||||
{
|
||||
ASSERT(scanFSMPtr != NULL);
|
||||
scanFSMPtr->isLocked = false;
|
||||
scanFSMPtr->isBmRcved = false;
|
||||
scanFSMPtr->isBmRecvd = false;
|
||||
scanFSMPtr->isAcked = false;
|
||||
scanFSMPtr->scanCnt = 0;
|
||||
scanFSMPtr->bmTimeout = 0;
|
||||
@@ -929,7 +924,7 @@ void ScanNet_Reset(L2_SCAN_FSM *scanFSMPtr)
|
||||
* @return NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
void ScanNet_Destroy(L2_SCAN_FSM *scanFSMPtr)
|
||||
void L2_Scan_Destroy(L2_SCAN_FSM *scanFSMPtr)
|
||||
{
|
||||
free(scanFSMPtr);
|
||||
}
|
||||
@@ -943,12 +938,12 @@ void ScanNet_Destroy(L2_SCAN_FSM *scanFSMPtr)
|
||||
* @return used slot (5ms slot).
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t ScanNet_Proc(L2_INST *instPtr)
|
||||
int32_t L2_Scan_Proc(L2_INST *instPtr)
|
||||
{
|
||||
L2_SCAN_FSM *scanFsmPtr = instPtr->scanNetFSM;
|
||||
L2_SCAN_FSM *scanFsmPtr = instPtr->scanFSM;
|
||||
if (L2_GetNodeType(instPtr) == L2_NODE_HEAD)
|
||||
{
|
||||
DBG_ERROR("Only member node needs to execute ScanNet_Proc. \n");
|
||||
DBG_ERROR("Only member node needs to execute L2_Scan_Proc. \n");
|
||||
return FAILURE;
|
||||
}
|
||||
int32_t Status;
|
||||
@@ -988,7 +983,7 @@ int32_t ScanNet_Proc(L2_INST *instPtr)
|
||||
*
|
||||
******************************************************************************/
|
||||
int acqSend = 0;
|
||||
int32_t ScanNet_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry)
|
||||
int32_t L2_Scan_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
L2_TOR_TYPE torState;
|
||||
@@ -1092,7 +1087,7 @@ int32_t ScanNet_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry)
|
||||
Status = FAILURE;
|
||||
goto routine_err;
|
||||
}
|
||||
W2ackStateUpdate(instPtr->scanNetFSM, true);
|
||||
W2ackStateUpdate(instPtr->scanFSM, true);
|
||||
acqSend++;
|
||||
}
|
||||
/* Antenna setting (reserved.) */
|
||||
|
||||
@@ -179,25 +179,45 @@ static int PduHeader_Packing(L2_INST *instPtr, BIT_ARRAY *bitarr, L2_PDU_HEADER_
|
||||
* Other Initialize failed.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t ServiceNet_Init(L2_SVC_FSM **serviceFSM)
|
||||
int32_t L2_Service_Init(L2_SVC_FSM **serviceFSM)
|
||||
{
|
||||
(*serviceFSM) = (L2_SVC_FSM *)malloc(sizeof(L2_SVC_FSM));
|
||||
*serviceFSM = (L2_SVC_FSM *)malloc(sizeof(L2_SVC_FSM));
|
||||
if (*serviceFSM == NULL)
|
||||
{
|
||||
return EALLOC;
|
||||
}
|
||||
ServiceNet_Reset(*serviceFSM);
|
||||
L2_Service_Reset(*serviceFSM);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
void ServiceNet_Reset(L2_SVC_FSM *serviceFSM)
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Reset ServiceNet FSM
|
||||
*
|
||||
* @param scanFsmPtr a pointer to service net finite state machine
|
||||
*
|
||||
* @return NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
void L2_Service_Reset(L2_SVC_FSM *serviceFSM)
|
||||
{
|
||||
ASSERT(serviceFSM != NULL);
|
||||
serviceFSM->isBisar = false;
|
||||
serviceFSM->isBisarEven = false;
|
||||
serviceFSM->bisarDst = L2_NONE_ID;
|
||||
}
|
||||
|
||||
void ServiceNet_Destroy(L2_SVC_FSM *serviceFSM)
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Destroy ServiceNet FSM, free memory
|
||||
*
|
||||
* @param scanFsmPtr a pointer to service net finite state machine
|
||||
*
|
||||
* @return NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
void L2_Service_Destroy(L2_SVC_FSM *serviceFSM)
|
||||
{
|
||||
free(serviceFSM);
|
||||
}
|
||||
@@ -211,7 +231,7 @@ void ServiceNet_Destroy(L2_SVC_FSM *serviceFSM)
|
||||
* other error occurred.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t ServiceNet_PktHandler(L2_INST *instPtr)
|
||||
int32_t L2_Service_PktHandler(L2_INST *instPtr)
|
||||
{
|
||||
// TODO:
|
||||
DBG_INFO("Scan net handling packet...\n");
|
||||
@@ -229,7 +249,7 @@ int32_t ServiceNet_PktHandler(L2_INST *instPtr)
|
||||
* @return Slot has been used.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t ServiceNet_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry)
|
||||
int32_t L2_Service_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
int32_t Status;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <stdbool.h>
|
||||
#include "linklayer814_types.h"
|
||||
#include "node_list.h"
|
||||
#include "../util/list.h"
|
||||
#include "../util/clist.h"
|
||||
#include "../common.h"
|
||||
#include "../error.h"
|
||||
|
||||
@@ -79,7 +79,7 @@ static int8_t entry_compare(void *a, void *b)
|
||||
******************************************************************************/
|
||||
int32_t L2_NodeList_Init(NODE_LIST **list)
|
||||
{
|
||||
(*list) = list_new();
|
||||
(*list) = clist_new();
|
||||
if (*list == NULL)
|
||||
{
|
||||
return ENOMEM;
|
||||
@@ -100,7 +100,7 @@ int32_t L2_NodeList_Init(NODE_LIST **list)
|
||||
void L2_NodeList_Clear(NODE_LIST *list)
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
list_clear(list);
|
||||
clist_clear(list);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -114,7 +114,7 @@ void L2_NodeList_Clear(NODE_LIST *list)
|
||||
******************************************************************************/
|
||||
void L2_NodeList_Destroy(NODE_LIST *list)
|
||||
{
|
||||
list_destroy(list);
|
||||
clist_destroy(list);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
@@ -131,7 +131,7 @@ NODE_ENTRY *L2_GetNodeById(NODE_LIST *list, uint8_t nodeId)
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
util_entry.nodeInfo.nodeId = nodeId;
|
||||
list_node_t *node = list_find(list, &util_entry);
|
||||
clist_node_t *node = clist_find(list, &util_entry);
|
||||
if (node == NULL)
|
||||
{
|
||||
return NULL;
|
||||
@@ -169,7 +169,7 @@ NODE_ENTRY *L2_AppendNode(NODE_LIST *list, uint8_t nodeId, L2_NODE_TYPE nodeType
|
||||
DBG_ERROR("Failed to allocated memory for nodeEntry.\n");
|
||||
return NULL;
|
||||
}
|
||||
list_node_t *node = list_node_new(nodeEntry);
|
||||
clist_node_t *node = clist_node_new(nodeEntry);
|
||||
if (node == NULL)
|
||||
{
|
||||
DBG_ERROR("Failed to allocated memory for list node.\n");
|
||||
@@ -186,7 +186,7 @@ NODE_ENTRY *L2_AppendNode(NODE_LIST *list, uint8_t nodeId, L2_NODE_TYPE nodeType
|
||||
nodeEntry->nodeInfo.speed.z = 0;
|
||||
nodeEntry->nodeInfo.beamNo = 0;
|
||||
nodeEntry->ttlCnt = 0;
|
||||
list_rpush(list, node);
|
||||
clist_rpush(list, node);
|
||||
return nodeEntry;
|
||||
}
|
||||
|
||||
@@ -205,14 +205,14 @@ int32_t L2_DeleteNodeById(NODE_LIST *list, uint8_t nodeId)
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
util_entry.nodeInfo.nodeId = nodeId;
|
||||
list_node_t *node = list_find(list, &util_entry);
|
||||
clist_node_t *node = clist_find(list, &util_entry);
|
||||
if (node == NULL)
|
||||
{
|
||||
DBG_WARNING("Node [%d] in not in node list, skip deleting process.\n", nodeId);
|
||||
return SUCCESS;
|
||||
}
|
||||
DBG_INFO("Deleting node [%d].\n", nodeId);
|
||||
list_remove(list, node);
|
||||
clist_remove(list, node);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -490,14 +490,14 @@ int32_t L2_IterEditNode(NODE_LIST *list, const void *param, int32_t (*operation)
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
int32_t Status;
|
||||
list_node_t *node;
|
||||
list_iterator_t *iter = list_iterator_new(list, LIST_HEAD);
|
||||
clist_node_t *node;
|
||||
clist_iterator_t *iter = clist_iterator_new(list, LIST_HEAD);
|
||||
if (iter == NULL)
|
||||
{
|
||||
DBG_ERROR("Failed to initialize list iteration process.\n");
|
||||
return EALLOC;
|
||||
}
|
||||
while ((node = list_iterator_next(iter)))
|
||||
while ((node = clist_iterator_next(iter)))
|
||||
{
|
||||
Status = operation((NODE_ENTRY *)node->val, param);
|
||||
if (Status != SUCCESS)
|
||||
@@ -506,7 +506,7 @@ int32_t L2_IterEditNode(NODE_LIST *list, const void *param, int32_t (*operation)
|
||||
break;
|
||||
}
|
||||
}
|
||||
list_iterator_destroy(iter);
|
||||
clist_iterator_destroy(iter);
|
||||
return Status;
|
||||
}
|
||||
|
||||
@@ -524,20 +524,20 @@ int32_t L2_IterEditNode(NODE_LIST *list, const void *param, int32_t (*operation)
|
||||
int32_t L2_IterDeleteNode(NODE_LIST *list, bool (*condition)(NODE_ENTRY *))
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
list_node_t *node;
|
||||
list_iterator_t *iter = list_iterator_new(list, LIST_HEAD);
|
||||
clist_node_t *node;
|
||||
clist_iterator_t *iter = clist_iterator_new(list, LIST_HEAD);
|
||||
if (iter == NULL)
|
||||
{
|
||||
DBG_ERROR("Failed to initialize list iteration process.\n");
|
||||
return EALLOC;
|
||||
}
|
||||
while ((node = list_iterator_next(iter)))
|
||||
while ((node = clist_iterator_next(iter)))
|
||||
{
|
||||
if (condition((NODE_ENTRY *)node->val) == false)
|
||||
{
|
||||
list_remove(list, node);
|
||||
clist_remove(list, node);
|
||||
}
|
||||
}
|
||||
list_iterator_destroy(iter);
|
||||
clist_iterator_destroy(iter);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "linklayer814_types.h"
|
||||
#include "geometry/coord.h"
|
||||
#include "../util/util.h"
|
||||
#include "../util/list.h"
|
||||
#include "../util/clist.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
@@ -36,7 +36,7 @@ typedef struct NODE_LIST_ENTRY
|
||||
int32_t timeDevi;
|
||||
} NODE_ENTRY;
|
||||
|
||||
typedef list_t NODE_LIST;
|
||||
typedef clist_t NODE_LIST;
|
||||
|
||||
/************************** Variable Definitions *****************************/
|
||||
|
||||
|
||||
@@ -0,0 +1,472 @@
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* Description: RTT algorithm.
|
||||
*
|
||||
* Author: FanHao
|
||||
* Date: 2023-12-10 20:43
|
||||
* LastEditors: FanHao
|
||||
* LastEditTime: 2023-12-10 20:43
|
||||
* Revisions: Rev 0.0
|
||||
* History:
|
||||
* [2023-12-10]: Initial version, split form time_sync.c
|
||||
*
|
||||
* Copyright(c) 2021 Beijing Institute of Technology.
|
||||
* Lab of Communication and Networking
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "linklayer814.h"
|
||||
#include "rtt.h"
|
||||
#include "../time_ctrl/time_ctrl.h"
|
||||
#include "../phy_ctrl/phy_ctrl.h"
|
||||
#include "../error.h"
|
||||
#include "../common.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
#define LIGHT_SPPED_AIR 299702547.0 // m/s
|
||||
#define LIGHT_SPPED_VAC 299792458.0 // m/s
|
||||
#define RTT_DOPPLER_NONE UINT32_MAX
|
||||
|
||||
const TIME_WORD RTT_TIME_NONE =
|
||||
{
|
||||
.int_part = UINT32_MAX,
|
||||
.frac_part = UINT32_MAX
|
||||
};
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
/**************************** Type Definitions *******************************/
|
||||
/************************** Variable Definitions *****************************/
|
||||
/************************** Function Prototypes ******************************/
|
||||
|
||||
static void RTT_StageUpdate(L2_RTT_FSM *rttFsmPtr, L2_RTT_STGE newStage);
|
||||
static void RTT_GetFrameStart(L2_INST *instPtr, TIME_WORD *tmStamp, L2_TOR_TYPE torType);
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Update corrent time-sync for RTT stage
|
||||
*
|
||||
* @param scanFsmPtr A pointer to scan net fsm.
|
||||
* @param newSatge New state.
|
||||
*
|
||||
* @return NONE.
|
||||
*
|
||||
******************************************************************************/
|
||||
static void RTT_StageUpdate(L2_RTT_FSM *rttFsmPtr, L2_RTT_STGE newStage)
|
||||
{
|
||||
ASSERT(rttFsmPtr != NULL);
|
||||
ASSERT(newStage >= RTT_NONE_STAGE && newStage <= RTT_RSP2);
|
||||
DBG_INFO("RTT Stage Update: %d -> %d.\n", rttFsmPtr->rttStage, newStage);
|
||||
rttFsmPtr->rttStage = newStage;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Reset RTT FSM
|
||||
*
|
||||
* @param rttFsmPtr a pointer to rtt FSM instance.
|
||||
*
|
||||
* @return NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
void RTT_Reset(L2_RTT_FSM *rttFsmPtr)
|
||||
{
|
||||
ASSERT(rttFsmPtr != NULL);
|
||||
memset(&(rttFsmPtr->rttRecord), 0x00, sizeof(RTT_RECORD));
|
||||
rttFsmPtr->rttStage = RTT_REQ1;
|
||||
rttFsmPtr->isR1Valid = false;
|
||||
rttFsmPtr->isR2Valid = false;
|
||||
rttFsmPtr->isR3Valid = false;
|
||||
rttFsmPtr->isR4Valid = false;
|
||||
rttFsmPtr->timeStamp.int_part = 0;
|
||||
rttFsmPtr->timeStamp.frac_part = 0;
|
||||
rttFsmPtr->doppler = 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Destroy RTT FSM, free allocated memory.
|
||||
*
|
||||
* @param rttFsmPtr a pointer to rtt FSM instance.
|
||||
*
|
||||
* @return NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
void RTT_Destroy(L2_RTT_FSM *rttFsmPtr)
|
||||
{
|
||||
free(rttFsmPtr);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Get the frame start time. If torType == L2_TOR_TX, get the next
|
||||
* slot start time, if torType == L2_TOR_RX get last frame start
|
||||
* time.
|
||||
*
|
||||
* @param instPtr a pointer to linklayer layer instance
|
||||
* @param tmStamp a pointer to store frame start time
|
||||
* @param torType tx/rx mode
|
||||
*
|
||||
* @return NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
void RTT_GetFrameStart(L2_INST *instPtr, TIME_WORD *tmStamp, L2_TOR_TYPE torType)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
ASSERT(tmStamp != NULL);
|
||||
// Get the next frame start time
|
||||
if (torType == L2_TOR_TX)
|
||||
{
|
||||
tmStamp->int_part = L2_GetNextFrameNum(instPtr) * L2_SLOTS_PER_FRAME + L2_GetNextSlotNum(instPtr);
|
||||
tmStamp->frac_part = 0;
|
||||
}
|
||||
// Get the last reiceive frame start time
|
||||
else if (torType == L2_TOR_RX)
|
||||
{
|
||||
PHY_INST *phyRef = instPtr->config.phyInstPtr;
|
||||
TIME_WORD timeStamp;
|
||||
int64_t timeDiff;
|
||||
Phy_GetLastReceivedFrameSyncTimeStamp(phyRef, &timeStamp);
|
||||
timeDiff = (uint64_t)timeStamp.frac_part;
|
||||
timeDiff += ((uint64_t)timeStamp.int_part) * TIME_FRAC_MAX;
|
||||
Phy_GetLastReceivedSlotStartTimeStamp(phyRef, tmStamp);
|
||||
timeDiff -= ((uint64_t)tmStamp->int_part) * TIME_FRAC_MAX;
|
||||
timeDiff -= (uint64_t)tmStamp->frac_part;
|
||||
timeDiff = (int64_t)Phy_GetTimeComp(L2_L2frame2L1frame(L2_GetLastFrameType(instPtr))) - timeDiff;
|
||||
if (timeDiff < 0)
|
||||
{
|
||||
timeDiff += TIME_FRAC_MAX;
|
||||
tmStamp->int_part--;
|
||||
_nop_();
|
||||
}
|
||||
tmStamp->frac_part = (TIME_FRAC)timeDiff;
|
||||
}
|
||||
else
|
||||
{
|
||||
*tmStamp = RTT_TIME_NONE;
|
||||
DBG_ERROR("Unexpected tx/rx mode, setting dummy values.\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Initialize RTT FSM, allocate memory for FSM instance.
|
||||
*
|
||||
* @param rttFsmPtr
|
||||
*
|
||||
* @return SUCCESS Initialization successful.
|
||||
* EMAC_MEMORY_ALLOC_ERROR Memory allocate error.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t RTT_Init(L2_RTT_FSM **rttFsmPtr)
|
||||
{
|
||||
(*rttFsmPtr) = (L2_RTT_FSM *)malloc(sizeof(L2_RTT_FSM));
|
||||
if (*rttFsmPtr == NULL)
|
||||
{
|
||||
free(*rttFsmPtr);
|
||||
return EALLOC;
|
||||
}
|
||||
RTT_Reset(*rttFsmPtr);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Update RTT FSM accordingly.
|
||||
*
|
||||
* @param instPtr a pointer to linklayer layer instance
|
||||
* @param torType tx/rx mode type
|
||||
*
|
||||
* @return SUCCESS
|
||||
* error code
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t RTT_FsmUpdate(L2_INST *instPtr, L2_TOR_TYPE torType)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
L2_RTT_FSM *rttFsmPtr = L2_GetRttFsm(instPtr);
|
||||
RTT_RECORD *rttRecord = &(rttFsmPtr->rttRecord);
|
||||
PHY_INST *phyRef = instPtr->config.phyInstPtr;
|
||||
|
||||
DBG_INFO("-------- RTT FSM Update --------\n");
|
||||
// Stage trans
|
||||
// For Head Node: Tx->Rx->Tx->Rx
|
||||
if (L2_GetNodeType(instPtr) == L2_NODE_HEAD)
|
||||
{
|
||||
switch (rttFsmPtr->rttStage)
|
||||
{
|
||||
case RTT_REQ1:
|
||||
if (torType == L2_TOR_TX)
|
||||
{
|
||||
DBG_INFO("Prepare data for RTT REQ-1\n");
|
||||
// Update Tt1
|
||||
RTT_GetFrameStart(instPtr, &(rttRecord->Tt1), torType);
|
||||
DBG_INFO("Tt1-timeL:%u.\n", rttRecord->Tt1.int_part);
|
||||
DBG_INFO("Tt1-timeH:%u.\n", rttRecord->Tt1.frac_part);
|
||||
|
||||
// Prepare data for sending...
|
||||
rttFsmPtr->timeStamp = rttRecord->Tt1;
|
||||
rttFsmPtr->doppler = RTT_DOPPLER_NONE;
|
||||
RTT_StageUpdate(rttFsmPtr, RTT_RSP1);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_INFO("RTT FSM remain current state [%d].\n", rttFsmPtr->rttStage);
|
||||
}
|
||||
break;
|
||||
case RTT_RSP1:
|
||||
if (torType == L2_TOR_RX)
|
||||
{
|
||||
if (L2_isDataAvail(instPtr) == true)
|
||||
{
|
||||
DBG_INFO("RTT RSP-1 have been received.\n");
|
||||
DBG_INFO("Preparing data for RTT REQ-2.\n");
|
||||
rttFsmPtr->isR2Valid = true;
|
||||
// Update doppler
|
||||
rttRecord->dopplerR2 = (int32_t)Phy_GetFreqEst(phyRef);
|
||||
// Update Tr2
|
||||
RTT_GetFrameStart(instPtr, &(rttRecord->Tr2), torType);
|
||||
// Calculate TroundA
|
||||
TimeCtrl_CalculateTimeGap(&(rttRecord->Tt1), &(rttRecord->Tr2), &(rttRecord->TroundA));
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_WARNING("RTT RSP-1 had not been received [Stage: %d].\n", rttFsmPtr->rttStage);
|
||||
DBG_WARNING("Set Tr2 dopplerR2 and TroundA to dummy value.\n");
|
||||
rttFsmPtr->isR2Valid = false;
|
||||
rttRecord->dopplerR2 = RTT_DOPPLER_NONE;
|
||||
rttRecord->Tr2 = RTT_TIME_NONE;
|
||||
rttRecord->TroundA = RTT_TIME_NONE;
|
||||
}
|
||||
DBG_INFO("dopplerR2:%d.\n", rttRecord->dopplerR2);
|
||||
DBG_INFO("Tr2-timeL:%u.\n", rttRecord->Tr2.frac_part);
|
||||
DBG_INFO("Tr2-timeH:%u.\n", rttRecord->Tr2.int_part);
|
||||
DBG_INFO("TroundA-timeL:%u.\n", rttRecord->TroundA.frac_part);
|
||||
DBG_INFO("TroundA-timeH:%u.\n", rttRecord->TroundA.int_part);
|
||||
RTT_StageUpdate(rttFsmPtr, RTT_REQ2);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_INFO("RTT FSM remain current state [%d].\n", rttFsmPtr->rttStage);
|
||||
}
|
||||
break;
|
||||
case RTT_REQ2:
|
||||
if (torType == L2_TOR_TX)
|
||||
{
|
||||
DBG_INFO("Prepare data for RTT REQ-2\n");
|
||||
// Update Tt3
|
||||
RTT_GetFrameStart(instPtr, &(rttRecord->Tt3), torType);
|
||||
|
||||
if (rttFsmPtr->isR2Valid)
|
||||
{
|
||||
// Calculate reply A
|
||||
TimeCtrl_CalculateTimeGap(&(rttRecord->Tt3), &(rttRecord->Tr2), &(rttRecord->TreplyA));
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_WARNING("RTT RSP-1 have not been received [Stage: %d].\n", rttFsmPtr->rttStage);
|
||||
DBG_WARNING("Set TreplyA to dummy value.\n");
|
||||
rttRecord->TreplyA = RTT_TIME_NONE;
|
||||
}
|
||||
DBG_INFO("Tt3-timeL:%u.\n", rttRecord->Tt3.frac_part);
|
||||
DBG_INFO("Tt3-timeH:%u.\n", rttRecord->Tt3.int_part);
|
||||
DBG_INFO("TreplyA-timeL:%u.\n", rttRecord->TreplyA.frac_part);
|
||||
DBG_INFO("TreplyA-timeH:%u.\n", rttRecord->TreplyA.int_part);
|
||||
|
||||
// Prepare data for sending.
|
||||
rttFsmPtr->timeStamp = rttRecord->TroundA;
|
||||
rttFsmPtr->doppler = rttRecord->dopplerR2;
|
||||
RTT_StageUpdate(rttFsmPtr, RTT_RSP2);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_INFO("RTT FSM remain current state [%d].\n", rttFsmPtr->rttStage);
|
||||
}
|
||||
break;
|
||||
case RTT_RSP2:
|
||||
if (torType == L2_TOR_RX)
|
||||
{
|
||||
if (L2_isDataAvail(instPtr) == true)
|
||||
{
|
||||
DBG_INFO("RTT RSP-2 have been received.\n");
|
||||
rttFsmPtr->isR4Valid = true;
|
||||
// Update doppler
|
||||
double doppler = Phy_GetFreqEst(phyRef);
|
||||
rttRecord->dopplerR2 = (int32_t)doppler;
|
||||
// Update Tr4
|
||||
RTT_GetFrameStart(instPtr, &(rttRecord->Tr4), torType);
|
||||
// Calculate TroundA
|
||||
TimeCtrl_CalculateTimeGap(&(rttRecord->Tt3), &(rttRecord->Tr4), &(rttRecord->TroundA));
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_WARNING("RTT RSP-1 have not been received [Stage: %d].\n", rttFsmPtr->rttStage);
|
||||
DBG_WARNING("Set Tr4 dopplerR4 and TroundA to dummy value.\n");
|
||||
rttFsmPtr->isR4Valid = false;
|
||||
rttRecord->dopplerR4 = RTT_DOPPLER_NONE;
|
||||
rttRecord->Tr4 = RTT_TIME_NONE;
|
||||
rttRecord->TroundA = RTT_TIME_NONE;
|
||||
}
|
||||
DBG_INFO("dopplerR4:%d.\n", rttRecord->dopplerR4);
|
||||
DBG_INFO("Tr4-timeL:%u.\n", rttRecord->Tr4.frac_part);
|
||||
DBG_INFO("Tr4-timeH:%u.\n", rttRecord->Tr4.int_part);
|
||||
DBG_INFO("TroundA-timeL:%u.\n", rttRecord->TroundA.frac_part);
|
||||
DBG_INFO("TroundA-timeH:%u.\n", rttRecord->TroundA.int_part);
|
||||
RTT_StageUpdate(rttFsmPtr, RTT_REQ1);
|
||||
DBG_INFO("RTT procedure end...\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_INFO("RTT FSM remain current state [%d].\n", rttFsmPtr->rttStage);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
DBG_ERROR("Unexpected RTT FSM stage [%d].\n", rttFsmPtr->rttStage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// For Member Node: Rx->Tx->Rx->Tx
|
||||
else
|
||||
{
|
||||
switch (rttFsmPtr->rttStage)
|
||||
{
|
||||
case RTT_REQ1:
|
||||
if (torType == L2_TOR_RX)
|
||||
{
|
||||
if (L2_isDataAvail(instPtr) == true)
|
||||
{
|
||||
DBG_INFO("RTT REQ-1 have been received.\n");
|
||||
DBG_INFO("Preparing data for RTT RSP-1.\n");
|
||||
rttFsmPtr->isR2Valid = true;
|
||||
// Update doppler
|
||||
rttRecord->dopplerR2 = (int32_t)Phy_GetFreqEst(phyRef);
|
||||
// Update Tr1
|
||||
RTT_GetFrameStart(instPtr, &(rttRecord->Tr1), torType);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_WARNING("RTT REQ-1 have not been received [Stage: %d].\n", rttFsmPtr->rttStage);
|
||||
DBG_WARNING("Set dopplerR1 and Tr1 to dummy value.\n");
|
||||
rttFsmPtr->isR1Valid = false;
|
||||
rttRecord->dopplerR1 = RTT_DOPPLER_NONE;
|
||||
rttRecord->Tr1 = RTT_TIME_NONE;
|
||||
}
|
||||
DBG_INFO("dopplerR1:%d.\n", rttRecord->dopplerR1);
|
||||
DBG_INFO("Tr1-timeL:%u.\n", rttRecord->Tr1.frac_part);
|
||||
DBG_INFO("Tr1-timeH:%u.\n", rttRecord->Tr1.int_part);
|
||||
RTT_StageUpdate(rttFsmPtr, RTT_RSP1);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_INFO("RTT FSM remain current state [%d].\n", rttFsmPtr->rttStage);
|
||||
}
|
||||
break;
|
||||
case RTT_RSP1:
|
||||
if (torType == L2_TOR_TX)
|
||||
{
|
||||
DBG_INFO("Prepare data for RTT RSP-1\n");
|
||||
// Update Tt2
|
||||
RTT_GetFrameStart(instPtr, &(rttRecord->Tt2), torType);
|
||||
if (rttFsmPtr->isR1Valid)
|
||||
{
|
||||
// Calculate reply B
|
||||
TimeCtrl_CalculateTimeGap(&(rttRecord->Tr1), &(rttRecord->Tt2), &(rttRecord->TreplyB));
|
||||
}
|
||||
else
|
||||
{
|
||||
rttRecord->TreplyB = RTT_TIME_NONE;
|
||||
DBG_WARNING("RTT REQ-1 have not been received [Stage: %d].\n", rttFsmPtr->rttStage);
|
||||
DBG_WARNING("Set ReplayB to dummy value.\n");
|
||||
}
|
||||
DBG_INFO("Tt2-timeL:%u.\n", rttRecord->Tt2.frac_part);
|
||||
DBG_INFO("Tt2-timeH:%u.\n", rttRecord->Tt2.int_part);
|
||||
DBG_INFO("TreplyB-timeL:%u.\n", rttRecord->TreplyB.frac_part);
|
||||
DBG_INFO("TreplyB-timeH:%u.\n", rttRecord->TreplyB.int_part);
|
||||
|
||||
// Prepare data for sending.
|
||||
rttFsmPtr->timeStamp = rttRecord->TreplyB;
|
||||
rttFsmPtr->doppler = rttRecord->dopplerR1;
|
||||
RTT_StageUpdate(rttFsmPtr, RTT_REQ2);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_INFO("RTT FSM remain current state [%d].\n", rttFsmPtr->rttStage);
|
||||
}
|
||||
break;
|
||||
case RTT_REQ2:
|
||||
if (torType == L2_TOR_RX)
|
||||
{
|
||||
if (L2_isDataAvail(instPtr) == true)
|
||||
{
|
||||
DBG_INFO("RTT REQ-2 have been received.\n");
|
||||
DBG_INFO("Preparing data for RTT RSP-2.\n");
|
||||
rttFsmPtr->isR3Valid = true;
|
||||
// Update doppler
|
||||
rttRecord->dopplerR2 = (int32_t)Phy_GetFreqEst(phyRef);
|
||||
// Update Tr3
|
||||
RTT_GetFrameStart(instPtr, &(rttRecord->Tr3), torType);
|
||||
// Calculate TroundB
|
||||
TimeCtrl_CalculateTimeGap(&(rttRecord->Tt2), &(rttRecord->Tr3), &(rttRecord->TroundB));
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_WARNING("RTT REQ-2 have not been received [Stage: %d].\n", rttFsmPtr->rttStage);
|
||||
DBG_WARNING("Set dopplerR3 and ReplayB to dummy value.\n");
|
||||
rttFsmPtr->isR3Valid = false;
|
||||
rttRecord->dopplerR3 = RTT_DOPPLER_NONE;
|
||||
rttRecord->TroundB = RTT_TIME_NONE;
|
||||
}
|
||||
DBG_INFO("dopplerR3:%d.\n", rttRecord->dopplerR3);
|
||||
DBG_INFO("Tr3-timeL:%u.\n", rttRecord->Tr3.frac_part);
|
||||
DBG_INFO("Tr3-timeH:%u.\n", rttRecord->Tr3.int_part);
|
||||
DBG_INFO("TroundB-timeL:%u.\n", rttRecord->TroundB.frac_part);
|
||||
DBG_INFO("TroundB-timeH:%u.\n", rttRecord->TroundB.int_part);
|
||||
RTT_StageUpdate(rttFsmPtr, RTT_RSP2);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_INFO("RTT FSM remain current state [%d].\n", rttFsmPtr->rttStage);
|
||||
}
|
||||
break;
|
||||
case RTT_RSP2:
|
||||
if (torType == L2_TOR_TX)
|
||||
{
|
||||
DBG_INFO("Prepare data for RTT RSP-2\n");
|
||||
// Update Tt4
|
||||
RTT_GetFrameStart(instPtr, &(rttRecord->Tt4), torType);
|
||||
if (rttFsmPtr->isR3Valid)
|
||||
{
|
||||
// Calculate reply B
|
||||
TimeCtrl_CalculateTimeGap(&(rttRecord->Tr3), &(rttRecord->Tt4), &(rttRecord->TreplyB));
|
||||
// TODO: implement a time adjustment.
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_WARNING("RTT REQ-2 have not been received [Stage: %d].\n", rttFsmPtr->rttStage);
|
||||
DBG_WARNING("Set ReplayB to dummy value.\n");
|
||||
rttRecord->TreplyB = RTT_TIME_NONE;
|
||||
}
|
||||
DBG_INFO("Tt4-timeL:%u.\n", rttRecord->Tt4.frac_part);
|
||||
DBG_INFO("Tt4-timeH:%u.\n", rttRecord->Tt4.int_part);
|
||||
DBG_INFO("TreplyB-timeL:%u.\n", rttRecord->TreplyB.frac_part);
|
||||
DBG_INFO("TreplyB-timeH:%u.\n", rttRecord->TreplyB.int_part);
|
||||
|
||||
// Prepare data for sending.
|
||||
rttFsmPtr->timeStamp = rttRecord->TreplyB;
|
||||
rttFsmPtr->doppler = rttRecord->dopplerR3;
|
||||
RTT_StageUpdate(rttFsmPtr, RTT_REQ1);
|
||||
DBG_INFO("RTT procedure end...\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_INFO("RTT FSM remain current state [%d].\n", rttFsmPtr->rttStage);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
DBG_ERROR("Unexpected RTT FSM stage [%d].\n", rttFsmPtr->rttStage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "linklayer814.h"
|
||||
#include "linklayer814_types.h"
|
||||
#include "../error.h"
|
||||
#include "../util/list.h"
|
||||
#include "../util/clist.h"
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
/**************************** Type Definitions *******************************/
|
||||
/************************** Variable Definitions *****************************/
|
||||
@@ -80,7 +80,7 @@ int32_t L2_CreateSchedEventPool(L2_SCHD_POOL **schdPool)
|
||||
DBG_ERROR("Failed to allocated memory for schdPool.\n");
|
||||
return EALLOC;
|
||||
}
|
||||
(*schdPool)->schdList = list_new();
|
||||
(*schdPool)->schdList = clist_new();
|
||||
if ((*schdPool)->schdList == NULL)
|
||||
{
|
||||
DBG_ERROR("Failed to allocated memory for schdPool->schdList.\n");
|
||||
@@ -106,7 +106,7 @@ int32_t L2_CreateSchedEventPool(L2_SCHD_POOL **schdPool)
|
||||
void L2_ClearSchedEventPool(L2_SCHD_POOL *schdPool)
|
||||
{
|
||||
ASSERT(schdPool != NULL);
|
||||
list_clear(schdPool->schdList);
|
||||
clist_clear(schdPool->schdList);
|
||||
schdPool->envCnt = 0;
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ void L2_DestroySchedEventPool(L2_SCHD_POOL *schdPool)
|
||||
{
|
||||
return;
|
||||
}
|
||||
list_destroy(schdPool->schdList);
|
||||
clist_destroy(schdPool->schdList);
|
||||
free(schdPool);
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ L2_SCHD_EVENT *L2_CreatNewSchdEvent(L2_SCHD_POOL *schdPool, L2_EVENT_TYPE event,
|
||||
DBG_ERROR("Failed to allocate schedule event.\n");
|
||||
return NULL;
|
||||
}
|
||||
list_node_t *node = list_node_new(schdEvent);
|
||||
clist_node_t *node = clist_node_new(schdEvent);
|
||||
if (node == NULL)
|
||||
{
|
||||
DBG_ERROR("Failed to allocate schedule event list node.\n");
|
||||
@@ -170,7 +170,7 @@ L2_SCHD_EVENT *L2_CreatNewSchdEvent(L2_SCHD_POOL *schdPool, L2_EVENT_TYPE event,
|
||||
schdEvent->isVolatile = isVolatile;
|
||||
schdEvent->schdSlot = L2_SLOTNO_NONE;
|
||||
schdEvent->schdFrame = L2_FRAMENO_NONE;
|
||||
list_rpush(schdPool->schdList, node);
|
||||
clist_rpush(schdPool->schdList, node);
|
||||
return schdEvent;
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ L2_SCHD_EVENT *L2_GetEventById(L2_SCHD_POOL *schdPool, uint32_t id)
|
||||
{
|
||||
ASSERT(schdPool != NULL);
|
||||
util_schdevent.eventId = id;
|
||||
list_node_t *node = list_find(schdPool->schdList, &util_schdevent);
|
||||
clist_node_t *node = clist_find(schdPool->schdList, &util_schdevent);
|
||||
if (node != NULL)
|
||||
{
|
||||
DBG_WARNING("Event with id=%d, dose not exist.\n", id);
|
||||
@@ -214,13 +214,13 @@ int32_t L2_DeleteSchdEventById(L2_SCHD_POOL *schdPool, uint32_t id)
|
||||
{
|
||||
ASSERT(schdPool != NULL);
|
||||
util_schdevent.eventId = id;
|
||||
list_node_t *node = list_find(schdPool->schdList, &util_schdevent);
|
||||
clist_node_t *node = clist_find(schdPool->schdList, &util_schdevent);
|
||||
if (node != NULL)
|
||||
{
|
||||
DBG_ERROR("Event with id=%d, dose not exist.\n", id);
|
||||
return EIGNORE;
|
||||
}
|
||||
list_remove(schdPool->schdList, node);
|
||||
clist_remove(schdPool->schdList, node);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -343,16 +343,16 @@ int32_t L2_RescheduleEventAfter(L2_INST *instPtr, L2_SCHD_EVENT *schdEvent, uint
|
||||
void L2_EventPoolHandler(L2_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
list_node_t *node;
|
||||
clist_node_t *node;
|
||||
L2_SCHD_EVENT *event;
|
||||
L2_SCHD_POOL *pool = instPtr->schdEventPool;
|
||||
list_iterator_t *iter = list_iterator_new(pool->schdList, LIST_HEAD);
|
||||
clist_iterator_t *iter = clist_iterator_new(pool->schdList, LIST_HEAD);
|
||||
if (iter == NULL)
|
||||
{
|
||||
DBG_ERROR("Failed to initialize schedule event pool iteration.\n");
|
||||
return;
|
||||
}
|
||||
while ((node = list_iterator_next(iter)))
|
||||
while ((node = clist_iterator_next(iter)))
|
||||
{
|
||||
event = (L2_SCHD_EVENT *)node->val;
|
||||
if (L2_isEventScheduled(event))
|
||||
@@ -364,7 +364,7 @@ void L2_EventPoolHandler(L2_INST *instPtr)
|
||||
if (event->isVolatile == true)
|
||||
{
|
||||
DBG_INFO("Deleting scheduled event [%d], since it is volatile.\n", event->eventId);
|
||||
list_remove(pool->schdList, node);
|
||||
clist_remove(pool->schdList, node);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -373,7 +373,7 @@ void L2_EventPoolHandler(L2_INST *instPtr)
|
||||
}
|
||||
}
|
||||
}
|
||||
list_iterator_destroy(iter);
|
||||
clist_iterator_destroy(iter);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "linklayer814_types.h"
|
||||
#include "../error.h"
|
||||
#include "../util/list.h"
|
||||
#include "../util/clist.h"
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
/**************************** Type Definitions *******************************/
|
||||
/** @name L2 event
|
||||
@@ -43,7 +43,7 @@ typedef struct
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
list_t *schdList;
|
||||
clist_t *schdList;
|
||||
uint32_t envCnt;
|
||||
} L2_SCHD_POOL;
|
||||
|
||||
|
||||
@@ -20,27 +20,17 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "linklayer814.h"
|
||||
#include "rtt.h"
|
||||
#include "../time_ctrl/time_ctrl.h"
|
||||
#include "../phy_ctrl/phy_ctrl.h"
|
||||
#include "../error.h"
|
||||
#include "../common.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
#define LIGHT_SPPED_AIR 299702547.0 // m/s
|
||||
#define LIGHT_SPPED_VAC 299792458.0 // m/s
|
||||
#define RTT_DOPPLER_NONE UINT32_MAX
|
||||
|
||||
const TIME_WORD RTT_TIME_NONE = {
|
||||
.int_part = UINT32_MAX,
|
||||
.frac_part = UINT32_MAX};
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
/**************************** Type Definitions *******************************/
|
||||
/************************** Variable Definitions *****************************/
|
||||
/************************** Function Prototypes ******************************/
|
||||
|
||||
static void RTT_StageUpdate(L2_RTT_FSM *rttFsmPtr, L2_RTT_STGE newStage);
|
||||
static void RTT_GetFrameStart(L2_INST *instPtr, TIME_WORD *tmStamp, L2_TOR_TYPE torType);
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief a slot alignment, base on physical layer information.
|
||||
@@ -61,9 +51,11 @@ int32_t L2_TimeAlign(L2_INST *instPtr, uint32_t frameNum, uint32_t slotNum, bool
|
||||
lastRecvdFrame = Phy_GetLastRecvFrameType(instPtr->config.phyInstPtr);
|
||||
if (lastRecvdFrame == L1_NONE_FRAME)
|
||||
{
|
||||
DBG_ERROR("Invalid TimeAlign operation, no frame was received.");
|
||||
return EIGNORE;
|
||||
}
|
||||
|
||||
DBG_INFO("Starting TimeAlign operation...\n");
|
||||
// read nextSendTime from physical layer
|
||||
uint64_t currTime, expctTime;
|
||||
int64_t timeDiff;
|
||||
@@ -87,431 +79,3 @@ int32_t L2_TimeAlign(L2_INST *instPtr, uint32_t frameNum, uint32_t slotNum, bool
|
||||
TimeCtrl_TimeAdjust(instPtr->config.tmcInstPtr, &slotTimerAdjmet, TM_ADJ_ADD);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Update corrent time-sync for RTT stage
|
||||
*
|
||||
* @param scanFsmPtr A pointer to scan net fsm.
|
||||
* @param newSatge New state.
|
||||
*
|
||||
* @return NONE.
|
||||
*
|
||||
******************************************************************************/
|
||||
static void RTT_StageUpdate(L2_RTT_FSM *rttFsmPtr, L2_RTT_STGE newStage)
|
||||
{
|
||||
ASSERT(rttFsmPtr != NULL);
|
||||
ASSERT(newStage >= RTT_NONE_STAGE && newStage <= RTT_RSP2);
|
||||
DBG_INFO("RTT Stage Update: %d -> %d.\n", rttFsmPtr->rttStage, newStage);
|
||||
rttFsmPtr->rttStage = newStage;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Reset RTT FSM
|
||||
*
|
||||
* @param rttFsmPtr a pointer to rtt FSM instance.
|
||||
*
|
||||
* @return NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
void RTT_Reset(L2_RTT_FSM *rttFsmPtr)
|
||||
{
|
||||
ASSERT(rttFsmPtr != NULL);
|
||||
memset(&(rttFsmPtr->rttRecord), 0x00, sizeof(RTT_RECORD));
|
||||
rttFsmPtr->rttStage = RTT_REQ1;
|
||||
rttFsmPtr->isR1Valid = false;
|
||||
rttFsmPtr->isR2Valid = false;
|
||||
rttFsmPtr->isR3Valid = false;
|
||||
rttFsmPtr->isR4Valid = false;
|
||||
rttFsmPtr->timeStamp.int_part = 0;
|
||||
rttFsmPtr->timeStamp.frac_part = 0;
|
||||
rttFsmPtr->doppler = 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Destroy RTT FSM, free allocated memory.
|
||||
*
|
||||
* @param rttFsmPtr a pointer to rtt FSM instance.
|
||||
*
|
||||
* @return NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
void RTT_Destroy(L2_RTT_FSM *rttFsmPtr)
|
||||
{
|
||||
free(rttFsmPtr);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Get the frame start time. If torType == L2_TOR_TX, get the next
|
||||
* slot start time, if torType == L2_TOR_RX get last frame start
|
||||
* time.
|
||||
*
|
||||
* @param instPtr a pointer to linklayer layer instance
|
||||
* @param tmStamp a pointer to store frame start time
|
||||
* @param torType tx/rx mode
|
||||
*
|
||||
* @return NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
void RTT_GetFrameStart(L2_INST *instPtr, TIME_WORD *tmStamp, L2_TOR_TYPE torType)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
ASSERT(tmStamp != NULL);
|
||||
// Get the next frame start time
|
||||
if (torType == L2_TOR_TX)
|
||||
{
|
||||
tmStamp->int_part = L2_GetNextFrameNum(instPtr) * L2_SLOTS_PER_FRAME + L2_GetNextSlotNum(instPtr);
|
||||
tmStamp->frac_part = 0;
|
||||
}
|
||||
// Get the last reiceive frame start time
|
||||
else if (torType == L2_TOR_RX)
|
||||
{
|
||||
PHY_INST *phyRef = instPtr->config.phyInstPtr;
|
||||
TIME_WORD timeStamp;
|
||||
int64_t timeDiff;
|
||||
Phy_GetLastReceivedFrameSyncTimeStamp(phyRef, &timeStamp);
|
||||
timeDiff = (uint64_t)timeStamp.frac_part;
|
||||
timeDiff += ((uint64_t)timeStamp.int_part) * TIME_FRAC_MAX;
|
||||
Phy_GetLastReceivedSlotStartTimeStamp(phyRef, tmStamp);
|
||||
timeDiff -= ((uint64_t)tmStamp->int_part) * TIME_FRAC_MAX;
|
||||
timeDiff -= (uint64_t)tmStamp->frac_part;
|
||||
timeDiff = (int64_t)Phy_GetTimeComp(L2_L2frame2L1frame(L2_GetLastFrameType(instPtr))) - timeDiff;
|
||||
if (timeDiff < 0)
|
||||
{
|
||||
timeDiff += TIME_FRAC_MAX;
|
||||
tmStamp->int_part--;
|
||||
_nop_();
|
||||
}
|
||||
tmStamp->frac_part = (TIME_FRAC)timeDiff;
|
||||
}
|
||||
else
|
||||
{
|
||||
*tmStamp = RTT_TIME_NONE;
|
||||
DBG_ERROR("Unexpected tx/rx mode, setting dummy values.\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Initialize RTT FSM, allocate memory for FSM instance.
|
||||
*
|
||||
* @param rttFsmPtr
|
||||
*
|
||||
* @return SUCCESS Initialization successful.
|
||||
* EMAC_MEMORY_ALLOC_ERROR Memory allocate error.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t RTT_Init(L2_RTT_FSM **rttFsmPtr)
|
||||
{
|
||||
(*rttFsmPtr) = (L2_RTT_FSM *)malloc(sizeof(L2_RTT_FSM));
|
||||
if (*rttFsmPtr == NULL)
|
||||
{
|
||||
free(*rttFsmPtr);
|
||||
return EALLOC;
|
||||
}
|
||||
RTT_Reset(*rttFsmPtr);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Update RTT FSM accordingly.
|
||||
*
|
||||
* @param instPtr a pointer to linklayer layer instance
|
||||
* @param torType tx/rx mode type
|
||||
*
|
||||
* @return SUCCESS
|
||||
* error code
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t RTT_FsmUpdate(L2_INST *instPtr, L2_TOR_TYPE torType)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
L2_RTT_FSM *rttFsmPtr = L2_GetRttFsm(instPtr);
|
||||
RTT_RECORD *rttRecord = &(rttFsmPtr->rttRecord);
|
||||
PHY_INST *phyRef = instPtr->config.phyInstPtr;
|
||||
|
||||
DBG_INFO("-------- RTT FSM Update --------\n");
|
||||
// Stage trans
|
||||
// For Head Node: Tx->Rx->Tx->Rx
|
||||
if (L2_GetNodeType(instPtr) == L2_NODE_HEAD)
|
||||
{
|
||||
switch (rttFsmPtr->rttStage)
|
||||
{
|
||||
case RTT_REQ1:
|
||||
if (torType == L2_TOR_TX)
|
||||
{
|
||||
DBG_INFO("Prepare data for RTT REQ-1\n");
|
||||
// Update Tt1
|
||||
RTT_GetFrameStart(instPtr, &(rttRecord->Tt1), torType);
|
||||
DBG_INFO("Tt1-timeL:%u.\n", rttRecord->Tt1.int_part);
|
||||
DBG_INFO("Tt1-timeH:%u.\n", rttRecord->Tt1.frac_part);
|
||||
|
||||
// Prepare data for sending...
|
||||
rttFsmPtr->timeStamp = rttRecord->Tt1;
|
||||
rttFsmPtr->doppler = RTT_DOPPLER_NONE;
|
||||
RTT_StageUpdate(rttFsmPtr, RTT_RSP1);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_INFO("RTT FSM remain current state [%d].\n", rttFsmPtr->rttStage);
|
||||
}
|
||||
break;
|
||||
case RTT_RSP1:
|
||||
if (torType == L2_TOR_RX)
|
||||
{
|
||||
if (L2_isDataAvail(instPtr) == true)
|
||||
{
|
||||
DBG_INFO("RTT RSP-1 have been received.\n");
|
||||
DBG_INFO("Preparing data for RTT REQ-2.\n");
|
||||
rttFsmPtr->isR2Valid = true;
|
||||
// Update doppler
|
||||
rttRecord->dopplerR2 = (int32_t)Phy_GetCoarseFreqEst(phyRef);
|
||||
// Update Tr2
|
||||
RTT_GetFrameStart(instPtr, &(rttRecord->Tr2), torType);
|
||||
// Calculate TroundA
|
||||
TimeCtrl_CalculateTimeGap(&(rttRecord->Tt1), &(rttRecord->Tr2), &(rttRecord->TroundA));
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_WARNING("RTT RSP-1 had not been received [Stage: %d].\n", rttFsmPtr->rttStage);
|
||||
DBG_WARNING("Set Tr2 dopplerR2 and TroundA to dummy value.\n");
|
||||
rttFsmPtr->isR2Valid = false;
|
||||
rttRecord->dopplerR2 = RTT_DOPPLER_NONE;
|
||||
rttRecord->Tr2 = RTT_TIME_NONE;
|
||||
rttRecord->TroundA = RTT_TIME_NONE;
|
||||
}
|
||||
DBG_INFO("dopplerR2:%d.\n", rttRecord->dopplerR2);
|
||||
DBG_INFO("Tr2-timeL:%u.\n", rttRecord->Tr2.frac_part);
|
||||
DBG_INFO("Tr2-timeH:%u.\n", rttRecord->Tr2.int_part);
|
||||
DBG_INFO("TroundA-timeL:%u.\n", rttRecord->TroundA.frac_part);
|
||||
DBG_INFO("TroundA-timeH:%u.\n", rttRecord->TroundA.int_part);
|
||||
RTT_StageUpdate(rttFsmPtr, RTT_REQ2);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_INFO("RTT FSM remain current state [%d].\n", rttFsmPtr->rttStage);
|
||||
}
|
||||
break;
|
||||
case RTT_REQ2:
|
||||
if (torType == L2_TOR_TX)
|
||||
{
|
||||
DBG_INFO("Prepare data for RTT REQ-2\n");
|
||||
// Update Tt3
|
||||
RTT_GetFrameStart(instPtr, &(rttRecord->Tt3), torType);
|
||||
|
||||
if (rttFsmPtr->isR2Valid)
|
||||
{
|
||||
// Calculate reply A
|
||||
TimeCtrl_CalculateTimeGap(&(rttRecord->Tt3), &(rttRecord->Tr2), &(rttRecord->TreplyA));
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_WARNING("RTT RSP-1 have not been received [Stage: %d].\n", rttFsmPtr->rttStage);
|
||||
DBG_WARNING("Set TreplyA to dummy value.\n");
|
||||
rttRecord->TreplyA = RTT_TIME_NONE;
|
||||
}
|
||||
DBG_INFO("Tt3-timeL:%u.\n", rttRecord->Tt3.frac_part);
|
||||
DBG_INFO("Tt3-timeH:%u.\n", rttRecord->Tt3.int_part);
|
||||
DBG_INFO("TreplyA-timeL:%u.\n", rttRecord->TreplyA.frac_part);
|
||||
DBG_INFO("TreplyA-timeH:%u.\n", rttRecord->TreplyA.int_part);
|
||||
|
||||
// Prepare data for sending.
|
||||
rttFsmPtr->timeStamp = rttRecord->TroundA;
|
||||
rttFsmPtr->doppler = rttRecord->dopplerR2;
|
||||
RTT_StageUpdate(rttFsmPtr, RTT_RSP2);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_INFO("RTT FSM remain current state [%d].\n", rttFsmPtr->rttStage);
|
||||
}
|
||||
break;
|
||||
case RTT_RSP2:
|
||||
if (torType == L2_TOR_RX)
|
||||
{
|
||||
if (L2_isDataAvail(instPtr) == true)
|
||||
{
|
||||
DBG_INFO("RTT RSP-2 have been received.\n");
|
||||
rttFsmPtr->isR4Valid = true;
|
||||
// Update doppler
|
||||
double doppler = Phy_GetCoarseFreqEst(phyRef);
|
||||
rttRecord->dopplerR2 = (int32_t)doppler;
|
||||
// Update Tr4
|
||||
RTT_GetFrameStart(instPtr, &(rttRecord->Tr4), torType);
|
||||
// Calculate TroundA
|
||||
TimeCtrl_CalculateTimeGap(&(rttRecord->Tt3), &(rttRecord->Tr4), &(rttRecord->TroundA));
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_WARNING("RTT RSP-1 have not been received [Stage: %d].\n", rttFsmPtr->rttStage);
|
||||
DBG_WARNING("Set Tr4 dopplerR4 and TroundA to dummy value.\n");
|
||||
rttFsmPtr->isR4Valid = false;
|
||||
rttRecord->dopplerR4 = RTT_DOPPLER_NONE;
|
||||
rttRecord->Tr4 = RTT_TIME_NONE;
|
||||
rttRecord->TroundA = RTT_TIME_NONE;
|
||||
}
|
||||
DBG_INFO("dopplerR4:%d.\n", rttRecord->dopplerR4);
|
||||
DBG_INFO("Tr4-timeL:%u.\n", rttRecord->Tr4.frac_part);
|
||||
DBG_INFO("Tr4-timeH:%u.\n", rttRecord->Tr4.int_part);
|
||||
DBG_INFO("TroundA-timeL:%u.\n", rttRecord->TroundA.frac_part);
|
||||
DBG_INFO("TroundA-timeH:%u.\n", rttRecord->TroundA.int_part);
|
||||
RTT_StageUpdate(rttFsmPtr, RTT_REQ1);
|
||||
DBG_INFO("RTT procedure end...\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_INFO("RTT FSM remain current state [%d].\n", rttFsmPtr->rttStage);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
DBG_ERROR("Unexpected RTT FSM stage [%d].\n", rttFsmPtr->rttStage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// For Member Node: Rx->Tx->Rx->Tx
|
||||
else
|
||||
{
|
||||
switch (rttFsmPtr->rttStage)
|
||||
{
|
||||
case RTT_REQ1:
|
||||
if (torType == L2_TOR_RX)
|
||||
{
|
||||
if (L2_isDataAvail(instPtr) == true)
|
||||
{
|
||||
DBG_INFO("RTT REQ-1 have been received.\n");
|
||||
DBG_INFO("Preparing data for RTT RSP-1.\n");
|
||||
rttFsmPtr->isR2Valid = true;
|
||||
// Update doppler
|
||||
rttRecord->dopplerR2 = (int32_t)Phy_GetCoarseFreqEst(phyRef);
|
||||
// Update Tr1
|
||||
RTT_GetFrameStart(instPtr, &(rttRecord->Tr1), torType);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_WARNING("RTT REQ-1 have not been received [Stage: %d].\n", rttFsmPtr->rttStage);
|
||||
DBG_WARNING("Set dopplerR1 and Tr1 to dummy value.\n");
|
||||
rttFsmPtr->isR1Valid = false;
|
||||
rttRecord->dopplerR1 = RTT_DOPPLER_NONE;
|
||||
rttRecord->Tr1 = RTT_TIME_NONE;
|
||||
}
|
||||
DBG_INFO("dopplerR1:%d.\n", rttRecord->dopplerR1);
|
||||
DBG_INFO("Tr1-timeL:%u.\n", rttRecord->Tr1.frac_part);
|
||||
DBG_INFO("Tr1-timeH:%u.\n", rttRecord->Tr1.int_part);
|
||||
RTT_StageUpdate(rttFsmPtr, RTT_RSP1);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_INFO("RTT FSM remain current state [%d].\n", rttFsmPtr->rttStage);
|
||||
}
|
||||
break;
|
||||
case RTT_RSP1:
|
||||
if (torType == L2_TOR_TX)
|
||||
{
|
||||
DBG_INFO("Prepare data for RTT RSP-1\n");
|
||||
// Update Tt2
|
||||
RTT_GetFrameStart(instPtr, &(rttRecord->Tt2), torType);
|
||||
if (rttFsmPtr->isR1Valid)
|
||||
{
|
||||
// Calculate reply B
|
||||
TimeCtrl_CalculateTimeGap(&(rttRecord->Tr1), &(rttRecord->Tt2), &(rttRecord->TreplyB));
|
||||
}
|
||||
else
|
||||
{
|
||||
rttRecord->TreplyB = RTT_TIME_NONE;
|
||||
DBG_WARNING("RTT REQ-1 have not been received [Stage: %d].\n", rttFsmPtr->rttStage);
|
||||
DBG_WARNING("Set ReplayB to dummy value.\n");
|
||||
}
|
||||
DBG_INFO("Tt2-timeL:%u.\n", rttRecord->Tt2.frac_part);
|
||||
DBG_INFO("Tt2-timeH:%u.\n", rttRecord->Tt2.int_part);
|
||||
DBG_INFO("TreplyB-timeL:%u.\n", rttRecord->TreplyB.frac_part);
|
||||
DBG_INFO("TreplyB-timeH:%u.\n", rttRecord->TreplyB.int_part);
|
||||
|
||||
// Prepare data for sending.
|
||||
rttFsmPtr->timeStamp = rttRecord->TreplyB;
|
||||
rttFsmPtr->doppler = rttRecord->dopplerR1;
|
||||
RTT_StageUpdate(rttFsmPtr, RTT_REQ2);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_INFO("RTT FSM remain current state [%d].\n", rttFsmPtr->rttStage);
|
||||
}
|
||||
break;
|
||||
case RTT_REQ2:
|
||||
if (torType == L2_TOR_RX)
|
||||
{
|
||||
if (L2_isDataAvail(instPtr) == true)
|
||||
{
|
||||
DBG_INFO("RTT REQ-2 have been received.\n");
|
||||
DBG_INFO("Preparing data for RTT RSP-2.\n");
|
||||
rttFsmPtr->isR3Valid = true;
|
||||
// Update doppler
|
||||
rttRecord->dopplerR2 = (int32_t)Phy_GetCoarseFreqEst(phyRef);
|
||||
// Update Tr3
|
||||
RTT_GetFrameStart(instPtr, &(rttRecord->Tr3), torType);
|
||||
// Calculate TroundB
|
||||
TimeCtrl_CalculateTimeGap(&(rttRecord->Tt2), &(rttRecord->Tr3), &(rttRecord->TroundB));
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_WARNING("RTT REQ-2 have not been received [Stage: %d].\n", rttFsmPtr->rttStage);
|
||||
DBG_WARNING("Set dopplerR3 and ReplayB to dummy value.\n");
|
||||
rttFsmPtr->isR3Valid = false;
|
||||
rttRecord->dopplerR3 = RTT_DOPPLER_NONE;
|
||||
rttRecord->TroundB = RTT_TIME_NONE;
|
||||
}
|
||||
DBG_INFO("dopplerR3:%d.\n", rttRecord->dopplerR3);
|
||||
DBG_INFO("Tr3-timeL:%u.\n", rttRecord->Tr3.frac_part);
|
||||
DBG_INFO("Tr3-timeH:%u.\n", rttRecord->Tr3.int_part);
|
||||
DBG_INFO("TroundB-timeL:%u.\n", rttRecord->TroundB.frac_part);
|
||||
DBG_INFO("TroundB-timeH:%u.\n", rttRecord->TroundB.int_part);
|
||||
RTT_StageUpdate(rttFsmPtr, RTT_RSP2);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_INFO("RTT FSM remain current state [%d].\n", rttFsmPtr->rttStage);
|
||||
}
|
||||
break;
|
||||
case RTT_RSP2:
|
||||
if (torType == L2_TOR_TX)
|
||||
{
|
||||
DBG_INFO("Prepare data for RTT RSP-2\n");
|
||||
// Update Tt4
|
||||
RTT_GetFrameStart(instPtr, &(rttRecord->Tt4), torType);
|
||||
if (rttFsmPtr->isR3Valid)
|
||||
{
|
||||
// Calculate reply B
|
||||
TimeCtrl_CalculateTimeGap(&(rttRecord->Tr3), &(rttRecord->Tt4), &(rttRecord->TreplyB));
|
||||
// TODO: implement a time adjustment.
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_WARNING("RTT REQ-2 have not been received [Stage: %d].\n", rttFsmPtr->rttStage);
|
||||
DBG_WARNING("Set ReplayB to dummy value.\n");
|
||||
rttRecord->TreplyB = RTT_TIME_NONE;
|
||||
}
|
||||
DBG_INFO("Tt4-timeL:%u.\n", rttRecord->Tt4.frac_part);
|
||||
DBG_INFO("Tt4-timeH:%u.\n", rttRecord->Tt4.int_part);
|
||||
DBG_INFO("TreplyB-timeL:%u.\n", rttRecord->TreplyB.frac_part);
|
||||
DBG_INFO("TreplyB-timeH:%u.\n", rttRecord->TreplyB.int_part);
|
||||
|
||||
// Prepare data for sending.
|
||||
rttFsmPtr->timeStamp = rttRecord->TreplyB;
|
||||
rttFsmPtr->doppler = rttRecord->dopplerR3;
|
||||
RTT_StageUpdate(rttFsmPtr, RTT_REQ1);
|
||||
DBG_INFO("RTT procedure end...\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_INFO("RTT FSM remain current state [%d].\n", rttFsmPtr->rttStage);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
DBG_ERROR("Unexpected RTT FSM stage [%d].\n", rttFsmPtr->rttStage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ L2_CONFIG l2Config = {
|
||||
.phyInstPtr = NULL,
|
||||
.tmcInstPtr = NULL};
|
||||
|
||||
TIMECTRL_CONFIG tmcConfig = {
|
||||
TMC_CONFIG tmcConfig = {
|
||||
.baseAddr = TIME_CONTROLLER_BASEADDR,
|
||||
.reset = 10};
|
||||
|
||||
@@ -73,7 +73,7 @@ void MPC_IntrHandler(void *callBackRef);
|
||||
#endif
|
||||
|
||||
/*********************** Driver Instance Definitions **************************/
|
||||
TIMECTRL_INST *tmcInstPtr = NULL;
|
||||
TMC_INST *tmcInstPtr = NULL;
|
||||
PHY_INST *phyInstPtr = NULL;
|
||||
L2_INST *linkInstPtr = NULL;
|
||||
static XScuGic gicInst; // General interrupt controller intance
|
||||
@@ -223,7 +223,7 @@ void MPC_IntrHandler(void *callBackRef)
|
||||
void PhysicalIntr_Handler(void *callBackRef)
|
||||
{
|
||||
Phy_UpdateState(phyInstPtr);
|
||||
if (phyInstPtr->TOR.curr == PHY_TOR_TX)
|
||||
if (phyInstPtr->tor.curr == PHY_TOR_TX)
|
||||
{
|
||||
switch (phyInstPtr->frameType.curr)
|
||||
{
|
||||
@@ -255,7 +255,7 @@ void PhysicalIntr_Handler(void *callBackRef)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (phyInstPtr->TOR.last == PHY_TOR_RX && phyInstPtr->isFrameSync)
|
||||
if (phyInstPtr->tor.last == PHY_TOR_RX && phyInstPtr->isFrameSync)
|
||||
{
|
||||
switch (phyInstPtr->frameType.last)
|
||||
{
|
||||
@@ -449,12 +449,12 @@ int main(void)
|
||||
if (linkInstPtr->buffSwitch == 0)
|
||||
{
|
||||
MPC_StateUpload(mpcInstPtr, linkInstPtr->mgmtMsgRecvBuff1, linkInstPtr->mgmtMsgRecvCnt1,
|
||||
linkInstPtr->svcMsgRecvBuff1, linkInstPtr->svcMsgRecvCnt1, &(linkInstPtr->mgmtNetFSM->mgmtMsgLog));
|
||||
linkInstPtr->svcMsgRecvBuff1, linkInstPtr->svcMsgRecvCnt1, &(linkInstPtr->mgmtFSM->mgmtMsgLog));
|
||||
}
|
||||
else
|
||||
{
|
||||
MPC_StateUpload(mpcInstPtr, linkInstPtr->mgmtMsgRecvBuff0, linkInstPtr->mgmtMsgRecvCnt0,
|
||||
linkInstPtr->svcMsgRecvBuff0, linkInstPtr->svcMsgRecvCnt0, &(linkInstPtr->mgmtNetFSM->mgmtMsgLog));
|
||||
linkInstPtr->svcMsgRecvBuff0, linkInstPtr->svcMsgRecvCnt0, &(linkInstPtr->mgmtFSM->mgmtMsgLog));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,34 +21,40 @@
|
||||
#include "../error.h"
|
||||
|
||||
#define ANT_PI 3.14159265358979323846
|
||||
|
||||
#define ANT_COINFO_HEAD 0xAA
|
||||
#define ANT_COINFO_TAIL 0xCC
|
||||
|
||||
#define CTRL_WORD_DEFAULT 0x00
|
||||
|
||||
#define ANT_MODE_BEAM_MASK 0xF0
|
||||
#define ANT_MODE_NARROR_BEAM 0x00 // 8
|
||||
#define ANT_MODE_WIDE_BEAM_1 0x10 // 25
|
||||
#define ANT_MODE_WIDE_BEAM_2 0x20 // 60
|
||||
#define ANT_MODE_WIDE_BEAM_3 0x30 // 120
|
||||
#define ANT_BEAM_NARROR 0x00 // 8
|
||||
#define ANT_BEAM_SUBNARROR_0 0x10 // 25
|
||||
#define ANT_BEAM_SUBNARROR_1 0x20 // 60
|
||||
#define ANT_BEAM_WIDE 0x30 // 120
|
||||
|
||||
#define ANT_MODE_HIGH_POWER 0x00
|
||||
#define ANT_MODE_LOWAPOWER 0x04
|
||||
#define ANT_MODE_STANDBY 0x0F
|
||||
#define ATN_MODE_DEFAULT (ANT_MODE_WIDE_BEAM_1 | ANT_MODE_LOWAPOWER)
|
||||
#define ATN_MODE_HIGH (ANT_MODE_WIDE_BEAM_1 | ANT_MODE_HIGH_POWER)
|
||||
#define ANT_MODE_POWER_MASK 0x0F
|
||||
#define ANT_POWER_FULL 0x00
|
||||
#define ANT_POWER_LOW 0x04
|
||||
#define ANT_POWER_STANDBY 0x0F
|
||||
#define ATN_MODE_SILENT (ANT_BEAM_SUBNARROR_0 | ANT_POWER_STANDBY)
|
||||
#define ATN_MODE_LOWPOWER (ANT_BEAM_SUBNARROR_0 | ANT_POWER_LOW)
|
||||
#define ATN_MODE_FULLPOWER (ANT_BEAM_SUBNARROR_0 | ANT_POWER_FULL)
|
||||
#define ATN_MODE_DEFAULT ATN_MODE_SILENT
|
||||
|
||||
#define DEFAULT_CENTRTAL_FREQ 0x06D7 // 26.25GHz
|
||||
#define ATN_ATTENUATION_MAX 0x1F
|
||||
#define ATN_ATTENUATION_SKIP 0xFF
|
||||
|
||||
#define RXTXMODE_RX 0x00
|
||||
#define RXTXMODE_TX 0x01
|
||||
#define DEFAULT_CARRIER_FREQ 0x06D7 // 26.25GHz
|
||||
|
||||
#define RXTXMODE_DEFAULT 0x00
|
||||
#define TORMODE_RX 0x00
|
||||
#define TORMODE_TX 0x01
|
||||
#define TORMODE_DEFAULT 0x00
|
||||
|
||||
#define CALIBRMODE_NORMAL 0x00
|
||||
#define CALIBRMODE_SINGLE_TR_CAL 0x01
|
||||
#define CALIMODE_NORMAL 0x00
|
||||
#define CALIMODE_SINGLE_TR_CAL 0x01
|
||||
|
||||
#define MODECTRL_DEFAULT 0x00
|
||||
#define RF_CTRL_DEFAULT 0x00
|
||||
|
||||
// Pair by regex
|
||||
// Regex: (([0-9]+, ){8})
|
||||
@@ -62,7 +68,8 @@ uint16_t hopPattern_2KBPS_20MS[L1_FRAME_2KBPS_20MS_HOPS] =
|
||||
1500
|
||||
};
|
||||
|
||||
uint16_t hopPattern_2KBPS_100MS[L1_FRAME_2KBPS_100MS_HOPS] = {
|
||||
uint16_t hopPattern_2KBPS_100MS[L1_FRAME_2KBPS_100MS_HOPS] =
|
||||
{
|
||||
2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400,
|
||||
2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400,
|
||||
2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400,
|
||||
@@ -117,63 +124,7 @@ uint16_t hopPattern_1M2BPS_5MS[L1_FRAME_1M2BPS_5MS_HOPS] =
|
||||
// Pair by regex
|
||||
// Regex: ((\{\.oaxis = [0-9]+[ ,]+\.raxis = [0-9]+[ ]*\}, ){2})
|
||||
#if defined(PHY_BEAM_SET_PRESET)
|
||||
PHY_ANT_ANGLE antSubnrrwPattern[NUM_ANT_SUBNRRW_PATTERN] =
|
||||
{
|
||||
{.oaxis = 0 , .raxis = 222}, {.oaxis = 10, .raxis = 85 },
|
||||
{.oaxis = 14, .raxis = 307}, {.oaxis = 17, .raxis = 170},
|
||||
{.oaxis = 19, .raxis = 32 }, {.oaxis = 21, .raxis = 255},
|
||||
{.oaxis = 24, .raxis = 117}, {.oaxis = 25, .raxis = 340},
|
||||
{.oaxis = 27, .raxis = 202}, {.oaxis = 29, .raxis = 65 },
|
||||
{.oaxis = 31, .raxis = 287}, {.oaxis = 32, .raxis = 150},
|
||||
{.oaxis = 34, .raxis = 12 }, {.oaxis = 35, .raxis = 235},
|
||||
{.oaxis = 36, .raxis = 97 }, {.oaxis = 38, .raxis = 320},
|
||||
{.oaxis = 39, .raxis = 182}, {.oaxis = 40, .raxis = 45 },
|
||||
{.oaxis = 41, .raxis = 267}, {.oaxis = 43, .raxis = 130},
|
||||
{.oaxis = 44, .raxis = 352}, {.oaxis = 45, .raxis = 215},
|
||||
{.oaxis = 46, .raxis = 77 }, {.oaxis = 47, .raxis = 300},
|
||||
{.oaxis = 48, .raxis = 162}, {.oaxis = 49, .raxis = 25 },
|
||||
{.oaxis = 50, .raxis = 247}, {.oaxis = 51, .raxis = 110},
|
||||
{.oaxis = 52, .raxis = 332}, {.oaxis = 53, .raxis = 195},
|
||||
{.oaxis = 54, .raxis = 57 }, {.oaxis = 55, .raxis = 280},
|
||||
{.oaxis = 56, .raxis = 142}, {.oaxis = 57, .raxis = 5 },
|
||||
{.oaxis = 58, .raxis = 227}, {.oaxis = 59, .raxis = 90 },
|
||||
{.oaxis = 60, .raxis = 312}
|
||||
};
|
||||
PHY_ANT_ANGLE antNrrwPattern[NUM_ANT_NRRW_PATTERN] = {
|
||||
{.oaxis = 0 , .raxis = 222}, {.oaxis = 7 , .raxis = 85 },
|
||||
{.oaxis = 10, .raxis = 307}, {.oaxis = 13, .raxis = 170},
|
||||
{.oaxis = 15, .raxis = 32 }, {.oaxis = 17, .raxis = 255},
|
||||
{.oaxis = 18, .raxis = 117}, {.oaxis = 20, .raxis = 340},
|
||||
{.oaxis = 21, .raxis = 202}, {.oaxis = 22, .raxis = 65 },
|
||||
{.oaxis = 24, .raxis = 287}, {.oaxis = 25, .raxis = 150},
|
||||
{.oaxis = 26, .raxis = 12 }, {.oaxis = 27, .raxis = 235},
|
||||
{.oaxis = 28, .raxis = 97 }, {.oaxis = 29, .raxis = 320},
|
||||
{.oaxis = 30, .raxis = 182}, {.oaxis = 31, .raxis = 45 },
|
||||
{.oaxis = 32, .raxis = 267}, {.oaxis = 33, .raxis = 130},
|
||||
{.oaxis = 34, .raxis = 352}, {.oaxis = 34, .raxis = 215},
|
||||
{.oaxis = 35, .raxis = 77 }, {.oaxis = 36, .raxis = 300},
|
||||
{.oaxis = 37, .raxis = 162}, {.oaxis = 38, .raxis = 25 },
|
||||
{.oaxis = 38, .raxis = 247}, {.oaxis = 39, .raxis = 110},
|
||||
{.oaxis = 40, .raxis = 332}, {.oaxis = 41, .raxis = 195},
|
||||
{.oaxis = 41, .raxis = 57 }, {.oaxis = 42, .raxis = 280},
|
||||
{.oaxis = 43, .raxis = 142}, {.oaxis = 44, .raxis = 5 },
|
||||
{.oaxis = 44, .raxis = 227}, {.oaxis = 45, .raxis = 90 },
|
||||
{.oaxis = 46, .raxis = 312}, {.oaxis = 46, .raxis = 175},
|
||||
{.oaxis = 47, .raxis = 37 }, {.oaxis = 48, .raxis = 260},
|
||||
{.oaxis = 48, .raxis = 122}, {.oaxis = 49, .raxis = 345},
|
||||
{.oaxis = 49, .raxis = 207}, {.oaxis = 50, .raxis = 70 },
|
||||
{.oaxis = 51, .raxis = 292}, {.oaxis = 51, .raxis = 155},
|
||||
{.oaxis = 52, .raxis = 17 }, {.oaxis = 53, .raxis = 240},
|
||||
{.oaxis = 53, .raxis = 102}, {.oaxis = 54, .raxis = 325},
|
||||
{.oaxis = 54, .raxis = 187}, {.oaxis = 55, .raxis = 50 },
|
||||
{.oaxis = 55, .raxis = 272}, {.oaxis = 56, .raxis = 135},
|
||||
{.oaxis = 57, .raxis = 357}, {.oaxis = 57, .raxis = 220},
|
||||
{.oaxis = 58, .raxis = 82 }, {.oaxis = 58, .raxis = 305},
|
||||
{.oaxis = 59, .raxis = 167}, {.oaxis = 59, .raxis = 30 },
|
||||
{.oaxis = 60, .raxis = 252}
|
||||
};
|
||||
#elif defined(PHY_BEAM_SET_PRESET_LSX)
|
||||
ANT_ANGLE antSubnrrwPattern[NUM_ANT_SUBNRRW_PATTERN] = {
|
||||
ANT_ANGLE antSubnrrwPattern[L1_NUM_ANT_SUBNRRW_PATTERN] = {
|
||||
{.oaxis = 0 , .raxis =2225},{.oaxis = 96 , .raxis =850 },
|
||||
{.oaxis = 135, .raxis =3075},{.oaxis = 166, .raxis =1700},
|
||||
{.oaxis = 192, .raxis =325 },{.oaxis = 215, .raxis =2550},
|
||||
@@ -194,7 +145,7 @@ ANT_ANGLE antSubnrrwPattern[NUM_ANT_SUBNRRW_PATTERN] = {
|
||||
{.oaxis = 581, .raxis =2272},{.oaxis = 591, .raxis =897 },
|
||||
{.oaxis = 600, .raxis =3122}
|
||||
};
|
||||
ANT_ANGLE antNrrwPattern[NUM_ANT_NRRW_PATTERN] = {
|
||||
ANT_ANGLE antNrrwPattern[L1_NUM_ANT_NRRW_PATTERN] = {
|
||||
{.oaxis = 0 , .raxis =2225},{.oaxis = 74 , .raxis =850 },
|
||||
{.oaxis = 105, .raxis =3075},{.oaxis = 128, .raxis =1700},
|
||||
{.oaxis = 148, .raxis =325 },{.oaxis = 166, .raxis =2550},
|
||||
@@ -228,11 +179,11 @@ ANT_ANGLE antNrrwPattern[NUM_ANT_NRRW_PATTERN] = {
|
||||
{.oaxis = 600, .raxis =2520}
|
||||
};
|
||||
#else
|
||||
PHY_ANT_ANGLE antSubnrrwPattern[NUM_ANT_SUBNRRW_PATTERN] =
|
||||
PHY_ANT_ANGLE antSubnrrwPattern[L1_NUM_ANT_SUBNRRW_PATTERN] =
|
||||
{
|
||||
0
|
||||
};
|
||||
PHY_ANT_ANGLE antNrrwPattern[NUM_ANT_NRRW_PATTERN] =
|
||||
PHY_ANT_ANGLE antNrrwPattern[L1_NUM_ANT_NRRW_PATTERN] =
|
||||
{
|
||||
0
|
||||
};
|
||||
@@ -241,171 +192,255 @@ PHY_ANT_ANGLE antNrrwPattern[NUM_ANT_NRRW_PATTERN] =
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param antCoinfoPtr
|
||||
* @param antConfig
|
||||
*
|
||||
* @return
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t Phy_AntCoinfoInit(PHY_ANT_CONFIG *antCoinfoPtr)
|
||||
void Phy_AntConfigInit(PHY_ANT_CONFIG *antConfig)
|
||||
{
|
||||
if (antCoinfoPtr == NULL)
|
||||
{
|
||||
return FAILURE;
|
||||
}
|
||||
antCoinfoPtr->head = ANT_COINFO_HEAD;
|
||||
antCoinfoPtr->tail = ANT_COINFO_TAIL;
|
||||
antCoinfoPtr->ctrlWord = 0x00;
|
||||
#ifdef ANT_HIGH_POWER
|
||||
antCoinfoPtr->antMode = ATN_MODE_HIGH;
|
||||
#else
|
||||
antCoinfoPtr->antMode = ATN_MODE_DEFAULT;
|
||||
#endif
|
||||
ASSERT(antConfig != NULL);
|
||||
antConfig->ctrlWord = CTRL_WORD_DEFAULT;
|
||||
antConfig->antMode = ATN_MODE_DEFAULT;
|
||||
|
||||
// FIXME: Dummy default value.
|
||||
// off axis angle setting
|
||||
antCoinfoPtr->oaxis[0] = 0;
|
||||
antCoinfoPtr->oaxis[1] = 0;
|
||||
antConfig->oaxis[0] = 0;
|
||||
antConfig->oaxis[1] = 0;
|
||||
// round axis angle setting
|
||||
antCoinfoPtr->raxis[0] = 0;
|
||||
antCoinfoPtr->raxis[1] = 0;
|
||||
// ***********************
|
||||
antConfig->raxis[0] = 0;
|
||||
antConfig->raxis[1] = 0;
|
||||
|
||||
antCoinfoPtr->antFreq[0] = (uint8_t)(DEFAULT_CENTRTAL_FREQ);
|
||||
antCoinfoPtr->antFreq[1] = (uint8_t)(DEFAULT_CENTRTAL_FREQ >> 8);
|
||||
antConfig->antFreq[0] = (uint8_t)(DEFAULT_CARRIER_FREQ);
|
||||
antConfig->antFreq[1] = (uint8_t)(DEFAULT_CARRIER_FREQ >> 8);
|
||||
|
||||
// FIXME: Dummy default value.
|
||||
// trSelect
|
||||
antCoinfoPtr->trSlect = 0;
|
||||
antConfig->trSelect = 0;
|
||||
// Antenna attenuation setting
|
||||
antCoinfoPtr->antAtt = 20;
|
||||
antConfig->antAtt = 20;
|
||||
// phase setting
|
||||
antCoinfoPtr->phase = 0;
|
||||
// ***********************
|
||||
antConfig->phase = 0;
|
||||
|
||||
antCoinfoPtr->rxtxMode = RXTXMODE_RX;
|
||||
antCoinfoPtr->calibrMode = CALIBRMODE_NORMAL;
|
||||
antConfig->torMode = TORMODE_DEFAULT;
|
||||
antConfig->caliMode = CALIMODE_NORMAL;
|
||||
antConfig->antReserved = 0x00;
|
||||
// ***********************
|
||||
|
||||
// FIXME: Dummy default value.
|
||||
// DD enable
|
||||
antCoinfoPtr->ddEn = 0;
|
||||
// DD mgc
|
||||
antCoinfoPtr->ddMgc = 0;
|
||||
// RF mode control
|
||||
antCoinfoPtr->rfCtrl = 0;
|
||||
antConfig->rfCtrl = RF_CTRL_DEFAULT;
|
||||
// RF frequency
|
||||
antConfig->rfFreq[0] = (uint8_t)(DEFAULT_CARRIER_FREQ);
|
||||
antConfig->rfFreq[1] = (uint8_t)(DEFAULT_CARRIER_FREQ >> 8);
|
||||
// RF MGC control
|
||||
antCoinfoPtr->rfMgc = 0;
|
||||
antConfig->rfTxMgc = 0;
|
||||
// RF channel 1&2 calibration mgc
|
||||
antCoinfoPtr->rf12CalMgc = 0;
|
||||
antConfig->rf12CalMgc = 0;
|
||||
// RF channel 2&3 calibration mgc
|
||||
antCoinfoPtr->rf34CalMgc = 0;
|
||||
// Receive channel 1 MGC
|
||||
antCoinfoPtr->rcv1Mgc = 0;
|
||||
// Receive channel 2 MGC
|
||||
antCoinfoPtr->rcv2Mgc = 0;
|
||||
// Receive channel 3 MGC
|
||||
antCoinfoPtr->rcv3Mgc = 0;
|
||||
// Receive channel 4 MGC
|
||||
antCoinfoPtr->rcv4Mgc = 0;
|
||||
// ***********************
|
||||
|
||||
memset(antCoinfoPtr->dummy, 0x00, sizeof(antCoinfoPtr->dummy));
|
||||
|
||||
return SUCCESS;
|
||||
antConfig->rf34CalMgc = 0;
|
||||
// Receive channel 1-4 MGC
|
||||
antConfig->rfRxMgc = 0;
|
||||
antConfig->rfReserved0 = 0x00;
|
||||
antConfig->rfReserved1 = 0x00;
|
||||
}
|
||||
|
||||
int32_t Phy_SetBeamNo(PHY_INST *instPtr, int32_t beamNo)
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Update antenna power mode setting
|
||||
*
|
||||
* @param instPtr pointer to physical layer instance
|
||||
* @param mode new antenna mode
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
******************************************************************************/
|
||||
void Phy_AntConfigMode(PHY_INST *instPtr, PHY_ANT_MODE mode)
|
||||
{
|
||||
if (instPtr->beamWd.next == PHY_ANT_BEAM_8)
|
||||
ASSERT(instPtr != NULL);
|
||||
uint8_t config = instPtr->antConfig.antMode & ANT_MODE_BEAM_MASK;
|
||||
switch (mode)
|
||||
{
|
||||
if (beamNo >= NUM_ANT_NRRW_PATTERN)
|
||||
case PHY_ANT_MODE_STANDBY:
|
||||
config |= ANT_POWER_STANDBY;
|
||||
break;
|
||||
case PHY_ANT_MODE_POWER_LOW:
|
||||
config |= ANT_POWER_LOW;
|
||||
break;
|
||||
case PHY_ANT_MODE_POWER_FULL:
|
||||
config |= ANT_POWER_FULL;
|
||||
break;
|
||||
default:
|
||||
DBG_ERROR("Unknown antenna mode: %" PRIu8 ", remain previous mode.\n", mode);
|
||||
return;
|
||||
}
|
||||
instPtr->antConfig.antMode = config;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Update antenna attenuation
|
||||
*
|
||||
* @param instPtr pointer to physical layer instance
|
||||
* @param rxAtt rx attenuation
|
||||
* @param txAtt tx attenuation
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
******************************************************************************/
|
||||
void Phy_AntConfigAttenuation(PHY_INST *instPtr, uint8_t rxAtt, uint8_t txAtt)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
if(rxAtt <= ATN_ATTENUATION_MAX)
|
||||
{
|
||||
instPtr->antConfig.rfRxMgc = rxAtt;
|
||||
}
|
||||
else if(rxAtt != ATN_ATTENUATION_SKIP)
|
||||
{
|
||||
DBG_ERROR("RX Attenuation exceeds range, %u.", rxAtt);
|
||||
}
|
||||
|
||||
if(txAtt <= ATN_ATTENUATION_MAX)
|
||||
{
|
||||
instPtr->antConfig.rfTxMgc = txAtt;
|
||||
}
|
||||
else if(txAtt != ATN_ATTENUATION_SKIP)
|
||||
{
|
||||
DBG_ERROR("TX Attenuation exceeds range, %u.", txAtt);
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Update antenna point direction using predefined beam table
|
||||
*
|
||||
* @param instPtr pointer to physical layer instance
|
||||
* @param beamNo new beam index
|
||||
*
|
||||
* @return SUCCESS.
|
||||
* FAILURE beamNo exceeds the table size
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t Phy_SetBeamNo(PHY_INST *instPtr, int32_t beamNo, PHY_ANT_BEAM_WIDTH beamWidth)
|
||||
{
|
||||
if (beamWidth == PHY_ANT_BEAM_16)
|
||||
{
|
||||
if (beamNo >= L1_NUM_ANT_NRRW_PATTERN)
|
||||
{
|
||||
return FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
instPtr->beamNo.next = beamNo;
|
||||
instPtr->antCoinfoPtr.oaxis[1] = (uint8_t)(antNrrwPattern[beamNo].oaxis);
|
||||
instPtr->antCoinfoPtr.oaxis[0] = (uint8_t)((antNrrwPattern[beamNo].oaxis) >> 8);
|
||||
instPtr->antCoinfoPtr.raxis[1] = (uint8_t)(antNrrwPattern[beamNo].raxis);
|
||||
instPtr->antCoinfoPtr.raxis[0] = (uint8_t)((antNrrwPattern[beamNo].raxis) >> 8);
|
||||
instPtr->antConfig.oaxis[1] = (uint8_t)(antNrrwPattern[beamNo].oaxis);
|
||||
instPtr->antConfig.oaxis[0] = (uint8_t)((antNrrwPattern[beamNo].oaxis) >> 8);
|
||||
instPtr->antConfig.raxis[1] = (uint8_t)(antNrrwPattern[beamNo].raxis);
|
||||
instPtr->antConfig.raxis[0] = (uint8_t)((antNrrwPattern[beamNo].raxis) >> 8);
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
else if (instPtr->beamWd.next == PHY_ANT_BEAM_25)
|
||||
else if (beamWidth == PHY_ANT_BEAM_25)
|
||||
{
|
||||
if (beamNo >= NUM_ANT_SUBNRRW_PATTERN)
|
||||
if (beamNo >= L1_NUM_ANT_SUBNRRW_PATTERN)
|
||||
{
|
||||
return FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
instPtr->beamNo.next = beamNo;
|
||||
instPtr->antCoinfoPtr.oaxis[1] = (uint8_t)(antSubnrrwPattern[beamNo].oaxis);
|
||||
instPtr->antCoinfoPtr.oaxis[0] = (uint8_t)((antSubnrrwPattern[beamNo].oaxis) >> 8);
|
||||
instPtr->antCoinfoPtr.raxis[1] = (uint8_t)(antSubnrrwPattern[beamNo].raxis);
|
||||
instPtr->antCoinfoPtr.raxis[0] = (uint8_t)((antSubnrrwPattern[beamNo].raxis) >> 8);
|
||||
instPtr->antConfig.oaxis[1] = (uint8_t)(antSubnrrwPattern[beamNo].oaxis);
|
||||
instPtr->antConfig.oaxis[0] = (uint8_t)((antSubnrrwPattern[beamNo].oaxis) >> 8);
|
||||
instPtr->antConfig.raxis[1] = (uint8_t)(antSubnrrwPattern[beamNo].raxis);
|
||||
instPtr->antConfig.raxis[0] = (uint8_t)((antSubnrrwPattern[beamNo].raxis) >> 8);
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if(beamWidth == PHY_ANT_BEAM_120)
|
||||
{
|
||||
// Beam number assign not support.
|
||||
// Assign default angle (0,0)
|
||||
instPtr->beamNo.next = 0;
|
||||
instPtr->antCoinfoPtr.oaxis[1] = 0;
|
||||
instPtr->antCoinfoPtr.oaxis[0] = 0;
|
||||
instPtr->antCoinfoPtr.raxis[1] = 0;
|
||||
instPtr->antCoinfoPtr.raxis[0] = 0;
|
||||
DBG_WARNING("Using default beam number...");
|
||||
instPtr->antConfig.oaxis[1] = 0;
|
||||
instPtr->antConfig.oaxis[0] = 0;
|
||||
instPtr->antConfig.raxis[1] = 0;
|
||||
instPtr->antConfig.raxis[0] = 0;
|
||||
DBG_WARNING("Using default beam number...\n");
|
||||
return SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Update antenna beam width setting
|
||||
*
|
||||
* @param instPtr pointer to physical layer instance
|
||||
* @param beamWidth new beam width
|
||||
*
|
||||
* @return SUCCESS.
|
||||
* EPARAM
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t Phy_SetBeamWidth(PHY_INST *instPtr, PHY_ANT_BEAM_WIDTH beamWidth)
|
||||
{
|
||||
uint8_t beamConfig = instPtr->antCoinfoPtr.antMode & (~ANT_MODE_BEAM_MASK);
|
||||
uint8_t beamConfig = instPtr->antConfig.antMode & (~ANT_MODE_BEAM_MASK);
|
||||
switch (beamWidth)
|
||||
{
|
||||
case PHY_ANT_BEAM_120:
|
||||
beamConfig |= ANT_MODE_WIDE_BEAM_3;
|
||||
beamConfig |= ANT_BEAM_WIDE;
|
||||
break;
|
||||
case PHY_ANT_BEAM_60:
|
||||
beamConfig |= ANT_MODE_WIDE_BEAM_2;
|
||||
beamConfig |= ANT_BEAM_SUBNARROR_1;
|
||||
break;
|
||||
case PHY_ANT_BEAM_25:
|
||||
beamConfig |= ANT_MODE_WIDE_BEAM_1;
|
||||
beamConfig |= ANT_BEAM_SUBNARROR_0;
|
||||
break;
|
||||
case PHY_ANT_BEAM_8:
|
||||
beamConfig |= ANT_MODE_NARROR_BEAM;
|
||||
case PHY_ANT_BEAM_16:
|
||||
beamConfig |= ANT_BEAM_NARROR;
|
||||
break;
|
||||
default:
|
||||
DBG_ERROR("Beam width code: 0x%08X is illegal.\n\r", beamWidth);
|
||||
DBG_ERROR("Beam width code: 0x%08X is illegal.\n", beamWidth);
|
||||
return EPARAM;
|
||||
break;
|
||||
}
|
||||
instPtr->antCoinfoPtr.antMode = beamConfig;
|
||||
instPtr->antConfig.antMode = beamConfig;
|
||||
instPtr->beamWd.next = beamWidth;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
// Common version radius double input
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Set antenna to a specific direction
|
||||
*
|
||||
* @param instPtr pointer to physical layer instance
|
||||
* @param offAx elevation angle
|
||||
* @param rndAx azimuth angle
|
||||
*
|
||||
* @return SUCCESS.
|
||||
* EPARAM - the direction is exceeds predefined range
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t Phy_SetBeamAngle(PHY_INST *instPtr, double offAx, double rndAx)
|
||||
{
|
||||
uint16_t offAxDeg = 0;
|
||||
uint16_t rndAxDeg = 0;
|
||||
offAxDeg = (offAx > 0) ? (((int32_t)(offAx * 180 / ANT_PI)) % 360) : (((int32_t)(offAx * 180 / ANT_PI)) % 360 + 360);
|
||||
rndAxDeg = (rndAx > 0) ? (((int32_t)(rndAx * 180 / ANT_PI)) % 360) : (((int32_t)(rndAx * 180 / ANT_PI)) % 360 + 360);
|
||||
offAxDeg = (offAx >= 0) ? (((int32_t)(offAx * 180 / ANT_PI)) % 360) : (((int32_t)(offAx * 180 / ANT_PI)) % 360 + 360);
|
||||
rndAxDeg = (rndAx >= 0) ? (((int32_t)(rndAx * 180 / ANT_PI)) % 360) : (((int32_t)(rndAx * 180 / ANT_PI)) % 360 + 360);
|
||||
if (offAxDeg > 60)
|
||||
{
|
||||
DBG_ERROR("Angle out of range, off axis angle: %u(should be 0~60), round axis angle: %u(should be 0~360).",
|
||||
DBG_ERROR("Angle out of range, off axis angle: %u (should be 0~60), round axis angle: %u (should be 0~360).\n",
|
||||
offAxDeg, rndAxDeg);
|
||||
return EPARAM;
|
||||
}
|
||||
offAxDeg = offAxDeg * 10;
|
||||
rndAxDeg = rndAxDeg * 10;
|
||||
instPtr->antCoinfoPtr.oaxis[1] = (uint8_t)offAxDeg;
|
||||
instPtr->antCoinfoPtr.oaxis[0] = (uint8_t)(offAxDeg >> 8);
|
||||
instPtr->antCoinfoPtr.raxis[1] = (uint8_t)rndAxDeg;
|
||||
instPtr->antCoinfoPtr.raxis[0] = (uint8_t)(rndAxDeg >> 8);
|
||||
instPtr->antConfig.oaxis[1] = (uint8_t)offAxDeg;
|
||||
instPtr->antConfig.oaxis[0] = (uint8_t)(offAxDeg >> 8);
|
||||
instPtr->antConfig.raxis[1] = (uint8_t)rndAxDeg;
|
||||
instPtr->antConfig.raxis[0] = (uint8_t)(rndAxDeg >> 8);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,30 @@
|
||||
#ifndef EMULATION
|
||||
#include "xbram.h"
|
||||
#endif
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
#define L1_FRAME_LEN_MAX (8192 / 8) // byte
|
||||
#define L1_FRAME_2KBPS_20MS_LEN 0 // byte
|
||||
#define L1_FRAME_2KBPS_100MS_LEN (312 / 8) // byte
|
||||
#define L1_FRAME_10KBPS_10MS_LEN 0 // byte
|
||||
#define L1_FRAME_10KBPS_20MS_LEN (232 / 8) // byte
|
||||
#define L1_FRAME_40KBPS_20MS_LEN (2152 / 8) // byte
|
||||
#define L1_FRAME_40KBPS_10MS_LEN (712 / 8) // byte
|
||||
#define L1_FRAME_200KBPS_5MS_LEN (2040 / 8) // byte
|
||||
#define L1_FRAME_1M2BPS_5MS_LEN (8176 / 8) // byte
|
||||
|
||||
#define L1_FRAME_2KBPS_20MS_COMP 1841158 // *10ns(Timer_L)
|
||||
#define L1_FRAME_2KBPS_100MS_COMP 1841158 // *10ns(Timer_L)
|
||||
#define L1_FRAME_10KBPS_10MS_COMP 850950 // *10ns(Timer_L)
|
||||
#define L1_FRAME_10KBPS_20MS_COMP 850950 // *10ns(Timer_L)
|
||||
#define L1_FRAME_40KBPS_20MS_COMP 111485 // *10ns(Timer_L)
|
||||
#define L1_FRAME_40KBPS_10MS_COMP 111485 // *10ns(Timer_L)
|
||||
#define L1_FRAME_200KBPS_5MS_COMP 22493 // *10ns(Timer_L)
|
||||
#define L1_FRAME_1M2BPS_5MS_COMP 22493 // *10ns(Timer_L)
|
||||
|
||||
#define ANT_CONFIG_LEN 32 // bytes
|
||||
#define L1_ANTCONFIG_MAX_LEN 8192
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
/************************** Function Prototypes ******************************/
|
||||
static void Phy_RcdShift(PHY_RCD *rcd, int32_t netxVal);
|
||||
@@ -39,7 +62,19 @@ static int32_t Phy_SetSendData(PHY_INST *instPtr, L1_FRAME_TYPE frameType, uint8
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
/************************** Variable Definitions *****************************/
|
||||
extern uint16_t hopPattern_Config[L1_FRAME_MAX_HOPS];
|
||||
extern uint16_t hopPattern_2KBPS_20MS[L1_FRAME_2KBPS_20MS_HOPS];
|
||||
extern uint16_t hopPattern_2KBPS_100MS[L1_FRAME_2KBPS_100MS_HOPS];
|
||||
extern uint16_t hopPattern_10KBPS_10MS[L1_FRAME_10KBPS_10MS_HOPS];
|
||||
extern uint16_t hopPattern_10KBPS_20MS[L1_FRAME_10KBPS_20MS_HOPS];
|
||||
extern uint16_t hopPattern_40KBPS_10MS[L1_FRAME_40KBPS_10MS_HOPS];
|
||||
extern uint16_t hopPattern_40KBPS_20MS[L1_FRAME_40KBPS_20MS_HOPS];
|
||||
|
||||
extern uint16_t hopPattern_200KBPS_5MS[L1_FRAME_200KBPS_5MS_HOPS];
|
||||
extern uint16_t hopPattern_1M2BPS_5MS[L1_FRAME_1M2BPS_5MS_HOPS];
|
||||
|
||||
extern PHY_ANT_ANGLE antSubnrrwPattern[L1_NUM_ANT_SUBNRRW_PATTERN];
|
||||
extern PHY_ANT_ANGLE antNrrwPattern[L1_NUM_ANT_NRRW_PATTERN];
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Setup data will be sent in next slot.
|
||||
@@ -63,7 +98,7 @@ static int32_t Phy_SetSendData(PHY_INST *instPtr, L1_FRAME_TYPE frameType, uint8
|
||||
DBG_ERROR("Invalid frame length.\n");
|
||||
return EPARAM;
|
||||
}
|
||||
instPtr->sendDataOffset = (TXRXDATA_MAX_LEN >> 1) - instPtr->sendDataOffset;
|
||||
instPtr->sendDataOffset = (L1_TXRXDATA_MAX_LEN >> 1) - instPtr->sendDataOffset;
|
||||
memcpy((uint8_t *)(instPtr->sendDataAddr + instPtr->sendDataOffset), dataBuff, frameLen);
|
||||
|
||||
sendCmd = frameLen & SEND_DATA_CMD_LEN_MASK;
|
||||
@@ -155,11 +190,27 @@ inline L1_FRAME_TYPE Phy_GetLastRecvFrameType(PHY_INST *instPtr)
|
||||
{
|
||||
return L1_NONE_FRAME;
|
||||
}
|
||||
int32_t frame_type = (PhyRead(instPtr, PHY_MODE_CTRL) & PHY_MODE_CTRL_FRAME_MASK) >> PHY_MODE_CTRL_FRAME_SHIFT;
|
||||
if (frame_type < L1_1M2BPS_5MS_FRAME)
|
||||
return frame_type;
|
||||
else
|
||||
int32_t frame_type = (PhyRead(instPtr, COASE_FREQEST) & COASE_TYPE_MASK);
|
||||
switch (frame_type) {
|
||||
case COASE_TYPE_2KBPS_20MS:
|
||||
return L1_2KBPS_20MS_FRAME;
|
||||
case COASE_TYPE_2KBPS_100MS:
|
||||
return L1_2KBPS_100MS_FRAME;
|
||||
case COASE_TYPE_10KBPS_10MS:
|
||||
return L1_10KBPS_10MS_FRAME;
|
||||
case COASE_TYPE_10KBPS_20MS:
|
||||
return L1_10KBPS_20MS_FRAME;
|
||||
case COASE_TYPE_40KBPS_20MS:
|
||||
return L1_40KBPS_20MS_FRAME;
|
||||
case COASE_TYPE_40KBPS_10MS:
|
||||
return L1_40KBPS_10MS_FRAME;
|
||||
case COASE_TYPE_200KBPS_5MS:
|
||||
return L1_200KBPS_5MS_FRAME;
|
||||
case COASE_TYPE_1M2BPS_5MS:
|
||||
return L1_1M2BPS_5MS_FRAME;
|
||||
default:
|
||||
return L1_NONE_FRAME;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -174,7 +225,7 @@ inline L1_FRAME_TYPE Phy_GetLastRecvFrameType(PHY_INST *instPtr)
|
||||
inline L1_FRAME_TYPE Phy_GetLastSendFrameType(PHY_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
if (instPtr->TOR.last != PHY_TOR_TX)
|
||||
if (instPtr->tor.last != PHY_TOR_TX)
|
||||
{
|
||||
return L1_NONE_FRAME;
|
||||
}
|
||||
@@ -271,7 +322,8 @@ void Phy_UpdateState(PHY_INST *instPtr)
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Initialize physical layer instance accordingly.
|
||||
* @brief Initialize Physical Layer instance, allocate memory for buffers,
|
||||
* apply a self test.
|
||||
*
|
||||
* @param instPtr a pointer to physical instance
|
||||
* @param phyConfig a pointer to configuration structure.
|
||||
@@ -290,42 +342,42 @@ int32_t Phy_InstInit(PHY_INST **instPtr, PHY_CONFIG *phyConfig)
|
||||
{
|
||||
return EALLOC;
|
||||
}
|
||||
memcpy(&(*instPtr)->phyCofig, phyConfig, sizeof(PHY_CONFIG));
|
||||
|
||||
memcpy(&(*instPtr)->phyCofig, phyConfig, sizeof(PHY_CONFIG));
|
||||
(*instPtr)->isPhyEn = false;
|
||||
(*instPtr)->isAcq = false;
|
||||
(*instPtr)->isFrameSync = false;
|
||||
(*instPtr)->isDecode = false;
|
||||
(*instPtr)->isValid = false;
|
||||
(*instPtr)->isPresetHop = true;
|
||||
(*instPtr)->recvFsTime.int_part = UINT32_MAX;
|
||||
(*instPtr)->recvFsTime.frac_part = UINT32_MAX;
|
||||
(*instPtr)->recvSlotTime.int_part = UINT32_MAX;
|
||||
(*instPtr)->recvSlotTime.frac_part = UINT32_MAX;
|
||||
(*instPtr)->isPresetHop = false;
|
||||
(*instPtr)->antConfigOffset = 0;
|
||||
(*instPtr)->sendDataOffset = 0;
|
||||
Phy_AntCoinfoInit(&((*instPtr)->antCoinfoPtr));
|
||||
Phy_AntConfigInit(&((*instPtr)->antConfig));
|
||||
|
||||
memset(&((*instPtr))->TOR, PHY_TOR_SUSPEND, sizeof(PHY_RCD));
|
||||
memset(&((*instPtr))->tor, PHY_TOR_SUSPEND, sizeof(PHY_RCD));
|
||||
memset(&((*instPtr)->frameType), L1_NONE_FRAME, sizeof(PHY_RCD));
|
||||
memset(&((*instPtr)->antNo), (int32_t)INIT_BEAM_NO, sizeof(PHY_RCD));
|
||||
memset(&((*instPtr)->beamNo), (int32_t)INIT_ANT_NO, sizeof(PHY_RCD));
|
||||
memset(&((*instPtr)->beamWd), (int32_t)INIT_ANT_WD, sizeof(PHY_RCD));
|
||||
memset(&((*instPtr)->antNo), (int32_t)L1_INIT_BEAM_NO, sizeof(PHY_RCD));
|
||||
memset(&((*instPtr)->beamNo), (int32_t)L1_INIT_ANT_NO, sizeof(PHY_RCD));
|
||||
memset(&((*instPtr)->beamWd), (int32_t)L1_INIT_ANT_WD, sizeof(PHY_RCD));
|
||||
|
||||
#ifndef EMULATION
|
||||
XBram antInfoBram;
|
||||
XBram txFrameBram;
|
||||
XBram rxFrameBram;
|
||||
XBram_Config *bramConfigPtr;
|
||||
XBram antConfigBram;
|
||||
XBram txDataBram;
|
||||
XBram rxDataBram;
|
||||
|
||||
XBram_Config *ConfigPtr;
|
||||
ConfigPtr = XBram_LookupConfig(phyConfig->antBramId);
|
||||
if (ConfigPtr == NULL)
|
||||
bramConfigPtr = XBram_LookupConfig(phyConfig->antBramId);
|
||||
if (bramConfigPtr == NULL)
|
||||
{
|
||||
Status = EDINVAL;
|
||||
goto error;
|
||||
}
|
||||
Status = XBram_CfgInitialize(&antInfoBram, ConfigPtr,
|
||||
ConfigPtr->CtrlBaseAddress);
|
||||
Status = XBram_CfgInitialize(&antConfigBram, bramConfigPtr,
|
||||
bramConfigPtr->CtrlBaseAddress);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
goto error;
|
||||
@@ -333,20 +385,20 @@ int32_t Phy_InstInit(PHY_INST **instPtr, PHY_CONFIG *phyConfig)
|
||||
/*
|
||||
* Execute the BRAM driver selftest.
|
||||
*/
|
||||
Status = XBram_SelfTest(&antInfoBram, 0);
|
||||
Status = XBram_SelfTest(&antConfigBram, 0);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
ConfigPtr = XBram_LookupConfig(phyConfig->txBramId);
|
||||
if (ConfigPtr == NULL)
|
||||
bramConfigPtr = XBram_LookupConfig(phyConfig->txBramId);
|
||||
if (bramConfigPtr == NULL)
|
||||
{
|
||||
Status = EDINVAL;
|
||||
goto error;
|
||||
}
|
||||
Status = XBram_CfgInitialize(&txFrameBram, ConfigPtr,
|
||||
ConfigPtr->CtrlBaseAddress);
|
||||
Status = XBram_CfgInitialize(&txDataBram, bramConfigPtr,
|
||||
bramConfigPtr->CtrlBaseAddress);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
goto error;
|
||||
@@ -354,20 +406,20 @@ int32_t Phy_InstInit(PHY_INST **instPtr, PHY_CONFIG *phyConfig)
|
||||
/*
|
||||
* Execute the BRAM driver selftest.
|
||||
*/
|
||||
Status = XBram_SelfTest(&txFrameBram, 0);
|
||||
Status = XBram_SelfTest(&txDataBram, 0);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
ConfigPtr = XBram_LookupConfig(phyConfig->rxBramId);
|
||||
if (ConfigPtr == NULL)
|
||||
bramConfigPtr = XBram_LookupConfig(phyConfig->rxBramId);
|
||||
if (bramConfigPtr == NULL)
|
||||
{
|
||||
Status = EDINVAL;
|
||||
goto error;
|
||||
}
|
||||
Status = XBram_CfgInitialize(&rxFrameBram, ConfigPtr,
|
||||
ConfigPtr->CtrlBaseAddress);
|
||||
Status = XBram_CfgInitialize(&rxDataBram, bramConfigPtr,
|
||||
bramConfigPtr->CtrlBaseAddress);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
goto error;
|
||||
@@ -375,29 +427,29 @@ int32_t Phy_InstInit(PHY_INST **instPtr, PHY_CONFIG *phyConfig)
|
||||
/*
|
||||
* Execute the BRAM driver selftest.
|
||||
*/
|
||||
Status = XBram_SelfTest(&rxFrameBram, 0);
|
||||
Status = XBram_SelfTest(&rxDataBram, 0);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
(*instPtr)->antConfigAddr = antInfoBram.Config.MemBaseAddress;
|
||||
(*instPtr)->recvDataAddr = rxFrameBram.Config.MemBaseAddress;
|
||||
(*instPtr)->sendDataAddr = txFrameBram.Config.MemBaseAddress;
|
||||
(*instPtr)->antConfigAddr = antConfigBram.Config.MemBaseAddress;
|
||||
(*instPtr)->recvDataAddr = rxDataBram.Config.MemBaseAddress;
|
||||
(*instPtr)->sendDataAddr = txDataBram.Config.MemBaseAddress;
|
||||
#else
|
||||
(*instPtr)->antConfigAddr = (uintptr_t)calloc(ANTCONFIG_MAX_LEN / sizeof(uint64_t), sizeof(uint64_t));
|
||||
(*instPtr)->antConfigAddr = (uintptr_t)calloc(L1_ANTCONFIG_MAX_LEN / sizeof(uint64_t), sizeof(uint64_t));
|
||||
if ((*instPtr)->antConfigAddr == (uintptr_t)NULL)
|
||||
{
|
||||
Status = EALLOC;
|
||||
goto error;
|
||||
}
|
||||
(*instPtr)->recvDataAddr = (uintptr_t)calloc(TXRXDATA_MAX_LEN / sizeof(uint64_t), sizeof(uint64_t));
|
||||
(*instPtr)->recvDataAddr = (uintptr_t)calloc(L1_TXRXDATA_MAX_LEN / sizeof(uint64_t), sizeof(uint64_t));
|
||||
if ((*instPtr)->recvDataAddr == (uintptr_t)NULL)
|
||||
{
|
||||
Status = EALLOC;
|
||||
goto error;
|
||||
}
|
||||
(*instPtr)->sendDataAddr = (uintptr_t)calloc(TXRXDATA_MAX_LEN / sizeof(uint64_t), sizeof(uint64_t));
|
||||
(*instPtr)->sendDataAddr = (uintptr_t)calloc(L1_TXRXDATA_MAX_LEN / sizeof(uint64_t), sizeof(uint64_t));
|
||||
if ((*instPtr)->sendDataAddr == (uintptr_t)NULL)
|
||||
{
|
||||
Status = EALLOC;
|
||||
@@ -448,7 +500,7 @@ void Phy_Start(PHY_INST *instPtr)
|
||||
uint32_t phyMainCtrl = PhyRead(instPtr, PHY_MAIN_CTRL);
|
||||
if ((phyMainCtrl & PHY_MAIN_CTRL_EN_MASK) == PHY_MAIN_CTRL_EN_EN)
|
||||
{
|
||||
DBG_WARNING("Physical layer was allready enabled.\n");
|
||||
DBG_WARNING("Physical layer was already enabled.\n");
|
||||
}
|
||||
instPtr->isPhyEn = true;
|
||||
// Enable CRC check automatically
|
||||
@@ -532,14 +584,11 @@ int32_t Phy_SetupNextSlot(PHY_INST *instPtr, PHY_TOR_TYPE txrxMode,
|
||||
ASSERT(instPtr != NULL);
|
||||
int32_t Status;
|
||||
uint32_t phyModeCtrl, hopNum;
|
||||
uint16_t *hopPattern = NULL;
|
||||
uint16_t *hopPattern;
|
||||
// Implement a ping-pong flow, offset always is 0 or half of buffer depth.
|
||||
instPtr->antConfigOffset = (ANTCONFIG_MAX_LEN >> 1) - instPtr->antConfigOffset;
|
||||
instPtr->antConfigOffset = (L1_ANTCONFIG_MAX_LEN >> 1) - instPtr->antConfigOffset;
|
||||
uint32_t antConfigAddr = instPtr->antConfigAddr + instPtr->antConfigOffset;
|
||||
|
||||
instPtr->TOR.next = txrxMode;
|
||||
instPtr->frameType.next = frameType;
|
||||
|
||||
switch (txrxMode)
|
||||
{
|
||||
case PHY_TOR_SUSPEND:
|
||||
@@ -554,6 +603,7 @@ int32_t Phy_SetupNextSlot(PHY_INST *instPtr, PHY_TOR_TYPE txrxMode,
|
||||
default:
|
||||
return EPARAM;
|
||||
}
|
||||
|
||||
switch (frameType)
|
||||
{
|
||||
case L1_2KBPS_20MS_FRAME:
|
||||
@@ -600,28 +650,30 @@ int32_t Phy_SetupNextSlot(PHY_INST *instPtr, PHY_TOR_TYPE txrxMode,
|
||||
return EPARAM;
|
||||
break;
|
||||
}
|
||||
hopPattern = (instPtr->isPresetHop) ? hopPattern : hopPattern_Config;
|
||||
if (instPtr->isPresetHop == false)
|
||||
{
|
||||
hopPattern = hopPattern_Config;
|
||||
}
|
||||
|
||||
uint8_t *dataSrcPtr = (uint8_t *)(&(instPtr->antCoinfoPtr));
|
||||
PhyWrite(instPtr, PHY_MODE_CTRL, phyModeCtrl | PHY_MODE_CTRL_CRC_EN);
|
||||
|
||||
uint8_t *dataSrcPtr = (uint8_t *)(&(instPtr->antConfig));
|
||||
for (int32_t i = 0; i < hopNum; i++)
|
||||
{
|
||||
instPtr->antCoinfoPtr.antFreq[1] = (uint8_t)(hopPattern[i] & 0x00FF);
|
||||
instPtr->antCoinfoPtr.antFreq[0] = (uint8_t)((hopPattern[i] >> 8) & 0x00FF);
|
||||
instPtr->antConfig.antFreq[1] = (uint8_t)hopPattern[i];
|
||||
instPtr->antConfig.antFreq[0] = (uint8_t)(hopPattern[i] >> 8);
|
||||
instPtr->antConfig.rfFreq[1] = (uint8_t)hopPattern[i];
|
||||
instPtr->antConfig.rfFreq[0] = (uint8_t)(hopPattern[i] >> 8);
|
||||
memcpy((uint8_t *)(antConfigAddr + i * sizeof(PHY_ANT_CONFIG)),
|
||||
dataSrcPtr, sizeof(PHY_ANT_CONFIG));
|
||||
dataSrcPtr, ANT_CONFIG_LEN);
|
||||
}
|
||||
uint32_t antCtrl = (instPtr->antConfigOffset & ANT_CONFIG_OFFSET_MASK) | ((hopNum << ANT_CONFIG_NUM_SHIFT) & ANT_CONFIG_NUM_MASK) | ((sizeof(PHY_ANT_CONFIG) << ANT_CONFIG_LEN_SHIFT) & ANT_CONFIG_LEN_MASK);
|
||||
uint32_t antCtrl = (instPtr->antConfigOffset & ANT_CONFIG_OFFSET_MASK)
|
||||
| ((hopNum << ANT_CONFIG_NUM_SHIFT) & ANT_CONFIG_NUM_MASK)
|
||||
| ((ANT_CONFIG_LEN << ANT_CONFIG_LEN_SHIFT) & ANT_CONFIG_LEN_MASK);
|
||||
|
||||
|
||||
/*
|
||||
memcpy((uint8_t*)antConfigDataAddr, hopPattern, hopNum*sizeof(uint16_t));
|
||||
uint32_t antCtrl = (instPtr->antCoinfigOffset & ANT_CONFIG_OFFSET_MASK)
|
||||
| ((hopNum << ANT_CONFIG_NUM_SHIFT) & ANT_CONFIG_NUM_MASK)
|
||||
| ((sizeof(uint16_t) << ANT_CONFIG_LEN_SHIFT) & ANT_CONFIG_LEN_MASK);
|
||||
*/
|
||||
PhyWrite(instPtr, PHY_MODE_CTRL, phyModeCtrl | PHY_MODE_CTRL_CRC_EN);
|
||||
PhyWrite(instPtr, ANT_CONFIG, antCtrl);
|
||||
|
||||
// Trigger physical configuration.
|
||||
if (txrxMode == PHY_TOR_TX)
|
||||
{
|
||||
Status = Phy_SetSendData(instPtr, frameType, dataBuff);
|
||||
@@ -631,59 +683,20 @@ int32_t Phy_SetupNextSlot(PHY_INST *instPtr, PHY_TOR_TYPE txrxMode,
|
||||
return Status;
|
||||
}
|
||||
}
|
||||
PhyWrite(instPtr, SLOT_CMD, SLOT_CMD_KEY); // Phy statr fetching data.
|
||||
|
||||
Phy_RcdShift(&(instPtr->TOR), txrxMode);
|
||||
// Trigger physical configuration.
|
||||
// Indicate physical layer that all the configurations were done.
|
||||
PhyWrite(instPtr, SLOT_CMD, SLOT_CMD_KEY);
|
||||
|
||||
Phy_RcdShift(&(instPtr->tor), txrxMode);
|
||||
Phy_RcdShift(&(instPtr->frameType), frameType);
|
||||
// TODO:
|
||||
Phy_RcdShift(&(instPtr->antNo), INIT_ANT_NO);
|
||||
Phy_RcdShift(&(instPtr->beamNo), INIT_BEAM_NO);
|
||||
Phy_RcdShift(&(instPtr->beamWd), INIT_ANT_WD);
|
||||
Phy_RcdShift(&(instPtr->antNo), L1_INIT_ANT_NO);
|
||||
Phy_RcdShift(&(instPtr->beamNo), L1_INIT_BEAM_NO);
|
||||
Phy_RcdShift(&(instPtr->beamWd), L1_INIT_ANT_WD);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Get coarse frequency estimation of last valid frame.
|
||||
*
|
||||
* @param instPtr a pointer to physical instance
|
||||
*
|
||||
* @return frequency estimation
|
||||
*
|
||||
******************************************************************************/
|
||||
double Phy_GetCoarseFreqEst(PHY_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
uint32_t regValue;
|
||||
uint8_t acqFreqIdx;
|
||||
int8_t syncFreqIdx;
|
||||
L1_FRAME_TYPE frameType;
|
||||
double freqEst;
|
||||
|
||||
frameType = Phy_GetLastRecvFrameType(instPtr);
|
||||
if (frameType > L1_1M2BPS_5MS_FRAME || frameType == L1_NONE_FRAME)
|
||||
{
|
||||
return INFINITY; // FIXME
|
||||
}
|
||||
regValue = PhyRead(instPtr, COASE_FREQEST);
|
||||
acqFreqIdx = (regValue & COASE_FREQEST_ACQ_MASK) >> COASE_FREQEST_ACQ_SHIFT;
|
||||
syncFreqIdx = (regValue & COASE_FREQEST_SYNC_MASK) >> COASE_FREQEST_SYNC_SHIFT;
|
||||
if (frameType >= L1_200KBPS_5MS_FRAME)
|
||||
{
|
||||
// 1.5M Rc
|
||||
freqEst = (double)(80 - acqFreqIdx) * (31.25e3 / 4);
|
||||
freqEst += (double)syncFreqIdx * 1.5e6 / 64 / 128;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 12M Rc
|
||||
freqEst = (double)(8 - acqFreqIdx) * (250e3 / 4);
|
||||
freqEst += (double)syncFreqIdx * 12e6 / 64 / 128;
|
||||
}
|
||||
|
||||
return freqEst;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Get the corresponding frequency hopping pattern length of a
|
||||
@@ -727,8 +740,7 @@ uint32_t Phy_GetHopLength(L1_FRAME_TYPE frameType)
|
||||
*
|
||||
* @param frameType a L1 frame type enumeration.
|
||||
*
|
||||
* @return SUCCESS
|
||||
* FAILURE frame type cannot be recognized
|
||||
* @return 32bit unsigned integer (10ns)
|
||||
*
|
||||
******************************************************************************/
|
||||
uint32_t Phy_GetTimeComp(L1_FRAME_TYPE frameType)
|
||||
@@ -756,6 +768,138 @@ uint32_t Phy_GetTimeComp(L1_FRAME_TYPE frameType)
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Get frequency estimation of last valid frame.
|
||||
*
|
||||
* @param instPtr a pointer to physical instance
|
||||
*
|
||||
* @return frequency estimation
|
||||
*
|
||||
******************************************************************************/
|
||||
double Phy_GetFreqEst(PHY_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
uint32_t coarseReg, fineReg, estAbs;
|
||||
uint8_t acqFreqIdx;
|
||||
int8_t syncFreqIdx;
|
||||
L1_FRAME_TYPE frameType;
|
||||
double coarse, fine;
|
||||
|
||||
|
||||
frameType = Phy_GetLastRecvFrameType(instPtr);
|
||||
if (frameType > L1_1M2BPS_5MS_FRAME || frameType <= L1_NONE_FRAME)
|
||||
{
|
||||
return INFINITY; // FIXME
|
||||
}
|
||||
|
||||
coarseReg = PhyRead(instPtr, COASE_FREQEST);
|
||||
acqFreqIdx = (coarseReg & COASE_FREQEST_ACQ_MASK) >> COASE_FREQEST_ACQ_SHIFT;
|
||||
syncFreqIdx = (coarseReg & COASE_FREQEST_SYNC_MASK) >> COASE_FREQEST_SYNC_SHIFT;
|
||||
fineReg = PhyRead(instPtr, FINE_FREQEST);
|
||||
estAbs = fineReg & FINE_FREQEST_VAL_MASK;
|
||||
if (frameType >= L1_200KBPS_5MS_FRAME)
|
||||
{
|
||||
// 1.5M Rc
|
||||
coarse = (double)(80 - acqFreqIdx) * (31.25e3 / 4);
|
||||
coarse += (double)syncFreqIdx * 1.5e6 / 64 / 128;
|
||||
|
||||
fine = 12e6/2048*((double)estAbs)/8192.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 12M Rc
|
||||
coarse = (double)(8 - acqFreqIdx) * (250e3 / 4);
|
||||
coarse += (double)syncFreqIdx * 12e6 / 64 / 128;
|
||||
|
||||
fine = 48e6/2048*((double)estAbs)/8192.0;
|
||||
}
|
||||
|
||||
fine = ((fineReg & FINE_FREQEST_SIGN_MASK) == FINE_FREQEST_SIGN_NEG) ?
|
||||
-fine : fine;
|
||||
|
||||
return (coarse + fine);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Get coarse frequency estimation of last valid frame.
|
||||
*
|
||||
* @param instPtr a pointer to physical instance
|
||||
*
|
||||
* @return frequency estimation
|
||||
*
|
||||
******************************************************************************/
|
||||
double Phy_GetCoarseFreqEst(PHY_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
uint32_t regValue;
|
||||
uint8_t acqFreqIdx;
|
||||
int8_t syncFreqIdx;
|
||||
L1_FRAME_TYPE frameType;
|
||||
double freqEst;
|
||||
|
||||
frameType = Phy_GetLastRecvFrameType(instPtr);
|
||||
if (frameType > L1_1M2BPS_5MS_FRAME || frameType <= L1_NONE_FRAME)
|
||||
{
|
||||
return INFINITY; // FIXME
|
||||
}
|
||||
regValue = PhyRead(instPtr, COASE_FREQEST);
|
||||
acqFreqIdx = (regValue & COASE_FREQEST_ACQ_MASK) >> COASE_FREQEST_ACQ_SHIFT;
|
||||
syncFreqIdx = (regValue & COASE_FREQEST_SYNC_MASK) >> COASE_FREQEST_SYNC_SHIFT;
|
||||
if (frameType >= L1_200KBPS_5MS_FRAME)
|
||||
{
|
||||
// 1.5M Rc
|
||||
freqEst = (double)(80 - acqFreqIdx) * (31.25e3 / 4);
|
||||
freqEst += (double)syncFreqIdx * 1.5e6 / 64 / 128;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 12M Rc
|
||||
freqEst = (double)(8 - acqFreqIdx) * (250e3 / 4);
|
||||
freqEst += (double)syncFreqIdx * 12e6 / 64 / 128;
|
||||
}
|
||||
|
||||
return freqEst;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Get fine frequency estimation of last valid frame.
|
||||
*
|
||||
* @param instPtr a pointer to physical instance
|
||||
*
|
||||
* @return frequency estimation
|
||||
*
|
||||
******************************************************************************/
|
||||
double Phy_GetFineFreqEst(PHY_INST *instPtr)
|
||||
{
|
||||
uint32_t regValue, estAbs;
|
||||
double freqEst;
|
||||
L1_FRAME_TYPE frameType;
|
||||
frameType = Phy_GetLastRecvFrameType(instPtr);
|
||||
if (frameType > L1_1M2BPS_5MS_FRAME || frameType <= L1_NONE_FRAME)
|
||||
{
|
||||
return INFINITY; // FIXME
|
||||
}
|
||||
|
||||
regValue = PhyRead(instPtr, FINE_FREQEST);
|
||||
estAbs = regValue & FINE_FREQEST_VAL_MASK;
|
||||
if (frameType >= L1_200KBPS_5MS_FRAME)
|
||||
{
|
||||
// 1.5M Rc
|
||||
freqEst = 12e6/2048*((double)estAbs)/8192.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 12M Rc
|
||||
freqEst = 48e6/2048*((double)estAbs)/8192.0;
|
||||
}
|
||||
freqEst = ((regValue & FINE_FREQEST_SIGN_MASK) == FINE_FREQEST_SIGN_NEG) ?
|
||||
-freqEst : freqEst;
|
||||
return freqEst;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Setup a frequency hopping pattern.
|
||||
@@ -782,8 +926,9 @@ int32_t Phy_SetHopPattern(void *patternBuff, uint32_t patternLen)
|
||||
/**
|
||||
* @brief Setup a specific timer word register in physical controller.
|
||||
*
|
||||
* @param patternBuff a pointer to hopping pattern buffer
|
||||
* @param patternLen a integer indicate the length of hopping pattern.
|
||||
* @param instPtr
|
||||
* @param tmWord
|
||||
* @param tmType
|
||||
*
|
||||
* @return SUCCESS
|
||||
* FAILURE pattern length exceeds maximum length.
|
||||
@@ -792,7 +937,7 @@ int32_t Phy_SetHopPattern(void *patternBuff, uint32_t patternLen)
|
||||
int32_t Phy_SetTimeWord(PHY_INST *instPtr, const TIME_WORD *tmWord, PHY_TIME_WORD_TYPE tmType)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
if (tmWord->frac_part >= PHY_TIME_WORD_L_MAX)
|
||||
if (tmWord->frac_part >= TIME_FRAC_MAX)
|
||||
{
|
||||
return EPARAM;
|
||||
}
|
||||
|
||||
@@ -27,16 +27,24 @@
|
||||
#include "phy_reg.h"
|
||||
#include "../common.h"
|
||||
#include "../time_ctrl/time_ctrl.h"
|
||||
/************************** Constant Definitions *****************************/
|
||||
#define TMWORD_FRAC_MAX 500000
|
||||
#define ANTCONFIG_MAX_LEN 8192
|
||||
#define TXRXDATA_MAX_LEN 2048
|
||||
#define NUM_ANT_SUBNRRW_PATTERN 37
|
||||
#define NUM_ANT_NRRW_PATTERN 61
|
||||
#define INIT_BEAM_NO 0
|
||||
#define INIT_ANT_WD PHY_ANT_BEAM_120
|
||||
#define INIT_ANT_NO 0
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
/************************** Constant Definitions *****************************/
|
||||
/**
|
||||
* @name PhysicalLayer_Common_Constant
|
||||
* @{
|
||||
*/
|
||||
#define L1_NUM_ANT_SUBNRRW_PATTERN 37
|
||||
#define L1_NUM_ANT_NRRW_PATTERN 61
|
||||
#define L1_INIT_BEAM_NO 0
|
||||
#define L1_INIT_ANT_WD PHY_ANT_BEAM_120
|
||||
#define L1_INIT_ANT_NO 0
|
||||
|
||||
#define L1_ANT_NUM_CH 4
|
||||
#define L1_TXRXDATA_MAX_LEN 2048
|
||||
|
||||
#define L1_FRAME_NONE_LEN UINT32_MAX // byte
|
||||
#define L1_FRAME_NONE_COMP UINT32_MAX // *10ns(Timer_L)
|
||||
#define L1_FRAME_NONE_HOPS UINT32_MAX
|
||||
#define L1_FRAME_MAX_HOPS 81
|
||||
#define L1_FRAME_2KBPS_20MS_HOPS 1
|
||||
@@ -47,34 +55,12 @@
|
||||
#define L1_FRAME_40KBPS_10MS_HOPS 9
|
||||
#define L1_FRAME_200KBPS_5MS_HOPS 20
|
||||
#define L1_FRAME_1M2BPS_5MS_HOPS 20
|
||||
|
||||
#define L1_FRAME_NONE_LEN UINT32_MAX // byte
|
||||
#define L1_FRAME_LEN_MAX (8192 / 8) // byte
|
||||
#define L1_FRAME_2KBPS_20MS_LEN 1 // byte
|
||||
#define L1_FRAME_2KBPS_100MS_LEN 312 / 8 // byte
|
||||
#define L1_FRAME_10KBPS_10MS_LEN 1 // byte
|
||||
#define L1_FRAME_10KBPS_20MS_LEN (232 / 8) // byte
|
||||
#define L1_FRAME_40KBPS_20MS_LEN (2152 / 8) // byte
|
||||
#define L1_FRAME_40KBPS_10MS_LEN (712 / 8) // byte
|
||||
#define L1_FRAME_200KBPS_5MS_LEN (2040 / 8) // byte
|
||||
#define L1_FRAME_1M2BPS_5MS_LEN (8176 / 8) // byte
|
||||
|
||||
#define L1_FRAME_NONE_COMP UINT32_MAX // *10ns(Timer_L)
|
||||
#define L1_FRAME_2KBPS_20MS_COMP 1841158 // *10ns(Timer_L)
|
||||
#define L1_FRAME_2KBPS_100MS_COMP 1841158 // *10ns(Timer_L)
|
||||
#define L1_FRAME_10KBPS_10MS_COMP 850950 // *10ns(Timer_L)
|
||||
#define L1_FRAME_10KBPS_20MS_COMP 850950 // *10ns(Timer_L)
|
||||
#define L1_FRAME_40KBPS_20MS_COMP 110667 // *10ns(Timer_L)
|
||||
#define L1_FRAME_40KBPS_10MS_COMP 110667 // *10ns(Timer_L)
|
||||
#define L1_FRAME_200KBPS_5MS_COMP 22493 // *10ns(Timer_L)
|
||||
#define L1_FRAME_1M2BPS_5MS_COMP 22493 // *10ns(Timer_L)
|
||||
|
||||
#define PHY_TIME_WORD_H_MAX UINT32_MAX
|
||||
#define PHY_TIME_WORD_L_MAX 0x0007A120 // 5ms/10ns
|
||||
|
||||
/** @} */
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
/**
|
||||
* @enum L1_FRAME_TYPE
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
L1_NONE_FRAME = 0,
|
||||
@@ -88,75 +74,67 @@ typedef enum
|
||||
L1_1M2BPS_5MS_FRAME = 8
|
||||
} L1_FRAME_TYPE;
|
||||
|
||||
/**
|
||||
* @struct PHY_ANT_CONFIG
|
||||
* @brief PhysicalLayer antenna config
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/* Antenna control frame head 0xAA */
|
||||
uint8_t head;
|
||||
/* default 0, reserved for further use */
|
||||
uint8_t ctrlWord;
|
||||
/* high 4 bits specified beam mode.
|
||||
* low 4 bits specified power control */
|
||||
uint8_t antMode;
|
||||
/* off-axis angle range is 0~60,
|
||||
* 0.1 degree each LSB */
|
||||
uint8_t oaxis[2];
|
||||
/* round-axis angle range is 0~360,
|
||||
* 0.1 degree each LSB */
|
||||
uint8_t raxis[2];
|
||||
/* 0~3500Mhz, step 1MHz */
|
||||
uint8_t antFreq[2];
|
||||
/* in single tr mode, 0~63 specified tr channel
|
||||
* in single subarray mode, 0~3 specified the subarray
|
||||
* Only in debug mode*/
|
||||
uint8_t trSlect;
|
||||
/* Antenna attenuation 0~31, 0.5dB each LSB, Only in debug mode */
|
||||
uint8_t antAtt;
|
||||
/* 0~63, 5.625 degree each LSB, Only in debug mode*/
|
||||
uint8_t phase;
|
||||
/* 0x00 Nromal RX, 0x01 Normal TX
|
||||
* 0x11~0xA1 beam debug mode (TR duty 1%~10%)*/
|
||||
uint8_t rxtxMode;
|
||||
/* 0x00 Normal, 0x01 single tr calibration */
|
||||
uint8_t calibrMode;
|
||||
/* reserved for further use */
|
||||
uint8_t reserved;
|
||||
/* DD enable */
|
||||
uint8_t ddEn;
|
||||
/* DD mgc */
|
||||
uint8_t ddMgc;
|
||||
/* [7:4]RF enable: 0-On, 1-Off(Default); [3:0]Work mode: 0(default) */
|
||||
uint8_t rfCtrl;
|
||||
/* RF MGC control: 0~31, 1dB each LSB*/
|
||||
uint8_t rfMgc;
|
||||
/* RF channel 1&2 calibration mgc: [7:4] Channle1 - max 15db, 1dB each LSB
|
||||
* [3:0] Channle2 - max 15db, 1dB each LSB*/
|
||||
uint8_t rf12CalMgc;
|
||||
/* RF channel 3&4 calibration mgc: [7:4] Channle3 - max 15db, 1dB each LSB
|
||||
* [3:0] Channle4 - max 15db, 1dB each LSB*/
|
||||
uint8_t rf34CalMgc;
|
||||
/* Receive channel 1 MGC: 0~31, 1dB each LSB */
|
||||
uint8_t rcv1Mgc;
|
||||
/* Receive channel 2 MGC: 0~31, 1dB each LSB */
|
||||
uint8_t rcv2Mgc;
|
||||
/* Receive channel 3 MGC: 0~31, 1dB each LSB */
|
||||
uint8_t rcv3Mgc;
|
||||
/* Receive channel 4 MGC: 0~31, 1dB each LSB */
|
||||
uint8_t rcv4Mgc;
|
||||
/* Antenna control frame tail 0xCC */
|
||||
uint8_t tail;
|
||||
uint8_t dummy[6];
|
||||
/*** Ant Control ***/
|
||||
uint8_t ctrlWord; ///< Antenna control frame head 0xAA\n
|
||||
/// default 0, reserved for further use
|
||||
uint8_t antMode; ///< high 4 bits specified beam mode.\n
|
||||
/// low 4 bits specified power control
|
||||
uint8_t oaxis[2]; ///< off-axis angle range is 0~60 \n
|
||||
/// 0.1 degree each LSB
|
||||
uint8_t raxis[2]; ///< round-axis angle range is 0~360, \n
|
||||
/// 0.1 degree each LSB
|
||||
uint8_t antFreq[2]; ///< 0~3500Mhz, step 1MHz
|
||||
uint8_t trSelect; ///< in single tr mode, 0~63 specified tr channel \n
|
||||
/// in single subarray mode, 0~3 specified the subarray
|
||||
/// ! Only in debug mode!
|
||||
uint8_t antAtt; ///< Antenna attenuation 0~31, 0.5dB each LSB, Only in debug mode
|
||||
uint8_t phase; ///< 0~63, 5.625 degree each LSB, Only in debug mode
|
||||
uint8_t torMode; ///< Only for debug \n
|
||||
/// default 0x00
|
||||
uint8_t caliMode; ///< 0x00 Normal, 0x01 single tr calibration
|
||||
uint8_t antReserved; ///< reserved for further use
|
||||
|
||||
/*** RF Control ***/
|
||||
uint8_t rfCtrl; ///< [7:4]RF enable: 0-On, 1-Off(Default); [3:0]Work mode: 0(default)
|
||||
uint8_t rfFreq[2]; ///< 0~3500Mhz, step 1MHz
|
||||
uint8_t rfTxMgc; ///< RF MGC control: 0~31, 1dB each LSB
|
||||
uint8_t rf12CalMgc; ///< RF channel 1&2 calibration mgc\n
|
||||
/// [7:4] Channle1 - max 15db, 1dB each LSB \n
|
||||
/// [3:0] Channle2 - max 15db, 1dB each LSB
|
||||
uint8_t rf34CalMgc; ///< RF channel 3&4 calibration mgc\n
|
||||
/// [7:4] Channle3 - max 15db, 1dB each LSB
|
||||
/// [3:0] Channle4 - max 15db, 1dB each LSB
|
||||
uint8_t rfRxMgc; ///< Receive channel 1-4 MGC: 0~31, 1dB each LSB
|
||||
uint8_t rfMonitor; ///< Receive monitor, 0-normal, 1-switch to monitor port
|
||||
uint8_t rfReserved0; ///< reserved for further use
|
||||
uint8_t rfReserved1; ///< reserved for further use
|
||||
uint8_t ch0Cal[2];
|
||||
uint8_t ch1Cal[2];
|
||||
uint8_t ch2Cal[2];
|
||||
uint8_t ch3Cal[2];
|
||||
} PHY_ANT_CONFIG;
|
||||
|
||||
/**
|
||||
* @struct PHY_ANT_ANGLE
|
||||
* @brief Describe the PhysicalLayer antenna angle
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/* off-axis angle range is 0~60,
|
||||
* 0.1 degree each LSB */
|
||||
uint16_t oaxis;
|
||||
/* round-axis angle range is 0~360,
|
||||
* 0.1 degree each LSB */
|
||||
uint16_t raxis;
|
||||
uint16_t oaxis; ///< off-axis angle range is 0~60
|
||||
/// 0.1 degree each LSB
|
||||
uint16_t raxis; ///< round-axis angle range is 0~360
|
||||
/// 0.1 degree each LSB
|
||||
} PHY_ANT_ANGLE;
|
||||
|
||||
/**
|
||||
* @enum PHY_TIME_WORD_TYPE
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
PHY_TIME_WORD_NONE = 0,
|
||||
@@ -164,15 +142,21 @@ typedef enum
|
||||
PHY_TIME_WORD_LISTEN_TIMEOUT = 2
|
||||
} PHY_TIME_WORD_TYPE;
|
||||
|
||||
/**
|
||||
* @enum PHY_ANT_BEAM_WIDTH
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
PHY_ANT_BEAM_NONE = 0,
|
||||
PHY_ANT_BEAM_120 = 1,
|
||||
PHY_ANT_BEAM_60 = 2,
|
||||
PHY_ANT_BEAM_25 = 3,
|
||||
PHY_ANT_BEAM_8 = 4
|
||||
PHY_ANT_BEAM_16 = 4
|
||||
} PHY_ANT_BEAM_WIDTH;
|
||||
|
||||
/**
|
||||
* @enum PHY_TOR_TYPE
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
PHY_TOR_SUSPEND = 0,
|
||||
@@ -180,6 +164,9 @@ typedef enum
|
||||
PHY_TOR_RX = 2
|
||||
} PHY_TOR_TYPE;
|
||||
|
||||
/**
|
||||
* @enum PHY_MODE
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
PHY_MODE_NONE = 0,
|
||||
@@ -188,6 +175,32 @@ typedef enum
|
||||
PHY_MODE_PULL = 3
|
||||
} PHY_MODE;
|
||||
|
||||
/**
|
||||
* @enum PHY_ANT_MODE
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
PHY_ANT_MODE_NONE = 0,
|
||||
PHY_ANT_MODE_STANDBY = 1,
|
||||
PHY_ANT_MODE_POWER_LOW = 2,
|
||||
PHY_ANT_MODE_POWER_FULL = 3,
|
||||
} PHY_ANT_MODE;
|
||||
|
||||
/**
|
||||
* @struct PHY_RCD
|
||||
* @brief Physical Layer recode buffer
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int32_t last;
|
||||
int32_t curr;
|
||||
int32_t next;
|
||||
} PHY_RCD;
|
||||
|
||||
/**
|
||||
* @struct PHY_CONFIG
|
||||
* @brief struct holds all physical layer initialization parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t devId;
|
||||
@@ -197,87 +210,70 @@ typedef struct
|
||||
uintptr_t baseAddr;
|
||||
} PHY_CONFIG;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int32_t last;
|
||||
int32_t curr;
|
||||
int32_t next;
|
||||
} PHY_RCD;
|
||||
|
||||
/**
|
||||
* @struct PHY_INST
|
||||
* @brief Physical Layer operating instance
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
PHY_CONFIG phyCofig; // Device address configs
|
||||
uintptr_t recvDataAddr;
|
||||
uintptr_t sendDataAddr;
|
||||
uintptr_t antConfigAddr;
|
||||
bool isPhyEn; // if physical layer running
|
||||
bool isAcq; // if last reception acquisition success
|
||||
bool isFrameSync; // if last reception frame sync success
|
||||
bool isDecode; // if last reception decode success
|
||||
bool isValid; // if last reception frame data valid (crc check pass)
|
||||
bool isPresetHop; // if using preset frequency hop
|
||||
TIME_WORD recvSlotTime; // last slot start time stamp
|
||||
TIME_WORD recvFsTime; // last frame sync time stamp
|
||||
PHY_RCD antNo; // antenna number record
|
||||
PHY_RCD beamNo; // beam number record
|
||||
PHY_RCD beamWd; // beam width record
|
||||
PHY_RCD TOR; // tx rx state record
|
||||
PHY_RCD frameType; // frame type record
|
||||
uint32_t sendDataOffset; // antenna configuration bram offset (to implement ping-pong data flow)
|
||||
uint32_t antConfigOffset; // antenna configuration bram offset (to implement ping-pong data flow)
|
||||
PHY_ANT_CONFIG antCoinfoPtr; // antenna configuration pointer
|
||||
bool isPhyEn; // if physical layer running
|
||||
bool isAcq; // if last reception acquisition success
|
||||
bool isFrameSync; // if last reception frame sync success
|
||||
bool isDecode; // if last reception decode success
|
||||
bool isValid; // if last reception frame data valid (crc check pass)
|
||||
bool isPresetHop; // if using preset frequency hop
|
||||
TIME_WORD recvSlotTime; // last slot start time stamp
|
||||
TIME_WORD recvFsTime; // last frame sync time stamp
|
||||
PHY_RCD antNo; // antenna number record
|
||||
PHY_RCD beamNo; // beam number record
|
||||
PHY_RCD beamWd; // beam width record
|
||||
PHY_RCD tor; // tx rx state record
|
||||
PHY_RCD frameType; // frame type record
|
||||
uint32_t sendDataOffset; // antenna configuration bram offset (to implement ping-pong data flow)
|
||||
uint32_t antConfigOffset; // antenna configuration bram offset (to implement ping-pong data flow)
|
||||
PHY_ANT_CONFIG antConfig; // antenna configuration pointer
|
||||
} PHY_INST;
|
||||
|
||||
/************************** Variable Definitions *****************************/
|
||||
extern uint16_t hopPattern_Config[L1_FRAME_MAX_HOPS];
|
||||
extern uint16_t hopPattern_2KBPS_20MS[L1_FRAME_2KBPS_20MS_HOPS];
|
||||
extern uint16_t hopPattern_2KBPS_100MS[L1_FRAME_2KBPS_100MS_HOPS];
|
||||
extern uint16_t hopPattern_10KBPS_10MS[L1_FRAME_10KBPS_10MS_HOPS];
|
||||
extern uint16_t hopPattern_10KBPS_20MS[L1_FRAME_10KBPS_20MS_HOPS];
|
||||
extern uint16_t hopPattern_40KBPS_10MS[L1_FRAME_40KBPS_10MS_HOPS];
|
||||
extern uint16_t hopPattern_40KBPS_20MS[L1_FRAME_40KBPS_20MS_HOPS];
|
||||
|
||||
extern uint16_t hopPattern_200KBPS_5MS[L1_FRAME_200KBPS_5MS_HOPS];
|
||||
extern uint16_t hopPattern_1M2BPS_5MS[L1_FRAME_1M2BPS_5MS_HOPS];
|
||||
|
||||
extern PHY_ANT_ANGLE antSubnrrwPattern[NUM_ANT_SUBNRRW_PATTERN];
|
||||
extern PHY_ANT_ANGLE antNrrwPattern[NUM_ANT_NRRW_PATTERN];
|
||||
|
||||
/************************** Function Prototypes ******************************/
|
||||
int32_t Phy_InstInit(PHY_INST **instPtr, PHY_CONFIG *phyConfig);
|
||||
void Phy_Destroy(PHY_INST *instPtr);
|
||||
|
||||
void Phy_UpdateState(PHY_INST *instPtr);
|
||||
|
||||
void Phy_Start(PHY_INST *instPtr);
|
||||
void Phy_Halt(PHY_INST *instPtr);
|
||||
int32_t Phy_SetMode(PHY_INST *instPtr, PHY_MODE modeCod);
|
||||
|
||||
int32_t Phy_SetMode(PHY_INST *instPtr, PHY_MODE modeCod);
|
||||
int32_t Phy_SetTimeWord(PHY_INST *instPtr, const TIME_WORD *tmWord, PHY_TIME_WORD_TYPE tmType);
|
||||
int32_t Phy_SetupNextSlot(PHY_INST *instPtr, PHY_TOR_TYPE txrxMode, L1_FRAME_TYPE frameType, uint8_t *dataBuff);
|
||||
void Phy_UpdateState(PHY_INST *instPtr);
|
||||
void Phy_PeekRecvData(PHY_INST *instPtr, uint8_t *dataBuff);
|
||||
void Phy_RetrieveRecvData(PHY_INST *instPtr, uint8_t *dataBuff);
|
||||
|
||||
bool Phy_IsFrameDetected(PHY_INST *instPtr);
|
||||
bool Phy_IsFrameReceived(PHY_INST *instPtr);
|
||||
bool Phy_IsFrameValid(PHY_INST *instPtr);
|
||||
uint32_t Phy_GetFrameLen(L1_FRAME_TYPE frameType);
|
||||
|
||||
L1_FRAME_TYPE Phy_GetLastRecvFrameType(PHY_INST *instPtr);
|
||||
L1_FRAME_TYPE Phy_GetLastSendFrameType(PHY_INST *instPtr);
|
||||
|
||||
int32_t Phy_SetHopPattern(void *patternBuff, uint32_t patternLen);
|
||||
uint32_t Phy_GetHopLength(L1_FRAME_TYPE frameType);
|
||||
uint32_t Phy_GetTimeComp(L1_FRAME_TYPE frameType);
|
||||
uint32_t Phy_GetFrameLen(L1_FRAME_TYPE frameType);
|
||||
L1_FRAME_TYPE Phy_GetLastRecvFrameType(PHY_INST *instPtr);
|
||||
L1_FRAME_TYPE Phy_GetLastSendFrameType(PHY_INST *instPtr);
|
||||
|
||||
int32_t Phy_AntCoinfoInit(PHY_ANT_CONFIG *antCoinfoPtr);
|
||||
int32_t Phy_SetBeamWidth(PHY_INST *instPtr, PHY_ANT_BEAM_WIDTH beamWidth);
|
||||
int32_t Phy_SetBeamNo(PHY_INST *instPtr, int32_t beamNo);
|
||||
int32_t Phy_SetBeamAngle(PHY_INST *phyInstPtr, double offAx, double rndAx);
|
||||
int32_t Phy_SetTimeWord(PHY_INST *instPtr, const TIME_WORD *tmWord, PHY_TIME_WORD_TYPE tmType);
|
||||
|
||||
double Phy_GetFreqEst(PHY_INST *instPtr);
|
||||
double Phy_GetCoarseFreqEst(PHY_INST *instPtr);
|
||||
double Phy_GetFineFreqEst(PHY_INST *instPtr);
|
||||
void Phy_GetFrameSyncTimeStamp(PHY_INST *instPtr, TIME_WORD *frameSyncT);
|
||||
void Phy_GetLastReceivedFrameSyncTimeStamp(PHY_INST *instPtr, TIME_WORD *frameSyncT);
|
||||
void Phy_GetSlotStartTimeStamp(PHY_INST *instPtr, TIME_WORD *slotStart);
|
||||
void Phy_GetLastReceivedSlotStartTimeStamp(PHY_INST *instPtr, TIME_WORD *slotStart);
|
||||
|
||||
void Phy_AntConfigInit(PHY_ANT_CONFIG *antConfig);
|
||||
void Phy_AntConfigMode(PHY_INST *instPtr, PHY_ANT_MODE mode);
|
||||
void Phy_AntConfigAttenuation(PHY_INST *instPtr, uint8_t rxAtt, uint8_t txAtt);
|
||||
int32_t Phy_SetBeamWidth(PHY_INST *instPtr, PHY_ANT_BEAM_WIDTH beamWidth);
|
||||
int32_t Phy_SetBeamNo(PHY_INST *instPtr, int32_t beamNo, PHY_ANT_BEAM_WIDTH beamWidth);
|
||||
int32_t Phy_SetBeamAngle(PHY_INST *phyInstPtr, double offAx, double rndAx);
|
||||
|
||||
#endif /* PHY_CTRL_H_ */
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef PHY_CTRLREG_H_
|
||||
#define PHY_CTRLREG_H_
|
||||
#ifndef PHY_REG_H_
|
||||
#define PHY_REG_H_
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
#include "../util/util.h"
|
||||
@@ -139,7 +139,7 @@
|
||||
#define SEND_DATA_CMD_OFFSET_MASK 0xFFFF0000U
|
||||
|
||||
/**
|
||||
* Register: SEND_CONFIG_CMD
|
||||
* Register: SLOT_CONFIG_CMD
|
||||
*/
|
||||
#define SLOT_CMD 0x00000020U
|
||||
#define SLOT_CMD_SHIFT 0
|
||||
@@ -186,10 +186,11 @@
|
||||
#define RECVDATA_STATE_OFFSET_SHIFT 16
|
||||
#define RECVDATA_STATE_OFFSET_WIDTH 16
|
||||
#define RECVDATA_STATE_OFFSET_MASK 0xFFFF0000U
|
||||
|
||||
/**
|
||||
* Register: FSTIME_L
|
||||
*/
|
||||
#define FSTIME_L 0x000002CU
|
||||
#define FSTIME_L 0x0000002CU
|
||||
#define FSTIME_L_SHIFT 0
|
||||
#define FSTIME_L_WIDTH 32
|
||||
#define FSTIME_L_MASK 0xFFFFFFFFU
|
||||
@@ -197,7 +198,7 @@
|
||||
/**
|
||||
* Register: FSTIME_INT1
|
||||
*/
|
||||
#define FSTIME_H 0x0000030U
|
||||
#define FSTIME_H 0x00000030U
|
||||
#define FSTIME_H_SHIFT 0
|
||||
#define FSTIME_H_WIDTH 32
|
||||
#define FSTIME_H_MASK 0xFFFFFFFFU
|
||||
@@ -205,7 +206,7 @@
|
||||
/**
|
||||
* Register: TM_TARGET_L
|
||||
*/
|
||||
#define TM_TARGET_L 0x0000064U
|
||||
#define TM_TARGET_L 0x00000064U
|
||||
#define TM_TARGET_L_SHIFT 0
|
||||
#define TM_TARGET_L_WIDTH 32
|
||||
#define TM_TARGET_L_MASK 0xFFFFFFFFU
|
||||
@@ -213,7 +214,7 @@
|
||||
/**
|
||||
* Register: TM_TARGET_H
|
||||
*/
|
||||
#define TM_TARGET_H 0x0000038U
|
||||
#define TM_TARGET_H 0x00000038U
|
||||
#define TM_TARGET_H_SHIFT 0
|
||||
#define TM_TARGET_H_WIDTH 32
|
||||
#define TM_TARGET_H_MASK 0xFFFFFFFFU
|
||||
@@ -227,15 +228,31 @@
|
||||
#define COASE_FREQEST_ACQ_MASK 0x000000FFU
|
||||
#define COASE_FREQEST_SYNC_SHIFT 8
|
||||
#define COASE_FREQEST_SYNC_WIDTH 8
|
||||
#define COASE_FREQEST_SYNC_MASK 0x000FF00U
|
||||
#define COASE_FREQEST_SYNC_MASK 0x0000FF00U
|
||||
#define COASE_TYPE_SHIFT 16
|
||||
#define COASE_TYPE_WIDTH 8
|
||||
#define COASE_TYPE_MASK 0x00FF0000U
|
||||
#define COASE_TYPE_2KBPS_20MS 0x00010000U
|
||||
#define COASE_TYPE_2KBPS_100MS 0x00020000U
|
||||
#define COASE_TYPE_10KBPS_10MS 0x00030000U
|
||||
#define COASE_TYPE_10KBPS_20MS 0x00040000U
|
||||
#define COASE_TYPE_40KBPS_20MS 0x00050000U
|
||||
#define COASE_TYPE_40KBPS_10MS 0x00060000U
|
||||
#define COASE_TYPE_200KBPS_5MS 0x00070000U
|
||||
#define COASE_TYPE_1M2BPS_5MS 0x00080000U
|
||||
|
||||
/**
|
||||
* Register: FINE_FREQEST
|
||||
*/
|
||||
#define FINE_FREQEST 0x00000040U
|
||||
#define FINE_FREQEST_SHIFT 0
|
||||
#define FINE_FREQEST_WIDTH 32
|
||||
#define FINE_FREQEST_MASK 0xFFFFFFFFU
|
||||
#define FINE_FREQEST_VAL_SHIFT 0
|
||||
#define FINE_FREQEST_VAL_WIDTH 24
|
||||
#define FINE_FREQEST_VAL_MASK 0x00FFFFFFU
|
||||
#define FINE_FREQEST_SIGN_SHIFT 24
|
||||
#define FINE_FREQEST_SIGN_WIDTH 8
|
||||
#define FINE_FREQEST_SIGN_MASK 0xFF000000U
|
||||
#define FINE_FREQEST_SIGN_POS 0x00000000U
|
||||
#define FINE_FREQEST_SIGN_NEG 0x01000000U
|
||||
|
||||
/**
|
||||
* Register: BEAM_SELECT
|
||||
@@ -246,7 +263,7 @@
|
||||
#define BEAM_SELECT_INDEX_MASK 0xFFFFFFFFU
|
||||
|
||||
/**
|
||||
* Register: BEAM_SELECT
|
||||
* Register: BEAM_AXIS
|
||||
*/
|
||||
#define BEAM_AXIS 0x00000044U
|
||||
#define BEAM_AXIS_EL_SHIFT 0
|
||||
@@ -257,4 +274,4 @@
|
||||
#define BEAM_AXIS_AZ_MASK 0xFFFF0000U
|
||||
|
||||
// Reserved.
|
||||
#endif /* PHY_CTRLREG_H_ */
|
||||
#endif /* PHY_REG_H_ */
|
||||
|
||||
@@ -51,12 +51,12 @@
|
||||
* FAILURE Initialization failed
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t TimeCtrl_Init(TIMECTRL_INST **instPtr, TIMECTRL_CONFIG *config)
|
||||
int32_t TimeCtrl_Init(TMC_INST **instPtr, TMC_CONFIG *config)
|
||||
{
|
||||
ASSERT(config != NULL);
|
||||
ASSERT(instPtr != NULL);
|
||||
(*instPtr) = malloc(sizeof(TIMECTRL_INST));
|
||||
memcpy(&((*instPtr)->config), config, sizeof(TIMECTRL_CONFIG));
|
||||
(*instPtr) = malloc(sizeof(TMC_INST));
|
||||
memcpy(&((*instPtr)->config), config, sizeof(TMC_CONFIG));
|
||||
(*instPtr)->modelVer = TMC_Read((*instPtr), VERSION_REG);
|
||||
return SUCCESS;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ int32_t TimeCtrl_Init(TIMECTRL_INST **instPtr, TIMECTRL_CONFIG *config)
|
||||
* @return NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
void TimeCtrl_Destroy(TIMECTRL_INST *instPtr)
|
||||
void TimeCtrl_Destroy(TMC_INST *instPtr)
|
||||
{
|
||||
free(instPtr);
|
||||
}
|
||||
@@ -84,7 +84,7 @@ void TimeCtrl_Destroy(TIMECTRL_INST *instPtr)
|
||||
* @return timer controller version.
|
||||
*
|
||||
******************************************************************************/
|
||||
uint32_t TimeCtrl_GetVersion(TIMECTRL_INST *instPtr)
|
||||
uint32_t TimeCtrl_GetVersion(TMC_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
return TMC_Read(instPtr, VERSION_REG);
|
||||
@@ -100,7 +100,7 @@ uint32_t TimeCtrl_GetVersion(TIMECTRL_INST *instPtr)
|
||||
* FAILURE Initialization failed
|
||||
*
|
||||
******************************************************************************/
|
||||
void TimeCtrl_Reset(TIMECTRL_INST *instPtr)
|
||||
void TimeCtrl_Reset(TMC_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
TMC_Write(instPtr, CNTSTEP_OPT, TM_RESET_CODE);
|
||||
@@ -115,7 +115,7 @@ void TimeCtrl_Reset(TIMECTRL_INST *instPtr)
|
||||
* @return NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
void TimeCtrl_ResetHigh(TIMECTRL_INST *instPtr)
|
||||
void TimeCtrl_ResetHigh(TMC_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
// TODO:
|
||||
@@ -130,7 +130,7 @@ void TimeCtrl_ResetHigh(TIMECTRL_INST *instPtr)
|
||||
* @return NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
void TimeCtrl_ResetLow(TIMECTRL_INST *instPtr)
|
||||
void TimeCtrl_ResetLow(TMC_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
// TODO:
|
||||
@@ -145,7 +145,7 @@ void TimeCtrl_ResetLow(TIMECTRL_INST *instPtr)
|
||||
* @return integer value
|
||||
*
|
||||
******************************************************************************/
|
||||
inline TIME_INT TimeCtrl_GetIntCnt(TIMECTRL_INST *instPtr)
|
||||
inline TIME_INT TimeCtrl_GetIntCnt(TMC_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
return TMC_Read(instPtr, TIME_INT_REG);
|
||||
@@ -160,7 +160,7 @@ inline TIME_INT TimeCtrl_GetIntCnt(TIMECTRL_INST *instPtr)
|
||||
* @return fractional value
|
||||
*
|
||||
******************************************************************************/
|
||||
inline TIME_FRAC TimeCtrl_GetFracCnt(TIMECTRL_INST *instPtr)
|
||||
inline TIME_FRAC TimeCtrl_GetFracCnt(TMC_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
return TMC_Read(instPtr, TIME_FRAC_REG);
|
||||
@@ -176,7 +176,7 @@ inline TIME_FRAC TimeCtrl_GetFracCnt(TIMECTRL_INST *instPtr)
|
||||
* @return NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
void TimeCtrl_GetCurrentTime(TIMECTRL_INST *instPtr, TIME_WORD *tmWord)
|
||||
void TimeCtrl_GetCurrentTime(TMC_INST *instPtr, TIME_WORD *tmWord)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
ASSERT(tmWord != NULL);
|
||||
@@ -194,7 +194,7 @@ void TimeCtrl_GetCurrentTime(TIMECTRL_INST *instPtr, TIME_WORD *tmWord)
|
||||
* @return NONE.
|
||||
*
|
||||
******************************************************************************/
|
||||
void TimeCtrl_GetCurrentStep(TIMECTRL_INST *instPtr, TIME_FRAC *tmFrac)
|
||||
void TimeCtrl_GetCurrentStep(TMC_INST *instPtr, TIME_FRAC *tmFrac)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
ASSERT(tmFrac != NULL);
|
||||
@@ -212,7 +212,7 @@ void TimeCtrl_GetCurrentStep(TIMECTRL_INST *instPtr, TIME_FRAC *tmFrac)
|
||||
* @return NONE.
|
||||
*
|
||||
******************************************************************************/
|
||||
void TimeCtrl_TimeAdjust(TIMECTRL_INST *instPtr, const TIME_WORD *tmWord, TIMECTRL_ADJ_TYPE type)
|
||||
void TimeCtrl_TimeAdjust(TMC_INST *instPtr, const TIME_WORD *tmWord, TIMECTRL_ADJ_TYPE type)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
ASSERT(tmWord != NULL);
|
||||
@@ -243,7 +243,7 @@ void TimeCtrl_TimeAdjust(TIMECTRL_INST *instPtr, const TIME_WORD *tmWord, TIMECT
|
||||
* @return NONE.
|
||||
*
|
||||
******************************************************************************/
|
||||
void TimeCtrl_SetOptimizeStep(TIMECTRL_INST *instPtr, TIME_FRAC *tmFrac)
|
||||
void TimeCtrl_SetOptimizeStep(TMC_INST *instPtr, TIME_FRAC *tmFrac)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
ASSERT(tmFrac != NULL);
|
||||
|
||||
@@ -45,30 +45,30 @@ typedef struct
|
||||
{
|
||||
uintptr_t baseAddr;
|
||||
uint32_t reset; // time for reset (unit: us)
|
||||
} TIMECTRL_CONFIG;
|
||||
} TMC_CONFIG;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
TIMECTRL_CONFIG config;
|
||||
TMC_CONFIG config;
|
||||
uint32_t modelVer;
|
||||
} TIMECTRL_INST;
|
||||
} TMC_INST;
|
||||
|
||||
/************************** Function Prototypes ******************************/
|
||||
int32_t TimeCtrl_Init(TIMECTRL_INST **instPtr, TIMECTRL_CONFIG *config);
|
||||
uint32_t TimeCtrl_GetVersion(TIMECTRL_INST *instPtr);
|
||||
void TimeCtrl_Destroy(TIMECTRL_INST *instPtr);
|
||||
void TimeCtrl_Reset(TIMECTRL_INST *instPtr);
|
||||
void TimeCtrl_ResetLow(TIMECTRL_INST *instPtr);
|
||||
void TimeCtrl_ResetHigh(TIMECTRL_INST *instPtr);
|
||||
int32_t TimeCtrl_Init(TMC_INST **instPtr, TMC_CONFIG *config);
|
||||
uint32_t TimeCtrl_GetVersion(TMC_INST *instPtr);
|
||||
void TimeCtrl_Destroy(TMC_INST *instPtr);
|
||||
void TimeCtrl_Reset(TMC_INST *instPtr);
|
||||
void TimeCtrl_ResetLow(TMC_INST *instPtr);
|
||||
void TimeCtrl_ResetHigh(TMC_INST *instPtr);
|
||||
|
||||
TIME_INT TimeCtrl_GetIntCnt(TIMECTRL_INST *instPtr);
|
||||
TIME_FRAC TimeCtrl_GetFracCnt(TIMECTRL_INST *instPtr);
|
||||
TIME_INT TimeCtrl_GetIntCnt(TMC_INST *instPtr);
|
||||
TIME_FRAC TimeCtrl_GetFracCnt(TMC_INST *instPtr);
|
||||
|
||||
void TimeCtrl_GetCurrentTime(TIMECTRL_INST *instPtr, TIME_WORD *tmWord);
|
||||
void TimeCtrl_GetCurrentStep(TIMECTRL_INST *instPtr, TIME_FRAC *tmFrac);
|
||||
void TimeCtrl_GetCurrentTime(TMC_INST *instPtr, TIME_WORD *tmWord);
|
||||
void TimeCtrl_GetCurrentStep(TMC_INST *instPtr, TIME_FRAC *tmFrac);
|
||||
|
||||
void TimeCtrl_SetOptimizeStep(TIMECTRL_INST *instPtr, TIME_FRAC *tmFrac);
|
||||
void TimeCtrl_TimeAdjust(TIMECTRL_INST *instPtr, const TIME_WORD *tmWord, TIMECTRL_ADJ_TYPE type);
|
||||
void TimeCtrl_SetOptimizeStep(TMC_INST *instPtr, TIME_FRAC *tmFrac);
|
||||
void TimeCtrl_TimeAdjust(TMC_INST *instPtr, const TIME_WORD *tmWord, TIMECTRL_ADJ_TYPE type);
|
||||
void TimeCtrl_CalculateTimeGap(const TIME_WORD *a, const TIME_WORD *b, TIME_WORD *gap);
|
||||
|
||||
#endif /* TIME_SYNC_H_ */
|
||||
|
||||
@@ -13,17 +13,17 @@
|
||||
//
|
||||
|
||||
#include <stdint.h>
|
||||
#include "list.h"
|
||||
#include "clist.h"
|
||||
|
||||
/*
|
||||
* Allocates a new list_node_t. NULL on failure.
|
||||
* Allocates a new clist_node_t. NULL on failure.
|
||||
*/
|
||||
|
||||
list_node_t *
|
||||
list_node_new(void *val)
|
||||
clist_node_t *
|
||||
clist_node_new(void *val)
|
||||
{
|
||||
list_node_t *self;
|
||||
if (!(self = LIST_MALLOC(sizeof(list_node_t))))
|
||||
clist_node_t *self;
|
||||
if (!(self = LIST_MALLOC(sizeof(clist_node_t))))
|
||||
return NULL;
|
||||
self->prev = NULL;
|
||||
self->next = NULL;
|
||||
@@ -32,14 +32,14 @@ list_node_new(void *val)
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a new list_t. NULL on failure.
|
||||
* Allocate a new clist_t. NULL on failure.
|
||||
*/
|
||||
|
||||
list_t *
|
||||
list_new(void)
|
||||
clist_t *
|
||||
clist_new(void)
|
||||
{
|
||||
list_t *self;
|
||||
if (!(self = LIST_MALLOC(sizeof(list_t))))
|
||||
clist_t *self;
|
||||
if (!(self = LIST_MALLOC(sizeof(clist_t))))
|
||||
return NULL;
|
||||
self->head = NULL;
|
||||
self->tail = NULL;
|
||||
@@ -54,21 +54,21 @@ list_new(void)
|
||||
* @self: Pointer to the list
|
||||
*/
|
||||
|
||||
void list_clear(list_t *self)
|
||||
void clist_clear(clist_t *self)
|
||||
{
|
||||
uint32_t len = self->len;
|
||||
list_node_t *next;
|
||||
list_node_t *curr = self->head;
|
||||
clist_node_t *next;
|
||||
clist_node_t *curr = self->head;
|
||||
|
||||
while (len)
|
||||
while (curr != NULL)
|
||||
{
|
||||
next = curr->next;
|
||||
if (self->free)
|
||||
self->free(curr->val);
|
||||
LIST_FREE(curr);
|
||||
curr = next;
|
||||
len--;
|
||||
}
|
||||
self->len = 0;
|
||||
self->head = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -76,9 +76,9 @@ void list_clear(list_t *self)
|
||||
* @self: Pointer to the list
|
||||
*/
|
||||
|
||||
void list_destroy(list_t *self)
|
||||
void clist_destroy(clist_t *self)
|
||||
{
|
||||
list_clear(self);
|
||||
clist_clear(self);
|
||||
LIST_FREE(self);
|
||||
}
|
||||
|
||||
@@ -89,8 +89,8 @@ void list_destroy(list_t *self)
|
||||
* @node: the node to push
|
||||
*/
|
||||
|
||||
list_node_t *
|
||||
list_rpush(list_t *self, list_node_t *node)
|
||||
clist_node_t *
|
||||
clist_rpush(clist_t *self, clist_node_t *node)
|
||||
{
|
||||
if (!node)
|
||||
return NULL;
|
||||
@@ -117,13 +117,13 @@ list_rpush(list_t *self, list_node_t *node)
|
||||
* @self: Pointer to the list for popping node
|
||||
*/
|
||||
|
||||
list_node_t *
|
||||
list_rpop(list_t *self)
|
||||
clist_node_t *
|
||||
clist_rpop(clist_t *self)
|
||||
{
|
||||
if (!self->len)
|
||||
return NULL;
|
||||
|
||||
list_node_t *node = self->tail;
|
||||
clist_node_t *node = self->tail;
|
||||
|
||||
if (--self->len)
|
||||
{
|
||||
@@ -143,13 +143,13 @@ list_rpop(list_t *self)
|
||||
* @self: Pointer to the list for popping node
|
||||
*/
|
||||
|
||||
list_node_t *
|
||||
list_lpop(list_t *self)
|
||||
clist_node_t *
|
||||
clist_lpop(clist_t *self)
|
||||
{
|
||||
if (!self->len)
|
||||
return NULL;
|
||||
|
||||
list_node_t *node = self->head;
|
||||
clist_node_t *node = self->head;
|
||||
|
||||
if (--self->len)
|
||||
{
|
||||
@@ -171,8 +171,8 @@ list_lpop(list_t *self)
|
||||
* @node: the node to push
|
||||
*/
|
||||
|
||||
list_node_t *
|
||||
list_lpush(list_t *self, list_node_t *node)
|
||||
clist_node_t *
|
||||
clist_lpush(clist_t *self, clist_node_t *node)
|
||||
{
|
||||
if (!node)
|
||||
return NULL;
|
||||
@@ -200,19 +200,19 @@ list_lpush(list_t *self, list_node_t *node)
|
||||
* @val: Value to find
|
||||
*/
|
||||
|
||||
list_node_t *
|
||||
list_find(list_t *self, void *val)
|
||||
clist_node_t *
|
||||
clist_find(clist_t *self, void *val)
|
||||
{
|
||||
list_iterator_t *it = list_iterator_new(self, LIST_HEAD);
|
||||
list_node_t *node;
|
||||
clist_iterator_t *it = clist_iterator_new(self, LIST_HEAD);
|
||||
clist_node_t *node;
|
||||
|
||||
while ((node = list_iterator_next(it)))
|
||||
while ((node = clist_iterator_next(it)))
|
||||
{
|
||||
if (self->compare)
|
||||
{
|
||||
if (self->compare(val, node->val) == 0)
|
||||
{
|
||||
list_iterator_destroy(it);
|
||||
clist_iterator_destroy(it);
|
||||
return node;
|
||||
}
|
||||
}
|
||||
@@ -220,13 +220,13 @@ list_find(list_t *self, void *val)
|
||||
{
|
||||
if (val == node->val)
|
||||
{
|
||||
list_iterator_destroy(it);
|
||||
clist_iterator_destroy(it);
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
list_iterator_destroy(it);
|
||||
clist_iterator_destroy(it);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -236,10 +236,10 @@ list_find(list_t *self, void *val)
|
||||
* @index: the index of node in the list
|
||||
*/
|
||||
|
||||
list_node_t *
|
||||
list_at(list_t *self, int index)
|
||||
clist_node_t *
|
||||
clist_at(clist_t *self, int index)
|
||||
{
|
||||
list_direction_t direction = LIST_HEAD;
|
||||
clist_direction_t direction = LIST_HEAD;
|
||||
|
||||
if (index < 0)
|
||||
{
|
||||
@@ -249,11 +249,11 @@ list_at(list_t *self, int index)
|
||||
|
||||
if ((unsigned)index < self->len)
|
||||
{
|
||||
list_iterator_t *it = list_iterator_new(self, direction);
|
||||
list_node_t *node = list_iterator_next(it);
|
||||
clist_iterator_t *it = clist_iterator_new(self, direction);
|
||||
clist_node_t *node = clist_iterator_next(it);
|
||||
while (index--)
|
||||
node = list_iterator_next(it);
|
||||
list_iterator_destroy(it);
|
||||
node = clist_iterator_next(it);
|
||||
clist_iterator_destroy(it);
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -266,7 +266,7 @@ list_at(list_t *self, int index)
|
||||
* @node: Pointer the node to be deleted
|
||||
*/
|
||||
|
||||
void list_remove(list_t *self, list_node_t *node)
|
||||
void clist_remove(clist_t *self, clist_node_t *node)
|
||||
{
|
||||
node->prev
|
||||
? (node->prev->next = node->next)
|
||||
@@ -284,29 +284,29 @@ void list_remove(list_t *self, list_node_t *node)
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a new list_iterator_t. NULL on failure.
|
||||
* Allocate a new clist_iterator_t. NULL on failure.
|
||||
* Accepts a direction, which may be LIST_HEAD or LIST_TAIL.
|
||||
*/
|
||||
|
||||
list_iterator_t *
|
||||
list_iterator_new(list_t *list, list_direction_t direction)
|
||||
clist_iterator_t *
|
||||
clist_iterator_new(clist_t *list, clist_direction_t direction)
|
||||
{
|
||||
list_node_t *node = direction == LIST_HEAD
|
||||
clist_node_t *node = direction == LIST_HEAD
|
||||
? list->head
|
||||
: list->tail;
|
||||
return list_iterator_new_from_node(node, direction);
|
||||
return clist_iterator_new_from_node(node, direction);
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a new list_iterator_t with the given start
|
||||
* Allocate a new clist_iterator_t with the given start
|
||||
* node. NULL on failure.
|
||||
*/
|
||||
|
||||
list_iterator_t *
|
||||
list_iterator_new_from_node(list_node_t *node, list_direction_t direction)
|
||||
clist_iterator_t *
|
||||
clist_iterator_new_from_node(clist_node_t *node, clist_direction_t direction)
|
||||
{
|
||||
list_iterator_t *self;
|
||||
if (!(self = LIST_MALLOC(sizeof(list_iterator_t))))
|
||||
clist_iterator_t *self;
|
||||
if (!(self = LIST_MALLOC(sizeof(clist_iterator_t))))
|
||||
return NULL;
|
||||
self->next = node;
|
||||
self->direction = direction;
|
||||
@@ -314,14 +314,14 @@ list_iterator_new_from_node(list_node_t *node, list_direction_t direction)
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the next list_node_t or NULL when no more
|
||||
* Return the next clist_node_t or NULL when no more
|
||||
* nodes remain in the list.
|
||||
*/
|
||||
|
||||
list_node_t *
|
||||
list_iterator_next(list_iterator_t *self)
|
||||
clist_node_t *
|
||||
clist_iterator_next(clist_iterator_t *self)
|
||||
{
|
||||
list_node_t *curr = self->next;
|
||||
clist_node_t *curr = self->next;
|
||||
if (curr)
|
||||
{
|
||||
self->next = self->direction == LIST_HEAD
|
||||
@@ -335,7 +335,7 @@ list_iterator_next(list_iterator_t *self)
|
||||
* Free the list iterator.
|
||||
*/
|
||||
|
||||
void list_iterator_destroy(list_iterator_t *self)
|
||||
void clist_iterator_destroy(clist_iterator_t *self)
|
||||
{
|
||||
LIST_FREE(self);
|
||||
self = NULL;
|
||||
@@ -0,0 +1,118 @@
|
||||
|
||||
//
|
||||
// clist.h
|
||||
//
|
||||
// Copyright (c) 2010 TJ Holowaychuk <[email protected]>
|
||||
//
|
||||
|
||||
#ifndef __CLIST_H__
|
||||
#define __CLIST_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* clist_t iterator direction.
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LIST_HEAD,
|
||||
LIST_TAIL
|
||||
} clist_direction_t;
|
||||
|
||||
/*
|
||||
* clist_t node struct.
|
||||
*/
|
||||
|
||||
typedef struct clist_node
|
||||
{
|
||||
struct clist_node *prev;
|
||||
struct clist_node *next;
|
||||
void *val;
|
||||
} clist_node_t;
|
||||
|
||||
/*
|
||||
* clist_t struct.
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
clist_node_t *head;
|
||||
clist_node_t *tail;
|
||||
uint32_t len;
|
||||
void (*free)(void *val);
|
||||
int8_t (*compare)(void *a, void *b);
|
||||
} clist_t;
|
||||
|
||||
/*
|
||||
* clist_t iterator struct.
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
clist_node_t *next;
|
||||
clist_direction_t direction;
|
||||
} clist_iterator_t;
|
||||
|
||||
// Node prototypes.
|
||||
|
||||
clist_node_t *
|
||||
clist_node_new(void *val);
|
||||
|
||||
// clist_t prototypes.
|
||||
|
||||
clist_t *
|
||||
clist_new(void);
|
||||
|
||||
clist_node_t *
|
||||
clist_rpush(clist_t *self, clist_node_t *node);
|
||||
|
||||
clist_node_t *
|
||||
clist_lpush(clist_t *self, clist_node_t *node);
|
||||
|
||||
clist_node_t *
|
||||
clist_find(clist_t *self, void *val);
|
||||
|
||||
clist_node_t *
|
||||
clist_at(clist_t *self, int index);
|
||||
|
||||
clist_node_t *
|
||||
clist_rpop(clist_t *self);
|
||||
|
||||
clist_node_t *
|
||||
clist_lpop(clist_t *self);
|
||||
|
||||
void
|
||||
clist_remove(clist_t *self, clist_node_t *node);
|
||||
|
||||
void
|
||||
clist_clear(clist_t *self);
|
||||
|
||||
void
|
||||
clist_destroy(clist_t *self);
|
||||
|
||||
// clist_t iterator prototypes.
|
||||
|
||||
clist_iterator_t *
|
||||
clist_iterator_new(clist_t *list, clist_direction_t direction);
|
||||
|
||||
clist_iterator_t *
|
||||
clist_iterator_new_from_node(clist_node_t *node, clist_direction_t direction);
|
||||
|
||||
clist_node_t *
|
||||
clist_iterator_next(clist_iterator_t *self);
|
||||
|
||||
void
|
||||
clist_iterator_destroy(clist_iterator_t *self);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CLIBS_LIST_H__ */
|
||||
@@ -1,118 +0,0 @@
|
||||
|
||||
//
|
||||
// list.h
|
||||
//
|
||||
// Copyright (c) 2010 TJ Holowaychuk <[email protected]>
|
||||
//
|
||||
|
||||
#ifndef __LIST_H__
|
||||
#define __LIST_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* list_t iterator direction.
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LIST_HEAD,
|
||||
LIST_TAIL
|
||||
} list_direction_t;
|
||||
|
||||
/*
|
||||
* list_t node struct.
|
||||
*/
|
||||
|
||||
typedef struct list_node
|
||||
{
|
||||
struct list_node *prev;
|
||||
struct list_node *next;
|
||||
void *val;
|
||||
} list_node_t;
|
||||
|
||||
/*
|
||||
* list_t struct.
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
list_node_t *head;
|
||||
list_node_t *tail;
|
||||
uint32_t len;
|
||||
void (*free)(void *val);
|
||||
int8_t (*compare)(void *a, void *b);
|
||||
} list_t;
|
||||
|
||||
/*
|
||||
* list_t iterator struct.
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
list_node_t *next;
|
||||
list_direction_t direction;
|
||||
} list_iterator_t;
|
||||
|
||||
// Node prototypes.
|
||||
|
||||
list_node_t *
|
||||
list_node_new(void *val);
|
||||
|
||||
// list_t prototypes.
|
||||
|
||||
list_t *
|
||||
list_new(void);
|
||||
|
||||
list_node_t *
|
||||
list_rpush(list_t *self, list_node_t *node);
|
||||
|
||||
list_node_t *
|
||||
list_lpush(list_t *self, list_node_t *node);
|
||||
|
||||
list_node_t *
|
||||
list_find(list_t *self, void *val);
|
||||
|
||||
list_node_t *
|
||||
list_at(list_t *self, int index);
|
||||
|
||||
list_node_t *
|
||||
list_rpop(list_t *self);
|
||||
|
||||
list_node_t *
|
||||
list_lpop(list_t *self);
|
||||
|
||||
void
|
||||
list_remove(list_t *self, list_node_t *node);
|
||||
|
||||
void
|
||||
list_clear(list_t *self);
|
||||
|
||||
void
|
||||
list_destroy(list_t *self);
|
||||
|
||||
// list_t iterator prototypes.
|
||||
|
||||
list_iterator_t *
|
||||
list_iterator_new(list_t *list, list_direction_t direction);
|
||||
|
||||
list_iterator_t *
|
||||
list_iterator_new_from_node(list_node_t *node, list_direction_t direction);
|
||||
|
||||
list_node_t *
|
||||
list_iterator_next(list_iterator_t *self);
|
||||
|
||||
void
|
||||
list_iterator_destroy(list_iterator_t *self);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CLIBS_LIST_H__ */
|
||||
@@ -15,7 +15,7 @@
|
||||
#define TIME_ADJ_TRIG (0x00000024 >> 2)
|
||||
#define CNTSTEP_OPT (0x00000028 >> 2)
|
||||
|
||||
TIMECTRL_INST *tmcInstPtr = NULL;
|
||||
TMC_INST *tmcInstPtr = NULL;
|
||||
PHY_INST *phyInstPtr = NULL;
|
||||
L2_INST *linkInstPtr = NULL;
|
||||
|
||||
@@ -197,7 +197,7 @@ PHY_CONFIG l1Config =
|
||||
.baseAddr = (uintptr_t)phycReg
|
||||
};
|
||||
|
||||
TIMECTRL_CONFIG tmcConfig =
|
||||
TMC_CONFIG tmcConfig =
|
||||
{
|
||||
.baseAddr = (uintptr_t)tmcReg,
|
||||
.reset = 10
|
||||
@@ -346,7 +346,7 @@ void forge_mgmt_frame(uint8_t *buff, L2_NODE_STATE state)
|
||||
default:
|
||||
dataChunk = NET_ERROR_STAGE;
|
||||
break;
|
||||
FrameInsertChunk(&bitarr, TK_MSG_INI_NET_STATE_OFFSET, TK_MSG_INI_NET_STATE_LEN, dataChunk);
|
||||
FrameInsertChunk(&bitarr, TK_MSG_INI_NET_STATE_OFFSET, TK_MSG_INI_NET_STATE_LEN, dataChunk);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,13 +384,30 @@ void forge_rtt_frame(uint8_t *buff, uint16_t srcId, uint16_t destId,
|
||||
return;
|
||||
}
|
||||
|
||||
TEST(linklayer_master_routine) {
|
||||
TEST(linklayer_reconfig)
|
||||
{
|
||||
int32_t Status;
|
||||
Status = Linklayer_Reconfig(linkInstPtr, &l2Config);
|
||||
ASSERT_EQUAL(SUCCESS, Status);
|
||||
ASSERT_EQUAL(false, linkInstPtr->isEnable);
|
||||
ASSERT_EQUAL(false, linkInstPtr->isEnable);
|
||||
ASSERT_EQUAL(0, linkInstPtr->nodeList->len);
|
||||
ASSERT_EQUAL(0, linkInstPtr->schdEventPool->envCnt);
|
||||
}
|
||||
|
||||
TEST(linklayer_master_routine)
|
||||
{
|
||||
int32_t Status;
|
||||
Linklayer_Start(linkInstPtr);
|
||||
TIME_WORD timeStampA, timeStampB, timeGap;
|
||||
uint32_t timeDiff;
|
||||
l2Config.myType = L2_NODE_HEAD;
|
||||
l2Config.myId = 1;
|
||||
Status = Linklayer_Reconfig(linkInstPtr, &l2Config);
|
||||
ASSERT_EQUAL(SUCCESS, Status);
|
||||
// 30 seconds
|
||||
for(int i = 0; i < 200*30; i++) {
|
||||
Linklayer_Start(linkInstPtr);
|
||||
for (int i = 0; i < 30 * L2_SLOTS_PER_FRAME; i++)
|
||||
{
|
||||
tmcReg[TIME_INT_REG]++;
|
||||
|
||||
if (L2_GetNextTor(linkInstPtr) == L2_TOR_TX)
|
||||
@@ -401,29 +418,29 @@ TEST(linklayer_master_routine) {
|
||||
// ASSERT_EQUAL(linkInstPtr->rttFSM->rttRecord.Tt1.int_part + linkInstPtr->netStartTime*L2_SLOTS_PER_FRAME,
|
||||
// timeStampA.int_part);
|
||||
// ASSERT_EQUAL(linkInstPtr->rttFSM->rttRecord.Tt1.frac_part, timeStampA.frac_part);
|
||||
timeStampA.frac_part = rand()%1000; // 10us deviation.
|
||||
|
||||
timeStampA.frac_part = rand_range(0, 1000); // up to 10us deviation.
|
||||
}
|
||||
}
|
||||
if (L2_GetCurrentTor(linkInstPtr) == L2_TOR_RX)
|
||||
{
|
||||
if(L2_GetCurrentFrameType(linkInstPtr) == L2_INTRA_W2_ACQ_FRAME) {
|
||||
forge_w2acq_frame((uint8_t*)phyInstPtr->recvDataAddr, L2_NODE_MEMBER, 2, 1, 1, -1, L2_INIT_STATE);
|
||||
if (L2_GetCurrentFrameType(linkInstPtr) == L2_INTRA_W2_ACQ_FRAME)
|
||||
{
|
||||
forge_w2acq_frame((uint8_t *)phyInstPtr->recvDataAddr, L2_NODE_MEMBER, 2, 1, 1, -1, L2_INIT_STATE);
|
||||
PhyWrite(phyInstPtr, TXRX_STATE, 0x01010101);
|
||||
PhyWrite(phyInstPtr, RECVDATA_STATE, INTRA_W2ACQ_FRAME_LENGTH_MAX);
|
||||
}
|
||||
|
||||
if (L2_GetCurrentFrameType(linkInstPtr) == L2_INTRA_MGMT_FRAME)
|
||||
{
|
||||
forge_mgmt_frame((uint8_t*)phyInstPtr->recvDataAddr, L2_NORMAL_STATE);
|
||||
forge_mgmt_frame((uint8_t *)phyInstPtr->recvDataAddr, L2_NORMAL_STATE);
|
||||
PhyWrite(phyInstPtr, TXRX_STATE, 0x01010101);
|
||||
PhyWrite(phyInstPtr, RECVDATA_STATE, INTRA_MGMT_FRAME_LENGTH_MAX);
|
||||
}
|
||||
if (L2_GetCurrentFrameType(linkInstPtr) == L2_INTRA_TSYNC_FRAME)
|
||||
{
|
||||
timeDiff = Phy_GetTimeComp(L2_L2frame2L1frame(L2_INTRA_TSYNC_FRAME)) + (rand()-RAND_MAX)%1000;
|
||||
timeDiff = Phy_GetTimeComp(L2_L2frame2L1frame(L2_INTRA_TSYNC_FRAME)) + (rand() - RAND_MAX) % 1000;
|
||||
TimeCtrl_CalculateTimeGap(&timeStampA, &timeStampB, &timeGap);
|
||||
forge_rtt_frame((uint8_t*)phyInstPtr->recvDataAddr, 2, 1, 1, &timeGap , rand()%200000);
|
||||
forge_rtt_frame((uint8_t *)phyInstPtr->recvDataAddr, 2, 1, 1, &timeGap, rand() % 200000);
|
||||
PhyWrite(phyInstPtr, TXRX_STATE, 0x01010101);
|
||||
PhyWrite(phyInstPtr, FSTIME_H, L2_GetLastFrameNum(linkInstPtr));
|
||||
PhyWrite(phyInstPtr, FSTIME_L, timeDiff);
|
||||
@@ -432,12 +449,13 @@ TEST(linklayer_master_routine) {
|
||||
|
||||
if (L2_GetCurrentFrameType(linkInstPtr) == L2_INTRA_SVC_FRAME)
|
||||
{
|
||||
forge_mgmt_frame((uint8_t*)phyInstPtr->recvDataAddr, L2_NORMAL_STATE);
|
||||
forge_mgmt_frame((uint8_t *)phyInstPtr->recvDataAddr, L2_NORMAL_STATE);
|
||||
PhyWrite(phyInstPtr, TXRX_STATE, 0x01010101);
|
||||
PhyWrite(phyInstPtr, RECVDATA_STATE, INTRA_MGMT_FRAME_LENGTH_MAX);
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
PhyWrite(phyInstPtr, TXRX_STATE, 0x02020202);
|
||||
}
|
||||
|
||||
@@ -445,15 +463,19 @@ TEST(linklayer_master_routine) {
|
||||
|
||||
Status = Linklayer_Proc(linkInstPtr);
|
||||
|
||||
if((tmcReg[TIME_INT_REG]+1)/200 < linkInstPtr->netStartTime) {
|
||||
if ((tmcReg[TIME_INT_REG] + 1) / 200 < linkInstPtr->netStartTime)
|
||||
{
|
||||
ASSERT_EQUAL(EIGNORE, Status);
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
ASSERT_EQUAL(SUCCESS, Status);
|
||||
}
|
||||
|
||||
if(L2_isDataAvail(linkInstPtr)) {
|
||||
if(L2_GetLastFrameType(linkInstPtr) == L2_INTRA_W2_ACQ_FRAME) {
|
||||
if (L2_isDataAvail(linkInstPtr))
|
||||
{
|
||||
if (L2_GetLastFrameType(linkInstPtr) == L2_INTRA_W2_ACQ_FRAME)
|
||||
{
|
||||
ASSERT_EQUAL(1, L2_GetNodeListLen(linkInstPtr->nodeList));
|
||||
ASSERT_TRUE(L2_isNodeInList(linkInstPtr->nodeList, 2));
|
||||
}
|
||||
@@ -461,23 +483,126 @@ TEST(linklayer_master_routine) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST(linklayer_reconfig) {
|
||||
TEST(linklayer_slave_netsetup)
|
||||
{
|
||||
int32_t Status;
|
||||
TIME_WORD timeStampA, timeStampB, timeGap;
|
||||
TIME_WORD bmTime;
|
||||
uint32_t netStart, timeDiff;
|
||||
// 30 seconds
|
||||
l2Config.myType = L2_NODE_MEMBER;
|
||||
l2Config.myId = 2;
|
||||
Status = Linklayer_Reconfig(linkInstPtr, &l2Config);
|
||||
ASSERT_EQUAL(SUCCESS, Status);
|
||||
tmcReg[TIME_FRAC_REG] = rand_range(0, TIME_FRAC_MAX);
|
||||
tmcReg[TIME_INT_REG] = rand_range(0, 60 * L2_SLOTS_PER_FRAME); // 0~60s
|
||||
bmTime.frac_part = rand_range(0, TIME_FRAC_MAX);
|
||||
bmTime.int_part = rand_range(tmcReg[TIME_INT_REG], tmcReg[TIME_INT_REG] + 5 * L2_SLOTS_PER_FRAME);
|
||||
|
||||
// 74 is the index of bm frame in routine table.
|
||||
netStart = bmTime.int_part % L2_SLOTS_PER_FRAME + rand_range(-12, 12);
|
||||
|
||||
Linklayer_Start(linkInstPtr);
|
||||
for (int i = 0; i < 12 * L2_SLOTS_PER_FRAME * TIME_FRAC_MAX; i++)
|
||||
{
|
||||
tmcReg[TIME_FRAC_REG]++;
|
||||
if (tmcReg[TIME_FRAC_REG] >= TIME_FRAC_MAX)
|
||||
{
|
||||
tmcReg[TIME_FRAC_REG] = 0;
|
||||
tmcReg[TIME_INT_REG]++;
|
||||
}
|
||||
|
||||
if (tmcReg[TIME_FRAC_REG] == bmTime.frac_part && tmcReg[TIME_INT_REG] == bmTime.int_part)
|
||||
{
|
||||
forge_bm_frame((uint8_t *)phyInstPtr->recvDataAddr, 1, 1, 1, netStart);
|
||||
PhyWrite(phyInstPtr, TXRX_STATE, 0x01010101);
|
||||
PhyWrite(phyInstPtr, RECVDATA_STATE, INTRA_BM_FRAME_LENGTH_MAX);
|
||||
}
|
||||
|
||||
if (L2_GetNextTor(linkInstPtr) == L2_TOR_TX)
|
||||
{
|
||||
if (L2_GetNextFrameType(linkInstPtr) == L2_INTRA_TSYNC_FRAME)
|
||||
{
|
||||
TimeCtrl_GetCurrentTime(tmcInstPtr, &timeStampA);
|
||||
timeStampA.frac_part = rand_range(0, 1000); // up to 10us deviation.
|
||||
}
|
||||
}
|
||||
if (L2_GetCurrentTor(linkInstPtr) == L2_TOR_RX)
|
||||
{
|
||||
if (L2_GetCurrentFrameType(linkInstPtr) == L2_INTRA_W2_ACQ_FRAME)
|
||||
{
|
||||
forge_w2acq_frame((uint8_t *)phyInstPtr->recvDataAddr, L2_NODE_MEMBER, 2, 1, 1, -1, L2_INIT_STATE);
|
||||
PhyWrite(phyInstPtr, TXRX_STATE, 0x01010101);
|
||||
PhyWrite(phyInstPtr, RECVDATA_STATE, INTRA_W2ACQ_FRAME_LENGTH_MAX);
|
||||
}
|
||||
|
||||
if (L2_GetCurrentFrameType(linkInstPtr) == L2_INTRA_MGMT_FRAME)
|
||||
{
|
||||
forge_mgmt_frame((uint8_t *)phyInstPtr->recvDataAddr, L2_NORMAL_STATE);
|
||||
PhyWrite(phyInstPtr, TXRX_STATE, 0x01010101);
|
||||
PhyWrite(phyInstPtr, RECVDATA_STATE, INTRA_MGMT_FRAME_LENGTH_MAX);
|
||||
}
|
||||
if (L2_GetCurrentFrameType(linkInstPtr) == L2_INTRA_TSYNC_FRAME)
|
||||
{
|
||||
timeDiff = Phy_GetTimeComp(L2_L2frame2L1frame(L2_INTRA_TSYNC_FRAME)) + (rand() - RAND_MAX) % 1000;
|
||||
TimeCtrl_CalculateTimeGap(&timeStampA, &timeStampB, &timeGap);
|
||||
forge_rtt_frame((uint8_t *)phyInstPtr->recvDataAddr, 2, 1, 1, &timeGap, rand() % 200000);
|
||||
PhyWrite(phyInstPtr, TXRX_STATE, 0x01010101);
|
||||
PhyWrite(phyInstPtr, FSTIME_H, L2_GetLastFrameNum(linkInstPtr));
|
||||
PhyWrite(phyInstPtr, FSTIME_L, timeDiff);
|
||||
PhyWrite(phyInstPtr, RECVDATA_STATE, INTRA_MGMT_FRAME_LENGTH_MAX);
|
||||
}
|
||||
|
||||
if (L2_GetCurrentFrameType(linkInstPtr) == L2_INTRA_SVC_FRAME)
|
||||
{
|
||||
forge_mgmt_frame((uint8_t *)phyInstPtr->recvDataAddr, L2_NORMAL_STATE);
|
||||
PhyWrite(phyInstPtr, TXRX_STATE, 0x01010101);
|
||||
PhyWrite(phyInstPtr, RECVDATA_STATE, INTRA_MGMT_FRAME_LENGTH_MAX);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PhyWrite(phyInstPtr, TXRX_STATE, 0x02020202);
|
||||
}
|
||||
if (PhyRead(phyInstPtr, TXRX_STATE) != 0x02020202)
|
||||
{
|
||||
Phy_UpdateState(phyInstPtr);
|
||||
}
|
||||
|
||||
if (tmcReg[TIME_FRAC_REG] == 200000)
|
||||
{ // 2ms
|
||||
Status = Linklayer_Proc(linkInstPtr);
|
||||
if ((tmcReg[TIME_INT_REG] + 1) / 200 < linkInstPtr->netStartTime)
|
||||
{
|
||||
ASSERT_EQUAL(EIGNORE, Status);
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT_EQUAL(SUCCESS, Status);
|
||||
}
|
||||
|
||||
if (L2_isDataAvail(linkInstPtr))
|
||||
{
|
||||
if (L2_GetLastFrameType(linkInstPtr) == L2_INTRA_W2_ACQ_FRAME)
|
||||
{
|
||||
ASSERT_EQUAL(1, L2_GetNodeListLen(linkInstPtr->nodeList));
|
||||
ASSERT_TRUE(L2_isNodeInList(linkInstPtr->nodeList, 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUITE(linklayer_unit_test) {
|
||||
TEST_SUITE(linklayer_unit_test)
|
||||
{
|
||||
TEST_SUITE_CONFIGURE(linklayer_setup, linklayer_teardown);
|
||||
RUN_TEST(linklayer_master_routine);
|
||||
RUN_TEST(linklayer_reconfig);
|
||||
RUN_TEST(linklayer_master_routine);
|
||||
RUN_TEST(linklayer_slave_netsetup);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int main(void)
|
||||
{
|
||||
RUN_TEST_SUITE(linklayer_unit_test);
|
||||
TEST_REPORT();
|
||||
return TEST_EXIT_CODE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
#define HARDWARE_VERSION 0x00000001
|
||||
#define MAX_OPT_DELAY 100 // 1us = 100*10ns
|
||||
|
||||
TIMECTRL_CONFIG tmcConfig = {
|
||||
TMC_CONFIG tmcConfig = {
|
||||
.baseAddr = 0 /*TODO: fill withe real base address*/,
|
||||
.reset = 10};
|
||||
|
||||
TIMECTRL_INST *tmcInstPtr = NULL;
|
||||
TMC_INST *tmcInstPtr = NULL;
|
||||
|
||||
void tmc_setup(void)
|
||||
{
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
|
||||
uint32_t tmcReg[32] = {0};
|
||||
|
||||
TIMECTRL_CONFIG tmcConfig = {
|
||||
TMC_CONFIG tmcConfig = {
|
||||
.baseAddr = 0,
|
||||
.reset = 10};
|
||||
|
||||
TIMECTRL_INST *tmcInstPtr = NULL;
|
||||
TMC_INST *tmcInstPtr = NULL;
|
||||
|
||||
void tmc_setup(void)
|
||||
{
|
||||
|
||||
@@ -130,7 +130,7 @@ static int32_t EvalPhyConfig(INTER_COMM_INST* instPtr, uint8_t* msgPtr){
|
||||
torState = PHY_TOR_RX;
|
||||
}
|
||||
else{
|
||||
DBG_ERROR("[PHY Control] Tx/Rx state cannot be recognized...\n\r");
|
||||
DBG_ERROR("[PHY Control] Tx/Rx state cannot be recognized...\n");
|
||||
return EIGNORE;
|
||||
}
|
||||
instPtr->lastCtrlTimeTag = GetTimeWord(msgPtr+CTRL_TIME_OFFSET);
|
||||
@@ -165,7 +165,7 @@ static int32_t EvalPhyConfig(INTER_COMM_INST* instPtr, uint8_t* msgPtr){
|
||||
frameType = L1_40KBPS_20MS_FRAME;
|
||||
break;
|
||||
default:
|
||||
DBG_ERROR("[PHY Control] Frame Type cannot be recognized...\n\r");
|
||||
DBG_ERROR("[PHY Control] Frame Type cannot be recognized...\n");
|
||||
return EIGNORE;
|
||||
break;
|
||||
}
|
||||
@@ -187,8 +187,8 @@ static int32_t EvalPhyConfig(INTER_COMM_INST* instPtr, uint8_t* msgPtr){
|
||||
phyRef->isPresetHop = false;
|
||||
}
|
||||
else{
|
||||
DBG_ERROR("[PHY Control] Hopping Pattern Configure cannot be recognized...\n\r");
|
||||
DBG_WARNING("[PHY Control] Using default preset hopping pattern instead...\n\r");
|
||||
DBG_ERROR("[PHY Control] Hopping Pattern Configure cannot be recognized...\n");
|
||||
DBG_WARNING("[PHY Control] Using default preset hopping pattern instead...\n");
|
||||
return EIGNORE;
|
||||
}
|
||||
if(phyRef->isPresetHop == false){
|
||||
@@ -205,11 +205,11 @@ static int32_t EvalPhyConfig(INTER_COMM_INST* instPtr, uint8_t* msgPtr){
|
||||
beamWidth = PHY_ANT_BEAM_25;
|
||||
}
|
||||
else if(msgPtr[INTER_MSG_CTRL_BEAM_MODE_OFFSET] == BEAM_MODE_NRW){
|
||||
beamWidth = PHY_ANT_BEAM_8;
|
||||
beamWidth = PHY_ANT_BEAM_16;
|
||||
}
|
||||
else{
|
||||
DBG_ERROR("[PHY Control] Beam Width Configure cannot be recognized...\n\r");
|
||||
DBG_WARNING("[PHY Control] Using default WILD beam (120 deg) instead...\n\r");
|
||||
DBG_ERROR("[PHY Control] Beam Width Configure cannot be recognized...\n");
|
||||
DBG_WARNING("[PHY Control] Using default WILD beam (120 deg) instead...\n");
|
||||
return EIGNORE;
|
||||
}
|
||||
Status = Phy_SetBeamWidth(phyRef, beamWidth);
|
||||
@@ -217,15 +217,15 @@ static int32_t EvalPhyConfig(INTER_COMM_INST* instPtr, uint8_t* msgPtr){
|
||||
return Status;
|
||||
}
|
||||
beamNo = (uint32_t)msgPtr[INTER_MSG_CTRL_BEAM_NO_OFFSET];
|
||||
if((beamNo<NUM_ANT_SUBNRRW_PATTERN && beamWidth == PHY_ANT_BEAM_25)
|
||||
||(beamNo<NUM_ANT_NRRW_PATTERN && beamWidth == PHY_ANT_BEAM_8)
|
||||
if((beamNo<L1_NUM_ANT_SUBNRRW_PATTERN && beamWidth == PHY_ANT_BEAM_25)
|
||||
||(beamNo<L1_NUM_ANT_NRRW_PATTERN && beamWidth == PHY_ANT_BEAM_16)
|
||||
|| (beamNo == 0 && beamWidth == PHY_ANT_BEAM_120)){
|
||||
Phy_SetBeamNo(phyRef, beamNo);
|
||||
Phy_SetBeamNo(phyRef, beamNo, beamWidth);
|
||||
}
|
||||
else{
|
||||
if(beamNo != 0x000000FF){
|
||||
DBG_ERROR("[PHY Control] Beam Number Configure cannot be recognized...\n\r");
|
||||
DBG_WARNING("[PHY Control] Using Beam Angle configure instead...\n\r");
|
||||
DBG_ERROR("[PHY Control] Beam Number Configure cannot be recognized...\n");
|
||||
DBG_WARNING("[PHY Control] Using Beam Angle configure instead...\n");
|
||||
return EIGNORE;
|
||||
}
|
||||
// the angle config is a 16 bit fixed point data
|
||||
@@ -242,6 +242,35 @@ static int32_t EvalPhyConfig(INTER_COMM_INST* instPtr, uint8_t* msgPtr){
|
||||
}
|
||||
}
|
||||
|
||||
// Power Mode and Attenuation control
|
||||
if (msgPtr[INTER_MSG_CTRL_POWER_OFFSET] == CTRL_POWER_LOW)
|
||||
{
|
||||
Phy_AntConfigMode(phyRef, PHY_ANT_MODE_POWER_LOW);
|
||||
}
|
||||
else if (msgPtr[INTER_MSG_CTRL_POWER_OFFSET] == CTRL_POWER_FULL)
|
||||
{
|
||||
Phy_AntConfigMode(phyRef, PHY_ANT_MODE_POWER_FULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_ERROR("[PHY Control] Unsupported power mode [0x%02X]\n",
|
||||
msgPtr[INTER_MSG_CTRL_POWER_OFFSET]);
|
||||
return FAILURE;
|
||||
}
|
||||
if(msgPtr[INTER_MSG_CTRL_RXATT_OFFSET] <= INTER_MSG_CTRL_RXATT_MAX
|
||||
&& msgPtr[INTER_MSG_CTRL_TXATT_OFFSET] <= INTER_MSG_CTRL_TXATT_MAX)
|
||||
{
|
||||
Phy_AntConfigAttenuation(phyRef,
|
||||
msgPtr[INTER_MSG_CTRL_RXATT_OFFSET],
|
||||
msgPtr[INTER_MSG_CTRL_TXATT_OFFSET]
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_ERROR("[PHY Control] Attenuation exceeds max range.\n");
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
TIME_WORD tmWord = {0};
|
||||
tmWord.int_part = (uint32_t)(instPtr->lastCtrlTimeTag >> 32);
|
||||
tmWord.frac_part = (uint32_t)(instPtr->lastCtrlTimeTag);
|
||||
@@ -305,13 +334,13 @@ int32_t InterComm_Init(INTER_COMM_INST** instPtr, INTER_COMM_CONFIG* configPtr){
|
||||
}
|
||||
|
||||
// Initial physical buffer
|
||||
(*instPtr)->phyRecvBuff = calloc(TXRXDATA_MAX_LEN/sizeof(uint32_t), sizeof(uint32_t));
|
||||
(*instPtr)->phyRecvBuff = calloc(L1_TXRXDATA_MAX_LEN/sizeof(uint32_t), sizeof(uint32_t));
|
||||
if ((*instPtr)->phyRecvBuff == NULL) {
|
||||
Status = EALLOC;
|
||||
goto init_failed;
|
||||
}
|
||||
|
||||
(*instPtr)->phySendBuff = calloc(TXRXDATA_MAX_LEN/sizeof(uint32_t), sizeof(uint32_t));
|
||||
(*instPtr)->phySendBuff = calloc(L1_TXRXDATA_MAX_LEN/sizeof(uint32_t), sizeof(uint32_t));
|
||||
if ((*instPtr)->phySendBuff == NULL) {
|
||||
Status = EALLOC;
|
||||
goto init_failed;
|
||||
@@ -499,16 +528,42 @@ int32_t InterComm_MsgHandler(INTER_COMM_INST* instPtr){
|
||||
break;
|
||||
}
|
||||
case INTER_MSG_MODESW_CODE:{
|
||||
if(msgRecvPtr[MODESW_MODE_OFFSET] == MODESW_MODE_NORMAL){
|
||||
if(msgRecvPtr[MODESW_MODE_OFFSET] == MODESW_MODE_NORMAL)
|
||||
{
|
||||
Phy_SetMode(instPtr->phyInstPtr, PHY_MODE_PULL);
|
||||
}
|
||||
else if(msgRecvPtr[MODESW_MODE_OFFSET] == MODESW_MODE_NETSET){
|
||||
else if(msgRecvPtr[MODESW_MODE_OFFSET] == MODESW_MODE_NETSET)
|
||||
{
|
||||
PHY_INST* phyRef = instPtr->phyInstPtr;
|
||||
// Power Mode and Attenuation control
|
||||
if (msgRecvPtr[MODESW_POWER_OFFSET] == CTRL_POWER_LOW)
|
||||
{
|
||||
Phy_AntConfigMode(phyRef, PHY_ANT_MODE_POWER_LOW);
|
||||
}
|
||||
else if (msgRecvPtr[MODESW_POWER_OFFSET] == CTRL_POWER_FULL)
|
||||
{
|
||||
Phy_AntConfigMode(phyRef, PHY_ANT_MODE_POWER_FULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_ERROR("[PHY Control] Unsupported power mode [0x%02X]\n",
|
||||
msgRecvPtr[MODESW_POWER_OFFSET]);
|
||||
break;
|
||||
}
|
||||
if(msgRecvPtr[MODESW_RXATT_OFFSET] <= MODESW_RXATT_MAX)
|
||||
{
|
||||
Phy_AntConfigAttenuation(phyRef, msgRecvPtr[MODESW_RXATT_OFFSET], MODESW_TXATT_SKIP);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_ERROR("[PHY Control] Attenuation exceeds max range.\n");
|
||||
}
|
||||
uint64_t timeTemp;
|
||||
TIME_WORD tmWord;
|
||||
timeTemp = GetTimeWord(msgRecvPtr + MODESW_START_TIME_OFFSET);
|
||||
tmWord.int_part = (uint32_t)(timeTemp>>32);;
|
||||
tmWord.frac_part = (uint32_t)(timeTemp);
|
||||
Status = Phy_SetTimeWord(instPtr->phyInstPtr, &tmWord, PHY_TIME_WORD_POLL);
|
||||
Status = Phy_SetTimeWord(phyRef, &tmWord, PHY_TIME_WORD_POLL);
|
||||
if(Status != SUCCESS){
|
||||
return EPARAM;
|
||||
}
|
||||
@@ -516,7 +571,7 @@ int32_t InterComm_MsgHandler(INTER_COMM_INST* instPtr){
|
||||
if(timeTemp == 0){
|
||||
tmWord.frac_part = 0;
|
||||
tmWord.int_part = 0;
|
||||
Status = Phy_SetTimeWord(instPtr->phyInstPtr, &tmWord, PHY_TIME_WORD_LISTEN_TIMEOUT);
|
||||
Status = Phy_SetTimeWord(phyRef, &tmWord, PHY_TIME_WORD_LISTEN_TIMEOUT);
|
||||
if(Status != SUCCESS){
|
||||
return EPARAM;
|
||||
}
|
||||
@@ -524,16 +579,16 @@ int32_t InterComm_MsgHandler(INTER_COMM_INST* instPtr){
|
||||
else{
|
||||
tmWord.frac_part += (uint32_t)(timeTemp);
|
||||
tmWord.int_part += (uint32_t)(timeTemp>>32);
|
||||
tmWord.int_part = (tmWord.frac_part >= TMWORD_FRAC_MAX) ? tmWord.int_part + 1:tmWord.int_part;
|
||||
tmWord.frac_part %= TMWORD_FRAC_MAX;
|
||||
Status = Phy_SetTimeWord(instPtr->phyInstPtr, &tmWord, PHY_TIME_WORD_LISTEN_TIMEOUT);
|
||||
tmWord.int_part = (tmWord.frac_part >= TIME_FRAC_MAX) ? tmWord.int_part + 1:tmWord.int_part;
|
||||
tmWord.frac_part %= TIME_FRAC_MAX;
|
||||
Status = Phy_SetTimeWord(phyRef, &tmWord, PHY_TIME_WORD_LISTEN_TIMEOUT);
|
||||
if(Status != SUCCESS){
|
||||
return EPARAM;
|
||||
}
|
||||
}
|
||||
instPtr->phyInstPtr->isPresetHop = true ;
|
||||
Status = Phy_SetMode(instPtr->phyInstPtr, PHY_MODE_LISTEN);
|
||||
Status = Phy_SetupNextSlot(instPtr->phyInstPtr, PHY_TOR_RX, L1_10KBPS_20MS_FRAME, NULL);
|
||||
phyRef->isPresetHop = true ;
|
||||
Status = Phy_SetMode(phyRef, PHY_MODE_LISTEN);
|
||||
Status = Phy_SetupNextSlot(phyRef, PHY_TOR_RX, L1_10KBPS_20MS_FRAME, NULL);
|
||||
}
|
||||
else{
|
||||
return EPARAM;
|
||||
@@ -702,18 +757,18 @@ int32_t InterComm_PhyDataUpload(INTER_COMM_INST* instPtr){
|
||||
instPtr->lastPhyTimeTag = fsTimeL;
|
||||
instPtr->lastPhyTimeTag |= ((uint64_t)fsTimeH)<<32;
|
||||
uint32_t timeComp = Phy_GetTimeComp(lastFrameType);
|
||||
if(timeComp == L1_FRAME_NONE_COMP){
|
||||
if(timeComp == TIME_FRAC_MAX){
|
||||
return FAILURE;
|
||||
}
|
||||
fsTimeH -= timeComp/TMWORD_FRAC_MAX;
|
||||
timeComp %= TMWORD_FRAC_MAX;
|
||||
fsTimeH -= timeComp/TIME_FRAC_MAX;
|
||||
timeComp %= TIME_FRAC_MAX;
|
||||
fsTimeH = (fsTimeL < timeComp)?(fsTimeH - 1):fsTimeH;
|
||||
fsTimeL = (fsTimeL < timeComp)?(TMWORD_FRAC_MAX + fsTimeL - timeComp) : (fsTimeL - timeComp);
|
||||
fsTimeL = (fsTimeL < timeComp)?(TIME_FRAC_MAX + fsTimeL - timeComp) : (fsTimeL - timeComp);
|
||||
memcpy(txMsgBuff+DSEGRD_TIME_OFFSET, &fsTimeL, DSEGRD_TIME_LEN/2);
|
||||
memcpy(txMsgBuff+DSEGRD_TIME_OFFSET + DSEGRD_TIME_LEN/2, &fsTimeH, DSEGRD_TIME_LEN/2);
|
||||
|
||||
// Doppler Estimate
|
||||
double doppler = Phy_GetCoarseFreqEst(instPtr->phyInstPtr);
|
||||
double doppler = Phy_GetFreqEst(instPtr->phyInstPtr);
|
||||
// LSB = 0.001Hz
|
||||
int64_t dopplerQnt = doppler*1000;
|
||||
memcpy(txMsgBuff+DSEGRD_DPL_OFFSET, &dopplerQnt, DSEGRD_DPL_LEN);
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
#define WAKE_CMD_LPW_UP 0xCCCC
|
||||
|
||||
// mode swicth command
|
||||
#define INTER_MSG_MODESW_LEN 0x0016 // 20byte + crc
|
||||
#define INTER_MSG_MODESW_LEN 0x0018 // 22byte + crc
|
||||
#define INTER_MSG_MODESW_CODE 0x0041
|
||||
#define MODESW_START_TIME_OFFSET 0x0002
|
||||
#define MODESW_START_TIME_LEN 0x0008
|
||||
@@ -75,6 +75,14 @@
|
||||
#define MODESW_MODE_LEN 0x0002
|
||||
#define MODESW_MODE_NORMAL 0x0001
|
||||
#define MODESW_MODE_NETSET 0x0002
|
||||
#define MODESW_POWER_OFFSET 0x0014
|
||||
#define MODESW_POWER_LEN 0x0001
|
||||
#define MODESW_POWER_LOW 0xAA
|
||||
#define MODESW_POWER_FULL 0xCC
|
||||
#define MODESW_RXATT_OFFSET 0x0015
|
||||
#define MODESW_RXATT_LEN 0x0001
|
||||
#define MODESW_RXATT_MAX 0x1F
|
||||
#define MODESW_TXATT_SKIP 0xFF
|
||||
|
||||
// physical layer control
|
||||
#define INTER_MSG_CTRL_LEN 0x00BC // 186byte + 2byte crc
|
||||
@@ -108,11 +116,10 @@
|
||||
#define CTRL_TOR_TX 0xAA
|
||||
#define CTRL_TOR_RX 0xCC
|
||||
|
||||
#define INTER_MSG_CTRL_SW_OFFSET 0x000D
|
||||
#define INTER_MSG_CTRL_SW_LEN 0x0001
|
||||
#define CTRL_SW_PW BIT(0)
|
||||
#define CTRL_SW_TR BIT(1)
|
||||
#define CTRL_SW_TOR BIT(2)
|
||||
#define INTER_MSG_CTRL_POWER_OFFSET 0x000D
|
||||
#define INTER_MSG_CTRL_POWER_LEN 0x0001
|
||||
#define CTRL_POWER_LOW 0xAA
|
||||
#define CTRL_POWER_FULL 0xCC
|
||||
|
||||
#define INTER_MSG_CTRL_HOP_MODE_OFFSET 0x000E
|
||||
#define INTER_MSG_CTRL_HOP_MODE_LEN 0x0002
|
||||
@@ -132,8 +139,12 @@
|
||||
#define INTER_MSG_CTRL_BEAM_NO_OFFSET 0x00B3
|
||||
#define INTER_MSG_CTRL_BEAM_NO_LEN 0x0001
|
||||
|
||||
#define INTER_MSG_CTRL_AMP_WT_OFFSET 0x00B4
|
||||
#define INTER_MSG_CTRL_AMP_WT_LEN 0x0002
|
||||
#define INTER_MSG_CTRL_RXATT_OFFSET 0x00B4
|
||||
#define INTER_MSG_CTRL_RXATT_LEN 0x0001
|
||||
#define INTER_MSG_CTRL_RXATT_MAX 0x1F
|
||||
#define INTER_MSG_CTRL_TXATT_OFFSET 0x00B5
|
||||
#define INTER_MSG_CTRL_TXATT_LEN 0x0001
|
||||
#define INTER_MSG_CTRL_TXATT_MAX 0x1F
|
||||
|
||||
#define INTER_MSG_CTRL_OFFAX_OFFSET 0x00B6
|
||||
#define INTER_MSG_CTRL_OFFAX_LEN 0x0002
|
||||
|
||||
@@ -747,7 +747,7 @@ int main(void) {
|
||||
else{
|
||||
Status = InterComm_MsgHandler(intrCommInstPtr);
|
||||
if(Status != SUCCESS){
|
||||
DBG_PRINT("####\tInterComm message handler finished with code: %d\n\r", Status);
|
||||
DBG_PRINT("####\tInterComm message handler finished with code: %d\n", Status);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user