Skip to content

Commit 36374f3

Browse files
committed
Rename pinning to core functions for readability. Move taskYIELD in F9PSerialWriteTask.
1 parent 0355f99 commit 36374f3

File tree

3 files changed

+33
-40
lines changed

3 files changed

+33
-40
lines changed

Firmware/RTK_Surveyor/Begin.ino

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,6 @@ void beginBoard()
128128
case ESP_RST_SDIO : Serial.println(F("ESP_RST_SDIO")); break;
129129
default : Serial.println(F("Unknown"));
130130
}
131-
132-
#ifdef ENABLE_DEVELOPER
133-
Serial.println("System reset");
134-
displayError("WDT RST"); //Freeze with displayed error
135-
while (1);
136-
#endif
137-
138131
}
139132
}
140133

@@ -202,26 +195,38 @@ void beginSD()
202195
}
203196
}
204197

198+
//We want the UART2 interrupts to be pinned to core 0 to avoid competing with I2C interrupts
205199
//We do not start the UART2 for GNSS->BT reception here because the interrupts would be pinned to core 1
206-
//competing with I2C interrupts
207-
//See issue: https://github.com/espressif/arduino-esp32/issues/3386
208200
//We instead start a task that runs on core 0, that then begins serial
201+
//See issue: https://github.com/espressif/arduino-esp32/issues/3386
209202
void beginUART2()
210203
{
211-
if (startUART2TaskHandle == NULL) xTaskCreatePinnedToCore(
212-
startUART2Task,
204+
if (pinUART2TaskHandle == NULL) xTaskCreatePinnedToCore(
205+
pinUART2Task,
213206
"UARTStart", //Just for humans
214207
2000, //Stack Size
215208
NULL, //Task input parameter
216209
0, // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
217-
&startUART2TaskHandle, //Task handle
210+
&pinUART2TaskHandle, //Task handle
218211
0); //Core where task should run, 0=core, 1=Arduino
219212

220-
while (uart2Started == false) //Wait for task to run once
213+
while (uart2pinned == false) //Wait for task to run once
221214
delay(1);
222215
}
223216

224-
//These must be started after BT is up and running otherwise SerialBT.available will call reboot
217+
//Assign UART2 interrupts to the core 0. See: https://github.com/espressif/arduino-esp32/issues/3386
218+
void pinUART2Task( void *pvParameters )
219+
{
220+
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.
221+
serialGNSS.setRxBufferSize(SERIAL_SIZE_RX);
222+
serialGNSS.setTimeout(50);
223+
224+
uart2pinned = true;
225+
226+
vTaskDelete( NULL ); //Delete task once it has run once
227+
}
228+
229+
//Serial Read/Write tasks for the F9P must be started after BT is up and running otherwise SerialBT.available will cause reboot
225230
void startUART2Tasks()
226231
{
227232
//Start the tasks for handling incoming and outgoing BT bytes to/from ZED-F9P
@@ -447,6 +452,6 @@ void beginSystemState()
447452
"BtnCheck", //Just for humans
448453
buttonTaskStackSize, //Stack Size
449454
NULL, //Task input parameter
450-
1, //Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
455+
0, //Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
451456
&ButtonCheckTaskHandle); //Task handle
452457
}

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ uint8_t wBuffer[SERIAL_SIZE_RX]; //Buffer for writing from incoming SPP to F9P
222222
TaskHandle_t F9PSerialReadTaskHandle = NULL; //Store handles so that we can kill them if user goes into WiFi NTRIP Server mode
223223
TaskHandle_t F9PSerialWriteTaskHandle = NULL; //Store handles so that we can kill them if user goes into WiFi NTRIP Server mode
224224

225-
TaskHandle_t startUART2TaskHandle = NULL; //Dummy task to start UART2 on core 0.
226-
bool uart2Started = false;
225+
TaskHandle_t pinUART2TaskHandle = NULL; //Dummy task to start UART2 on core 0.
226+
bool uart2pinned = false;
227227

