Compare commits

...
15 Commits
19 changed files with 170 additions and 115 deletions
+1 -1
View File
@@ -40,6 +40,6 @@
*
******************************************************************************/
void AppAssert(const char * file, int line){
DBG_PRINT("in %s #%4d [assert] .\n",file, line);
DBG_PRINT("[assert]\tin %s:%4d.\n",file, line);
while(1);
}
+1 -1
View File
@@ -43,7 +43,7 @@
#endif
#if _814_DEBUG_LEVEL >= 1
#define DBG_ERROR(...) __PRINT_BLOCK( \
printf("[error]\tin"__FILE__":%4d ",__LINE__); \
printf("[error]\tin "__FILE__":%4d ",__LINE__); \
printf(__VA_ARGS__); \
)
#endif
+1
View File
@@ -59,6 +59,7 @@
#define PHY_DEVICE_ID 0
// Interrupt Configs
#define PHY_INTR_ID XPAR_FABRIC_PHY_IRQ_INTR
#define PERIODIC_5MS_INTR_ID XPAR_FABRIC_PHY_5MS_DELAY_2MS_INTR
#define MPC_RX_DONE_INTR_ID XPAR_FABRIC_MPC_IRQ_INTR
#define MPC_BUFFER_LENGTH (XPAR_MPC_BRAM_INTERFACE_MPC_BRAM_CTRL_S_AXI_HIGHADDR \
+6 -12
View File
@@ -296,9 +296,6 @@ void L2_FrameStateUpdate(L2_INST* instPtr) {
ASSERT(instPtr != NULL);
PHY_INST* phyRef = instPtr->config.phyInstPtr;
// Update physical layer status.
// Phy_UpdateState(phyRef);
// Update frame state.
if (Phy_IsFrameValid(phyRef) == false) {
L2_DataAvailUpdate(instPtr, false);
@@ -450,8 +447,9 @@ int32_t L2_SetupNextSlot(L2_INST* instPtr, L2_TOR_TYPE txrxMode, L2_FRAME_TYPE f
#endif
// Update frame and tx/rx mode record.
instPtr->frame.next = frameType;
instPtr->tor.next = txrxMode;
// Frame types shift (last <- curr <- next)
L2_RcdShift(&(instPtr->frame), frameType);
L2_RcdShift(&(instPtr->tor), txrxMode);
TIME_WORD pullTime = {0, 0};
pullTime.int_part = TimeCtrl_GetIntCnt(instPtr->config.tmcInstPtr) + 1;
@@ -1106,6 +1104,9 @@ int32_t Linklayer_Proc(L2_INST* instPtr) {
return SUCCESS;
}
// Update slot number.
L2_UpdateSlotNum(instPtr);
DBG_INFO("######## Current frameNum: %u, SlotNo: %u ########\n",
instPtr->frameNum.curr, instPtr->slotNum.curr);
@@ -1140,13 +1141,6 @@ int32_t Linklayer_Proc(L2_INST* instPtr) {
// Check and execute scheduled event.
L2_EventPoolHandler(instPtr);
// Update slot number.
L2_UpdateSlotNum(instPtr);
// Frame types shift (last <- curr <- next)
L2_RcdShift(&(instPtr->frame), L2_NONE_FRAME);
L2_RcdShift(&(instPtr->tor), L2_TOR_SUSPEND);
// Update link layer state.
instPtr->mainState = instPtr->nextState;
+4 -4
View File
@@ -584,11 +584,11 @@ int32_t ScanNet_PktHandler(L2_INST* instPtr) {
switch (L2_GetLastFrameType(instPtr)) {
case L2_INTER_SCAN_FRAME:
case L2_INTRA_SCAN_FRAME:
// refer to "linklayer814.c/L2_FrameStateUpdate"
// INTRA_BM_FRAME could be received if current frame type is INTRA_BM_FRAME
// in net setup stage(for member node).
// INTRA_BM_FRAME could be received if current frame type is L2_INTRA_SCAN_FRAME
// in net setup stage (for member node).
// When SCAN frame was considered as received, handle the frame as BM frame.
break;
LockStateUpdate(scanFsmPtr, true);
StageUpdate(scanFsmPtr, L2_SCAN_BMADVT_STAGE);
case L2_INTER_BM_FRAME:
case L2_INTRA_BM_FRAME: {
for (int i = 0; i < ARRAY_SIZE(intraBmFrameMsgs); i++) {
+18 -6
View File
@@ -45,11 +45,23 @@ static void entry_free(void* val){
/**
* @brief helper function to match node entries by nodeIds
*/
static bool entry_match(void* a, void* b){
static int8_t entry_compare(void* a, void* b){
ASSERT(a != NULL);
ASSERT(b != NULL);
return (((NODE_ENTRY*)a)->nodeInfo.nodeId
== ((NODE_ENTRY*)b)->nodeInfo.nodeId);
register uint8_t idA, idB;
idA = ((NODE_ENTRY*)a)->nodeInfo.nodeId;
idB = ((NODE_ENTRY*)b)->nodeInfo.nodeId;
if (idA == idB)
{
return 0;
}
else if(idA < idB) {
return -1;
}
else {
return 1;
}
}
/*****************************************************************************/
/**
@@ -67,7 +79,7 @@ int32_t L2_NodeList_Init(NODE_LIST **list) {
return ENOMEM;
}
(*list)->free = entry_free;
(*list)->match = entry_match;
(*list)->compare = entry_compare;
return SUCCESS;
}
@@ -98,7 +110,7 @@ void L2_NodeList_Destroy(NODE_LIST *list){
}
/*****************************************************************************/
/**
* @brief Get node entry frome node list base on node id.
* @brief Get node entry from node list base on node id.
*
* @param list
* @param nodeId
@@ -334,7 +346,7 @@ int32_t L2_GetNodeSpeed(NODE_LIST *list, uint8_t nodeId, COORD *speed) {
*
* @param list
* @param nodeId
* @param defl
* @param devi
*
* @return SUCCESS update successfully.
* FAILURE Node not exist.
+16 -6
View File
@@ -40,11 +40,21 @@ static void schdevent_free(void* val){
/**
* @brief helper function to match events by ids.
*/
static bool schdevent_match(void* a, void* b){
static int8_t schdevent_compare(void* a, void* b){
ASSERT(a == NULL);
ASSERT(b != NULL);
return (((L2_SCHD_EVENT*)a)->eventId
== ((L2_SCHD_EVENT*)b)->eventId);
register uint32_t idA, idB;
idA = ((L2_SCHD_EVENT*)a)->eventId;
idB = ((L2_SCHD_EVENT*)b)->eventId;
if( idA== idB) {
return 0;
}
else if (idA < idB) {
return -1;
}
else {
return 1;
}
}
/*****************************************************************************/
@@ -69,7 +79,7 @@ int32_t L2_CreateSchedEventPool(L2_SCHD_POOL** schdPool) {
return EALLOC;
}
(*schdPool)->schdList->free = schdevent_free;
(*schdPool)->schdList->match = schdevent_match;
(*schdPool)->schdList->compare = schdevent_compare;
(*schdPool)->envCnt = 0;
return SUCCESS;
}
@@ -137,7 +147,7 @@ L2_SCHD_EVENT* L2_CreatNewSchdEvent(L2_SCHD_POOL* schdPool, L2_EVENT_TYPE event,
return NULL;
}
schdEvent->eventId = schdPool->envCnt++;
schdEvent->ocurrCnt = 0;
schdEvent->occurCnt = 0;
schdEvent->l2Event.event = event;
schdEvent->l2Event.msg = NULL;
schdEvent->isSchd = false;
@@ -327,7 +337,7 @@ void L2_EventPoolHandler(L2_INST* instPtr){
list_remove(pool->schdList, node);
}
else {
event->ocurrCnt++;
event->occurCnt++;
}
}
}
+1 -1
View File
@@ -32,7 +32,7 @@ typedef struct {
bool isVolatile;
L2_EVENT l2Event;
uint32_t eventId;
uint32_t ocurrCnt;
uint32_t occurCnt;
uint32_t schdFrame;
uint32_t schdSlot;
} L2_SCHD_EVENT;
+8 -8
View File
@@ -60,7 +60,7 @@ static void RTT_GetFrameStart(L2_INST* instPtr, TIME_WORD *tmStamp, L2_TOR_TYPE
int32_t L2_TimeAlign(L2_INST* instPtr, uint32_t frameNum, uint32_t slotNum){
L1_FRAME_TYPE lastRecvdFrame;
lastRecvdFrame = Phy_GetLastRecvFrameType(instPtr->config.phyInstPtr);
if(lastRecvdFrame != L1_NONE_FRAME){
if(lastRecvdFrame == L1_NONE_FRAME){
return EIGNORE;
}
@@ -68,17 +68,17 @@ int32_t L2_TimeAlign(L2_INST* instPtr, uint32_t frameNum, uint32_t slotNum){
uint64_t currTime, expctTime;
int64_t timeDiff;
TIME_WORD timeStamp, slotTimerAdjmet;
expctTime = ((uint64_t)(frameNum*L2_SLOTS_PER_FRAME + slotNum))*COUNTE_FRAC_MAX;
expctTime = ((uint64_t)(frameNum*L2_SLOTS_PER_FRAME + slotNum))*TIME_FRAC_MAX;
expctTime += Phy_GetTimeComp(lastRecvdFrame);
Phy_GetFrameSyncTimeStamp(instPtr->config.phyInstPtr, &timeStamp);
currTime = (uint64_t)timeStamp.frac_part;
currTime += ((uint64_t)timeStamp.int_part) * COUNTE_FRAC_MAX;
currTime += ((uint64_t)timeStamp.int_part) * TIME_FRAC_MAX;
timeDiff = (int64_t)(expctTime - currTime);
slotTimerAdjmet.int_part = (uint32_t)(timeDiff / COUNTE_FRAC_MAX);
slotTimerAdjmet.frac_part = (uint32_t)(timeDiff % COUNTE_FRAC_MAX);
slotTimerAdjmet.int_part = (uint32_t)(timeDiff / TIME_FRAC_MAX);
slotTimerAdjmet.frac_part = (uint32_t)(timeDiff % TIME_FRAC_MAX);
TimeCtrl_TimeAdjust(instPtr->config.tmcInstPtr, &slotTimerAdjmet, TM_ADJ_ADD);
return SUCCESS;
}
@@ -164,13 +164,13 @@ void RTT_GetFrameStart(L2_INST* instPtr, TIME_WORD *tmStamp, L2_TOR_TYPE torType
int64_t timeDiff;
Phy_GetFrameSyncTimeStamp(phyRef, &timeStamp);
timeDiff = (uint64_t) timeStamp.frac_part;
timeDiff += ((uint64_t)timeStamp.int_part) * COUNTE_FRAC_MAX;
timeDiff += ((uint64_t)timeStamp.int_part) * TIME_FRAC_MAX;
Phy_GetLastSlotStartTimeStamp(phyRef, tmStamp);
timeDiff -= ((uint64_t) tmStamp->int_part) * COUNTE_FRAC_MAX;
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 += COUNTE_FRAC_MAX;
timeDiff += TIME_FRAC_MAX;
tmStamp->int_part--;
_nop_();
}
+42 -33
View File
@@ -69,6 +69,7 @@ MPC_CONFIG mpcConfig = {
static bool mpcStatusUpAssert = false;
/************************** Function Prototypes ******************************/
int SetupInterruptSystem(XScuGic* instPtr, uint32_t devId);
void PhysicalIntr_Handler(void *callBackRef);
void PeriodicPull_Handler(void *callBackRef);
#ifdef _MPC_CTRL
void MPC_IntrHandler(void* CallBackRef);
@@ -134,29 +135,41 @@ int SetupInterruptSystem(XScuGic* instPtr, uint32_t devId){
* rising edge 0x03.
*/
// Initialize physical layer interrupt.
XScuGic_SetPriorityTriggerType(instPtr, PHY_INTR_ID, 0x00, 0x03);
// Connect the interrupt service routine isr1 to the interrupt controller
Status = XScuGic_Connect(instPtr, PHY_INTR_ID,
(Xil_ExceptionHandler) PhysicalIntr_Handler, (void *) phyInstPtr);
if (Status != SUCCESS) {
return Status;
}
// Initialize physical layer interrupt.
XScuGic_SetPriorityTriggerType(instPtr, PERIODIC_5MS_INTR_ID, 0x00, 0x03);
// Connect the interrupt service routine isr1 to the interrupt controller
Status = XScuGic_Connect(instPtr, PERIODIC_5MS_INTR_ID,
(Xil_ExceptionHandler) PeriodicPull_Handler, (void *) instPtr);
(Xil_ExceptionHandler) PeriodicPull_Handler, (void *) linkInstPtr);
if (Status != SUCCESS) {
return Status;
}
XScuGic_Enable(instPtr, PERIODIC_5MS_INTR_ID);
#ifdef _MPC_CTRL
// Initialize MPC interrupt.
XScuGic_SetPriorityTriggerType(instPtr, MPC_RX_DONE_INTR_ID, 0x00, 0x03);
// Connect the interrupt service routine isr1 to the interrupt controller
Status = XScuGic_Connect(instPtr, MPC_RX_DONE_INTR_ID,
(Xil_ExceptionHandler) MPC_IntrHandler, (void *) instPtr);
(Xil_ExceptionHandler) MPC_IntrHandler, (void *) mpcInstPtr);
if (Status != XST_SUCCESS) {
return Status;
}
XScuGic_Enable(instPtr, MPC_RX_DONE_INTR_ID);
#endif
XScuGic_Enable(instPtr, PHY_INTR_ID);
XScuGic_Enable(instPtr, PERIODIC_5MS_INTR_ID);
/* Initialize the exception table and register the interrupt controller
* handler with the exception table
*/
@@ -185,7 +198,7 @@ void MPC_PCIESentStart(){
/**
* @brief Handler of mater pc contrl interrupt.
*
* @param CallBackRef A pointer to corresponding frame UART instance.
* @param CallBackRef A pointer to corresponding mpcInstPtr instance.
*
* @return None.
*
@@ -195,22 +208,21 @@ void MPC_IntrHandler(void* CallBackRef) {
}
#endif
/****************************************************************************/
/*****************************************************************************/
/**
* This function is a interrupt service routine for IRQ_F2P[1:1], IRQ_F2P[1:1]
* tells CPU that the data in OCM is ready!
* @brief Handler of physical layer interrupt.
*
* @param callBackRef is the SCUGIC instance pointer.
* @param CallBackRef A pointer to corresponding physical layer instance.
*
* @return None.
* @return None.
*
* @note None.
*
*****************************************************************************/
void PeriodicPull_Handler(void *callBackRef) {
int32_t Status;
Phy_UpdateState(phyInstPtr);
******************************************************************************/
void PhysicalIntr_Handler(void *callBackRef) {
uint32_t GpioConfig = XGpio_DiscreteRead(&configGpio, 2);
if(L2_isDataAvail(linkInstPtr) == true ){
GpioConfig^=0x00000001;
}
Phy_UpdateState(phyInstPtr);
if(phyInstPtr->TOR.curr == PHY_TOR_TX){
switch(phyInstPtr->frameType.curr){
case L1_1M2BPS_5MS_FRAME:
@@ -271,17 +283,27 @@ void PeriodicPull_Handler(void *callBackRef) {
break;
}
}
XGpio_DiscreteWrite(&configGpio, 2, GpioConfig);
}
/****************************************************************************/
/**
* Handler of periodic 5ms interrupt
*
* @param callBackRef is the linklayer instance pointer.
*
* @return None.
*
*****************************************************************************/
void PeriodicPull_Handler(void *callBackRef) {
int32_t Status;
Status = Linklayer_Proc(linkInstPtr);
if(Status != SUCCESS){
DBG_ERROR("Link layer runs failed, with error code: %ld\n", Status);
_nop_();
}
if(L2_isDataAvail(linkInstPtr) == true ){
GpioConfig^=0x00000001;
}
if (linkInstPtr->slotNum.next % DATA_STORE_INTERVAL == 1) {
mpcStatusUpAssert = true;
mpcRecord->frame1Cnt = mpcRecord->frame1Recv - mpcRecord->frame1CntLast;
@@ -303,11 +325,6 @@ void PeriodicPull_Handler(void *callBackRef) {
mpcRecord->frame7CntLast = mpcRecord->frame7Recv;
mpcRecord->frame8CntLast = mpcRecord->frame8Recv;
}
// TODO: Dijian frequency pattern TX_RX State.
GpioConfig ^= 0x80000000;
GpioConfig = (phyInstPtr->TOR.next == PHY_TOR_TX) ? GpioConfig|0x40000000 : GpioConfig&0xBFFFFFFF;
XGpio_DiscreteWrite(&configGpio, 2, GpioConfig);
} // PhyIntr_Handler
/*****************************************************************************/
@@ -392,18 +409,10 @@ int main(void) {
return Status;
}
Status = Phy_SetMode(phyInstPtr, PHY_MODE_SCHEDULE);
if (Status == SUCCESS) {
DBG_PRINT("Physical Mode %u Setup SUCCESS! \n", PHY_MODE_LISTEN);
}
else {
DBG_PRINT("Physical Mode %u Setup FAILED! \n", PHY_MODE_LISTEN);
return Status;
}
DBG_PRINT("Starting Physical Layer...");
Phy_Start(phyInstPtr);
// FIXME: only for debug, linklayer should be start by MPC
Linklayer_Start(linkInstPtr);
while(true) {
+37 -13
View File
@@ -242,12 +242,6 @@ void Phy_UpdateState(PHY_INST* instPtr) {
else {
instPtr->isValid = false;
}
Phy_RcdShift(&(instPtr->TOR),PHY_TOR_SUSPEND);
Phy_RcdShift(&(instPtr->frameType),L1_NONE_FRAME);
Phy_RcdShift(&(instPtr->antNo), INIT_ANT_NO);
Phy_RcdShift(&(instPtr->beamNo), INIT_BEAM_NO);
Phy_RcdShift(&(instPtr->beamWd), INIT_ANT_WD);
}
@@ -586,6 +580,13 @@ int32_t Phy_SetupNextSlot(PHY_INST* instPtr, PHY_TOR_TYPE txrxMode,
}
}
PhyWrite(instPtr, SLOT_CMD, SLOT_CMD_KEY); // Phy statr fetching data.
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);
return SUCCESS;
}
@@ -596,8 +597,7 @@ int32_t Phy_SetupNextSlot(PHY_INST* instPtr, PHY_TOR_TYPE txrxMode,
*
* @param instPtr a pointer to physical instance
*
* @return SUCCESS If load the data successfully.
* FAILURE If last receive frame is not valid.
* @return frequency estimation
*
******************************************************************************/
@@ -626,7 +626,7 @@ double Phy_GetCoarseFreqEst(PHY_INST* instPtr) {
freqEst = acqFreqIdx*(250e3/4);
freqEst += (double)syncFreqIdx*12e6/64/128;
}
return freqEst;
}
@@ -786,17 +786,20 @@ void Phy_GetLastSlotStartTimeStamp(PHY_INST* instPtr, TIME_WORD* slotStart) {
/*****************************************************************************/
/**
* @brief Get received data (base on PL Record), store it to data buffer.
* @brief Copy ans store the received data, if received data valid.
*
* @param instPtr a pointer to physical layer control instance.
*
* @return SUCCESS
* FAILURE last frame type cannot be recognized.
* @return NONE
*
******************************************************************************/
void Phy_RetrieveRecvData(PHY_INST* instPtr, uint8_t* dataBuff) {
void Phy_PeekRecvData(PHY_INST* instPtr, uint8_t* dataBuff) {
ASSERT(instPtr != NULL);
ASSERT(dataBuff != NULL);
if (instPtr->isValid == false)
{
return;
}
uint32_t frameLen, offset;
frameLen = (PhyRead(instPtr, RECVDATA_STATE) & RECVDATA_STATE_LEN_MASK) >> RECVDATA_STATE_LEN_SHIFT;
@@ -804,3 +807,24 @@ void Phy_RetrieveRecvData(PHY_INST* instPtr, uint8_t* dataBuff) {
memcpy(dataBuff, (uint8_t*)(instPtr->recvDataAddr + offset), frameLen);
}
/*****************************************************************************/
/**
* @brief Get the received data (if valid), store it to data buffer.
* and clear data valid flag.
*
* @param instPtr a pointer to physical layer control instance.
*
* @return NONE
*
******************************************************************************/
void Phy_RetrieveRecvData(PHY_INST* instPtr, uint8_t* dataBuff) {
ASSERT(instPtr != NULL);
ASSERT(dataBuff != NULL);
if (instPtr->isValid == false)
{
return;
}
Phy_PeekRecvData(instPtr, dataBuff);
instPtr->isValid = false;
}
+1
View File
@@ -242,6 +242,7 @@ void Phy_Halt(PHY_INST* instPtr);
int32_t Phy_SetMode(PHY_INST* instPtr, PHY_MODE modeCod);
int32_t Phy_SetupNextSlot(PHY_INST* instPtr, PHY_TOR_TYPE txrxMode, L1_FRAME_TYPE frameType, uint8_t* dataBuff);
void Phy_PeekRecvData(PHY_INST* instPtr, uint8_t* dataBuff);
void Phy_RetrieveRecvData(PHY_INST* instPtr, uint8_t* dataBuff);
bool Phy_IsFrameDetected(PHY_INST* instPtr);
+8 -7
View File
@@ -194,9 +194,10 @@ void TimeCtrl_TimeAdjust(TIMECTRL_INST *instPtr, const TIME_WORD* tmWord, TIMECT
DBG_ERROR("Unsupported adjustment type: %d", type);
return;
}
if(((int32_t)tmWord->frac_part) > COUNTE_FRAC_MAX ) {
DBG_ERROR("Invalid fractional value 0x%08X (should <= 0x%08X).\n",
tmWord->frac_part, COUNTE_FRAC_MAX);
if(((int32_t)tmWord->frac_part) > TIME_FRAC_MAX
|| ((int32_t)tmWord->frac_part) < -TIME_FRAC_MAX) {
DBG_WARNING("Invalid fractional value %d (should between %d~%d)\n",
tmWord->frac_part, -TIME_FRAC_MAX, TIME_FRAC_MAX);
return;
}
TMC_Write(instPtr, TIME_ADJ_FRAC, tmWord->frac_part);
@@ -238,9 +239,9 @@ void TimeCtrl_CalculateTimeGap(const TIME_WORD *a, const TIME_WORD *b, TIME_WORD
ASSERT(gap != NULL);
uint64_t timeDiff;
timeDiff = (uint64_t) b->frac_part;
timeDiff += ((uint64_t)b->int_part) * COUNTE_FRAC_MAX;
timeDiff -= ((uint64_t)a->int_part) * COUNTE_FRAC_MAX;
timeDiff += ((uint64_t)b->int_part) * TIME_FRAC_MAX;
timeDiff -= ((uint64_t)a->int_part) * TIME_FRAC_MAX;
timeDiff -= (uint64_t) a->frac_part;
gap->frac_part = (TIME_FRAC)(timeDiff % COUNTE_FRAC_MAX);
gap->frac_part = (TIME_INT)(timeDiff / COUNTE_FRAC_MAX);
gap->frac_part = (TIME_FRAC)(timeDiff % TIME_FRAC_MAX);
gap->frac_part = (TIME_INT)(timeDiff / TIME_FRAC_MAX);
}
+1 -1
View File
@@ -21,7 +21,7 @@
/***************************** Include Files *********************************/
#include <stdint.h>
/************************** Constant Definitions *****************************/
#define COUNTE_FRAC_MAX 500000 // how many 10ns in a 5ms
#define TIME_FRAC_MAX 500000 // how many 10ns in a 5ms
/***************** Macros (Inline Functions) Definitions *********************/
/**************************** Type Definitions *******************************/
typedef enum {
+4 -3
View File
@@ -12,6 +12,7 @@
// Copyright (c) 2010 TJ Holowaychuk <[email protected]>
//
#include <stdint.h>
#include "list.h"
/*
@@ -41,7 +42,7 @@ list_new(void) {
self->head = NULL;
self->tail = NULL;
self->free = NULL;
self->match = NULL;
self->compare = NULL;
self->len = 0;
return self;
}
@@ -181,8 +182,8 @@ list_find(list_t *self, void *val) {
list_node_t *node;
while ((node = list_iterator_next(it))) {
if (self->match) {
if (self->match(val, node->val)) {
if (self->compare) {
if (self->compare(val, node->val) == 0) {
list_iterator_destroy(it);
return node;
}
+1 -2
View File
@@ -13,7 +13,6 @@ extern "C" {
#endif
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
/*
@@ -44,7 +43,7 @@ typedef struct {
list_node_t *tail;
uint32_t len;
void (*free)(void *val);
bool (*match)(void *a, void *b);
int8_t (*compare)(void *a, void *b);
} list_t;
/*
@@ -371,30 +371,33 @@ TEST(linklayer_master_routine) {
for(int i = 0; i < 200*30; i++) {
tmcReg[TIME_INT_REG]++;
if (L2_GetLastTor(linkInstPtr) == L2_TOR_TX)
if (L2_GetNextTor(linkInstPtr) == L2_TOR_TX)
{
if (L2_GetLastFrameType(linkInstPtr) == L2_INTRA_TSYNC_FRAME)
if (L2_GetNextFrameType(linkInstPtr) == L2_INTRA_TSYNC_FRAME)
{
TimeCtrl_GetCurrentTime(tmcInstPtr, &timeStampA);
timeStampA.int_part--;
// 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.
}
}
if (L2_GetLastTor(linkInstPtr) == L2_TOR_RX)
if (L2_GetCurrentTor(linkInstPtr) == L2_TOR_RX)
{
if(L2_GetLastFrameType(linkInstPtr) == L2_INTRA_W2_ACQ_FRAME) {
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_GetLastFrameType(linkInstPtr) == L2_INTRA_MGMT_FRAME)
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_GetLastFrameType(linkInstPtr) == L2_INTRA_TSYNC_FRAME)
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);
@@ -405,7 +408,7 @@ TEST(linklayer_master_routine) {
PhyWrite(phyInstPtr, RECVDATA_STATE, INTRA_MGMT_FRAME_LENGTH_MAX);
}
if (L2_GetLastFrameType(linkInstPtr) == L2_INTRA_SVC_FRAME)
if (L2_GetCurrentFrameType(linkInstPtr) == L2_INTRA_SVC_FRAME)
{
forge_mgmt_frame((uint8_t*)phyInstPtr->recvDataAddr, L2_NORMAL_STATE);
PhyWrite(phyInstPtr, TXRX_STATE, 0x01010101);
@@ -45,7 +45,7 @@ TEST(tmc_read_time) {
}
else {
ASSERT_EQUAL(timeH, timeStamp.int_part+1);
ASSERT_TRUE(timeL + COUNTE_FRAC_MAX - timeStamp.frac_part < MAX_OPT_DELAY);
ASSERT_TRUE(timeL + TIME_FRAC_MAX - timeStamp.frac_part < MAX_OPT_DELAY);
}
}
@@ -69,14 +69,14 @@ TEST(tmc_adjustment) {
ASSERT_EQUAL(timeAdj.int_part, timeStampPost.int_part);
ASSERT_TRUE(timeStampPost.frac_part < MAX_OPT_DELAY);
timeAdj.frac_part = COUNTE_FRAC_MAX;
timeAdj.frac_part = TIME_FRAC_MAX;
timeAdj.int_part = 0x00000203;
TimeCtrl_TimeAdjust(tmcInstPtr, &timeAdj, TM_ADJ_SET);
TimeCtrl_GetCurrentTime(tmcInstPtr, &timeStampPost);
ASSERT_EQUAL(timeAdj.int_part, timeStampPost.int_part+1);
ASSERT_TRUE(timeStampPost.frac_part < MAX_OPT_DELAY);
timeAdj.frac_part = COUNTE_FRAC_MAX*2;
timeAdj.frac_part = TIME_FRAC_MAX*2;
timeAdj.int_part = 0x00000203;
TimeCtrl_GetCurrentTime(tmcInstPtr, &timeStampPre);
TimeCtrl_TimeAdjust(tmcInstPtr, &timeAdj, TM_ADJ_SET);
@@ -87,7 +87,7 @@ TEST(tmc_adjustment) {
}
else {
ASSERT_EQUAL(timeStampPost.int_part, timeStampPre.int_part + 1);
ASSERT_TRUE(timeStampPost.frac_part + COUNTE_FRAC_MAX - timeStampPre.frac_part < MAX_OPT_DELAY);
ASSERT_TRUE(timeStampPost.frac_part + TIME_FRAC_MAX - timeStampPre.frac_part < MAX_OPT_DELAY);
}
// Adjustment -- add
@@ -96,9 +96,9 @@ TEST(tmc_adjustment) {
TimeCtrl_GetCurrentTime(tmcInstPtr, &timeStampPre);
TimeCtrl_TimeAdjust(tmcInstPtr, &timeAdj, TM_ADJ_ADD);
TimeCtrl_GetCurrentTime(tmcInstPtr, &timeStampPost);
if(timeStampPre.frac_part + timeAdj.frac_part > COUNTE_FRAC_MAX) {
if(timeStampPre.frac_part + timeAdj.frac_part > TIME_FRAC_MAX) {
ASSERT_TRUE(timeStampPost.int_part <= timeStampPre.int_part + timeAdj.int_part + 2);
ASSERT_TRUE(timeStampPost.frac_part + COUNTE_FRAC_MAX - timeStampPre.frac_part
ASSERT_TRUE(timeStampPost.frac_part + TIME_FRAC_MAX - timeStampPre.frac_part
< MAX_OPT_DELAY + timeAdj.frac_part);
}
@@ -107,9 +107,9 @@ TEST(tmc_adjustment) {
TimeCtrl_GetCurrentTime(tmcInstPtr, &timeStampPre);
TimeCtrl_TimeAdjust(tmcInstPtr, &timeAdj, TM_ADJ_ADD);
TimeCtrl_GetCurrentTime(tmcInstPtr, &timeStampPost);
if(timeStampPre.frac_part + timeAdj.frac_part > COUNTE_FRAC_MAX) {
if(timeStampPre.frac_part + timeAdj.frac_part > TIME_FRAC_MAX) {
ASSERT_TRUE(timeStampPost.int_part <= timeStampPre.int_part + timeAdj.int_part + 2);
ASSERT_TRUE(timeStampPost.frac_part + COUNTE_FRAC_MAX - timeStampPre.frac_part
ASSERT_TRUE(timeStampPost.frac_part + TIME_FRAC_MAX - timeStampPre.frac_part
< MAX_OPT_DELAY + timeAdj.frac_part);
}
}
@@ -57,7 +57,7 @@ TEST(tmc_basic_operations) {
}
else {
ASSERT_EQUAL(timeH, timeStamp.int_part+1);
ASSERT_TRUE(timeL + COUNTE_FRAC_MAX - timeStamp.frac_part < MAX_OPT_DELAY);
ASSERT_TRUE(timeL + TIME_FRAC_MAX - timeStamp.frac_part < MAX_OPT_DELAY);
}
TIME_FRAC stepOpt;