From 70dfd4af78eedc36cf9ee92847b8a19073d44926 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Sun, 15 Aug 2021 13:04:58 -0700 Subject: [PATCH] inhibit sensor timeout during flash (#3146) * inhibit timeout during flash * do it up a level Co-authored-by: Matthew Kennedy --- firmware/controllers/flash_main.cpp | 4 ++++ firmware/controllers/sensors/sensor.cpp | 6 ++++++ firmware/controllers/sensors/sensor.h | 8 ++++++++ firmware/controllers/sensors/stored_value_sensor.h | 5 +++++ 4 files changed, 23 insertions(+) diff --git a/firmware/controllers/flash_main.cpp b/firmware/controllers/flash_main.cpp index aa585869ae..5b2f75c0bd 100644 --- a/firmware/controllers/flash_main.cpp +++ b/firmware/controllers/flash_main.cpp @@ -116,9 +116,13 @@ void writeToFlashIfPending() { // with a flash write thread, the schedule happens directly from // setNeedToWriteConfiguration, so there's nothing to do here if (allowFlashWhileRunning() || !getNeedToWriteConfiguration()) { + // Allow sensor timeouts again now that we're done (and a little time has passed) + Sensor::inhibitTimeouts(false); return; } + // Prevent sensor timeouts while flashing + Sensor::inhibitTimeouts(true); writeToFlashNow(); } diff --git a/firmware/controllers/sensors/sensor.cpp b/firmware/controllers/sensors/sensor.cpp index a923ddbc38..438f8373fc 100644 --- a/firmware/controllers/sensors/sensor.cpp +++ b/firmware/controllers/sensors/sensor.cpp @@ -261,6 +261,12 @@ bool Sensor::Register() { return s_sensorNames[static_cast(type)]; } +/*static*/ bool Sensor::s_inhibitSensorTimeouts = false; + +/*static*/ void Sensor::inhibitTimeouts(bool inhibit) { + Sensor::s_inhibitSensorTimeouts = inhibit; +} + // Print information about all sensors /*static*/ void Sensor::showAllSensorInfo() { for (size_t i = 1; i < efi::size(s_sensorRegistry); i++) { diff --git a/firmware/controllers/sensors/sensor.h b/firmware/controllers/sensors/sensor.h index 5a5f5745d2..7333b410dd 100644 --- a/firmware/controllers/sensors/sensor.h +++ b/firmware/controllers/sensors/sensor.h @@ -121,6 +121,12 @@ public: */ static void resetAllMocks(); + /* + * Inhibit sensor timeouts. Used if you're doing something that will block sensor updates, such as + * erasing flash memory (which stalls the CPU on some MCUs) + */ + static void inhibitTimeouts(bool inhibit); + /* * Get a friendly name for the sensor. * For example, CLT, IAT, Throttle Position 2, etc. @@ -160,6 +166,8 @@ protected: explicit Sensor(SensorType type) : m_type(type) {} + static bool s_inhibitSensorTimeouts; + private: const SensorType m_type; diff --git a/firmware/controllers/sensors/stored_value_sensor.h b/firmware/controllers/sensors/stored_value_sensor.h index ed17e70541..8d4a7c7582 100644 --- a/firmware/controllers/sensors/stored_value_sensor.h +++ b/firmware/controllers/sensors/stored_value_sensor.h @@ -37,6 +37,11 @@ public: return unexpected; } + // Timeouts are disabled, return last value + if (Sensor::s_inhibitSensorTimeouts) { + return value; + } + if (m_timeoutPeriod != 0) { // zero m_timeoutPeriod means value lasts forever if (getTimeNowNt() - m_timeoutPeriod > m_lastUpdate) { return unexpected;