1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-22 07:45:29 +03:00

Remove shared MSP buffer

This commit is contained in:
Hans Christian Olaussen 2021-12-16 23:42:04 +01:00
parent fcb3ed4959
commit 5f4ed614f1
5 changed files with 18 additions and 17 deletions

View file

@ -391,10 +391,10 @@ static int mspSerialEncode(mspPort_t *msp, mspPacket_t *packet, mspVersion_e msp
return mspSerialSendFrame(msp, hdrBuf, hdrLen, sbufPtr(&packet->buf), dataLen, crcBuf, crcLen); return mspSerialSendFrame(msp, hdrBuf, hdrLen, sbufPtr(&packet->buf), dataLen, crcBuf, crcLen);
} }
uint8_t mspSerialOutBuf[MSP_PORT_OUTBUF_SIZE]; // this buffer also used in msp_shared.c
static mspPostProcessFnPtr mspSerialProcessReceivedCommand(mspPort_t *msp, mspProcessCommandFnPtr mspProcessCommandFn) static mspPostProcessFnPtr mspSerialProcessReceivedCommand(mspPort_t *msp, mspProcessCommandFnPtr mspProcessCommandFn)
{ {
static uint8_t mspSerialOutBuf[MSP_PORT_OUTBUF_SIZE];
mspPacket_t reply = { mspPacket_t reply = {
.buf = { .ptr = mspSerialOutBuf, .end = ARRAYEND(mspSerialOutBuf), }, .buf = { .ptr = mspSerialOutBuf, .end = ARRAYEND(mspSerialOutBuf), },
.cmd = -1, .cmd = -1,

View file

@ -124,5 +124,3 @@ void mspSerialReleasePortIfAllocated(struct serialPort_s *serialPort);
void mspSerialReleaseSharedTelemetryPorts(void); void mspSerialReleaseSharedTelemetryPorts(void);
int mspSerialPush(serialPortIdentifier_e port, uint8_t cmd, uint8_t *data, int datalen, mspDirection_e direction); int mspSerialPush(serialPortIdentifier_e port, uint8_t cmd, uint8_t *data, int datalen, mspDirection_e direction);
uint32_t mspSerialTxBytesFree(void); uint32_t mspSerialTxBytesFree(void);
extern uint8_t mspSerialOutBuf[MSP_PORT_OUTBUF_SIZE]; // this buffer also used in msp_shared.c

View file

@ -121,7 +121,8 @@ enum { // byte position(index) in msp-over-telemetry request payload
MSP_INDEX_PAYLOAD_V2 = MSP_INDEX_SIZE_V2_HI + 1, // MSPv2 first byte of payload itself MSP_INDEX_PAYLOAD_V2 = MSP_INDEX_SIZE_V2_HI + 1, // MSPv2 first byte of payload itself
}; };
STATIC_UNIT_TESTED uint8_t requestBuffer[MSP_PORT_INBUF_SIZE]; STATIC_UNIT_TESTED uint8_t requestBuffer[MSP_TLM_INBUF_SIZE];
STATIC_UNIT_TESTED uint8_t responseBuffer[MSP_TLM_OUTBUF_SIZE];
STATIC_UNIT_TESTED mspPacket_t requestPacket; STATIC_UNIT_TESTED mspPacket_t requestPacket;
STATIC_UNIT_TESTED mspPacket_t responsePacket; STATIC_UNIT_TESTED mspPacket_t responsePacket;
static uint8_t lastRequestVersion; // MSP version of last request. Temporary solution. It's better to keep it in requestPacket. static uint8_t lastRequestVersion; // MSP version of last request. Temporary solution. It's better to keep it in requestPacket.
@ -130,8 +131,8 @@ static mspDescriptor_t mspSharedDescriptor;
void initSharedMsp(void) void initSharedMsp(void)
{ {
responsePacket.buf.ptr = mspSerialOutBuf; responsePacket.buf.ptr = responseBuffer;
responsePacket.buf.end = ARRAYEND(mspSerialOutBuf); responsePacket.buf.end = ARRAYEND(responseBuffer);
mspSharedDescriptor = mspDescriptorAlloc(); mspSharedDescriptor = mspDescriptorAlloc();
} }
@ -140,8 +141,8 @@ static void processMspPacket(void)
{ {
responsePacket.cmd = 0; responsePacket.cmd = 0;
responsePacket.result = 0; responsePacket.result = 0;
responsePacket.buf.ptr = mspSerialOutBuf; responsePacket.buf.ptr = responseBuffer;
responsePacket.buf.end = ARRAYEND(mspSerialOutBuf); responsePacket.buf.end = ARRAYEND(responseBuffer);
mspPostProcessFnPtr mspPostProcessFn = NULL; mspPostProcessFnPtr mspPostProcessFn = NULL;
if (mspFcProcessCommand(mspSharedDescriptor, &requestPacket, &responsePacket, &mspPostProcessFn) == MSP_RESULT_ERROR) { if (mspFcProcessCommand(mspSharedDescriptor, &requestPacket, &responsePacket, &mspPostProcessFn) == MSP_RESULT_ERROR) {
@ -151,18 +152,18 @@ static void processMspPacket(void)
mspPostProcessFn(NULL); mspPostProcessFn(NULL);
} }
sbufSwitchToReader(&responsePacket.buf, mspSerialOutBuf); sbufSwitchToReader(&responsePacket.buf, responseBuffer);
} }
void sendMspErrorResponse(uint8_t error, int16_t cmd) void sendMspErrorResponse(uint8_t error, int16_t cmd)
{ {
responsePacket.cmd = cmd; responsePacket.cmd = cmd;
responsePacket.result = 0; responsePacket.result = 0;
responsePacket.buf.ptr = mspSerialOutBuf; responsePacket.buf.ptr = responseBuffer;
sbufWriteU8(&responsePacket.buf, error); sbufWriteU8(&responsePacket.buf, error);
responsePacket.result = TELEMETRY_MSP_RES_ERROR; responsePacket.result = TELEMETRY_MSP_RES_ERROR;
sbufSwitchToReader(&responsePacket.buf, mspSerialOutBuf); sbufSwitchToReader(&responsePacket.buf, responseBuffer);
} }
// despite its name, the function actually handles telemetry frame payload with MSP in it // despite its name, the function actually handles telemetry frame payload with MSP in it
@ -272,7 +273,7 @@ bool sendMspReply(const uint8_t payloadSizeMax, mspResponseFnPtr responseFn)
sbuf_t *payloadBuf = sbufInit(&payloadBufStruct, payloadArray, payloadArray + payloadSizeMax); sbuf_t *payloadBuf = sbufInit(&payloadBufStruct, payloadArray, payloadArray + payloadSizeMax);
// detect first reply packet // detect first reply packet
if (responsePacket.buf.ptr == mspSerialOutBuf) { if (responsePacket.buf.ptr == responseBuffer) {
// this is the first frame of the response packet. Add proper header and size. // this is the first frame of the response packet. Add proper header and size.
// header // header
uint8_t status = MSP_STATUS_START_MASK | (seq++ & MSP_STATUS_SEQUENCE_MASK) | (lastRequestVersion << MSP_STATUS_VERSION_SHIFT); uint8_t status = MSP_STATUS_START_MASK | (seq++ & MSP_STATUS_SEQUENCE_MASK) | (lastRequestVersion << MSP_STATUS_VERSION_SHIFT);
@ -314,7 +315,7 @@ bool sendMspReply(const uint8_t payloadSizeMax, mspResponseFnPtr responseFn)
// last/only chunk // last/only chunk
sbufWriteData(payloadBuf, responsePacket.buf.ptr, inputRemainder); sbufWriteData(payloadBuf, responsePacket.buf.ptr, inputRemainder);
sbufAdvance(&responsePacket.buf, inputRemainder); sbufAdvance(&responsePacket.buf, inputRemainder);
sbufSwitchToReader(&responsePacket.buf, mspSerialOutBuf);// for CRC calculation sbufSwitchToReader(&responsePacket.buf, responseBuffer);// for CRC calculation
responseFn(payloadArray, payloadBuf->ptr - payloadArray); responseFn(payloadArray, payloadBuf->ptr - payloadArray);
return false; return false;

View file

@ -20,6 +20,9 @@
#pragma once #pragma once
#define MSP_TLM_INBUF_SIZE 128
#define MSP_TLM_OUTBUF_SIZE 128
// type of function to send MSP response chunk over telemetry. // type of function to send MSP response chunk over telemetry.
typedef void (*mspResponseFnPtr)(uint8_t *payload, const uint8_t payloadSize); typedef void (*mspResponseFnPtr)(uint8_t *payload, const uint8_t payloadSize);

View file

@ -51,7 +51,6 @@ extern "C" {
#include "io/gps.h" #include "io/gps.h"
#include "msp/msp.h" #include "msp/msp.h"
#include "msp/msp_serial.h"
#include "rx/rx.h" #include "rx/rx.h"
#include "rx/crsf.h" #include "rx/crsf.h"
@ -88,7 +87,7 @@ extern "C" {
extern bool crsfFrameDone; extern bool crsfFrameDone;
extern crsfFrame_t crsfFrame; extern crsfFrame_t crsfFrame;
extern uint8_t requestBuffer[MSP_PORT_INBUF_SIZE]; extern uint8_t requestBuffer[MSP_TLM_INBUF_SIZE];
extern struct mspPacket_s requestPacket; extern struct mspPacket_s requestPacket;
extern struct mspPacket_s responsePacket; extern struct mspPacket_s responsePacket;
@ -254,7 +253,7 @@ extern "C" {
gpsSolutionData_t gpsSol; gpsSolutionData_t gpsSol;
attitudeEulerAngles_t attitude = { { 0, 0, 0 } }; attitudeEulerAngles_t attitude = { { 0, 0, 0 } };
uint8_t mspSerialOutBuf[MSP_PORT_OUTBUF_SIZE]; uint8_t responseBuffer[MSP_TLM_OUTBUF_SIZE];
uint32_t micros(void) {return dummyTimeUs;} uint32_t micros(void) {return dummyTimeUs;}
uint32_t microsISR(void) {return micros();} uint32_t microsISR(void) {return micros();}