rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
error_handling.cpp File Reference

Detailed Description

Date
Apr 1, 2014
Author
Andrey Belomutskiy, (c) 2012-2020

Definition in file error_handling.cpp.

Functions

void efiCriticalError (const char *message)
 
const chargetCriticalErrorMessage ()
 
bool hasConfigError ()
 
void clearConfigErrorMessage ()
 
bool hasErrorReportFile ()
 
void errorHandlerInit ()
 
bool errorHandlerIsStartFromError ()
 
const charerrorCookieToName (ErrorCookie cookie)
 
void errorHandlerShowBootReasonAndErrors ()
 
PUBLIC_API_WEAK void onBoardWriteErrorFile (FIL *)
 
static const charerrorHandlerGetErrorName (ErrorCookie cookie)
 
void errorHandlerWriteReportFile (FIL *fd)
 
static int errorHandlerIsReportExist (ErrorCookie cookie)
 
int errorHandlerCheckReportFiles ()
 
static void errorHandlerDeleteTypedReport (ErrorCookie cookie)
 
void errorHandlerDeleteReports ()
 
static void errorHandlerSaveStack (backupErrorState *err, uint32_t *sp)
 
void logHardFault (uint32_t type, uintptr_t faultAddress, void *sp, port_extctx *ctx, uint32_t csfr)
 
void chDbgPanic3 (const char *msg, const char *file, int line)
 
bool warningVA (ObdCode code, bool reportToTs, const char *fmt, va_list args)
 
bool warning (ObdCode code, const char *fmt,...)
 
bool warningTsReport (ObdCode code, const char *fmt,...)
 
void onLockHook (void)
 
void onUnlockHook (void)
 
void configError (const char *fmt,...)
 
const chargetConfigErrorMessage ()
 
static void firmwareErrorV (ObdCode code, const char *fmt, va_list ap)
 
void firmwareError (ObdCode code, const char *fmt,...)
 
void criticalErrorC (const char *fmt,...)
 

Variables

static critical_msg_t warningBuffer
 
static critical_msg_t criticalErrorMessageBuffer
 
static critical_msg_t configErrorMessageBuffer
 
bool hasCriticalFirmwareErrorFlag = false
 
static bool hasConfigErrorFlag = false
 
static bool hasReportFile = false
 
bool isInHardFaultHandler = false
 
const chardbg_panic_file
 
int dbg_panic_line
 
static backupErrorState lastBootError
 
static uint32_t bootCount = 0
 
bool needErrorReportFile = false
 
uint32_t lastLockTime
 
uint32_t maxLockedDuration = 0
 

Function Documentation

◆ chDbgPanic3()

void chDbgPanic3 ( const char msg,
const char file,
int  line 
)

Definition at line 428 of file error_handling.cpp.

428 {
429#if EFI_PROD_CODE
430#if EFI_BACKUP_SRAM
431 // following is allocated on stack
432 // add some marker
433 uint32_t tmp = 0xfffffa11;
434#endif
435 // Attempt to break in to the debugger, if attached
436 if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk)
437 {
438 bkpt();
439 }
440#endif // EFI_PROD_CODE
441
442#if EFI_BACKUP_SRAM
443 auto bkpram = getBackupSram();
444 auto err = &bkpram->err;
445 if (err->Cookie == ErrorCookie::None) {
446 strlncpy(err->file, file, efi::size(err->file));
447 err->line = line;
448 strlncpy(err->msg, msg, efi::size(err->msg));
449 err->Cookie = ErrorCookie::ChibiOsPanic;
450 // copy stack last as it can be corrupted and cause another exeption
451 uint32_t *sp = &tmp;
452 errorHandlerSaveStack(err, sp);
453 }
454#endif // EFI_BACKUP_SRAM
455
456 if (hasOsPanicError())
457 return;
458 dbg_panic_file = file;
459 dbg_panic_line = line;
460#if CH_DBG_SYSTEM_STATE_CHECK
461 ch0.dbg.panic_msg = msg;
462#endif /* CH_DBG_SYSTEM_STATE_CHECK */
463
464#if !EFI_PROD_CODE
465 printf("chDbgPanic3 %s %s%d", msg, file, line);
466 exit(-1);
467#else // EFI_PROD_CODE
468
469 criticalError("assert fail %s %s:%d", msg, file, line);
470
471 // If on the main thread, longjmp back to the init process so we can keep USB alive
472 if (chThdGetSelfX()->threadId == 0) {
473 // Force unlock, since we may be throwing-under-lock
474 chSysUnconditionalUnlock();
475
476 // there was a port_disable in chSysHalt, reenable interrupts so USB works
477 port_enable();
478
479 __NO_RETURN void onAssertionFailure();
481 } else {
482 // Not the main thread.
483 // All hope is now lost.
484
485 // Reboot!
486 NVIC_SystemReset();
487 }
488
489#endif // EFI_PROD_CODE
490}
BackupSramData * getBackupSram()
int dbg_panic_line
const char * dbg_panic_file
static void errorHandlerSaveStack(backupErrorState *err, uint32_t *sp)
void onAssertionFailure()
Definition rusefi.cpp:165
printf("\n")
Here is the call graph for this function:

