parameters: defer auto-saving to after disarming for flash-based params

This is especially important for DShot, that does not update when the CPU
stalls.
This commit is contained in:
Beat Küng
2019-09-25 10:58:19 +02:00
parent 67500123e3
commit 82106105b7

View File

@@ -66,6 +66,8 @@ using namespace time_literals;
#if !defined(PARAM_NO_ORB)
# include "uORB/uORB.h"
# include "uORB/topics/parameter_update.h"
# include <uORB/topics/actuator_armed.h>
# include <uORB/Subscription.hpp>
#endif
#if defined(FLASH_BASED_PARAMS)
@@ -614,6 +616,21 @@ autosave_worker(void *arg)
{
bool disabled = false;
#if !defined(PARAM_NO_ORB)
if (!param_get_default_file()) {
// In case we save to FLASH, defer param writes until disarmed,
// as writing to FLASH can stall the entire CPU (in rare cases around 300ms on STM32F7)
uORB::SubscriptionData<actuator_armed_s> armed_sub{ORB_ID(actuator_armed)};
if (armed_sub.get().armed) {
work_queue(LPWORK, &autosave_work, (worker_t)&autosave_worker, nullptr, USEC2TICK(1_s));
return;
}
}
#endif
param_lock_writer();
last_autosave_timestamp = hrt_absolute_time();
autosave_scheduled = false;