Skip to content

Commit 0d69e2b

Browse files
committed
Reduce Dual RX RAM pressure
1 parent 0cb4d41 commit 0d69e2b

3 files changed

Lines changed: 14 additions & 12 deletions

File tree

src/main/rx/msp.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ typedef struct mspRxState_s {
3636
uint8_t lastChannelCount;
3737
} mspRxState_t;
3838

39-
static mspRxState_t mspRxStates[RX_LINK_COUNT];
40-
static mspRxState_t mspOverrideState;
39+
// MSP+MSP is not a supported Dual RX pair, and the legacy MSP override is only
40+
// initialized when MSP is not a configured receiver. One state object therefore
41+
// covers all mutually-exclusive MSP RX roles.
42+
static mspRxState_t mspRxState;
4143

4244
static uint16_t rxMspReadRawRC(const rxRuntimeConfig_t *rxRuntimeConfig, uint8_t chan)
4345
{
@@ -71,8 +73,7 @@ static void rxMspInitState(rxRuntimeConfig_t *rxRuntimeConfig, mspRxState_t *sta
7173

7274
void rxMspFrameReceive(uint16_t *frame, int channelCount)
7375
{
74-
const int8_t mspLink = rxGetMspLink();
75-
mspRxState_t *state = mspLink >= 0 && mspLink < RX_LINK_COUNT ? &mspRxStates[mspLink] : &mspOverrideState;
76+
mspRxState_t *state = &mspRxState;
7677

7778
channelCount = constrain(channelCount, 0, MAX_SUPPORTED_RC_CHANNEL_COUNT);
7879
for (int i = 0; i < channelCount; i++) {
@@ -87,21 +88,22 @@ void rxMspFrameReceive(uint16_t *frame, int channelCount)
8788

8889
uint8_t rxMspGetLastChannelCount(rxLink_e link)
8990
{
90-
return (unsigned)link < RX_LINK_COUNT ? mspRxStates[link].lastChannelCount : 0;
91+
const int8_t mspLink = rxGetMspLink();
92+
return mspLink >= 0 && link == (rxLink_e)mspLink ? mspRxState.lastChannelCount : 0;
9193
}
9294

9395
void rxMspInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig, rxLink_e link)
9496
{
9597
UNUSED(rxConfig);
9698
if ((unsigned)link < RX_LINK_COUNT) {
97-
rxMspInitState(rxRuntimeConfig, &mspRxStates[link], true);
99+
rxMspInitState(rxRuntimeConfig, &mspRxState, true);
98100
}
99101
}
100102

101103
void rxMspOverrideInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
102104
{
103105
UNUSED(rxConfig);
104-
rxMspInitState(rxRuntimeConfig, &mspOverrideState, false);
106+
rxMspInitState(rxRuntimeConfig, &mspRxState, false);
105107
}
106108

107109
#endif

src/main/rx/rx.c

100755100644
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ typedef struct rxLinkState_s {
9999
timeUs_t needRxSignalBefore;
100100
} rxLinkState_t;
101101

102-
static rxLinkState_t rxLinks[RX_LINK_COUNT];
102+
STATIC_FASTRAM rxLinkState_t rxLinks[RX_LINK_COUNT];
103103
static rxLink_e activeLink = RX_LINK_PRIMARY;
104104
static rxLink_e pendingHandoverLink = RX_LINK_COUNT;
105105
static rxLinkSwitchReason_e pendingHandoverReason = RX_LINK_SWITCH_HANDOVER_API;
@@ -113,10 +113,10 @@ static void rxApplyActiveLink(rxLink_e link, bool copyChannels);
113113
static bool mspOverrideDataProcessingRequired = false;
114114
#endif
115115

116-
static rcChannel_t rcChannels[MAX_SUPPORTED_RC_CHANNEL_COUNT];
116+
STATIC_FASTRAM rcChannel_t rcChannels[MAX_SUPPORTED_RC_CHANNEL_COUNT];
117117

118118
// MSP aux channel overlay: non-zero values override rcChannels[].data for CH9-CH32
119-
static uint16_t mspAuxOverlay[MAX_SUPPORTED_RC_CHANNEL_COUNT];
119+
STATIC_FASTRAM uint16_t mspAuxOverlay[MAX_SUPPORTED_RC_CHANNEL_COUNT];
120120

121121
rxLinkStatistics_t rxLinkStatistics;
122122
rxRuntimeConfig_t rxRuntimeConfig;

src/main/telemetry/crsf.c

100755100644
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ static uint8_t crsfFrame[CRSF_FRAME_SIZE_MAX];
8383

8484
#if defined(USE_MSP_OVER_TELEMETRY)
8585
static mspSharedContext_t crsfMspContexts[RX_LINK_COUNT];
86-
static uint8_t crsfMspRxBuffers[RX_LINK_COUNT][CRSF_MSP_RX_BUF_SIZE];
87-
static uint8_t crsfMspTxBuffers[RX_LINK_COUNT][CRSF_MSP_TX_BUF_SIZE];
86+
STATIC_FASTRAM uint8_t crsfMspRxBuffers[RX_LINK_COUNT][CRSF_MSP_RX_BUF_SIZE];
87+
STATIC_FASTRAM uint8_t crsfMspTxBuffers[RX_LINK_COUNT][CRSF_MSP_TX_BUF_SIZE];
8888
static uint8_t crsfMspRequestOriginId[RX_LINK_COUNT];
8989
static volatile bool crsfMspRequestOriginValid[RX_LINK_COUNT];
9090
static bool crsfMspInitialized;

0 commit comments

Comments
 (0)