Skip to content

Commit 6bf9290

Browse files
committed
Change semaphore name from xFATSemaphore to sdCardSemaphore
The semaphore is protecting access to the SPI controller used to access the SD card. Any operations to the SD card need to be protected by this semaphore.
1 parent 42ec4c7 commit 6bf9290

File tree

10 files changed

+50
-50
lines changed

10 files changed

+50
-50
lines changed

Firmware/RTK_Surveyor/Begin.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,11 @@ void beginSD()
241241
}
242242

243243
//Setup FAT file access semaphore
244-
if (xFATSemaphore == NULL)
244+
if (sdCardSemaphore == NULL)
245245
{
246-
xFATSemaphore = xSemaphoreCreateMutex();
247-
if (xFATSemaphore != NULL)
248-
xSemaphoreGive(xFATSemaphore); //Make the file system available for use
246+
sdCardSemaphore = xSemaphoreCreateMutex();
247+
if (sdCardSemaphore != NULL)
248+
xSemaphoreGive(sdCardSemaphore); //Make the file system available for use
249249
}
250250

251251
if (createTestFile() == false)

Firmware/RTK_Surveyor/Buttons.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ void powerDown(bool displayInfo)
3131
{
3232
//Attempt to write to file system. This avoids collisions with file writing from other functions like recordSystemSettingsToFile()
3333
//Wait up to 1000ms
34-
if (xSemaphoreTake(xFATSemaphore, 1000 / portTICK_PERIOD_MS) == pdPASS)
34+
if (xSemaphoreTake(sdCardSemaphore, 1000 / portTICK_PERIOD_MS) == pdPASS)
3535
{
3636
//Close down file system
3737
ubxFile.sync();
3838
ubxFile.close();
39-
//xSemaphoreGive(xFATSemaphore); //Do not release semaphore
40-
} //End xFATSemaphore
39+
//xSemaphoreGive(sdCardSemaphore); //Do not release semaphore
40+
} //End sdCardSemaphore
4141

4242
online.logging = false;
4343
}

Firmware/RTK_Surveyor/NVM.ino

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void recordSystemSettingsToFileSD(char *fileName)
6262
if (online.microSD == true)
6363
{
6464
//Attempt to write to file system. This avoids collisions with file writing from other functions like updateLogs()
65-
if (xSemaphoreTake(xFATSemaphore, fatSemaphore_longWait_ms) == pdPASS)
65+
if (xSemaphoreTake(sdCardSemaphore, fatSemaphore_longWait_ms) == pdPASS)
6666
{
6767
if (sd.exists(fileName))
6868
sd.remove(fileName);
@@ -84,7 +84,7 @@ void recordSystemSettingsToFileSD(char *fileName)
8484

8585
log_d("Settings recorded to SD: %s", fileName);
8686

87-
xSemaphoreGive(xFATSemaphore);
87+
xSemaphoreGive(sdCardSemaphore);
8888
}
8989
}
9090
}
@@ -226,15 +226,15 @@ bool loadSystemSettingsFromFileSD(char* fileName, Settings *settings)
226226
if (online.microSD == true)
227227
{
228228
//Attempt to access file system. This avoids collisions with file writing from other functions like recordSystemSettingsToFile() and F9PSerialReadTask()
229-
if (xSemaphoreTake(xFATSemaphore, fatSemaphore_longWait_ms) == pdPASS)
229+
if (xSemaphoreTake(sdCardSemaphore, fatSemaphore_longWait_ms) == pdPASS)
230230
{
231231
if (sd.exists(fileName))
232232
{
233233
SdFile settingsFile; //FAT32
234234
if (settingsFile.open(fileName, O_READ) == false)
235235
{
236236
Serial.println(F("Failed to open settings file"));
237-
xSemaphoreGive(xFATSemaphore);
237+
xSemaphoreGive(sdCardSemaphore);
238238
return (false);
239239
}
240240

@@ -255,7 +255,7 @@ bool loadSystemSettingsFromFileSD(char* fileName, Settings *settings)
255255
{
256256
//If we can't read the first line of the settings file, give up
257257
Serial.println(F("Giving up on settings file"));
258-
xSemaphoreGive(xFATSemaphore);
258+
xSemaphoreGive(sdCardSemaphore);
259259
return (false);
260260
}
261261
}
@@ -265,7 +265,7 @@ bool loadSystemSettingsFromFileSD(char* fileName, Settings *settings)
265265
{
266266
//If we can't read the first line of the settings file, give up
267267
Serial.println(F("Giving up on settings file"));
268-
xSemaphoreGive(xFATSemaphore);
268+
xSemaphoreGive(sdCardSemaphore);
269269
return (false);
270270
}
271271
}
@@ -275,13 +275,13 @@ bool loadSystemSettingsFromFileSD(char* fileName, Settings *settings)
275275

276276
//Serial.println(F("Config file read complete"));
277277
settingsFile.close();
278-
xSemaphoreGive(xFATSemaphore);
278+
xSemaphoreGive(sdCardSemaphore);
279279
return (true);
280280
}
281281
else
282282
{
283283
log_d("File %s not found", fileName);
284-
xSemaphoreGive(xFATSemaphore);
284+
xSemaphoreGive(sdCardSemaphore);
285285
return (false);
286286
}
287287

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ SdFile newFirmwareFile; //File that is available if user uploads new firmware vi
141141

