config logic simplification

This commit is contained in:
Gatsby Van
2024-03-18 11:01:56 +08:00
parent 6c64421336
commit 33545b63e1
+25 -34
View File
@@ -278,56 +278,55 @@ 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 // head node config
if (L2_GetNodeType(linkInstPtr) != L2_NODE_HEAD) reconfig = (L2_NODE_HEAD != linkConfig.myType);
{ linkConfig.myType = L2_NODE_HEAD;
// head node config linkConfig.myId = 1;
linkConfig.myType = L2_NODE_HEAD;
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 // member node config
if (L2_GetNodeType(linkInstPtr) != L2_NODE_MEMBER) reconfig = (L2_NODE_MEMBER != linkConfig.myType);
{ linkConfig.myType = L2_NODE_MEMBER;
// member node config linkConfig.myId = 2;
linkConfig.myType = L2_NODE_MEMBER;
linkConfig.myId = 2;
reconfig = true;
}
} }
else else
{ {
// Ignore current command // Ignore current command
DBG_ERROR("Unexpected config command 0x%02X:0x%02X", 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; 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); 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;