mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-20 14:55:21 +03:00
Remove shared MSP buffer
This commit is contained in:
parent
fcb3ed4959
commit
5f4ed614f1
5 changed files with 18 additions and 17 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
uint8_t mspSerialOutBuf[MSP_PORT_OUTBUF_SIZE]; // this buffer also used in msp_shared.c
|
||||
|
||||
static mspPostProcessFnPtr mspSerialProcessReceivedCommand(mspPort_t *msp, mspProcessCommandFnPtr mspProcessCommandFn)
|
||||
{
|
||||
static uint8_t mspSerialOutBuf[MSP_PORT_OUTBUF_SIZE];
|
||||
|
||||
mspPacket_t reply = {
|
||||
.buf = { .ptr = mspSerialOutBuf, .end = ARRAYEND(mspSerialOutBuf), },
|
||||
.cmd = -1,
|
||||
|
|
|
@ -124,5 +124,3 @@ void mspSerialReleasePortIfAllocated(struct serialPort_s *serialPort);
|
|||
void mspSerialReleaseSharedTelemetryPorts(void);
|
||||
int mspSerialPush(serialPortIdentifier_e port, uint8_t cmd, uint8_t *data, int datalen, mspDirection_e direction);
|
||||
uint32_t mspSerialTxBytesFree(void);
|
||||
|
||||
extern uint8_t mspSerialOutBuf[MSP_PORT_OUTBUF_SIZE]; // this buffer also used in msp_shared.c
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
||||
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 responsePacket;
|
||||
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)
|
||||
{
|
||||
responsePacket.buf.ptr = mspSerialOutBuf;
|
||||
responsePacket.buf.end = ARRAYEND(mspSerialOutBuf);
|
||||
responsePacket.buf.ptr = responseBuffer;
|
||||
responsePacket.buf.end = ARRAYEND(responseBuffer);
|
||||
|
||||
mspSharedDescriptor = mspDescriptorAlloc();
|
||||
}
|
||||
|
@ -140,8 +141,8 @@ static void processMspPacket(void)
|
|||
{
|
||||
responsePacket.cmd = 0;
|
||||
responsePacket.result = 0;
|
||||
responsePacket.buf.ptr = mspSerialOutBuf;
|
||||
responsePacket.buf.end = ARRAYEND(mspSerialOutBuf);
|
||||
responsePacket.buf.ptr = responseBuffer;
|
||||
responsePacket.buf.end = ARRAYEND(responseBuffer);
|
||||
|
||||
mspPostProcessFnPtr mspPostProcessFn = NULL;
|
||||
if (mspFcProcessCommand(mspSharedDescriptor, &requestPacket, &responsePacket, &mspPostProcessFn) == MSP_RESULT_ERROR) {
|
||||
|
@ -151,18 +152,18 @@ static void processMspPacket(void)
|
|||
mspPostProcessFn(NULL);
|
||||
}
|
||||
|
||||
sbufSwitchToReader(&responsePacket.buf, mspSerialOutBuf);
|
||||
sbufSwitchToReader(&responsePacket.buf, responseBuffer);
|
||||
}
|
||||
|
||||
void sendMspErrorResponse(uint8_t error, int16_t cmd)
|
||||
{
|
||||
responsePacket.cmd = cmd;
|
||||
responsePacket.result = 0;
|
||||
responsePacket.buf.ptr = mspSerialOutBuf;
|
||||
responsePacket.buf.ptr = responseBuffer;
|
||||
|
||||
sbufWriteU8(&responsePacket.buf, 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
|
||||
|
@ -272,7 +273,7 @@ bool sendMspReply(const uint8_t payloadSizeMax, mspResponseFnPtr responseFn)
|
|||
sbuf_t *payloadBuf = sbufInit(&payloadBufStruct, payloadArray, payloadArray + payloadSizeMax);
|
||||
|
||||
// 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.
|
||||
// header
|
||||
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
|
||||
sbufWriteData(payloadBuf, responsePacket.buf.ptr, inputRemainder);
|
||||
sbufAdvance(&responsePacket.buf, inputRemainder);
|
||||
sbufSwitchToReader(&responsePacket.buf, mspSerialOutBuf);// for CRC calculation
|
||||
sbufSwitchToReader(&responsePacket.buf, responseBuffer);// for CRC calculation
|
||||
|
||||
responseFn(payloadArray, payloadBuf->ptr - payloadArray);
|
||||
return false;
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#define MSP_TLM_INBUF_SIZE 128
|
||||
#define MSP_TLM_OUTBUF_SIZE 128
|
||||
|
||||
// type of function to send MSP response chunk over telemetry.
|
||||
typedef void (*mspResponseFnPtr)(uint8_t *payload, const uint8_t payloadSize);
|
||||
|
||||
|
|
|
@ -51,7 +51,6 @@ extern "C" {
|
|||
#include "io/gps.h"
|
||||
|
||||
#include "msp/msp.h"
|
||||
#include "msp/msp_serial.h"
|
||||
|
||||
#include "rx/rx.h"
|
||||
#include "rx/crsf.h"
|
||||
|
@ -88,7 +87,7 @@ extern "C" {
|
|||
|
||||
extern bool crsfFrameDone;
|
||||
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 responsePacket;
|
||||
|
||||
|
@ -254,7 +253,7 @@ extern "C" {
|
|||
|
||||
gpsSolutionData_t gpsSol;
|
||||
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 microsISR(void) {return micros();}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue