FuSa 8-Bit Libraries Safety Framework
Loading...
Searching...
No Matches
error_handler.c
Go to the documentation of this file.
1
22
23// Standard Libraries Includes
24#include <stdbool.h>
25
26// Framework Includes
28#include <error_handler.h>
31
32static errId_t DetermineValidErrorId(errFlag_t flag, errId_t id);
33static errCrit_t DetermineErrorIdCriticality(errId_t validId);
34
36{
37 const errId_t validId = DetermineValidErrorId(flag, id);
38 const errCrit_t criticality = DetermineErrorIdCriticality(validId);
39
40 switch (criticality)
41 {
42 case IGNORE:
43 // Exit error handler without doing anything
44 break;
45 case NOTIFICATION:
46 // Push to log and handle later
48 break;
49 case NON_CRITICAL:
50 // Handle error right away by issuing configured callback
52 break;
53 case CRITICAL:
54 // Intentional fallthrough to handle error as CRITICAL by default
55 default:
56 EH_InitiateSafeState(validId);
57 break;
58 }
59}
60
61static errId_t DetermineValidErrorId(errFlag_t flag, errId_t id)
62{
63 if (flag == NO_ERROR)
64 {
65 /* cppcheck-suppress misra-c2012-15.5 */
66 return ERRID_NONE;
67 }
68
69 // Invalid error flag
70 if (flag != ERROR)
71 {
72 /* cppcheck-suppress misra-c2012-15.5 */
73 return ERRID_ERRFLAG_VAL;
74 }
75
76 // Invalid error ID
77 if (id >= ERRID_MAX)
78 {
79 /* cppcheck-suppress misra-c2012-15.5 */
80 return ERRID_ERRID_VAL;
81 }
82
83 // Input ID is valid
84 return id;
85}
86
87static errCrit_t DetermineErrorIdCriticality(errId_t validId)
88{
89 errCrit_t criticality = IGNORE;
90
91 // ERRID_NONE is always ignored
92 if (validId != ERRID_NONE)
93 {
94 // Get configured Error ID criticality from lookup table
95 criticality = errorIdCritLut[validId];
96 }
97
98 return criticality;
99}
100
102{
103 while (true)
104 {
105 // Get and clear the latest Error ID added to the log
106 const errId_t id = EH_PopNotificationLog();
107
108 // Assumes pop only returns ERRID_NONE when log is empty
109 if (id == ERRID_NONE)
110 {
111 break; // End processing if log is empty
112 }
113
115 }
116}
Define for criticality of specific errors.
errCrit_t
Defines criticality levels used by EH_HandleError to determine the appropriate response for each repo...
errFlag_t
Defines the error flag used by Middleware services to indicate error detection.
@ NO_ERROR
errId_t
Defines unique Error IDs for reporting system errors to EH_HandleError.
@ ERRID_MAX
@ ERRID_NONE
@ ERRID_ERRID_VAL
@ ERRID_ERRFLAG_VAL
Contains API prototypes for Error Handler Actions.
const errCallback_t nonCriticalErrorCallback
Configures the callback function used for 'NON_CRITICAL' Error IDs in EH_HandleError.
const errCrit_t errorIdCritLut[ERRID_MAX]
Configures the criticality of all Error IDs for handling in EH_HandleError.
const errCallback_t notificationErrorCallback
Configures the callback function used for 'NOTIFICATION' Error IDs in EH_ProcessNotificationLog.
void EH_ProcessNotificationLog(void)
Processes all Error IDs in the log by calling the configured handler callback.
errId_t EH_PopNotificationLog(void)
Pops the last Error ID from the Notification Error Log for error handling.
void EH_HandleError(errFlag_t flag, errId_t id)
Handles error based on configured Error ID criticality if the error flag is set.
void EH_PushNotificationLog(errId_t id)
Pushes Error ID to the Notification Error Log for later handling.
void EH_InitiateSafeState(errId_t id)
Transitions the system into a Safe State and resets the device.