Skip to content

Commit 201183f

Browse files
committed
Move log file sync into task.
If the log file was syncing, and the task fired it would not get a semaphore lock
1 parent 84f0a1a commit 201183f

File tree

3 files changed

+28
-38
lines changed

3 files changed

+28
-38
lines changed

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -379,41 +379,6 @@ void updateLogs()
379379
online.logging = false;
380380
}
381381

382-
if (online.logging == true)
383-
{
384-
//Check if we are inside the max time window for logging
385-
if ((systemTime_minutes - startLogTime_minutes) < settings.maxLogTime_minutes)
386-
{
387-
//Attempt log file sync every 3000ms
388-
if (millis() - lastUBXLogSyncTime > 3000)
389-
{
390-
//Attempt to write to file system. This avoids collisions with file writing from other functions like F9PSerialReadTask() and recordSystemSettingsToFile()
391-
if (xSemaphoreTake(xFATSemaphore, fatSemaphore_maxWait) == pdPASS)
392-
{
393-
if (productVariant == RTK_SURVEYOR)
394-
digitalWrite(pin_baseStatusLED, !digitalRead(pin_baseStatusLED)); //Blink LED to indicate logging activity
395-
396-
long startWriteTime = micros();
397-
ubxFile.sync();
398-
long stopWriteTime = micros();
399-
totalWriteTime += stopWriteTime - startWriteTime; //Used to calculate overall write speed
400-
401-
if (productVariant == RTK_SURVEYOR)
402-
digitalWrite(pin_baseStatusLED, !digitalRead(pin_baseStatusLED)); //Return LED to previous state
403-
404-
updateDataFileAccess(&ubxFile); // Update the file access time & date
405-
406-
xSemaphoreGive(xFATSemaphore);
407-
}
408-
409-
lastUBXLogSyncTime = millis();
410-
}
411-
412-
// In case the SD writing is slow or there is a lot of data to write, keep checking for the arrival of new data
413-
i2cGNSS.checkUblox(); // Check for the arrival of new data and process it.
414-
}
415-
}
416-
417382
//Report file sizes to show recording is working
418383
if (online.logging == true)
419384
{

Firmware/RTK_Surveyor/Tasks.ino

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ void F9PSerialReadTask(void *e)
7070
if (xSemaphoreTake(xFATSemaphore, fatSemaphore_maxWait) == pdPASS)
7171
{
7272
ubxFile.write(rBuffer, s);
73+
74+
//Force file sync every 5000ms
75+
if (millis() - lastUBXLogSyncTime > 5000)
76+
{
77+
if (productVariant == RTK_SURVEYOR)
78+
digitalWrite(pin_baseStatusLED, !digitalRead(pin_baseStatusLED)); //Blink LED to indicate logging activity
79+
80+
long startWriteTime = micros();
81+
ubxFile.sync();
82+
long stopWriteTime = micros();
83+
totalWriteTime += stopWriteTime - startWriteTime; //Used to calculate overall write speed
84+
85+
if (productVariant == RTK_SURVEYOR)
86+
digitalWrite(pin_baseStatusLED, !digitalRead(pin_baseStatusLED)); //Return LED to previous state
87+
88+
updateDataFileAccess(&ubxFile); // Update the file access time & date
89+
90+
lastUBXLogSyncTime = millis();
91+
}
92+
7393
xSemaphoreGive(xFATSemaphore);
7494
} //End xFATSemaphore
7595
} //End maxLogTime
@@ -92,7 +112,6 @@ void startUART2Task( void *pvParameters )
92112
vTaskDelete( NULL ); //Delete task once it has run once
93113
}
94114

95-
96115
//Control BT status LED according to bluetoothState
97116
void updateBTled()
98117
{

Firmware/RTK_Surveyor/menuMain.ino

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,14 @@ void menuMain()
5858
menuLog();
5959
else if (incoming == '6' && settings.enableSD == true && online.microSD == true)
6060
{
61-
Serial.println(F("Files found (date time size name):\n\r"));
62-
sd.ls(LS_R | LS_DATE | LS_SIZE);
61+
//Attempt to write to file system. This avoids collisions with file writing from other functions like recordSystemSettingsToFile() and F9PSerialReadTask()
62+
if (xSemaphoreTake(xFATSemaphore, fatSemaphore_maxWait) == pdPASS)
63+
{
64+
Serial.println(F("Files found (date time size name):\n\r"));
65+
sd.ls(LS_R | LS_DATE | LS_SIZE);
66+
67+
xSemaphoreGive(xFATSemaphore);
68+
}
6369
}
6470
else if (incoming == 'd')
6571
menuDebug();

0 commit comments

Comments
 (0)