◆ 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

◆ criticalErrorC()

void criticalErrorC ( const char fmt,
  ... 
)

Definition at line 682 of file error_handling.cpp.

682 {
683 va_list ap;
684 va_start(ap, fmt);
686 va_end(ap);
687}
static void firmwareErrorV(ObdCode code, const char *fmt, va_list ap)
@ OBD_PCM_Processor_Fault
Here is the call graph for this function:

◆ efiCriticalError()

void efiCriticalError ( const char message)

Definition at line 50 of file error_handling.cpp.

50 {
51 criticalError(message);
52}

Referenced by action_s::execute().

Here is the caller graph for this function:

◆ 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}

◆ errorHandlerCheckReportFiles()

int errorHandlerCheckReportFiles ( )

Definition at line 343 of file error_handling.cpp.

343 {
348
349 return hasReportFile;
350}
static int errorHandlerIsReportExist(ErrorCookie cookie)
static bool hasReportFile

Referenced by errorHandlerDeleteReports(), and sdReportStorageInit().

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

◆ errorHandlerDeleteReports()

void errorHandlerDeleteReports ( )

Definition at line 378 of file error_handling.cpp.

Referenced by sdModeExecuter().

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

◆ errorHandlerDeleteTypedReport()

static void errorHandlerDeleteTypedReport ( ErrorCookie  cookie)
static

Definition at line 352 of file error_handling.cpp.

352 {
353 bool failed = false;
354 FRESULT fr; /* Return value */
355 DIR dj; /* Directory object */
356 FILINFO fno; /* File information */
357 TCHAR pattern[32];
358
359 sprintf(pattern, "*%s*", errorHandlerGetErrorName(cookie));
360
361 do {
362 fr = f_findfirst(&dj, &fno, "", pattern);
363 f_closedir(&dj);
364
365 if ((fr == FR_OK) && (fno.fname[0])) {
366 efiPrintf("deleting %s", fno.fname);
367 FRESULT ret = f_unlink(fno.fname);
368 if (ret != FR_OK) {
369 efiPrintf("Faield to delete %s: %d", fno.fname, ret);
370 failed = true;
371 } else {
372 efiPrintf("%s removed", fno.fname);
373 }
374 }
375 } while ((!failed) && (fr == FR_OK) && (fno.fname[0]));
376}
static const char * errorHandlerGetErrorName(ErrorCookie cookie)

Referenced by errorHandlerDeleteReports().

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

◆ errorHandlerGetErrorName()

static const char * errorHandlerGetErrorName ( ErrorCookie  cookie)
static

Definition at line 257 of file error_handling.cpp.

258{
259 switch (cookie) {
261 return "none";
263 return "FWerror";
265 return "HardFault";
267 return "OSpanic";
268 }
269
270 return "unknown";
271}

Referenced by errorHandlerDeleteTypedReport(), errorHandlerIsReportExist(), and errorHandlerWriteReportFile().

Here is the caller graph for this function:

