simplified function signature.
This commit is contained in:
@@ -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,46 +384,63 @@ 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++) {
|
||||
for (int i = 0; i < 30 * L2_SLOTS_PER_FRAME; i++)
|
||||
{
|
||||
tmcReg[TIME_INT_REG]++;
|
||||
|
||||
if (L2_GetNextTor(linkInstPtr) == L2_TOR_TX)
|
||||
if (L2_GetNextTor(linkInstPtr) == L2_TOR_TX)
|
||||
{
|
||||
if (L2_GetNextFrameType(linkInstPtr) == L2_INTRA_TSYNC_FRAME)
|
||||
{
|
||||
TimeCtrl_GetCurrentTime(tmcInstPtr, &timeStampA);
|
||||
// ASSERT_EQUAL(linkInstPtr->rttFSM->rttRecord.Tt1.int_part + linkInstPtr->netStartTime*L2_SLOTS_PER_FRAME,
|
||||
// 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;
|
||||
Linklayer_Start(linkInstPtr);
|
||||
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);
|
||||
|
||||
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_slave_netsetup);
|
||||
RUN_TEST(linklayer_master_routine);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int main(void)
|
||||
{
|
||||
RUN_TEST_SUITE(linklayer_unit_test);
|
||||
TEST_REPORT();
|
||||
return TEST_EXIT_CODE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user