only:stronger stack shortage response

This commit is contained in:
rusefillc 2023-06-25 02:16:31 -04:00
parent bc2a2b9ab9
commit 256e25a452
5 changed files with 6 additions and 11 deletions

View File

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

View File

@ -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<const uint8_t*>(wabase);

View File

@ -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) {

View File

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

View File

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