◆ 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://github.com/rusefi/rusefi/wiki/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()
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:104
@ Reset_Cause_WWatchdog
Definition mpu_util.h:107
@ Reset_Cause_IWatchdog
Definition mpu_util.h:106
@ RUNTIME_CRITICAL_TEST_ERROR

Referenced by runRusEfi().

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

◆ errorHandlerIsReportExist()

static int errorHandlerIsReportExist ( ErrorCookie  cookie)
static

Definition at line 327 of file error_handling.cpp.

327 {
328 bool exist = false;
329 FRESULT fr; /* Return value */
330 DIR dj; /* Directory object */
331 FILINFO fno; /* File information */
332 TCHAR pattern[32];
333
334 sprintf(pattern, "*%s*", errorHandlerGetErrorName(cookie));
335
336 fr = f_findfirst(&dj, &fno, "", pattern);
337 exist = ((fr == FR_OK) && (fno.fname[0]));
338 f_closedir(&dj);
339
340 return exist;
341}

Referenced by errorHandlerCheckReportFiles().

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}

◆ errorHandlerSaveStack()

static void errorHandlerSaveStack ( backupErrorState err,
uint32_t *  sp 
)
static

Definition at line 390 of file error_handling.cpp.

391{
392 err->sp = (uint32_t)sp;
393 for (size_t i = 0; i < ERROR_STACK_DEPTH; i++) {
394 // avoid optimizatio and usage of __builtin_memcpy
395 // to avoid "error: '__builtin_memcpy' reading 128 bytes from a region of size 4"
396 err->stack[i] = *(volatile uint32_t *)sp;
397 sp++;
398 }
399}
uint32_t stack[ERROR_STACK_DEPTH]

Referenced by chDbgPanic3(), firmwareErrorV(), and logHardFault().

Here is the caller graph for this function:

◆ 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:

◆ errorHandlerWriteReportFile()

void errorHandlerWriteReportFile ( FIL *  fd)

Definition at line 275 of file error_handling.cpp.

275 {
276#if EFI_BACKUP_SRAM
278 ErrorCookie cookie = err->Cookie;
279#else
281#endif
282
283 if (cookie != ErrorCookie::None) {
284 needErrorReportFile = true;
285 }
286
287 auto cause = getMCUResetCause();
288 // TODO: should we also report Unknown?
289 if ((cause != Reset_Cause_NRST_Pin) && (cause != Reset_Cause_BOR) &&
290 (cause != Reset_Cause_POR) && (cause != Reset_Cause_Unknown)) {
291 // not an expected cause
292 needErrorReportFile = true;
293 }
294
296 char fileName[_MAX_FILLER + 20];
297 memset(fd, 0, sizeof(FIL)); // clear the memory
298 //TODO: use date + time for file name?
299#if EFI_BACKUP_SRAM
300 sprintf(fileName, "%05ld_%s_%s.txt",
301 bootCount, FAIL_REPORT_PREFIX, errorHandlerGetErrorName(cookie));
302#else
303 sprintf(fileName, "last_%s_%s.txt",
304 FAIL_REPORT_PREFIX, errorHandlerGetErrorName(cookie));
305#endif
306
307 FRESULT ret = f_open(fd, fileName, FA_CREATE_ALWAYS | FA_WRITE);
308 if (ret == FR_OK) {
309 //this is file print
310 #define PRINT(format, ...) f_printf(fd, format "\r\n", __VA_ARGS__)
311 printResetReason();
312 printWdResetCounter();
313#if EFI_BACKUP_SRAM
314 printErrorState();
315 printErrorStack();
316#endif // EFI_BACKUP_SRAM
317 f_printf(fd, "rusEFI v%d@%u", getRusEfiVersion(), /*do we have a working way to print 64 bit values?!*/(int)SIGNATURE_HASH);
318 // additional board-specific data
320 // todo: figure out what else would be useful
321 f_close(fd);
323 }
324 }
325}
OutputPin warningLedPin
Definition efi_gpio.h:107
void setValue(const char *msg, int logicValue, bool isForce=false)
Definition efi_gpio.cpp:604
EnginePins enginePins
Definition efi_gpio.cpp:24
bool needErrorReportFile
PUBLIC_API_WEAK void onBoardWriteErrorFile(FIL *)
@ Reset_Cause_NRST_Pin
Definition mpu_util.h:109
@ Reset_Cause_Unknown
Definition mpu_util.h:105
@ Reset_Cause_POR
Definition mpu_util.h:110
@ Reset_Cause_BOR
Definition mpu_util.h:112
static NO_CACHE FIL fd

Referenced by sdReportStorageInit().

Here is the call graph for this function:
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

Referenced by TriggerWaveform::addEvent(), applyUnknownEngineType(), 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:

◆ firmwareErrorV()

static void firmwareErrorV ( ObdCode  code,
const char fmt,
va_list  ap 
)
static

in case of simple error message let's reduce stack usage chvsnprintf could cause an overflow if we're already low

Definition at line 605 of file error_handling.cpp.

605 {
606#if EFI_PROD_CODE
607#if EFI_BACKUP_SRAM
608 // following is allocated on stack
609 // add some marker
610 uint32_t tmp = 0xfaaaaa11;
611#endif
613 return;
615
616 // construct error message
617 if (indexOf(fmt, '%') == -1) {
618 /**
619 * in case of simple error message let's reduce stack usage
620 * chvsnprintf could cause an overflow if we're already low
621 */
622 strlncpy((char*) criticalErrorMessageBuffer, fmt, sizeof(criticalErrorMessageBuffer));
623 criticalErrorMessageBuffer[sizeof(criticalErrorMessageBuffer) - 1] = 0; // just to be sure
624 } else {
625 chvsnprintf(criticalErrorMessageBuffer, sizeof(criticalErrorMessageBuffer), fmt, ap);
626 }
627
628 int errorMessageSize = strlen((char*)criticalErrorMessageBuffer);
629 static char versionBuffer[32];
630 chsnprintf(versionBuffer, sizeof(versionBuffer), " %d@%s", getRusEfiVersion(), FIRMWARE_ID);
631
632 if (errorMessageSize + strlen(versionBuffer) < sizeof(criticalErrorMessageBuffer)) {
633 strcpy((char*)(criticalErrorMessageBuffer) + errorMessageSize, versionBuffer);
634 }
635
636 // Evidence first!
637#if EFI_BACKUP_SRAM
638 auto bkpram = getBackupSram();
639 auto err = &bkpram->err;
640 if (err->Cookie == ErrorCookie::None) {
641 strlncpy(err->msg, criticalErrorMessageBuffer, sizeof(err->msg));
642 err->Cookie = ErrorCookie::FirmwareError;
643 // copy stack last as it can be corrupted and cause another exeption
644 uint32_t *sp = &tmp;
645 errorHandlerSaveStack(err, sp);
646 }
647#endif // EFI_BACKUP_SRAM
648
649#if EFI_ENGINE_CONTROL
651#endif // EFI_ENGINE_CONTROL
653 // criticalShutdown() shutdown can cause cascaded fault.
654 // So we first save some valuable evidence and only after try to gracefully shutdown HW
655 criticalShutdown();
656 enginePins.communicationLedPin.setValue(1, /*force*/true);
657#else // EFI_PROD_CODE
658
659 // large buffer on stack is risky we better use normal memory
660 static char errorBuffer[200];
661
662 vsnprintf(errorBuffer, sizeof(errorBuffer), fmt, ap);
663
664 printf("\x1B[31m>>>>>>>>>> firmwareError [%s]\r\n\x1B[0m\r\n", errorBuffer);
665
666 throw std::logic_error(errorBuffer);
667#endif // EFI_PROD_CODE
668}
EngineState engineState
Definition engine.h:344
OutputPin communicationLedPin
Definition efi_gpio.h:106
WarningCodeState warnings
void addWarningCode(ObdCode code, const char *text=nullptr)
Definition engine2.cpp:38
LimpManager * getLimpManager()
Definition engine.cpp:596
static EngineAccessor engine
Definition engine.h:413
bool hasCriticalFirmwareErrorFlag
static critical_msg_t criticalErrorMessageBuffer

