mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-13 03:20:00 +03:00
Simplify cliWriter structure definition as use of uint8_t data[] (flexible array member) at the end of the bufWriter_t structure is breaking the F411 build
This commit is contained in:
parent
a3a3b74fd5
commit
aa833b2b2f
6 changed files with 13 additions and 17 deletions
|
@ -186,7 +186,7 @@ __ALIGN_BEGIN uint8_t CmdBuff[CDC_CMD_PACKET_SZE] __ALIGN_END ;
|
||||||
|
|
||||||
volatile uint32_t APP_Rx_ptr_in = 0;
|
volatile uint32_t APP_Rx_ptr_in = 0;
|
||||||
volatile uint32_t APP_Rx_ptr_out = 0;
|
volatile uint32_t APP_Rx_ptr_out = 0;
|
||||||
volatile uint32_t APP_Rx_length = 0;
|
uint32_t APP_Rx_length = 0;
|
||||||
|
|
||||||
uint8_t USB_Tx_State = USB_CDC_IDLE;
|
uint8_t USB_Tx_State = USB_CDC_IDLE;
|
||||||
|
|
||||||
|
@ -641,7 +641,7 @@ uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum)
|
||||||
DCD_EP_Tx(pdev, CDC_IN_EP, (uint8_t*)&APP_Rx_Buffer[APP_Rx_ptr_out], USB_Tx_length);
|
DCD_EP_Tx(pdev, CDC_IN_EP, (uint8_t*)&APP_Rx_Buffer[APP_Rx_ptr_out], USB_Tx_length);
|
||||||
|
|
||||||
// Advance the out pointer
|
// Advance the out pointer
|
||||||
APP_Rx_ptr_out = (APP_Rx_ptr_out + USB_Tx_length) % APP_RX_DATA_SIZE;;
|
APP_Rx_ptr_out = (APP_Rx_ptr_out + USB_Tx_length) % APP_RX_DATA_SIZE;
|
||||||
APP_Rx_length -= USB_Tx_length;
|
APP_Rx_length -= USB_Tx_length;
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
|
|
|
@ -181,9 +181,10 @@ static serialPort_t *cliPort = NULL;
|
||||||
#define CLI_IN_BUFFER_SIZE 256
|
#define CLI_IN_BUFFER_SIZE 256
|
||||||
#define CLI_OUT_BUFFER_SIZE 64
|
#define CLI_OUT_BUFFER_SIZE 64
|
||||||
|
|
||||||
|
static bufWriter_t cliWriterDesc;
|
||||||
static bufWriter_t *cliWriter = NULL;
|
static bufWriter_t *cliWriter = NULL;
|
||||||
static bufWriter_t *cliErrorWriter = NULL;
|
static bufWriter_t *cliErrorWriter = NULL;
|
||||||
static uint8_t cliWriteBuffer[sizeof(bufWriter_t) + CLI_OUT_BUFFER_SIZE];
|
static uint8_t cliWriteBuffer[CLI_OUT_BUFFER_SIZE];
|
||||||
|
|
||||||
static char cliBuffer[CLI_IN_BUFFER_SIZE];
|
static char cliBuffer[CLI_IN_BUFFER_SIZE];
|
||||||
static uint32_t bufferIndex = 0;
|
static uint32_t bufferIndex = 0;
|
||||||
|
@ -6863,8 +6864,8 @@ void cliEnter(serialPort_t *serialPort)
|
||||||
cliMode = true;
|
cliMode = true;
|
||||||
cliPort = serialPort;
|
cliPort = serialPort;
|
||||||
setPrintfSerialPort(cliPort);
|
setPrintfSerialPort(cliPort);
|
||||||
cliWriter = bufWriterInit(cliWriteBuffer, sizeof(cliWriteBuffer), (bufWrite_t)serialWriteBufShim, serialPort);
|
bufWriterInit(&cliWriterDesc, cliWriteBuffer, sizeof(cliWriteBuffer), (bufWrite_t)serialWriteBufShim, serialPort);
|
||||||
cliErrorWriter = cliWriter;
|
cliErrorWriter = cliWriter = &cliWriterDesc;
|
||||||
|
|
||||||
#ifndef MINIMAL_CLI
|
#ifndef MINIMAL_CLI
|
||||||
cliPrintLine("\r\nEntering CLI Mode, type 'exit' to return, or 'help'");
|
cliPrintLine("\r\nEntering CLI Mode, type 'exit' to return, or 'help'");
|
||||||
|
|
|
@ -24,15 +24,14 @@
|
||||||
|
|
||||||
#include "buf_writer.h"
|
#include "buf_writer.h"
|
||||||
|
|
||||||
bufWriter_t *bufWriterInit(uint8_t *b, int total_size, bufWrite_t writer, void *arg)
|
void bufWriterInit(bufWriter_t *b, uint8_t *data, int size, bufWrite_t writer, void *arg)
|
||||||
{
|
{
|
||||||
bufWriter_t *buf = (bufWriter_t *)b;
|
bufWriter_t *buf = (bufWriter_t *)b;
|
||||||
buf->writer = writer;
|
buf->writer = writer;
|
||||||
buf->arg = arg;
|
buf->arg = arg;
|
||||||
buf->at = 0;
|
buf->at = 0;
|
||||||
buf->capacity = total_size - sizeof(*buf);
|
buf->capacity = size;
|
||||||
|
buf->data = data;
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bufWriterAppend(bufWriter_t *b, uint8_t ch)
|
void bufWriterAppend(bufWriter_t *b, uint8_t ch)
|
||||||
|
|
|
@ -26,16 +26,12 @@ typedef void (*bufWrite_t)(void *arg, void *data, int count);
|
||||||
typedef struct bufWriter_s {
|
typedef struct bufWriter_s {
|
||||||
bufWrite_t writer;
|
bufWrite_t writer;
|
||||||
void *arg;
|
void *arg;
|
||||||
|
uint8_t *data;
|
||||||
uint8_t capacity;
|
uint8_t capacity;
|
||||||
uint8_t at;
|
uint8_t at;
|
||||||
uint8_t data[];
|
|
||||||
} bufWriter_t;
|
} bufWriter_t;
|
||||||
|
|
||||||
// Initialise a block of memory as a buffered writer.
|
// Initialise a block of memory as a buffered writer.
|
||||||
//
|
void bufWriterInit(bufWriter_t *b, uint8_t *data, int size, bufWrite_t writer, void *p);
|
||||||
// b should be sizeof(bufWriter_t) + the number of bytes to buffer.
|
|
||||||
// total_size should be the total size of b.
|
|
||||||
//
|
|
||||||
bufWriter_t *bufWriterInit(uint8_t *b, int total_size, bufWrite_t writer, void *p);
|
|
||||||
void bufWriterAppend(bufWriter_t *b, uint8_t ch);
|
void bufWriterAppend(bufWriter_t *b, uint8_t ch);
|
||||||
void bufWriterFlush(bufWriter_t *b);
|
void bufWriterFlush(bufWriter_t *b);
|
||||||
|
|
|
@ -191,7 +191,7 @@ uint32_t CDC_Send_DATA(const uint8_t *ptrBuffer, uint32_t sendLength)
|
||||||
|
|
||||||
uint32_t CDC_Send_FreeBytes(void)
|
uint32_t CDC_Send_FreeBytes(void)
|
||||||
{
|
{
|
||||||
return APP_RX_DATA_SIZE - CDC_Receive_BytesAvailable();;
|
return APP_RX_DATA_SIZE - CDC_Receive_BytesAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -325,7 +325,7 @@ uint8_t serialRead(serialPort_t *){return 0;}
|
||||||
|
|
||||||
void bufWriterAppend(bufWriter_t *, uint8_t ch){ printf("%c", ch); }
|
void bufWriterAppend(bufWriter_t *, uint8_t ch){ printf("%c", ch); }
|
||||||
void serialWriteBufShim(void *, const uint8_t *, int) {}
|
void serialWriteBufShim(void *, const uint8_t *, int) {}
|
||||||
bufWriter_t *bufWriterInit(uint8_t *, int, bufWrite_t, void *) {return NULL;}
|
void bufWriterInit(bufWriter_t *, uint8_t *, int, bufWrite_t, void *) { }
|
||||||
void setArmingDisabled(armingDisableFlags_e) {}
|
void setArmingDisabled(armingDisableFlags_e) {}
|
||||||
|
|
||||||
void waitForSerialPortToFinishTransmitting(serialPort_t *) {}
|
void waitForSerialPortToFinishTransmitting(serialPort_t *) {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue