mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 04:45:24 +03:00
CF/BF - Improve performance of mspSerialPush / MSP_DISPLAYPORT.
* avoiding the use of an unncessesary buffer and memcopy * the `pushBuf` was a fixed size * the size didn't correlate to the size of the buffer being passed in. * avoids repeating the memcpy for each port being used for MSP. * reduces ram usage.
This commit is contained in:
parent
ca5bafeab9
commit
b307007ac3
3 changed files with 12 additions and 17 deletions
|
@ -262,17 +262,10 @@ void mspSerialInit(void)
|
|||
mspSerialAllocatePorts();
|
||||
}
|
||||
|
||||
int mspSerialPush(uint8_t cmd, const uint8_t *data, int datalen)
|
||||
int mspSerialPush(uint8_t cmd, uint8_t *data, int datalen)
|
||||
{
|
||||
static uint8_t pushBuf[34];
|
||||
int ret = 0;
|
||||
|
||||
mspPacket_t push = {
|
||||
.buf = { .ptr = pushBuf, .end = ARRAYEND(pushBuf), },
|
||||
.cmd = cmd,
|
||||
.result = 0,
|
||||
};
|
||||
|
||||
for (int portIndex = 0; portIndex < MAX_MSP_PORT_COUNT; portIndex++) {
|
||||
mspPort_t * const mspPort = &mspPorts[portIndex];
|
||||
if (!mspPort->port) {
|
||||
|
@ -284,9 +277,11 @@ int mspSerialPush(uint8_t cmd, const uint8_t *data, int datalen)
|
|||
continue;
|
||||
}
|
||||
|
||||
sbufWriteData(&push.buf, data, datalen);
|
||||
|
||||
sbufSwitchToReader(&push.buf, pushBuf);
|
||||
mspPacket_t push = {
|
||||
.buf = { .ptr = data, .end = data + datalen, },
|
||||
.cmd = cmd,
|
||||
.result = 0,
|
||||
};
|
||||
|
||||
ret = mspSerialEncode(mspPort, &push);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue