SPIFFS mount sometimes fail
This commit is contained in:
@@ -50,13 +50,12 @@ void loop()
|
||||
{
|
||||
// global variables
|
||||
bool running = true;
|
||||
|
||||
const uint32_t max_queue = 128;
|
||||
PSRAMVector<ignitionBoxStatus> ignA_history_0(max_history);
|
||||
PSRAMVector<ignitionBoxStatus> ignA_history_1(max_history);
|
||||
auto *active_history = &ignA_history_0;
|
||||
auto *writable_history = &ignA_history_1;
|
||||
|
||||
|
||||
// Resources Initialization
|
||||
static Devices dev;
|
||||
// Task handle
|
||||
@@ -100,7 +99,6 @@ void loop()
|
||||
.rt_resets = rtTaskResets{.rst_io_12p = RST_EXT_B12P, .rst_io_12n = RST_EXT_B12N, .rst_io_34p = RST_EXT_B34P, .rst_io_34n = RST_EXT_B34N}};
|
||||
#endif
|
||||
|
||||
|
||||
// Spi ok flags
|
||||
bool spiA_ok = true;
|
||||
bool spiB_ok = true;
|
||||
@@ -184,30 +182,38 @@ void loop()
|
||||
|
||||
while (running)
|
||||
{
|
||||
if (counter >= active_history->size())
|
||||
if (counter >= active_history->size()) // not concurrent with write task
|
||||
{
|
||||
counter = 0;
|
||||
partial_save = false; // reset partial save flag on new data cycle
|
||||
std::swap(active_history, writable_history); // switch active and writable buffers
|
||||
auto *temp = active_history;
|
||||
active_history = writable_history; // switch active and writable buffers
|
||||
writable_history = temp; // ensure writable_history points to the buffer we just filled
|
||||
dataSaveParams save_params{
|
||||
.history = writable_history,
|
||||
.file_path = "ignition_history.csv"
|
||||
};
|
||||
if (SAVE_HISTORY_TO_SPIFFS)
|
||||
xTaskCreate(
|
||||
saveHistoryTask,
|
||||
"saveHistoryTask",
|
||||
RT_TASK_STACK / 2,
|
||||
&save_params,
|
||||
RT_TASK_PRIORITY - 10, // higher priority to ensure it runs asap after buffer switch
|
||||
NULL);
|
||||
.file_path = "ignition_history.csv"};
|
||||
saveHistoryTask(&save_params); // directly call the save task function to save without delay, since we already switched buffers and writable_history is now empty and ready for new data
|
||||
// if (SAVE_HISTORY_TO_SPIFFS)
|
||||
// if (pdFAIL ==
|
||||
// xTaskCreatePinnedToCore(
|
||||
// saveHistoryTask,
|
||||
// "saveHistoryTask",
|
||||
// RT_TASK_STACK,
|
||||
// &save_params,
|
||||
// RT_TASK_PRIORITY - 1, // higher priority to ensure it runs asap after buffer switch
|
||||
// NULL,
|
||||
// CORE_1))
|
||||
// {
|
||||
// LOG_ERROR("Unable to create saveHistoryTask");
|
||||
// }
|
||||
}
|
||||
|
||||
if (xQueueReceive(rt_taskA_queue, &ign_info, pdMS_TO_TICKS(1000)) == pdTRUE)
|
||||
{
|
||||
printInfo(ign_info);
|
||||
// printInfo(ign_info);
|
||||
auto &hist = *active_history;
|
||||
hist[counter++ % active_history->size()] = ign_info;
|
||||
Serial.print("Data Received: " + String(counter) + "/" + String(hist.size()) + '\r');
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user