rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Data Structures | Typedefs | Enumerations | Functions | Variables
error_handling.h File Reference

Detailed Description

Date
Mar 6, 2014
Author
Andrey Belomutskiy, (c) 2012-2020

Definition in file error_handling.h.

Data Structures

struct  backupErrorState
 

Typedefs

using critical_msg_t = char[CRITICAL_BUFFER_SIZE]
 

Enumerations

enum class  ErrorCookie : uint32_t { None = 0 , FirmwareError = 0xcafebabe , HardFault = 0xdeadbeef , ChibiOsPanic = 0xdeadfa11 }
 

Functions

bool warning (ObdCode code, const char *fmt,...)
 
bool warningTsReport (ObdCode code, const char *fmt,...)
 
void firmwareError (ObdCode code, const char *fmt,...)
 
const char * getCriticalErrorMessage ()
 
void configError (const char *fmt,...)
 
void clearConfigErrorMessage ()
 
const char * getConfigErrorMessage ()
 
bool hasConfigError ()
 
bool hasErrorReportFile ()
 
int getRusEfiVersion ()
 
const char * errorCookieToName (ErrorCookie cookie)
 
void errorHandlerInit ()
 
bool errorHandlerIsStartFromError ()
 
void errorHandlerShowBootReasonAndErrors ()
 

Variables

bool hasCriticalFirmwareErrorFlag
 

Typedef Documentation

◆ critical_msg_t

using critical_msg_t = char[CRITICAL_BUFFER_SIZE]

Definition at line 27 of file error_handling.h.

Enumeration Type Documentation

◆ ErrorCookie

enum class ErrorCookie : uint32_t
strong
Enumerator
None 
FirmwareError 
HardFault 
ChibiOsPanic 

Definition at line 88 of file error_handling.h.

88 : uint32_t {
89 None = 0,
90 FirmwareError = 0xcafebabe,
91 HardFault = 0xdeadbeef,
92 ChibiOsPanic = 0xdeadfa11,
93};

Function Documentation

◆ clearConfigErrorMessage()

void clearConfigErrorMessage ( )

Definition at line 62 of file error_handling.cpp.

62 {
63 hasConfigErrorFlag = false;
64}
static bool hasConfigErrorFlag

◆ configError()

void configError ( const char *  fmt,
  ... 
)

Definition at line 593 of file error_handling.cpp.

593 {
594 va_list ap;
595 va_start(ap, fmt);
596 chvsnprintf(configErrorMessageBuffer, sizeof(configErrorMessageBuffer), fmt, ap);
597 va_end(ap);
598 hasConfigErrorFlag = true;
599}
static critical_msg_t configErrorMessageBuffer

◆ errorCookieToName()

const char * errorCookieToName ( ErrorCookie  cookie)

Definition at line 134 of file error_handling.cpp.

135{
136 switch (cookie) {
138 return "No error";
140 return "firmware";
142 return "HardFault";
144 return "ChibiOS panic";
145 }
146
147 return "Unknown";
148}

◆ errorHandlerInit()

void errorHandlerInit ( )

Definition at line 77 of file error_handling.cpp.

77 {
78#if EFI_BACKUP_SRAM
79 /* copy error state from backup RAM and clear it in backup RAM.
80 * so few users can access previous error state and we should not care about who sohuld clear backup ram. */
81 auto sramState = getBackupSram();
82 memcpy(&lastBootError, &sramState->err, sizeof(backupErrorState));
83 memset(&sramState->err, 0x00, sizeof(sramState->err));
84 // Reset cookie so we don't report it again.
85 sramState->err.Cookie = ErrorCookie::None;
86
87 // Cookie can be some random value at first power on
88 // reset to None to avoid generating 'Unknown' fail report
93 }
94
95 //bootcount
96 if (sramState->BootCountCookie != 0xdeadbeef) {
97 sramState->BootCountCookie = 0xdeadbeef;
98 sramState->BootCount = 0;
99 }
100 // save current bootcounter
101 bootCount = sramState->BootCount;
102
103 sramState->BootCount++;
104
107 if (err->Cookie == ErrorCookie::HardFault) {
108 criticalError("Last boot had hard fault type: %lx addr: %lx CSFR: %lx",
109 err->FaultType, err->FaultAddress, err->Csfr);
110 }
111 }
112
114 // if reset by watchdog, signal a fatal error
115 if ((cause == Reset_Cause_IWatchdog) || (cause == Reset_Cause_WWatchdog)) {
116 firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Watchdog Reset detected! Check SD card for report file.");
117 }
118#endif // EFI_PROD_CODE
119
120 // see https://wiki.rusefi.com/Resilience
121 addConsoleAction("chibi_fault", [](){ chDbgCheck(0); } );
122 addConsoleAction("soft_fault", [](){ firmwareError(ObdCode::RUNTIME_CRITICAL_TEST_ERROR, "firmwareError: %d", getRusEfiVersion()); });
123 addConsoleAction("hard_fault", [](){ causeHardFault(); } );
124}
void causeHardFault()
Reset_Cause_t getMCUResetCause()
BackupSramData * getBackupSram()
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
static constexpr engine_configuration_s * engineConfiguration
void firmwareError(ObdCode code, const char *fmt,...)
static uint32_t bootCount
static backupErrorState lastBootError
int getRusEfiVersion()
Reset_Cause_t
Definition mpu_util.h:106
@ Reset_Cause_WWatchdog
Definition mpu_util.h:109
@ Reset_Cause_IWatchdog
Definition mpu_util.h:108
@ RUNTIME_CRITICAL_TEST_ERROR
@ OBD_PCM_Processor_Fault