142142
//System crashes if two tasks access a file at the same time
143143
//So we use a semaphore to see if file system is available
144-
SemaphoreHandle_t xFATSemaphore;
144+
SemaphoreHandle_t sdCardSemaphore;
145145
const TickType_t fatSemaphore_shortWait_ms = 10 / portTICK_PERIOD_MS;
146146
const TickType_t fatSemaphore_longWait_ms = 200 / portTICK_PERIOD_MS;
147147

@@ -157,7 +157,7 @@ uint32_t sdUsedSpaceMB = 0;
157157
#include <WiFi.h> //Built-in.
158158
#include <HTTPClient.h> //Built-in. Needed for ThingStream API for ZTP
159159
#include <ArduinoJson.h> //http://librarymanager/All#Arduino_JSON_messagepack v6.19.4
160-
#include <WiFiClientSecure.h> //Built-in.
160+
#include <WiFiClientSecure.h> //Built-in.
161161
#include <PubSubClient.h> //Built-in. Used for MQTT obtaining of keys
162162

163163
#include "base64.h" //Built-in. Needed for NTRIP Client credential encoding.
@@ -340,7 +340,7 @@ unsigned long lastRockerSwitchChange = 0; //If quick toggle is detected (less th
340340
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
341341
#ifdef COMPILE_WIFI
342342
#ifdef COMPILE_AP
343-
#include "ESPAsyncWebServer.h" //Get from: https://github.com/me-no-dev/ESPAsyncWebServer
343+
#include "ESPAsyncWebServer.h" //Get from: https://github.com/me-no-dev/ESPAsyncWebServer
344344
#include "form.h"
345345

346346
AsyncWebServer server(80);
@@ -563,23 +563,23 @@ void updateLogs()
563563
else if (online.logging == true && settings.enableLogging == false)
564564
{
565565
//Close down file
566-
if (xSemaphoreTake(xFATSemaphore, fatSemaphore_longWait_ms) == pdPASS)
566+
if (xSemaphoreTake(sdCardSemaphore, fatSemaphore_longWait_ms) == pdPASS)
567567
{
568568
ubxFile.sync();
569569
ubxFile.close();
570570
online.logging = false;
571-
xSemaphoreGive(xFATSemaphore); //Release semaphore
571+
xSemaphoreGive(sdCardSemaphore); //Release semaphore
572572
}
573573
}
574574
else if (online.logging == true && settings.enableLogging == true && (systemTime_minutes - startCurrentLogTime_minutes) >= settings.maxLogLength_minutes)
575575
{
576576
//Close down file. A new one will be created at the next calling of updateLogs().
577-
if (xSemaphoreTake(xFATSemaphore, fatSemaphore_longWait_ms) == pdPASS)
577+
if (xSemaphoreTake(sdCardSemaphore, fatSemaphore_longWait_ms) == pdPASS)
578578
{
579579
ubxFile.sync();
580580
ubxFile.close();
581581
online.logging = false;
582-
xSemaphoreGive(xFATSemaphore); //Release semaphore
582+
xSemaphoreGive(sdCardSemaphore); //Release semaphore
583583
}
584584
}
585585