228228
//Reduced stack size from 10,000 to 2,000 to make room for WiFi/NTRIP server capabilities
229229
const int readTaskStackSize = 2000;
@@ -269,7 +269,7 @@ SPARKFUN_LIS2DH12 accel;
269269
//Buttons - Interrupt driven and debounce
270270
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
271271
#include <JC_Button.h> // http://librarymanager/All#JC_Button
272-
Button *setupBtn = NULL; //We can't instatiate the buttons here because we don't yet know what pin numbers to use
272+
Button *setupBtn = NULL; //We can't instantiate the buttons here because we don't yet know what pin numbers to use
273273
Button *powerBtn = NULL;
274274

275275
TaskHandle_t ButtonCheckTaskHandle = NULL;
@@ -403,8 +403,6 @@ void loop()
403403
{
404404
i2cGNSS.checkUblox(); //Regularly poll to get latest data and any RTCM
405405

406-
//checkButtons(); //Change system state as needed
407-
408406
updateSystemState();
409407

410408
updateBattLEDs();

Firmware/RTK_Surveyor/Tasks.ino

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ void F9PSerialWriteTask(void *e)
1313
{
1414
while (SerialBT.available())
1515
{
16-
taskYIELD();
1716
if (inTestMode == false)
1817
{
1918
//Pass bytes to GNSS receiver
@@ -29,6 +28,7 @@ void F9PSerialWriteTask(void *e)
2928
Serial.printf("I heard: %c\n", incoming);
3029
incomingBTTest = incoming; //Displayed during system test
3130
}
31+
taskYIELD();
3232
}
3333
}
3434
#endif
@@ -124,17 +124,7 @@ void F9PSerialReadTask(void *e)
124124
}
125125
}
126126

127-
//Assign UART2 interrupts to the current core. See: https://github.com/espressif/arduino-esp32/issues/3386
128-
void startUART2Task( void *pvParameters )
129-
{
130-
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.
131-
serialGNSS.setRxBufferSize(SERIAL_SIZE_RX);
132-
serialGNSS.setTimeout(50);
133127

134-
uart2Started = true;
135-
136-
vTaskDelete( NULL ); //Delete task once it has run once
137-
}
138128

139129
//Control BT status LED according to radioState
140130
void updateBTled()
@@ -174,8 +164,6 @@ void ButtonCheckTask(void *e)
174164

175165
while (true)
176166
{
177-
delay(1); //Yield to other tasks. Pet WDT.
178-
179167
if (productVariant == RTK_SURVEYOR)
180168
{
181169
setupBtn->read();
@@ -330,12 +318,12 @@ void ButtonCheckTask(void *e)
330318
forceSystemStateUpdate = true;
331319
requestChangeState(STATE_SHUTDOWN);
332320
}
333-
// else if ((setupBtn != NULL && setupBtn->pressedFor(500)) &&
334-
// (powerBtn != NULL && powerBtn->pressedFor(500)))
335-
// {
336-
// forceSystemStateUpdate = true;
337-
// requestChangeState(STATE_TEST);
338-
// }
321+
// else if ((setupBtn != NULL && setupBtn->pressedFor(500)) &&
322+
// (powerBtn != NULL && powerBtn->pressedFor(500)))
323+
// {
324+
// forceSystemStateUpdate = true;
325+
// requestChangeState(STATE_TEST);
326+
// }
339327
else if (powerBtn != NULL && powerBtn->wasReleased())
340328
{
341329
switch (systemState)
@@ -423,8 +411,10 @@ void ButtonCheckTask(void *e)
423411
requestChangeState(STATE_ROVER_NOT_STARTED);
424412
break;
425413
}
426-
} } //End Platform = RTK Facet
414+
}
415+
} //End Platform = RTK Facet
427416

417+
delay(1); //Yield to other tasks. Pet WDT.
428418
taskYIELD();
429419
}
430420
}

0 commit comments

Comments
 (0)