Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
Fix MSP/Telemetry Arm/Disarm problems.
Browse files Browse the repository at this point in the history
Tested with two MSP ports, one via softserial. Both with telemetry
enabled and without telemetry enabled.
  • Loading branch information
hydra committed Nov 8, 2014
1 parent f42d603 commit 28da97f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
31 changes: 15 additions & 16 deletions src/main/io/serial_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,17 @@ static void resetMspPort(mspPort_t *mspPortToReset, serialPort_t *serialPort, ms
// This rate is chosen since softserial supports it.
#define MSP_FALLBACK_BAUDRATE 19200

static void openAllMSPSerialPorts(serialConfig_t *serialConfig)
void mspAllocateSerialPorts(serialConfig_t *serialConfig)
{
serialPort_t *port;

uint8_t portIndex = 0;
do {
uint8_t portIndex;

for (portIndex = 0; portIndex < MAX_MSP_PORT_COUNT; portIndex++) {
mspPort_t *mspPort = &mspPorts[portIndex];
if (mspPort->mspPortUsage != UNUSED_PORT) {
continue;
}

uint32_t baudRate = serialConfig->msp_baudrate;

Expand All @@ -549,12 +554,12 @@ static void openAllMSPSerialPorts(serialConfig_t *serialConfig)
} while (!port);

if (port && portIndex < MAX_MSP_PORT_COUNT) {
mspPort_t *newMspPort = &mspPorts[portIndex++];

resetMspPort(newMspPort, port, FOR_GENERAL_MSP);
resetMspPort(mspPort, port, FOR_GENERAL_MSP);
}

} while (port);
if (!port) {
break;
}
}

// XXX this function might help with adding support for MSP on more than one port, if not delete it.
const serialPortFunctionList_t *serialPortFunctionList = getSerialPortFunctionList();
Expand All @@ -565,7 +570,7 @@ void mspReleasePortIfAllocated(serialPort_t *serialPort)
{
uint8_t portIndex;
for (portIndex = 0; portIndex < MAX_MSP_PORT_COUNT; portIndex++) {
mspPort_t *candidateMspPort = &mspPorts[portIndex++];
mspPort_t *candidateMspPort = &mspPorts[portIndex];
if (candidateMspPort->port == serialPort) {
endSerialPortFunction(serialPort, FUNCTION_MSP);
memset(candidateMspPort, 0, sizeof(mspPort_t));
Expand Down Expand Up @@ -627,14 +632,8 @@ void mspInit(serialConfig_t *serialConfig)
activeBoxIds[activeBoxIdCount++] = BOXSONAR;
}

mspReset(serialConfig);
}

void mspReset(serialConfig_t *serialConfig)
{
memset(mspPorts, 0x00, sizeof(mspPorts));

openAllMSPSerialPorts(serialConfig);
mspAllocateSerialPorts(serialConfig);
}

#define IS_ENABLED(mask) (mask == 0 ? 0 : 1)
Expand Down
2 changes: 1 addition & 1 deletion src/main/io/serial_msp.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
void mspProcess(void);
void sendMspTelemetry(void);
void mspSetTelemetryPort(serialPort_t *mspTelemetryPort);
void mspReset(serialConfig_t *serialConfig);
void mspAllocateSerialPorts(serialConfig_t *serialConfig);
void mspReleasePortIfAllocated(serialPort_t *serialPort);
2 changes: 1 addition & 1 deletion src/main/mw.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ void mwDisarm(void)
// the telemetry state must be checked immediately so that shared serial ports are released.
checkTelemetryState();
if (isSerialPortFunctionShared(FUNCTION_TELEMETRY, FUNCTION_MSP)) {
mspReset(&masterConfig.serialConfig);
mspAllocateSerialPorts(&masterConfig.serialConfig);
}
}
#endif
Expand Down

0 comments on commit 28da97f

Please sign in to comment.