@@ -588,7 +588,7 @@ void updateLogs()
588588
//Force file sync every 5000ms
589589
if (millis() - lastUBXLogSyncTime > 5000)
590590
{
591-
if (xSemaphoreTake(xFATSemaphore, fatSemaphore_shortWait_ms) == pdPASS)
591+
if (xSemaphoreTake(sdCardSemaphore, fatSemaphore_shortWait_ms) == pdPASS)
592592
{
593593
if (productVariant == RTK_SURVEYOR)
594594
digitalWrite(pin_baseStatusLED, !digitalRead(pin_baseStatusLED)); //Blink LED to indicate logging activity
@@ -604,8 +604,8 @@ void updateLogs()
604604
updateDataFileAccess(&ubxFile); // Update the file access time & date
605605

606606
lastUBXLogSyncTime = millis();
607-
xSemaphoreGive(xFATSemaphore);
608-
} //End xFATSemaphore
607+
xSemaphoreGive(sdCardSemaphore);
608+
} //End sdCardSemaphore
609609
else
610610
{
611611
log_d("Semaphore failed to yield");
@@ -624,11 +624,11 @@ void updateLogs()
624624
char nmeaMessage[82]; //Max NMEA sentence length is 82
625625
createNMEASentence(CUSTOM_NMEA_TYPE_EVENT, nmeaMessage, eventData); //textID, buffer, text
626626

627-
if (xSemaphoreTake(xFATSemaphore, fatSemaphore_shortWait_ms) == pdPASS)
627+
if (xSemaphoreTake(sdCardSemaphore, fatSemaphore_shortWait_ms) == pdPASS)
628628
{
629629
ubxFile.println(nmeaMessage);
630630

631-
xSemaphoreGive(xFATSemaphore);
631+
xSemaphoreGive(sdCardSemaphore);
632632
newEventToRecord = false;
633633
}
634634
}
@@ -639,11 +639,11 @@ void updateLogs()
639639
long fileSize = 0;
640640

641641
//Attempt to access file system. This avoids collisions with file writing from other functions like recordSystemSettingsToFile() and F9PSerialReadTask()
642-
if (xSemaphoreTake(xFATSemaphore, fatSemaphore_shortWait_ms) == pdPASS)
642+
if (xSemaphoreTake(sdCardSemaphore, fatSemaphore_shortWait_ms) == pdPASS)
643643
{
644644
fileSize = ubxFile.fileSize();
645645

646-
xSemaphoreGive(xFATSemaphore);
646+
xSemaphoreGive(sdCardSemaphore);
647647
}
648648

649649
if (fileSize > 0)

Firmware/RTK_Surveyor/System.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -556,25 +556,25 @@ bool createTestFile()
556556
SdFile testFile;
557557
char testFileName[40] = "testfile.txt";
558558

559-
if (xFATSemaphore == NULL)
559+
if (sdCardSemaphore == NULL)
560560
{
561-
log_d("xFATSemaphore is Null");
561+
log_d("sdCardSemaphore is Null");
562562
return (false);
563563
}
564564

565565
//Attempt to write to file system. This avoids collisions with file writing from other functions like recordSystemSettingsToFile() and F9PSerialReadTask()
566-
if (xSemaphoreTake(xFATSemaphore, fatSemaphore_shortWait_ms) == pdPASS)
566+
if (xSemaphoreTake(sdCardSemaphore, fatSemaphore_shortWait_ms) == pdPASS)
567567
{
568568
if (testFile.open(testFileName, O_CREAT | O_APPEND | O_WRITE) == true)
569569
{
570570
testFile.close();
571571

572572
if (sd.exists(testFileName))
573573
sd.remove(testFileName);
574-
xSemaphoreGive(xFATSemaphore);
574+
xSemaphoreGive(sdCardSemaphore);
575575
return (true);
576576
}
577-
xSemaphoreGive(xFATSemaphore);
577+
xSemaphoreGive(sdCardSemaphore);
578578
}
579579

580580
return (false);

Firmware/RTK_Surveyor/Tasks.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ void F9PSerialReadTask(void *e)
7575
if ((systemTime_minutes - startLogTime_minutes) < settings.maxLogTime_minutes)
7676
{
7777
//Attempt to write to file system. This avoids collisions with file writing from other functions like recordSystemSettingsToFile()
78-
if (xSemaphoreTake(xFATSemaphore, fatSemaphore_shortWait_ms) == pdPASS)
78+
if (xSemaphoreTake(sdCardSemaphore, fatSemaphore_shortWait_ms) == pdPASS)
7979
{
8080
ubxFile.write(rBuffer, s);
8181

82-
xSemaphoreGive(xFATSemaphore);
83-
} //End xFATSemaphore
82+
xSemaphoreGive(sdCardSemaphore);
83+
} //End sdCardSemaphore
8484
else
8585
{
8686
log_d("Semaphore failed to yield");

Firmware/RTK_Surveyor/menuFirmware.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void scanForFirmware()
5252
{
5353
//Attempt to access file system. This avoids collisions with file writing in F9PSerialReadTask()
5454
//Wait up to 5s, this is important
55-
if (xSemaphoreTake(xFATSemaphore, 5000 / portTICK_PERIOD_MS) == pdPASS)
55+
if (xSemaphoreTake(sdCardSemaphore, 5000 / portTICK_PERIOD_MS) == pdPASS)
5656
{
5757
//Count available binaries
5858
SdFile tempFile;
@@ -92,7 +92,7 @@ void scanForFirmware()
9292
tempFile.close();
9393
}
9494

95-
xSemaphoreGive(xFATSemaphore);
95+
xSemaphoreGive(sdCardSemaphore);
9696
}
9797

9898
}

