rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
error_handling.h
Go to the documentation of this file.
1/**
2 * @file error_handling.h
3 *
4 * @date Mar 6, 2014
5 * @author Andrey Belomutskiy, (c) 2012-2020
6 */
7
8#pragma once
9
10#include "obd_error_codes.h"
12#include <cstdint>
13
14/**
15 * Something is wrong, but we can live with it: some minor sensor is disconnected
16 * or something like that
17 *
18 * see also firmwareError()
19 */
20bool warning(ObdCode code, const char *fmt, ...);
21
22/**
23 * Same as above, but also report to user by pop-up window in TunerStudio
24 */
25bool warningTsReport(ObdCode code, const char *fmt, ...);
26
27using critical_msg_t = char[CRITICAL_BUFFER_SIZE];
28
29#define criticalShutdown() \
30 TURN_FATAL_LED(); \
31 turnAllPinsOff();
32
33/**
34 * Something really bad had happened - firmware cannot function, we cannot run the engine
35 * We definitely use this critical error approach in case of invalid configuration. If user sets a self-contradicting
36 * configuration we have to just put a hard stop on this.
37 *
38 * see also warning()
39 */
40void firmwareError(ObdCode code, const char *fmt, ...);
41
42#define criticalError(...) firmwareError(ObdCode::OBD_PCM_Processor_Fault, __VA_ARGS__)
43
45
46#define hasFirmwareError() hasCriticalFirmwareErrorFlag
47
48const char* getCriticalErrorMessage();
49
50// report recoverable configuration error
51void configError(const char *fmt, ...);
53const char* getConfigErrorMessage();
54bool hasConfigError();
56
57// todo: better place for this shared declaration?
59
60#if EFI_ENABLE_ASSERTS
61 #define efiAssert(code, condition, message, result) { if (!(condition)) { firmwareError(code, message); return result; } }
62 #define efiAssertVoid(code, condition, message) { if (!(condition)) { firmwareError(code, message); return; } }
63#else /* EFI_ENABLE_ASSERTS */
64 #define efiAssert(code, condition, message, result) { UNUSED(code);UNUSED(condition);UNUSED(message);UNUSED(result); }
65 #define efiAssertVoid(code, condition, message) { UNUSED(condition);UNUSED(message);}
66#endif /* EFI_ENABLE_ASSERTS */
67
68#define criticalAssert(condition, message, result) efiAssert(ObdCode::OBD_PCM_Processor_Fault, condition, message, result)
69#define criticalAssertVoid(condition, message) efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, condition, message)
70
71//todo?#define GET_MACRO(_0, _1, _2, NAME, ...) NAME
72//todo? #define FOO(...) GET_MACRO(_0, ##__VA_ARGS__, FOO2, FOO1, FOO0)(__VA_ARGS__)
73
74#define assertNotNullVoid(pointer) efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, pointer != nullptr, "unexpected nullptr")
75#define assertNotNull(pointer, result) efiAssert(ObdCode::OBD_PCM_Processor_Fault, pointer != nullptr, "unexpected nullptr", result)
76
77#ifdef __cplusplus
78extern "C"
79{
80#endif /* __cplusplus */
81
82#if EFI_PROD_CODE
83
84// for port_extctx
85#include "ch.h"
86
87// These use very specific values to avoid interpreting random garbage memory as a real value
88enum class ErrorCookie : uint32_t {
89 None = 0,
90 FirmwareError = 0xcafebabe,
91 HardFault = 0xdeadbeef,
92 ChibiOsPanic = 0xdeadfa11,
93};
94
95const char *errorCookieToName(ErrorCookie cookie);
96
97// Error handling/recovery/reporting information
98
99#define ERROR_STACK_DEPTH 96
100
101typedef struct {
103
106 int line;
107 port_extctx FaultCtx;
108 uint32_t FaultType;
109 uint32_t FaultAddress;
110 uint32_t Csfr;
111 uint32_t sp;
112 uint32_t stack[ERROR_STACK_DEPTH];
114
115// reads backup ram and checks for any error report
116void errorHandlerInit();
117// true if we just started from some crash
119// If there was an error on the last boot, print out information about it now and reset state.
121
122//void errorHandlerWriteReportFile(FIL *fd);
123
124#endif // EFI_PROD_CODE
125
126#ifdef __cplusplus
127}
128#endif /* __cplusplus */
129
130// todo log red LED reason on SD card #7290 bool isRuntimeCritical(ObdCode error);
uint8_t code
Definition bluetooth.cpp:40
bool warning(ObdCode code, const char *fmt,...)
void firmwareError(ObdCode code, const char *fmt,...)
bool warningTsReport(ObdCode code, const char *fmt,...)
const char * getCriticalErrorMessage()
bool errorHandlerIsStartFromError()
void clearConfigErrorMessage()
bool hasCriticalFirmwareErrorFlag
bool hasConfigError()
void errorHandlerInit()
char[CRITICAL_BUFFER_SIZE] critical_msg_t
const char * errorCookieToName(ErrorCookie cookie)
void configError(const char *fmt,...)
bool hasErrorReportFile()
void errorHandlerShowBootReasonAndErrors()
ErrorCookie
int getRusEfiVersion()
const char * getConfigErrorMessage()
Standard and custom OBD-II error codes.
ObdCode
port_extctx FaultCtx
critical_msg_t file
critical_msg_t msg