Referenced by criticalErrorC(), and firmwareError().

Here is the call graph for this function:
Here is the caller 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}

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

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}

Referenced by updateTunerStudioState().

Here is the caller graph for this function:

◆ logHardFault()

void logHardFault ( uint32_t  type,
uintptr_t  faultAddress,
void *  sp,
port_extctx *  ctx,
uint32_t  csfr 
)

Definition at line 402 of file error_handling.cpp.

402 {
403 // todo: reuse hasCriticalFirmwareErrorFlag? something?
405 // Evidence first!
406#if EFI_BACKUP_SRAM
407 auto bkpram = getBackupSram();
408 auto err = &bkpram->err;
409 if (err->Cookie == ErrorCookie::None) {
410 err->FaultType = type;
411 err->FaultAddress = faultAddress;
412 err->Csfr = csfr;
413 memcpy(&err->FaultCtx, ctx, sizeof(port_extctx));
414 err->Cookie = ErrorCookie::HardFault;
415 // copy stack last as it can be corrupted and cause another exeption
416 errorHandlerSaveStack(err, (uint32_t *)sp);
417 }
418#endif // EFI_BACKUP_SRAM
419 // criticalShutdown() shutdown can cause cascaded fault.
420 // So we first save some valuable evidence and only after try to gracefully shutdown HW
421 criticalShutdown();
422}
bool isInHardFaultHandler

Referenced by HardFault_Handler_C(), MemManage_Handler_C(), and UsageFault_Handler_C().

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

◆ onBoardWriteErrorFile()

PUBLIC_API_WEAK void onBoardWriteErrorFile ( FIL *  )

Definition at line 254 of file error_handling.cpp.

254 {
255}

Referenced by errorHandlerWriteReportFile().

Here is the caller graph for this function:

◆ onLockHook()

void onLockHook ( void  )

this depends on chdebug.h patch #if CH_DBG_SYSTEM_STATE_CHECK == TRUE -#define _dbg_enter_lock() (ch.dbg.lock_cnt = (cnt_t)1) -#define _dbg_leave_lock() (ch.dbg.lock_cnt = (cnt_t)0) +#define _dbg_enter_lock() {(ch.dbg.lock_cnt = (cnt_t)1); ON_LOCK_HOOK;} +#define _dbg_leave_lock() {ON_UNLOCK_HOOK;(ch.dbg.lock_cnt = (cnt_t)0);} #endif

Definition at line 562 of file error_handling.cpp.

562 {
563#if ENABLE_PERF_TRACE
565#endif /* ENABLE_PERF_TRACE */
566
567#if EFI_CLOCK_LOCKS
569#endif /* EFI_CLOCK_LOCKS */
570}
uint32_t lastLockTime
uint32_t getTimeNowLowerNt()
void perfEventInstantGlobal(PE event)
@ GlobalLock
Here is the call graph for this function:

◆ onUnlockHook()

void onUnlockHook ( void  )

Definition at line 572 of file error_handling.cpp.

572 {
573#if EFI_CLOCK_LOCKS
574 uint32_t lockedDuration = getTimeNowLowerNt() - lastLockTime;
575 if (lockedDuration > maxLockedDuration) {
576 maxLockedDuration = lockedDuration;
577 }
578// if (lockedDuration > 2800) {
579// // un-comment this if you want a nice stop for a breakpoint
580// maxLockedDuration = lockedDuration + 1;
581// }
582#endif /* EFI_CLOCK_LOCKS */
583
584#if ENABLE_PERF_TRACE
586#endif /* ENABLE_PERF_TRACE */
587}
uint32_t maxLockedDuration
@ GlobalUnlock
Here is the call 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(), check(), customTrigger(), CanTsListener::decodeFrame(), AemXSeriesWideband::decodeRusefiDiag(), Engine::efiWatchdog(), findIndexMsg(), fireSparkBySettingPinLow(), flexCallback(), 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(), 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:

◆ warningVA()

