1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-26 17:55:30 +03:00

Improved MSP post process function handling

This commit is contained in:
Martin Budden 2016-10-02 16:13:42 +01:00
parent b8260fdf40
commit 1bc9cc83fe
3 changed files with 10 additions and 9 deletions

View file

@ -109,6 +109,7 @@ void mspSerialProcess(void)
uint8_t buf[sizeof(bufWriter_t) + 20]; uint8_t buf[sizeof(bufWriter_t) + 20];
writer = bufWriterInit(buf, sizeof(buf), (bufWrite_t)serialWriteBufShim, mspPort->port); writer = bufWriterInit(buf, sizeof(buf), (bufWrite_t)serialWriteBufShim, mspPort->port);
mspPostProcessFuncPtr mspPostProcessFn = NULL;
while (serialRxBytesWaiting(mspPort->port)) { while (serialRxBytesWaiting(mspPort->port)) {
const uint8_t c = serialRead(mspPort->port); const uint8_t c = serialRead(mspPort->port);
@ -119,7 +120,7 @@ void mspSerialProcess(void)
} }
if (mspPort->c_state == COMMAND_RECEIVED) { if (mspPort->c_state == COMMAND_RECEIVED) {
mspProcessReceivedCommand(mspPort); mspPostProcessFn = mspProcessReceivedCommand(mspPort);
break; // process one command at a time so as not to block. break; // process one command at a time so as not to block.
} }
} }
@ -128,7 +129,6 @@ void mspSerialProcess(void)
if (mspPostProcessFn) { if (mspPostProcessFn) {
mspPostProcessFn(mspPort); mspPostProcessFn(mspPort);
mspPostProcessFn = NULL;
} }
} }
} }

View file

@ -17,10 +17,9 @@
#pragma once #pragma once
struct mspPort_s;
typedef void (*mspPostProcessFuncPtr)(mspPort_t *); // msp post process function, used for gracefully handling reboots, etc. typedef void (*mspPostProcessFuncPtr)(struct mspPort_s *); // msp post process function, used for gracefully handling reboots, etc.
extern mspPostProcessFuncPtr mspPostProcessFn;
void mspInit(void); void mspInit(void);
bool mspProcessReceivedData(mspPort_t *mspPort, uint8_t c); bool mspProcessReceivedData(struct mspPort_s *mspPort, uint8_t c);
void mspProcessReceivedCommand(mspPort_t *mspPort); mspPostProcessFuncPtr mspProcessReceivedCommand(struct mspPort_s *mspPort);

View file

@ -112,7 +112,7 @@ extern uint16_t cycleTime; // FIXME dependency on mw.c
extern void resetProfile(profile_t *profile); extern void resetProfile(profile_t *profile);
// cause reboot after MSP processing complete // cause reboot after MSP processing complete
mspPostProcessFuncPtr mspPostProcessFn = NULL; static mspPostProcessFuncPtr mspPostProcessFn = NULL;
static mspPort_t *currentPort; static mspPort_t *currentPort;
static const char * const flightControllerIdentifier = BETAFLIGHT_IDENTIFIER; // 4 UPPER CASE alpha numeric characters that identify the flight controller. static const char * const flightControllerIdentifier = BETAFLIGHT_IDENTIFIER; // 4 UPPER CASE alpha numeric characters that identify the flight controller.
@ -1914,14 +1914,16 @@ static bool processInCommand(uint8_t cmdMSP)
return true; return true;
} }
void mspProcessReceivedCommand(mspPort_t *mspPort) mspPostProcessFuncPtr mspProcessReceivedCommand(mspPort_t *mspPort)
{ {
currentPort = mspPort; currentPort = mspPort;
mspPostProcessFn = NULL;
if (!(processOutCommand(mspPort->cmdMSP) || processInCommand(mspPort->cmdMSP))) { if (!(processOutCommand(mspPort->cmdMSP) || processInCommand(mspPort->cmdMSP))) {
headSerialError(0); headSerialError(0);
} }
tailSerialReply(); tailSerialReply();
mspPort->c_state = IDLE; mspPort->c_state = IDLE;
return mspPostProcessFn;
} }
bool mspProcessReceivedData(mspPort_t *mspPort, uint8_t c) bool mspProcessReceivedData(mspPort_t *mspPort, uint8_t c)