Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
729bbeb60e | ||
|
|
33545b63e1 | ||
|
|
6c64421336 | ||
|
|
dda9d09f2a | ||
|
|
14f2be3053 |
@@ -31,7 +31,7 @@
|
|||||||
#endif
|
#endif
|
||||||
/************************** Constant Definitions *****************************/
|
/************************** Constant Definitions *****************************/
|
||||||
#define NET_START_TIME_INFTY UINT32_MAX
|
#define NET_START_TIME_INFTY UINT32_MAX
|
||||||
#define LINK_BROCK_THRESHOLD (3 * 200) // 3 secods
|
#define LINK_BROCK_THRESHOLD L2_SLOTS_PER_FRAME // 0.5 secods
|
||||||
|
|
||||||
/************************** Variable Definitions *****************************/
|
/************************** Variable Definitions *****************************/
|
||||||
/***************** Macros (Inline Functions) Definitions *********************/
|
/***************** Macros (Inline Functions) Definitions *********************/
|
||||||
@@ -147,6 +147,15 @@ inline L2_NODE_STATE L2_GetMainState(L2_INST *instPtr)
|
|||||||
return instPtr->mainState;
|
return instPtr->mainState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if there is a valid l2 frame.
|
||||||
|
*/
|
||||||
|
inline bool L2_isStarted(L2_INST *instPtr)
|
||||||
|
{
|
||||||
|
ASSERT(instPtr != NULL);
|
||||||
|
return instPtr->isEnable;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check if there is a valid l2 frame.
|
* @brief Check if there is a valid l2 frame.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -155,6 +155,7 @@ uint8_t L2_GetClusterId(L2_INST *instPtr);
|
|||||||
uint8_t L2_GetHeadId(L2_INST *instPtr);
|
uint8_t L2_GetHeadId(L2_INST *instPtr);
|
||||||
L2_NODE_TYPE L2_GetNodeType(L2_INST *instPtr);
|
L2_NODE_TYPE L2_GetNodeType(L2_INST *instPtr);
|
||||||
L2_NODE_STATE L2_GetMainState(L2_INST *instPtr);
|
L2_NODE_STATE L2_GetMainState(L2_INST *instPtr);
|
||||||
|
bool L2_isStarted(L2_INST *instPtr);
|
||||||
bool L2_isDataAvail(L2_INST *instPtr);
|
bool L2_isDataAvail(L2_INST *instPtr);
|
||||||
bool L2_isCxn2Net(L2_INST *instPtr);
|
bool L2_isCxn2Net(L2_INST *instPtr);
|
||||||
uint32_t L2_GetFrameLen(L2_FRAME_TYPE l2FrameType);
|
uint32_t L2_GetFrameLen(L2_FRAME_TYPE l2FrameType);
|
||||||
|
|||||||
@@ -449,14 +449,18 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg)
|
|||||||
ASSERT(msg != NULL);
|
ASSERT(msg != NULL);
|
||||||
int32_t Status;
|
int32_t Status;
|
||||||
L2_SCAN_FSM *scanFsmPtr = instPtr->scanFSM;
|
L2_SCAN_FSM *scanFsmPtr = instPtr->scanFSM;
|
||||||
L2_FRAME_TYPE frameType = L2_GetLastOptFrameType(instPtr);
|
L2_FRAME_TYPE frameType = L2_NONE_FRAME;
|
||||||
|
L2_FrameGetChunk(msg, L2_MSG_TYPE, L2_MSG_TYPE_LEN, &frameType);
|
||||||
switch (frameType)
|
switch (frameType)
|
||||||
{
|
{
|
||||||
case L2_SCAN_FRAME:
|
case L2_SCAN_FRAME:
|
||||||
LockStateUpdate(scanFsmPtr, true);
|
|
||||||
StageUpdate(scanFsmPtr, L2_SCAN_ADV_STAGE);
|
|
||||||
case L2_ADV_FRAME:
|
case L2_ADV_FRAME:
|
||||||
{
|
{
|
||||||
|
if (L2_GetLastOptFrameType(instPtr) == L2_SCAN_FRAME)
|
||||||
|
{
|
||||||
|
LockStateUpdate(scanFsmPtr, true);
|
||||||
|
StageUpdate(scanFsmPtr, L2_SCAN_ADV_STAGE);
|
||||||
|
}
|
||||||
if (L2_GetNodeType(instPtr) == L2_NODE_HEAD)
|
if (L2_GetNodeType(instPtr) == L2_NODE_HEAD)
|
||||||
{
|
{
|
||||||
DBG_ERROR("Unexpected call from head node, only member Node can handle L2_SCAN_FRAME and L2_ADV_FRAME.\n");
|
DBG_ERROR("Unexpected call from head node, only member Node can handle L2_SCAN_FRAME and L2_ADV_FRAME.\n");
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ int32_t L2_Service_PktHandler(L2_INST *instPtr, uint8_t *msg)
|
|||||||
ASSERT(msg != NULL);
|
ASSERT(msg != NULL);
|
||||||
int32_t Status;
|
int32_t Status;
|
||||||
#ifndef DATALINK_ENABLE_BERTEST
|
#ifndef DATALINK_ENABLE_BERTEST
|
||||||
uint8_t frameType;
|
L2_FRAME_TYPE frameType = L2_NONE_FRAME;
|
||||||
L2_FrameGetChunk(msg, L2_MSG_TYPE, L2_MSG_TYPE_LEN, &frameType);
|
L2_FrameGetChunk(msg, L2_MSG_TYPE, L2_MSG_TYPE_LEN, &frameType);
|
||||||
switch (frameType)
|
switch (frameType)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -190,7 +190,6 @@
|
|||||||
|
|
||||||
#define LJ_RM_TEST_RESP_LEN 158
|
#define LJ_RM_TEST_RESP_LEN 158
|
||||||
|
|
||||||
|
|
||||||
// My Production Type
|
// My Production Type
|
||||||
#define MY_PRD_ID PRD_DL_K
|
#define MY_PRD_ID PRD_DL_K
|
||||||
|
|
||||||
@@ -238,7 +237,8 @@ static int32_t SystemBus_GenSelfTestRsp(SYSBUS *instPtr)
|
|||||||
{
|
{
|
||||||
ASSERT(instPtr != NULL);
|
ASSERT(instPtr != NULL);
|
||||||
SYSBUS_UART_FRAME *sysbusRsp = malloc(sizeof(SYSBUS_UART_FRAME));
|
SYSBUS_UART_FRAME *sysbusRsp = malloc(sizeof(SYSBUS_UART_FRAME));
|
||||||
if (sysbusRsp == NULL) {
|
if (sysbusRsp == NULL)
|
||||||
|
{
|
||||||
DBG_ERROR("Failed to allocate memory for SELF TEST Response!\n");
|
DBG_ERROR("Failed to allocate memory for SELF TEST Response!\n");
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
@@ -278,30 +278,21 @@ static int32_t SystemBus_SystemConfig(SYSBUS *instPtr, uint8_t *msg)
|
|||||||
PHY_INST *phyRef = linkInstPtr->config.phyInstPtr;
|
PHY_INST *phyRef = linkInstPtr->config.phyInstPtr;
|
||||||
TMC_INST *tmcRef = linkInstPtr->config.tmcInstPtr;
|
TMC_INST *tmcRef = linkInstPtr->config.tmcInstPtr;
|
||||||
bool reconfig = false;
|
bool reconfig = false;
|
||||||
bool start = false;
|
|
||||||
|
|
||||||
if (msg[WD_MODE_CMD] == MODE_CMD_HEAD)
|
if (msg[WD_MODE_CMD] == MODE_CMD_HEAD)
|
||||||
{
|
|
||||||
// omit unnecessary reconfiguration
|
|
||||||
if (L2_GetNodeType(linkInstPtr) != L2_NODE_HEAD)
|
|
||||||
{
|
{
|
||||||
// head node config
|
// head node config
|
||||||
|
reconfig = (L2_NODE_HEAD != linkConfig.myType);
|
||||||
linkConfig.myType = L2_NODE_HEAD;
|
linkConfig.myType = L2_NODE_HEAD;
|
||||||
linkConfig.myId = 1;
|
linkConfig.myId = 1;
|
||||||
reconfig = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (msg[WD_MODE_CMD] == MODE_CMD_MEMBER)
|
else if (msg[WD_MODE_CMD] == MODE_CMD_MEMBER)
|
||||||
{
|
|
||||||
// omit unnecessary reconfiguration
|
|
||||||
if (L2_GetNodeType(linkInstPtr) != L2_NODE_MEMBER)
|
|
||||||
{
|
{
|
||||||
// member node config
|
// member node config
|
||||||
|
reconfig = (L2_NODE_MEMBER != linkConfig.myType);
|
||||||
linkConfig.myType = L2_NODE_MEMBER;
|
linkConfig.myType = L2_NODE_MEMBER;
|
||||||
linkConfig.myId = 2;
|
linkConfig.myId = 2;
|
||||||
reconfig = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -313,21 +304,29 @@ static int32_t SystemBus_SystemConfig(SYSBUS *instPtr, uint8_t *msg)
|
|||||||
|
|
||||||
if (msg[WD_EN_CMD] == EN_CMD_ON_HIGH_POWER)
|
if (msg[WD_EN_CMD] == EN_CMD_ON_HIGH_POWER)
|
||||||
{
|
{
|
||||||
// high power config
|
// full power config
|
||||||
Phy_AntConfigMode(phyRef, PHY_ANT_MODE_POWER_FULL);
|
Phy_AntConfigMode(phyRef, PHY_ANT_MODE_POWER_FULL);
|
||||||
start = true;
|
if (reconfig || !L2_isStarted(linkInstPtr))
|
||||||
|
{
|
||||||
|
Linklayer_Reconfig(linkInstPtr, &linkConfig);
|
||||||
|
}
|
||||||
|
Linklayer_Start(linkInstPtr);
|
||||||
}
|
}
|
||||||
else if (msg[WD_EN_CMD] == EN_CMD_ON_LOW_POWER)
|
else if (msg[WD_EN_CMD] == EN_CMD_ON_LOW_POWER)
|
||||||
{
|
{
|
||||||
// low power config
|
// low power config
|
||||||
Phy_AntConfigMode(phyRef, PHY_ANT_MODE_POWER_LOW);
|
Phy_AntConfigMode(phyRef, PHY_ANT_MODE_POWER_LOW);
|
||||||
start = true;
|
reconfig = reconfig || (true != L2_isStarted(linkInstPtr));
|
||||||
|
if (reconfig || !L2_isStarted(linkInstPtr))
|
||||||
|
{
|
||||||
|
Linklayer_Reconfig(linkInstPtr, &linkConfig);
|
||||||
|
}
|
||||||
|
Linklayer_Start(linkInstPtr);
|
||||||
}
|
}
|
||||||
else if (msg[WD_EN_CMD] == EN_CMD_SILENT)
|
else if (msg[WD_EN_CMD] == EN_CMD_SILENT)
|
||||||
{
|
{
|
||||||
// silence config
|
// silence config
|
||||||
// TODO: better approach?
|
// TODO: better approach?
|
||||||
start = false;
|
|
||||||
Linklayer_Halt(linkInstPtr);
|
Linklayer_Halt(linkInstPtr);
|
||||||
Phy_AntConfigMode(phyRef, PHY_ANT_MODE_STANDBY);
|
Phy_AntConfigMode(phyRef, PHY_ANT_MODE_STANDBY);
|
||||||
TIME_WORD pullTime = {0, 0};
|
TIME_WORD pullTime = {0, 0};
|
||||||
@@ -338,14 +337,6 @@ static int32_t SystemBus_SystemConfig(SYSBUS *instPtr, uint8_t *msg)
|
|||||||
}
|
}
|
||||||
Phy_SetupNextSlot(phyRef, PHY_TOR_RX, L1_10KBPS_10MS_FRAME, NULL);
|
Phy_SetupNextSlot(phyRef, PHY_TOR_RX, L1_10KBPS_10MS_FRAME, NULL);
|
||||||
}
|
}
|
||||||
if (reconfig == true)
|
|
||||||
{
|
|
||||||
Linklayer_Reconfig(linkInstPtr, &linkConfig);
|
|
||||||
}
|
|
||||||
if (start == true)
|
|
||||||
{
|
|
||||||
Linklayer_Start(linkInstPtr);
|
|
||||||
}
|
|
||||||
instPtr->sysbusLog.lastConfig[0] = msg[WD_MODE_CMD];
|
instPtr->sysbusLog.lastConfig[0] = msg[WD_MODE_CMD];
|
||||||
instPtr->sysbusLog.lastConfig[1] = msg[WD_EN_CMD];
|
instPtr->sysbusLog.lastConfig[1] = msg[WD_EN_CMD];
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
@@ -359,7 +350,8 @@ static int32_t SystemBus_Echo(SYSBUS *instPtr, SYSBUS_UART_FRAME *frame)
|
|||||||
ASSERT(instPtr != NULL);
|
ASSERT(instPtr != NULL);
|
||||||
ASSERT(frame != NULL);
|
ASSERT(frame != NULL);
|
||||||
SYSBUS_UART_FRAME *sysbusRsp = malloc(sizeof(SYSBUS_UART_FRAME));
|
SYSBUS_UART_FRAME *sysbusRsp = malloc(sizeof(SYSBUS_UART_FRAME));
|
||||||
if (sysbusRsp == NULL) {
|
if (sysbusRsp == NULL)
|
||||||
|
{
|
||||||
DBG_ERROR("Failed to allocate memory for DATA TEST A Response!\n");
|
DBG_ERROR("Failed to allocate memory for DATA TEST A Response!\n");
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
@@ -384,7 +376,8 @@ static int32_t SystemBus_GenPollRsp(SYSBUS *instPtr, uint8_t *msg)
|
|||||||
size_t dataLen;
|
size_t dataLen;
|
||||||
uint8_t *payload;
|
uint8_t *payload;
|
||||||
SYSBUS_UART_FRAME *sysbusRsp = malloc(sizeof(SYSBUS_UART_FRAME));
|
SYSBUS_UART_FRAME *sysbusRsp = malloc(sizeof(SYSBUS_UART_FRAME));
|
||||||
if (sysbusRsp == NULL) {
|
if (sysbusRsp == NULL)
|
||||||
|
{
|
||||||
DBG_ERROR("Failed to allocate memory for FLJ POLL Response!\n");
|
DBG_ERROR("Failed to allocate memory for FLJ POLL Response!\n");
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
@@ -437,7 +430,8 @@ static int32_t SystemBus_GenRemoteTestRsp(SYSBUS *instPtr, uint8_t *msg)
|
|||||||
ASSERT(instPtr != NULL);
|
ASSERT(instPtr != NULL);
|
||||||
ASSERT(msg != NULL);
|
ASSERT(msg != NULL);
|
||||||
SYSBUS_UART_FRAME *sysbusRsp = malloc(sizeof(SYSBUS_UART_FRAME));
|
SYSBUS_UART_FRAME *sysbusRsp = malloc(sizeof(SYSBUS_UART_FRAME));
|
||||||
if (sysbusRsp == NULL) {
|
if (sysbusRsp == NULL)
|
||||||
|
{
|
||||||
DBG_ERROR("Failed to allocate memory for LJ REMOTE TEST Response!\n");
|
DBG_ERROR("Failed to allocate memory for LJ REMOTE TEST Response!\n");
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
@@ -485,7 +479,8 @@ static int32_t SystemBus_GenRemoteTestRsp(SYSBUS *instPtr, uint8_t *msg)
|
|||||||
return EUNEXP;
|
return EUNEXP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CircQueuePush(instPtr->txQueue, (void *)sysbusRsp) == false){
|
if (CircQueuePush(instPtr->txQueue, (void *)sysbusRsp) == false)
|
||||||
|
{
|
||||||
free(sysbusRsp);
|
free(sysbusRsp);
|
||||||
DBG_WARNING("SystemBus::TX Queue overflowed!\n");
|
DBG_WARNING("SystemBus::TX Queue overflowed!\n");
|
||||||
return EQUEUE;
|
return EQUEUE;
|
||||||
|
|||||||
Reference in New Issue
Block a user