From 256e25a452465e24b7cd1cf89766a832339ee4cd Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sun, 25 Jun 2023 02:16:31 -0400 Subject: [PATCH] only:stronger stack shortage response --- firmware/console/binary/tunerstudio.cpp | 2 +- firmware/console/eficonsole.cpp | 7 ------- firmware/controllers/bench_test.cpp | 2 +- firmware/controllers/gauges/malfunction_indicator.cpp | 2 +- firmware/controllers/global_shared.h | 4 +++- 5 files changed, 6 insertions(+), 11 deletions(-) diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index 7496b87945..0c0a932e6a 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -457,7 +457,7 @@ bool TunerStudio::handlePlainCommand(TsChannelBase* tsChannel, uint8_t command) TunerStudio tsInstance; static int tsProcessOne(TsChannelBase* tsChannel) { - validateStack("communication", ObdCode::STACK_USAGE_COMMUNICATION, EXPECTED_REMAINING_STACK); + assertStack("communication", ObdCode::STACK_USAGE_COMMUNICATION, EXPECTED_REMAINING_STACK, -1); if (!tsChannel->isReady()) { chThdSleepMilliseconds(10); diff --git a/firmware/console/eficonsole.cpp b/firmware/console/eficonsole.cpp index a681654fb3..3c98d02fd1 100644 --- a/firmware/console/eficonsole.cpp +++ b/firmware/console/eficonsole.cpp @@ -142,13 +142,6 @@ static void sayHello() { chThdSleepMilliseconds(5); } -void validateStack(const char*msg, ObdCode code, int desiredStackUnusedSize) { - int unusedStack = getCurrentRemainingStack(); - if (unusedStack < desiredStackUnusedSize) { - warning(code, "Stack low on %s: %d", msg, unusedStack); - } -} - #if CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS int CountFreeStackSpace(const void* wabase) { const uint8_t* stackBase = reinterpret_cast(wabase); diff --git a/firmware/controllers/bench_test.cpp b/firmware/controllers/bench_test.cpp index 238f39e99b..e945dba438 100644 --- a/firmware/controllers/bench_test.cpp +++ b/firmware/controllers/bench_test.cpp @@ -283,7 +283,7 @@ private: UNUSED(nowNt); setPeriod(50 /* ms */); - validateStack("Bench", ObdCode::STACK_USAGE_BENCH, EXPECTED_REMAINING_STACK); + assertStackVoid("Bench", ObdCode::STACK_USAGE_BENCH, EXPECTED_REMAINING_STACK); // naive inter-thread communication - waiting for a flag if (isBenchTestPending) { diff --git a/firmware/controllers/gauges/malfunction_indicator.cpp b/firmware/controllers/gauges/malfunction_indicator.cpp index fae877345c..86721a760b 100644 --- a/firmware/controllers/gauges/malfunction_indicator.cpp +++ b/firmware/controllers/gauges/malfunction_indicator.cpp @@ -84,7 +84,7 @@ private: void PeriodicTask(efitick_t nowNt) override { UNUSED(nowNt); - validateStack("MIL", ObdCode::STACK_USAGE_MIL, EXPECTED_REMAINING_STACK); + assertStackVoid("MIL", ObdCode::STACK_USAGE_MIL, EXPECTED_REMAINING_STACK); #if EFI_SHAFT_POSITION_INPUT if (nowNt - engine->triggerCentral.triggerState.mostRecentSyncTime < MS2NT(500)) { enginePins.checkEnginePin.setValue(1); diff --git a/firmware/controllers/global_shared.h b/firmware/controllers/global_shared.h index ae04892306..e0a3d35dca 100644 --- a/firmware/controllers/global_shared.h +++ b/firmware/controllers/global_shared.h @@ -32,4 +32,6 @@ */ EXTERNC int getRemainingStack(thread_t *otp); int CountFreeStackSpace(const void* wabase); -void validateStack(const char*msg, ObdCode code, int stackUnusedSize); + +#define assertStackVoid(message, code, desiredAvailableStack) { if (getCurrentRemainingStack() < desiredAvailableStack) { firmwareError(code, "stack: %s", message); return; } } +#define assertStack(message, code, desiredAvailableStack, result) { if (getCurrentRemainingStack() < desiredAvailableStack) { firmwareError(code, "stack: %s", message); return result; } }