Referenced by runRusEfi().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ errorHandlerIsStartFromError()

bool errorHandlerIsStartFromError ( )

Definition at line 126 of file error_handling.cpp.

126 {
127#if EFI_BACKUP_SRAM
129#else
130 return 0;
131#endif
132}

◆ errorHandlerShowBootReasonAndErrors()

void errorHandlerShowBootReasonAndErrors ( )

Definition at line 232 of file error_handling.cpp.

232 {
233 //this is console print
234 #define PRINT(...) efiPrintf(__VA_ARGS__)
235
236 printResetReason();
237 printWdResetCounter();
238
239#if EFI_BACKUP_SRAM
241 ErrorCookie cookie = err->Cookie;
242
243 printErrorState();
244 printErrorStack();
245#endif // EFI_BACKUP_SRAM
246 #undef PRINT
247}
ErrorCookie

Referenced by runRusEfi().

Here is the caller graph for this function:

◆ firmwareError()

void firmwareError ( ObdCode  code,
const char *  fmt,
  ... 
)

Something really bad had happened - firmware cannot function, we cannot run the engine We definitely use this critical error approach in case of invalid configuration. If user sets a self-contradicting configuration we have to just put a hard stop on this.

see also warning()

Definition at line 670 of file error_handling.cpp.

670 {
671 va_list ap;
672 va_start(ap, fmt);
673 firmwareErrorV(code, fmt, ap);
674 va_end(ap);
675}
uint8_t code
Definition bluetooth.cpp:40
static void firmwareErrorV(ObdCode code, const char *fmt, va_list ap)

Referenced by TriggerWaveform::addEvent(), applyEngineType(), assertInterruptPriority(), TriggerScheduler::assertNotInList(), assertTimeIsLinear(), TriggerWaveform::calculateExpectedEventCounts(), calculateTriggerSynchPoint(), MultiChannelStateSequence::checkSwitchTimes(), TripOdometer::consumeFuel(), AemXSeriesWideband::decodeRusefiStandard(), TriggerDecoderBase::decodeTriggerEvent(), EtbImpl< TBase >::doAutocal(), doInitElectronicThrottle(), efiExtiEnablePin(), ensureArrayIsAscending(), errorHandlerInit(), SingleTimerExecutor::executeAllPendingActions(), findIndexMsg(), TriggerCentral::findNextTriggerToothAngle(), TriggerStimulatorHelper::findTriggerSyncPoint(), getAdcChannelBrainPin(), getAirmassModel(), getCylinderNumberAtIndex(), getFiringOrderLength(), getFiringOrderTable(), getHwPin(), getHwPort(), getIgnitionPinForIndex(), getInjectionModeDurationMultiplier(), getMapCfg(), getNumberOfInjections(), getNumberOfSparks(), getPortIndex(), getPortIndex(), getPortIndex(), getSpiDevice(), gpio_pin_markUsed(), PwmConfig::handleCycleStart(), initAuxValves(), initEgoSensor(), initHistogram(), initializeSkippedToothTrigger(), OutputPin::initPin(), look_up_rpm_can_id(), look_up_vss_can_id(), onCliCaseError(), onCliDuplicateError(), onCliOverflowError(), TachometerModule::onFastCallback(), FLStack< T, MAXSIZE >::pop(), portSetHardwareSchedulerTimer(), FLStack< T, MAXSIZE >::push(), recalculateAuxValveTiming(), EventQueue::remove(), runBench(), SingleTimerExecutor::schedule(), setHardwareSchedulerTimer(), GppwmChannel::setOutput(), startCanPins(), swapOutputBuffers(), timerCallback(), timerValidationCallback(), turnOnTriggerInputPin(), InjectionEvent::update(), validateHardwareTimer(), validateThermistorConfig(), and wrapAngle().

Here is the call graph for this function:

◆ getConfigErrorMessage()

const char * getConfigErrorMessage ( )

Definition at line 601 of file error_handling.cpp.

601 {
603}

Referenced by handleGetConfigErorr().

