summaryrefslogtreecommitdiff
path: root/src/tangara/system_fsm/running.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-09-13 10:12:40 +1000
committerjacqueline <me@jacqueline.id.au>2024-09-13 10:12:40 +1000
commita174d76aa16e09ddfc2ce67393c92ed947a817a5 (patch)
treefd23a5470bb6979768a7b702ac6299e09a5e50b6 /src/tangara/system_fsm/running.cpp
parentca5e866a2ffff822b96ce12177c6d10aa04bd9c7 (diff)
downloadtangara-fw-a174d76aa16e09ddfc2ce67393c92ed947a817a5.tar.gz
Mount the SD card asynchronously when it becomes available
Previously we were doing it synchronously, which led to some odd looking livelock stacktraces... we still don't have a consistent repro, but this at least makes the stack when we mount a lot more predictable
Diffstat (limited to 'src/tangara/system_fsm/running.cpp')
-rw-r--r--src/tangara/system_fsm/running.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/tangara/system_fsm/running.cpp b/src/tangara/system_fsm/running.cpp
index 07166e2f..33c6c7dc 100644
--- a/src/tangara/system_fsm/running.cpp
+++ b/src/tangara/system_fsm/running.cpp
@@ -40,7 +40,7 @@ void Running::entry() {
sUnmountTimer = xTimerCreate("unmount_timeout", kTicksBeforeUnmount, false,
NULL, timer_callback);
}
- mountStorage();
+ events::System().Dispatch(internal::Mount{});
}
void Running::exit() {
@@ -72,7 +72,8 @@ void Running::react(const SdDetectChanged& ev) {
}
if (ev.has_sd_card && !sStorage) {
- mountStorage();
+ events::System().Dispatch(internal::Mount{});
+ return;
}
// Don't automatically unmount, since this event seems to occasionally happen
@@ -120,7 +121,7 @@ void Running::react(const SamdUsbMscChanged& ev) {
gpios.WriteSync(drivers::IGpios::Pin::kSdPowerEnable, 0);
// Now it's ready for us.
- mountStorage();
+ events::System().Dispatch(internal::Mount{});
}
}
@@ -145,7 +146,7 @@ auto Running::updateSdState(drivers::SdState state) -> void {
events::System().Dispatch(SdStateChanged{});
}
-auto Running::mountStorage() -> void {
+void Running::react(const internal::Mount&) {
// Only mount our storage if we know it's not currently in use by the SAMD.
if (sServices->samd().UsbMassStorage()) {
updateSdState(drivers::SdState::kNotMounted);