Skip to content

Commit 475789c

Browse files
committed
Reduce buffer sizes, pin UART2 to core 0.
1 parent 141cd90 commit 475789c

File tree

3 files changed

+28
-39
lines changed

3 files changed

+28
-39
lines changed

Firmware/RTK_Surveyor/Begin.ino

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -327,27 +327,17 @@ void beginUART2()
327327
{
328328
rBuffer = (uint8_t*)malloc(settings.gnssHandlerBufferSize);
329329

330-
//TODO - For testing, pin to core 1
331-
serialGNSS.setRxBufferSize(settings.uartReceiveBufferSize);
332-
serialGNSS.setTimeout(settings.serialTimeoutGNSS);
333-
serialGNSS.begin(settings.dataPortBaud); //UART2 on pins 16/17 for SPP. The ZED-F9P will be configured to output NMEA over its UART1 at the same rate.
334-
335-
//Reduce threshold value above which RX FIFO full interrupt is generated
336-
//Allows more time between when the UART interrupt occurs and when the FIFO buffer overruns
337-
//serialGNSS.setRxFIFOFull(50); //Available in >v2.0.5
338-
uart_set_rx_full_threshold(2, 50); //uart_num, threshold
330+
if (pinUART2TaskHandle == NULL) xTaskCreatePinnedToCore(
331+
pinUART2Task,
332+
"UARTStart", //Just for humans
333+
2000, //Stack Size
334+
NULL, //Task input parameter
335+
0, // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest
336+
&pinUART2TaskHandle, //Task handle
337+
0); //Core where task should run, 0=core, 1=Arduino
339338

340-
// if (pinUART2TaskHandle == NULL) xTaskCreatePinnedToCore(
341-
// pinUART2Task,
342-
// "UARTStart", //Just for humans
343-
// 2000, //Stack Size
344-
// NULL, //Task input parameter
345-
// 0, // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest
346-
// &pinUART2TaskHandle, //Task handle
347-
// 0); //Core where task should run, 0=core, 1=Arduino
348-
//
349-
// while (uart2pinned == false) //Wait for task to run once
350-
// delay(1);
339+
while (uart2pinned == false) //Wait for task to run once
340+
delay(1);
351341
}
352342

353343
//Assign UART2 interrupts to the core 0. See: https://github.com/espressif/arduino-esp32/issues/3386

Firmware/RTK_Surveyor/Tasks.ino

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -343,29 +343,28 @@ void handleGNSSDataTask(void *e)
343343
} //End logging
344344

345345
//Update space available for use in UART task
346-
// btBytesToSend = lastDataHead - btTail;
347-
// if (btBytesToSend < 0)
348-
// btBytesToSend += settings.gnssHandlerBufferSize;
349-
//
350-
// nmeaBytesToSend = lastDataHead - nmeaTail;
351-
// if (nmeaBytesToSend < 0)
352-
// nmeaBytesToSend += settings.gnssHandlerBufferSize;
346+
btBytesToSend = lastDataHead - btTail;
347+
if (btBytesToSend < 0)
348+
btBytesToSend += settings.gnssHandlerBufferSize;
349+
350+
nmeaBytesToSend = lastDataHead - nmeaTail;
351+
if (nmeaBytesToSend < 0)
352+
nmeaBytesToSend += settings.gnssHandlerBufferSize;
353353

354354
sdBytesToRecord = lastDataHead - sdTail;
355355
if (sdBytesToRecord < 0)
356356
sdBytesToRecord += settings.gnssHandlerBufferSize;
357357

358358
//Determine the inteface that is most behind: SD writing, SPP transmission, or TCP transmission
359-
// int usedSpace = 0;
360-
// if (sdBytesToRecord >= btBytesToSend && sdBytesToRecord >= nmeaBytesToSend)
361-
// usedSpace = sdBytesToRecord;
362-
// else if (btBytesToSend >= sdBytesToRecord && btBytesToSend >= nmeaBytesToSend)
363-
// usedSpace = btBytesToSend;
364-
// else
365-
// usedSpace = nmeaBytesToSend;
366-
367-
// availableHandlerSpace = settings.gnssHandlerBufferSize - usedSpace;
368-
availableHandlerSpace = settings.gnssHandlerBufferSize - sdBytesToRecord;
359+
int usedSpace = 0;
360+
if (nmeaBytesToSend >= btBytesToSend && nmeaBytesToSend >= sdBytesToRecord)
361+
usedSpace = nmeaBytesToSend;
362+
else if (btBytesToSend >= sdBytesToRecord && btBytesToSend >= nmeaBytesToSend)
363+
usedSpace = btBytesToSend;
364+
else
365+
usedSpace = sdBytesToRecord;
366+
367+
availableHandlerSpace = settings.gnssHandlerBufferSize - usedSpace;
369368

370369
//Don't fill the last byte to prevent buffer overflow
371370
if (availableHandlerSpace)

Firmware/RTK_Surveyor/settings.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,8 @@ typedef struct {
523523
uint16_t antennaHeight = 0; //in mm
524524
float antennaReferencePoint = 0.0; //in mm
525525
bool echoUserInput = true;
526-
int uartReceiveBufferSize = 1024 * 5; //This buffer is filled automatically as the UART receives characters.
527-
int gnssHandlerBufferSize = 1024 * 5; //This buffer is filled from the UART receive buffer, and is then written to SD
526+
int uartReceiveBufferSize = 1024 * 2; //This buffer is filled automatically as the UART receives characters.
527+
int gnssHandlerBufferSize = 1024 * 4; //This buffer is filled from the UART receive buffer, and is then written to SD
528528
bool enablePrintBufferOverrun = false;
529529
bool enablePrintSDBuffers = false;
530530
} Settings;

0 commit comments

Comments
 (0)