inhibit sensor timeout during flash (#3146)

* inhibit timeout during flash

* do it up a level

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2021-08-15 13:04:58 -07:00 committed by GitHub
parent 048801e95e
commit 70dfd4af78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 0 deletions

View File

@ -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();
}

View File

@ -261,6 +261,12 @@ bool Sensor::Register() {
return s_sensorNames[static_cast<size_t>(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++) {

View File

@ -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;

View File

@ -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;