Basic SD working
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
#include "storage_task.h"
|
||||
|
||||
|
||||
StorageTask::StorageTask(SDManager& manager)
|
||||
:
|
||||
storage(manager),
|
||||
taskHandle(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void StorageTask::start()
|
||||
{
|
||||
// Dedicated task on core 0 so SD card work never blocks the services
|
||||
// running on core 1 (SystemTask / DiagnosticsTask). The 8 KB stack is
|
||||
// sized for the recursive boot-time file listing; the eventual
|
||||
// producer/consumer logging loop will also live here.
|
||||
xTaskCreatePinnedToCore(
|
||||
taskEntry,
|
||||
"StorageTask",
|
||||
8192,
|
||||
this,
|
||||
3,
|
||||
&taskHandle,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void StorageTask::taskEntry(void* parameter)
|
||||
{
|
||||
StorageTask* task =
|
||||
static_cast<StorageTask*>(parameter);
|
||||
|
||||
task->run();
|
||||
}
|
||||
|
||||
|
||||
void StorageTask::run()
|
||||
{
|
||||
Serial.println("[Storage] Initializing SD card...");
|
||||
|
||||
// Retry the mount until it succeeds. This keeps the card dead-pin-capable:
|
||||
// reseating the card, fixing a wire, or powering the module will bring it
|
||||
// up without rebooting the Hub. (The SD init handshake runs at 400 kHz, so
|
||||
// a failure here is wiring/power/seating/pull-up related, not speed.)
|
||||
while (!storage.begin())
|
||||
{
|
||||
Serial.println("[Storage] SD card mount FAILED.");
|
||||
Serial.println("[Storage] Check: 3.3V power + common ground, CS/SCK/MOSI/MISO wiring,");
|
||||
Serial.println("[Storage] card fully seated (click), and module pull-ups.");
|
||||
Serial.println("[Storage] Retrying in 5 s...");
|
||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||
}
|
||||
|
||||
storage.printCardInfo();
|
||||
storage.listFiles();
|
||||
|
||||
TickType_t lastWake =
|
||||
xTaskGetTickCount();
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Future integration point: a producer/consumer queue will feed
|
||||
// audio data here to be flushed to the card. For now the task
|
||||
// simply idles while the system runs.
|
||||
vTaskDelayUntil(
|
||||
&lastWake,
|
||||
pdMS_TO_TICKS(1000)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user