bool warningVA ( ObdCode  code,
bool  reportToTs,
const char fmt,
va_list  args 
)
Returns
TRUE in case there were warnings recently

Definition at line 496 of file error_handling.cpp.

496 {
498 return true;
499 }
500
502
503 if (known) {
504 // if known - just reset timer
506#if EFI_SIMULATOR || EFI_PROD_CODE
507 // we just had this same warning, let's not spam
508 return true;
509#endif
510 }
511
512 // print Pxxxx (for standard OBD) or Cxxxx (for custom) prefix
513 size_t size = snprintf(warningBuffer, sizeof(warningBuffer), "%s%04d: ",
514 code < ObdCode::CUSTOM_NAN_ENGINE_LOAD ? "P" : "C", (int) code);
515
516 chvsnprintf(warningBuffer + size, sizeof(warningBuffer) - size, fmt, args);
517
519#if EFI_SIMULATOR || EFI_PROD_CODE
520 efiPrintf("WARNING: %s", warningBuffer);
521#else
522 printf("unit_test_warning: %s\n", warningBuffer);
523#endif /* EFI_SIMULATOR || EFI_PROD_CODE */
524
525 return false;
526}
bool isWarningNow() const
Definition engine2.cpp:114
static critical_msg_t warningBuffer
@ CUSTOM_NAN_ENGINE_LOAD
composite packet size

Referenced by warning(), and warningTsReport().

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

Variable Documentation

◆ bootCount

uint32_t bootCount = 0
static

Definition at line 74 of file error_handling.cpp.

Referenced by errorHandlerInit(), and errorHandlerWriteReportFile().

◆ configErrorMessageBuffer

critical_msg_t configErrorMessageBuffer
static

Definition at line 33 of file error_handling.cpp.

Referenced by configError(), and getConfigErrorMessage().

◆ criticalErrorMessageBuffer

critical_msg_t criticalErrorMessageBuffer
static

Definition at line 32 of file error_handling.cpp.

Referenced by firmwareErrorV(), and getCriticalErrorMessage().

◆ dbg_panic_file

const char* dbg_panic_file

Definition at line 46 of file error_handling.cpp.

Referenced by chDbgPanic3().

◆ dbg_panic_line

int dbg_panic_line

Definition at line 47 of file error_handling.cpp.

Referenced by chDbgPanic3().

◆ hasConfigErrorFlag

bool hasConfigErrorFlag = false
static

not critical error: TS would display text error message until clearConfigErrorMessage() is invoked

Definition at line 39 of file error_handling.cpp.

Referenced by clearConfigErrorMessage(), configError(), and hasConfigError().

◆ hasCriticalFirmwareErrorFlag

bool hasCriticalFirmwareErrorFlag = false

Definition at line 35 of file error_handling.cpp.

Referenced by firmwareErrorV(), and warningVA().

◆ hasReportFile

bool hasReportFile = false
static

Definition at line 40 of file error_handling.cpp.

Referenced by errorHandlerCheckReportFiles(), and hasErrorReportFile().

◆ isInHardFaultHandler

bool isInHardFaultHandler = false

Definition at line 44 of file error_handling.cpp.

Referenced by gpiochips_writePad(), and logHardFault().

◆ lastBootError

backupErrorState lastBootError
static

◆ lastLockTime

uint32_t lastLockTime

Definition at line 545 of file error_handling.cpp.

Referenced by onLockHook(), and onUnlockHook().

◆ maxLockedDuration

uint32_t maxLockedDuration = 0

Maximum time before requesting lock and releasing lock at the end of critical section

Definition at line 549 of file error_handling.cpp.

Referenced by onUnlockHook(), printRuntimeStats(), resetMaxValues(), and updateTunerStudioState().

◆ needErrorReportFile

bool needErrorReportFile = false

Definition at line 273 of file error_handling.cpp.

Referenced by errorHandlerWriteReportFile().

◆ warningBuffer

critical_msg_t warningBuffer
static

Definition at line 31 of file error_handling.cpp.

Referenced by warningVA().

Go to the source code of this file.