config logic simplification

This commit is contained in:
Gatsby Van
2024-03-18 11:01:56 +08:00
parent 6c64421336
commit 33545b63e1
+14 -23
View File
@@ -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;