Skip to content

Commit d98a524

Browse files
committed
Move task priorities and cores to NVM. Rename tasks.
1 parent 75e1944 commit d98a524

File tree

4 files changed

+96
-86
lines changed

4 files changed

+96
-86
lines changed

Firmware/RTK_Surveyor/Begin.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ void pinUART2Task(void *pvParameters)
586586
// Reduce threshold value above which RX FIFO full interrupt is generated
587587
// Allows more time between when the UART interrupt occurs and when the FIFO buffer overruns
588588
// serialGNSS.setRxFIFOFull(50); //Available in >v2.0.5
589-
uart_set_rx_full_threshold(2, 50); // uart_num, threshold
589+
uart_set_rx_full_threshold(2, settings.serialGNSSRxFullThreshold); // uart_num, threshold
590590
}
591591

592592
uart2pinned = true;

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
The RTK Surveyor implements classic Bluetooth SPP to transfer data from the
1616
ZED-F9P to the phone and receive any RTCM from the phone and feed it back
17-
to the ZED-F9P to achieve RTK: F9PSerialWriteTask(), F9PSerialReadTask().
17+
to the ZED-F9P to achieve RTK: btReadTask(), gnssReadTask().
1818
1919
Settings are loaded from microSD if available otherwise settings are pulled from ESP32's file system LittleFS.
2020
*/
@@ -392,21 +392,19 @@ HardwareSerial serialGNSS(2); // TX on 17, RX on 16
392392

393393
#define SERIAL_SIZE_TX 512
394394
uint8_t wBuffer[SERIAL_SIZE_TX]; // Buffer for writing from incoming SPP to F9P
395-
TaskHandle_t F9PSerialWriteTaskHandle =
395+
TaskHandle_t btReadTaskHandle =
396396
nullptr; // Store handles so that we can kill them if user goes into WiFi NTRIP Server mode
397-
const uint8_t F9PSerialWriteTaskPriority = 1; // 3 being the highest, and 0 being the lowest
398-
const int writeTaskStackSize = 2000;
397+
const uint8_t btReadTaskPriority = 1; // 3 being the highest, and 0 being the lowest
398+
const int btReadTaskStackSize = 2000;
399399

400400
uint8_t *ringBuffer; // Buffer for reading from F9P. At 230400bps, 23040 bytes/s. If SD blocks for 250ms, we need 23040
401401
// * 0.25 = 5760 bytes worst case.
402-
TaskHandle_t F9PSerialReadTaskHandle =
402+
TaskHandle_t gnssReadTaskHandle =
403403
nullptr; // Store handles so that we can kill them if user goes into WiFi NTRIP Server mode
404-
const uint8_t F9PSerialReadTaskPriority = 1; // 3 being the highest, and 0 being the lowest
405-
const int readTaskStackSize = 2000;
404+
const int gnssReadTaskStackSize = 2000;
406405

407-
TaskHandle_t handleGNSSDataTaskHandle = nullptr;
408-
const uint8_t handleGNSSDataTaskPriority = 1; // 3 being the highest, and 0 being the lowest
409-
const int handleGNSSDataTaskStackSize = 3000;
406+
TaskHandle_t handleGnssDataTaskHandle = nullptr;
407+
const int handleGnssDataTaskStackSize = 3000;
410408

411409
TaskHandle_t pinUART2TaskHandle = nullptr; // Dummy task to start UART2 on core 0.
412410
volatile bool uart2pinned = false; // This variable is touched by core 0 but checked by core 1. Must be volatile.

Firmware/RTK_Surveyor/Tasks.ino

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ volatile int availableHandlerSpace = 0; // settings.gnssHandlerBufferSize - used
66

