diff --git a/firmware/controllers/core/error_handling.cpp b/firmware/controllers/core/error_handling.cpp index 81806cd3ea..1d3a8b96d9 100644 --- a/firmware/controllers/core/error_handling.cpp +++ b/firmware/controllers/core/error_handling.cpp @@ -8,6 +8,7 @@ #include "pch.h" #include "backup_ram.h" +#include "error_handling_led.h" static critical_msg_t warningBuffer; static critical_msg_t criticalErrorMessageBuffer; @@ -65,6 +66,7 @@ void checkLastBootError() { } void logHardFault(uint32_t type, uintptr_t faultAddress, port_extctx* ctx, uint32_t csfr) { + TURN_FATAL_LED(); #if EFI_BACKUP_SRAM auto sramState = getBackupSram(); sramState->Cookie = ErrorCookie::HardFault; @@ -75,9 +77,6 @@ void logHardFault(uint32_t type, uintptr_t faultAddress, port_extctx* ctx, uint3 #endif // EFI_BACKUP_SRAM } -extern ioportid_t criticalErrorLedPort; -extern ioportmask_t criticalErrorLedPin; -extern uint8_t criticalErrorLedState; #endif /* EFI_PROD_CODE */ #if EFI_SIMULATOR || EFI_PROD_CODE @@ -238,7 +237,7 @@ void firmwareError(ObdCode code, const char *fmt, ...) { chvsnprintf(warningBuffer, sizeof(warningBuffer), fmt, ap); va_end(ap); #endif - palWritePad(criticalErrorLedPort, criticalErrorLedPin, criticalErrorLedState); + TURN_FATAL_LED(); turnAllPinsOff(); enginePins.communicationLedPin.setValue(1); diff --git a/firmware/controllers/core/error_handling_led.h b/firmware/controllers/core/error_handling_led.h new file mode 100644 index 0000000000..813e1885e0 --- /dev/null +++ b/firmware/controllers/core/error_handling_led.h @@ -0,0 +1,11 @@ +#pragma once + +#if EFI_PROD_CODE + +extern ioportid_t criticalErrorLedPort; +extern ioportmask_t criticalErrorLedPin; +extern uint8_t criticalErrorLedState; + +#define TURN_FATAL_LED() palWritePad(criticalErrorLedPort, criticalErrorLedPin, criticalErrorLedState); + +#endif /* EFI_PROD_CODE */