forked from 0xha0/df_datalink
feat: 增加上位机消息发送队列
This commit is contained in:
+48
-61
@@ -27,6 +27,9 @@
|
||||
#include "common.h"
|
||||
#include "error.h"
|
||||
#include "circ_queue.h"
|
||||
// TODO: better approach?
|
||||
#include "../networking/link_layer/link_layer.h"
|
||||
#include "../networking/phy_layer/phy_layer.h"
|
||||
|
||||
/**
|
||||
* @addtogroup SystemBus_Protocol_Routine
|
||||
@@ -175,8 +178,8 @@ typedef struct
|
||||
typedef struct
|
||||
{
|
||||
SYSMON_CONFIG config; ///< system monitor initialization parameters
|
||||
CIRC_QUEUE *sendQueue; ///< send queue
|
||||
CIRC_QUEUE *recvQueue; ///< receive queue
|
||||
CIRC_QUEUE *sendQueue[L2_NET_SCALE]; ///< send queue
|
||||
CIRC_QUEUE *recvQueue[L2_NET_SCALE]; ///< receive queue
|
||||
PINGPONG sysInfoCtrl;
|
||||
SYSINFO sysInfo[2];
|
||||
PINGPONG linkLogCtrl;
|
||||
@@ -196,8 +199,6 @@ static int32_t SystemBus_GenRemoteTestRsp(SYSBUS *instPtr, uint8_t *msg);
|
||||
/**************************** Type Definitions *******************************/
|
||||
/************************** Variable Definitions *****************************/
|
||||
// TODO: better approach?
|
||||
#include "../networking/link_layer/link_layer.h"
|
||||
#include "../networking/phy_layer/phy_layer.h"
|
||||
extern L2_INST *linkInstPtr;
|
||||
extern L2_CONFIG linkConfig;
|
||||
extern SYSBUS *sysbusDescPtr;
|
||||
@@ -339,6 +340,39 @@ static int32_t SystemBus_SystemConfig(SYSBUS *instPtr, uint8_t *msg)
|
||||
}
|
||||
}
|
||||
|
||||
// Routing table selection
|
||||
if (msg[WD_RTNE_CMD] != instPtr->sysbusLog.lastConfig[3])
|
||||
{
|
||||
switch (msg[WD_RTNE_CMD])
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
reconfig |= (linkConfig.normalTable != normalRoutTable0);
|
||||
linkConfig.normalTable = normalRoutTable0;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
reconfig |= (linkConfig.normalTable != normalRoutTable1);
|
||||
linkConfig.normalTable = normalRoutTable1;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
reconfig |= (linkConfig.normalTable != normalRoutTable2);
|
||||
linkConfig.normalTable = normalRoutTable2;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
// Ignore current command
|
||||
DBG_ERROR("Unexpected config command 0x%02X:0x%02X",
|
||||
WD_RTNE_CMD, msg[WD_RTNE_CMD]);
|
||||
return EIGNORE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Enable control
|
||||
if (msg[WD_EN_CMD] == EN_CMD_ENABLE)
|
||||
{
|
||||
@@ -368,58 +402,6 @@ static int32_t SystemBus_SystemConfig(SYSBUS *instPtr, uint8_t *msg)
|
||||
return EIGNORE;
|
||||
}
|
||||
|
||||
// Routing table selection
|
||||
if (msg[WD_RTNE_CMD] != instPtr->sysbusLog.lastConfig[3])
|
||||
{
|
||||
L2_RTNE_CONFIG newRtneConfig;
|
||||
switch (msg[WD_RTNE_CMD])
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
newRtneConfig.rtneTable = normalTable0;
|
||||
newRtneConfig.rtnePrd = ARRAY_SIZE(normalTable0);
|
||||
L2_EVENT l2Event =
|
||||
{
|
||||
.event = L2_ROUTINE_UPDATE,
|
||||
.msg = &newRtneConfig
|
||||
};
|
||||
AssertL2Event(linkInstPtr, &l2Event);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
newRtneConfig.rtneTable = normalTable1;
|
||||
newRtneConfig.rtnePrd = ARRAY_SIZE(normalTable1);
|
||||
L2_EVENT l2Event =
|
||||
{
|
||||
.event = L2_ROUTINE_UPDATE,
|
||||
.msg = &newRtneConfig
|
||||
};
|
||||
AssertL2Event(linkInstPtr, &l2Event);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
newRtneConfig.rtneTable = normalTable2;
|
||||
newRtneConfig.rtnePrd = ARRAY_SIZE(normalTable2);
|
||||
L2_EVENT l2Event =
|
||||
{
|
||||
.event = L2_ROUTINE_UPDATE,
|
||||
.msg = &newRtneConfig
|
||||
};
|
||||
AssertL2Event(linkInstPtr, &l2Event);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
// Ignore current command
|
||||
DBG_ERROR("Unexpected config command 0x%02X:0x%02X",
|
||||
WD_RTNE_CMD, msg[WD_RTNE_CMD]);
|
||||
return EIGNORE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
instPtr->sysbusLog.lastConfig[0] = msg[WD_EN_CMD];
|
||||
instPtr->sysbusLog.lastConfig[1] = msg[WD_ID_CMD];
|
||||
instPtr->sysbusLog.lastConfig[2] = msg[WD_RATE_CMD];
|
||||
@@ -780,8 +762,8 @@ int32_t SysMonitor_Init(SYSMON_CONFIG *config)
|
||||
}
|
||||
|
||||
memcpy(&(sysMonitorInst->config), config, sizeof(SYSMON_CONFIG));
|
||||
sysMonitorInst->sendQueue = NULL;
|
||||
sysMonitorInst->recvQueue = NULL;
|
||||
sysMonitorInst->sendQueue[1] = NULL;
|
||||
sysMonitorInst->recvQueue[1] = NULL;
|
||||
memset(&(sysMonitorInst->sysInfoCtrl), BUFF_NONE, sizeof(PINGPONG));
|
||||
memset(&(sysMonitorInst->linkLogCtrl), BUFF_NONE, sizeof(PINGPONG));
|
||||
memset(&(sysMonitorInst->phyLogCtrl), BUFF_NONE, sizeof(PINGPONG));
|
||||
@@ -874,6 +856,11 @@ int32_t SysMonitor_UpdateSendPayload(SYSBUS_SVC_PLD *payload)
|
||||
DBG_ERROR("Payload length %d exceeds valid range.", payload->dataLen);
|
||||
return EPARAM;
|
||||
}
|
||||
if (payload->nodeId < L2_NODE_NONE || payload->nodeId > L2_NET_SCALE)
|
||||
{
|
||||
DBG_ERROR("Node ID %d exceeds valid range.", payload->nodeId);
|
||||
return EPARAM;
|
||||
}
|
||||
|
||||
// push message into send queue
|
||||
SYSBUS_SVC_PLD *payloadCopy = malloc(sizeof(SYSBUS_SVC_PLD));
|
||||
@@ -883,7 +870,7 @@ int32_t SysMonitor_UpdateSendPayload(SYSBUS_SVC_PLD *payload)
|
||||
return ENOMEM;
|
||||
}
|
||||
memcpy(payloadCopy, payload, sizeof(SYSBUS_SVC_PLD));
|
||||
if (CircQueuePush(sysMonitorInst->sendQueue, (void *)payloadCopy) == false)
|
||||
if (CircQueuePush(sysMonitorInst->sendQueue[payload->nodeId], (void *)payloadCopy) == false)
|
||||
{
|
||||
DBG_WARNING("SystemMonitor::SEND Queue overflowed!\n");
|
||||
free(payloadCopy);
|
||||
@@ -898,12 +885,12 @@ int32_t SysMonitor_UpdateSendPayload(SYSBUS_SVC_PLD *payload)
|
||||
*
|
||||
* @param payload
|
||||
*/
|
||||
void SysMonitor_GetSendPayload(SYSBUS_SVC_PLD **payload)
|
||||
void SysMonitor_GetSendPayload(SYSBUS_SVC_PLD **payload, uint8_t dstId)
|
||||
{
|
||||
ASSERT(sysMonitorInst != NULL);
|
||||
ASSERT(payload != NULL);
|
||||
|
||||
if (CircQueuePop(sysMonitorInst->sendQueue, (void **)payload) == false)
|
||||
if (CircQueuePop(sysMonitorInst->sendQueue[dstId], (void **)payload) == false)
|
||||
{
|
||||
*payload = NULL;
|
||||
DBG_INFO("SystemMonitor::Empty sendQueue, nothing need sent.\n");
|
||||
|
||||
Reference in New Issue
Block a user