77
// If the phone has any new data (NTRIP RTCM, etc), read it in over Bluetooth and pass along to ZED
88
// Scan for escape characters to enter config menu
9-
void F9PSerialWriteTask(void *e)
9+
void btReadTask(void *e)
1010
{
1111
while (true)
1212
{
@@ -126,7 +126,7 @@ void F9PSerialWriteTask(void *e)
126126
// The ESP32 Arduino FIFO is ~120 bytes by default but overridden to 50 bytes (see pinUART2Task() and
127127
// uart_set_rx_full_threshold()). We use this task to harvest from FIFO into circular buffer during SD write blocking
128128
// time.
129-
void F9PSerialReadTask(void *e)
129+
void gnssReadTask(void *e)
130130
{
131131
static PARSE_STATE parse = {waitForPreamble, processUart1Message, "Log"};
132132

@@ -258,7 +258,7 @@ void processUart1Message(PARSE_STATE *parse, uint8_t type)
258258

259259
// If new data is in the ringBuffer, dole it out to appropriate interface
260260
// Send data out Bluetooth, record to SD, or send over TCP
261-
void handleGNSSDataTask(void *e)
261+
void handleGnssDataTask(void *e)
262262
{
263263
volatile static uint16_t btTail = 0; // BT Tail advances as it is sent over BT
264264
volatile static uint16_t tcpTailWiFi = 0; // TCP client tail
@@ -657,8 +657,8 @@ void ButtonCheckTask(void *e)
657657
if (millis() - lastRockerSwitchChange < 500)
658658
{
659659
if (systemState == STATE_ROVER_NOT_STARTED && online.display == true) // Catch during Power On
660-
requestChangeState(STATE_TEST); // If RTK Surveyor, with display attached, during Rover not
661-
// started, then enter test mode
660+
requestChangeState(STATE_TEST); // If RTK Surveyor, with display attached, during Rover not
661+
// started, then enter test mode
662662
else
663663
requestChangeState(STATE_WIFI_CONFIG_NOT_STARTED);
664664
}
@@ -1137,51 +1137,54 @@ void idleTask(void *e)
11371137
void tasksStartUART2()
11381138
{
11391139
// Reads data from ZED and stores data into circular buffer
1140-
if (F9PSerialReadTaskHandle == nullptr)
1141-
xTaskCreate(F9PSerialReadTask, // Function to call
1142-
"F9Read", // Just for humans
1143-
readTaskStackSize, // Stack Size
1144-
nullptr, // Task input parameter
1145-
F9PSerialReadTaskPriority, // Priority
1146-
&F9PSerialReadTaskHandle); // Task handle
1140+
if (gnssReadTaskHandle == nullptr)
1141+
xTaskCreatePinnedToCore(gnssReadTask, // Function to call
1142+
"gnssRead", // Just for humans
1143+
gnssReadTaskStackSize, // Stack Size
1144+
nullptr, // Task input parameter
1145+
settings.gnssReadTaskPriority, // Priority
1146+
&gnssReadTaskHandle, // Task handle
1147+
settings.gnssReadTaskCore); // Core where task should run, 0=core, 1=Arduino
11471148

11481149
// Reads data from circular buffer and sends data to SD, SPP, or TCP
1149-
if (handleGNSSDataTaskHandle == nullptr)
1150-
xTaskCreate(handleGNSSDataTask, // Function to call
1151-
"handleGNSSData", // Just for humans
1152-
handleGNSSDataTaskStackSize, // Stack Size
1153-
nullptr, // Task input parameter
1154-
handleGNSSDataTaskPriority, // Priority
1155-
&handleGNSSDataTaskHandle); // Task handle
1150+
if (handleGnssDataTaskHandle == nullptr)
1151+
xTaskCreatePinnedToCore(handleGnssDataTask, // Function to call
1152+
"handleGNSSData", // Just for humans
1153+
handleGnssDataTaskStackSize, // Stack Size
1154+
nullptr, // Task input parameter
1155+
settings.handleGnssDataTaskPriority, // Priority
1156+
&handleGnssDataTaskHandle, // Task handle
1157+
settings.handleGnssDataTaskCore); // Core where task should run, 0=core, 1=Arduino
11561158

11571159
// Reads data from BT and sends to ZED
1158-
if (F9PSerialWriteTaskHandle == nullptr)
1159-
xTaskCreate(F9PSerialWriteTask, // Function to call
1160-
"F9Write", // Just for humans
1161-
writeTaskStackSize, // Stack Size
1162-
nullptr, // Task input parameter
1163-
F9PSerialWriteTaskPriority, // Priority
1164-
&F9PSerialWriteTaskHandle); // Task handle
1160+
if (btReadTaskHandle == nullptr)
1161+
xTaskCreatePinnedToCore(btReadTask, // Function to call
1162+
"btRead", // Just for humans
1163+
btReadTaskStackSize, // Stack Size
1164+
nullptr, // Task input parameter
1165+
settings.btReadTaskPriority, // Priority
1166+
&btReadTaskHandle, // Task handle
1167+
settings.btReadTaskCore); // Core where task should run, 0=core, 1=Arduino
11651168
}
11661169

11671170
// Stop tasks - useful when running firmware update or WiFi AP is running
11681171
void tasksStopUART2()
11691172
{
11701173
// Delete tasks if running
1171-
if (F9PSerialReadTaskHandle != nullptr)
1174+
if (gnssReadTaskHandle != nullptr)
11721175
{
1173-
vTaskDelete(F9PSerialReadTaskHandle);
1174-
F9PSerialReadTaskHandle = nullptr;
1176+
vTaskDelete(gnssReadTaskHandle);
1177+
gnssReadTaskHandle = nullptr;
11751178
}
1176-
if (handleGNSSDataTaskHandle != nullptr)
1179+
if (handleGnssDataTaskHandle != nullptr)
11771180
{
1178-
vTaskDelete(handleGNSSDataTaskHandle);
1179-
handleGNSSDataTaskHandle = nullptr;
1181+
vTaskDelete(handleGnssDataTaskHandle);
1182+
handleGnssDataTaskHandle = nullptr;
11801183
}
1181-
if (F9PSerialWriteTaskHandle != nullptr)
1184+
if (btReadTaskHandle != nullptr)
11821185
{
1183-
vTaskDelete(F9PSerialWriteTaskHandle);
1184-
F9PSerialWriteTaskHandle = nullptr;
1186+
vTaskDelete(btReadTaskHandle);
1187+
btReadTaskHandle = nullptr;
11851188
}
11861189

11871190
// Give the other CPU time to finish

0 commit comments

Comments
 (0)