Firmware/RTK_Surveyor/menuMain.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,12 @@ void factoryReset()
219219
//Attempt to write to file system. This avoids collisions with file writing from other functions like recordSystemSettingsToFile() and F9PSerialReadTask()
220220
if (settings.enableSD && online.microSD)
221221
{
222-
if (xSemaphoreTake(xFATSemaphore, fatSemaphore_longWait_ms) == pdPASS)
222+
if (xSemaphoreTake(sdCardSemaphore, fatSemaphore_longWait_ms) == pdPASS)
223223
{
224224
//Remove this specific settings file. Don't remove the other profiles.
225225
sd.remove(settingsFileName);
226-
xSemaphoreGive(xFATSemaphore);
227-
} //End xFATSemaphore
226+
xSemaphoreGive(sdCardSemaphore);
227+
} //End sdCardSemaphore
228228
}
229229

230230
if (online.gnss == true)

Firmware/RTK_Surveyor/menuMessages.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ void beginLogging()
345345
}
346346

347347
//Attempt to write to file system. This avoids collisions with file writing in F9PSerialReadTask()
348-
if (xSemaphoreTake(xFATSemaphore, fatSemaphore_longWait_ms) == pdPASS)
348+
if (xSemaphoreTake(sdCardSemaphore, fatSemaphore_longWait_ms) == pdPASS)
349349
{
350350
// O_CREAT - create the file if it does not exist
351351
// O_APPEND - seek to the end of the file prior to each write
@@ -354,7 +354,7 @@ void beginLogging()
354354
{
355355
Serial.printf("Failed to create GNSS UBX data file: %s\n\r", fileName);
356356
online.logging = false;
357-
xSemaphoreGive(xFATSemaphore);
357+
xSemaphoreGive(sdCardSemaphore);
358358
return;
359359
}
360360

@@ -405,7 +405,7 @@ void beginLogging()
405405
Serial.println(F("Appending last available log"));
406406
}
407407

408-
xSemaphoreGive(xFATSemaphore);
408+
xSemaphoreGive(sdCardSemaphore);
409409
}
410410
else
411411
{
@@ -448,7 +448,7 @@ bool findLastLog(char *lastLogName)
448448
{
449449
//Attempt to access file system. This avoids collisions with file writing in F9PSerialReadTask()
450450
//Wait up to 5s, this is important
451-
if (xSemaphoreTake(xFATSemaphore, 5000 / portTICK_PERIOD_MS) == pdPASS)
451+
if (xSemaphoreTake(sdCardSemaphore, 5000 / portTICK_PERIOD_MS) == pdPASS)
452452
{
453453
//Count available binaries
454454
SdFile tempFile;
@@ -478,7 +478,7 @@ bool findLastLog(char *lastLogName)
478478
tempFile.close();
479479
}
480480

481-
xSemaphoreGive(xFATSemaphore);
481+
xSemaphoreGive(sdCardSemaphore);
482482
}
483483
}
484484

Firmware/RTK_Surveyor/menuSystem.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ void menuSystem()
126126
else if (incoming == 'f' && settings.enableSD == true && online.microSD == true)
127127
{
128128
//Attempt to write to file system. This avoids collisions with file writing from other functions like recordSystemSettingsToFile() and F9PSerialReadTask()
129-
if (xSemaphoreTake(xFATSemaphore, fatSemaphore_longWait_ms) == pdPASS)
129+
if (xSemaphoreTake(sdCardSemaphore, fatSemaphore_longWait_ms) == pdPASS)
130130
{
131131
Serial.println(F("Files found (date time size name):\n\r"));
132132
sd.ls(LS_R | LS_DATE | LS_SIZE);
133133

134-
xSemaphoreGive(xFATSemaphore);
134+
xSemaphoreGive(sdCardSemaphore);
135135
}
136136
}
137137
else if (incoming == 'x')
@@ -290,7 +290,7 @@ void menuDebug()
290290
else if (incoming == 'r')
291291
{
292292
recordSystemSettings();
293-
293+
294294
ESP.restart();
295295
}
296296
else if (incoming == 't')

0 commit comments

Comments
 (0)