Here is the caller graph for this function:

◆ getCriticalErrorMessage()

const char * getCriticalErrorMessage ( )

Definition at line 54 of file error_handling.cpp.

54 {
56}
static critical_msg_t criticalErrorMessageBuffer

Referenced by handleGetConfigErorr(), handleTestCommand(), and updateDevConsoleState().

Here is the caller graph for this function:

◆ getRusEfiVersion()

int getRusEfiVersion ( )

See also SIGNATURE_HASH

Definition at line 777 of file engine_controller.cpp.

777 {
778#if defined(EFI_BOOTLOADER_INCLUDE_CODE)
779 // make bootloader code happy too
780 if (initBootloader() != 0)
781 return 123;
782#endif /* EFI_BOOTLOADER_INCLUDE_CODE */
783 return VCS_DATE;
784}

Referenced by errorHandlerInit(), errorHandlerWriteReportFile(), firmwareErrorV(), handleGetVersion(), printVersionForConsole(), readFromFlash(), sayHello(), and updateTunerStudioState().

Here is the caller graph for this function:

◆ hasConfigError()

bool hasConfigError ( )

Definition at line 58 of file error_handling.cpp.

58 {
59 return hasConfigErrorFlag;
60}

Referenced by updateTunerStudioState().

Here is the caller graph for this function:

◆ hasErrorReportFile()

bool hasErrorReportFile ( )

Definition at line 66 of file error_handling.cpp.

66 {
67 return hasReportFile;
68}
static bool hasReportFile

Referenced by updateTunerStudioState().

Here is the caller graph for this function:

◆ warning()

bool warning ( ObdCode  code,
const char *  fmt,
  ... 
)

Something is wrong, but we can live with it: some minor sensor is disconnected or something like that

see also firmwareError()

Definition at line 528 of file error_handling.cpp.

528 {
529 va_list args;
530 va_start(args, fmt);
531 bool ret = warningVA(code, false, fmt, args);
532 va_end(args);
533 return ret;
534}
bool warningVA(ObdCode code, bool reportToTs, const char *fmt, va_list args)

Referenced by TriggerWaveform::addEvent(), TriggerScheduler::assertNotInList(), assertPinAssigned(), TriggerStimulatorHelper::assertSyncPosition(), buildTimingMap(), FlexSensor::callback(), check(), customTrigger(), CanTsListener::decodeFrame(), AemXSeriesWideband::decodeRusefiDiag(), Engine::efiWatchdog(), findIndexMsg(), fireSparkBySettingPinLow(), IgnitionState::getAdvance(), SpeedDensityAirmass::getAirmass(), getBaroCorrection(), getCrankingFuel3(), getCylinderNumberAtIndex(), InjectorModelWithConfig::getFuelDifferentialPressure(), getInjectionOffset(), getInternalAdcValue(), getRunningAdvance(), IgnitionState::getSparkDwell(), IFuelComputer::getTCharge(), Pid::getUnclampedOutput(), TriggerCentral::handleShaftSignal(), handleVvtCamSignal(), interpolateMsg(), TriggerCentral::isToothExpectedNow(), mapAveragingAdcCallback(), PrimaryTriggerDecoder::onNotEnoughTeeth(), VvtTriggerDecoder::onNotEnoughTeeth(), SensorChecker::onSlowCallback(), PrimaryTriggerDecoder::onTooManyTeeth(), VvtTriggerDecoder::onTooManyTeeth(), onTriggerEventSparkLogic(), InjectionEvent::onTriggerTooth(), overFireSparkAndPrepareNextSchedule(), EngineState::periodicFastCallback(), prepareIgnitionSchedule(), readFromFlash(), sdFormat(), sdLoggerCreateFile(), setHardwareSchedulerTimer(), OutputPin::setOnchipValue(), SimplePwm::setSimplePwmDutyCycle(), startDwellByTurningSparkPinHigh(), startSimplePwm(), MapAverager::stop(), tooSoonToHandleSignal(), InjectionEvent::update(), LimpManager::updateState(), validateBaroMap(), and TriggerCentral::validateCamVvtCounters().

Here is the call graph for this function:

◆ warningTsReport()

bool warningTsReport ( ObdCode  code,
const char *  fmt,
  ... 
)

Same as above, but also report to user by pop-up window in TunerStudio

Definition at line 536 of file error_handling.cpp.

536 {
537 va_list args;
538 va_start(args, fmt);
539 bool ret = warningVA(code, true, fmt, args);
540 va_end(args);
541 return ret;
542}

Referenced by Engine::periodicSlowCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ hasCriticalFirmwareErrorFlag

bool hasCriticalFirmwareErrorFlag
extern

Definition at line 35 of file error_handling.cpp.

Referenced by firmwareErrorV(), and warningVA().

Go to the source code of this file.