config logic simplification
This commit is contained in:
@@ -278,56 +278,55 @@ static int32_t SystemBus_SystemConfig(SYSBUS *instPtr, uint8_t *msg)
|
||||
PHY_INST *phyRef = linkInstPtr->config.phyInstPtr;
|
||||
TMC_INST *tmcRef = linkInstPtr->config.tmcInstPtr;
|
||||
bool reconfig = false;
|
||||
bool start = false;
|
||||
|
||||
if (msg[WD_MODE_CMD] == MODE_CMD_HEAD)
|
||||
{
|
||||
// omit unnecessary reconfiguration
|
||||
if (L2_GetNodeType(linkInstPtr) != L2_NODE_HEAD)
|
||||
{
|
||||
// head node config
|
||||
linkConfig.myType = L2_NODE_HEAD;
|
||||
linkConfig.myId = 1;
|
||||
reconfig = true;
|
||||
}
|
||||
// head node config
|
||||
reconfig = (L2_NODE_HEAD != linkConfig.myType);
|
||||
linkConfig.myType = L2_NODE_HEAD;
|
||||
linkConfig.myId = 1;
|
||||
}
|
||||
|
||||
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
|
||||
linkConfig.myType = L2_NODE_MEMBER;
|
||||
linkConfig.myId = 2;
|
||||
reconfig = true;
|
||||
}
|
||||
// member node config
|
||||
reconfig = (L2_NODE_MEMBER != linkConfig.myType);
|
||||
linkConfig.myType = L2_NODE_MEMBER;
|
||||
linkConfig.myId = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ignore current command
|
||||
DBG_ERROR("Unexpected config command 0x%02X:0x%02X",
|
||||
WD_MODE_CMD, msg[WD_MODE_CMD]);
|
||||
WD_MODE_CMD, msg[WD_MODE_CMD]);
|
||||
return EPARAM;
|
||||
}
|
||||
|
||||
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);
|
||||
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
|
||||
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
|
||||
// TODO: better approach?
|
||||
start = false;
|
||||
Linklayer_Halt(linkInstPtr);
|
||||
Phy_AntConfigMode(phyRef, PHY_ANT_MODE_STANDBY);
|
||||
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);
|
||||
}
|
||||
if (reconfig == true)
|
||||
{
|
||||
Linklayer_Reconfig(linkInstPtr, &linkConfig);
|
||||
}
|
||||
if (start == true)
|
||||
{
|
||||
Linklayer_Start(linkInstPtr);
|
||||
}
|
||||
instPtr->sysbusLog.lastConfig[0] = msg[WD_MODE_CMD];
|
||||
instPtr->sysbusLog.lastConfig[1] = msg[WD_EN_CMD];
|
||||
return SUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user