Choco OS  V.0.16.9.0
Join to the chocolate world
oc_errors.c
Go to the documentation of this file.
1 
30 /*==========================================================================================================================================
31 //
32 // INCLUDES
33 //
34 //========================================================================================================================================*/
35 
36 #include <oc_errors.h>
37 #include <oc_array.h>
38 #include <oc_null.h>
39 #include <stdio.h>
40 #include <stdint.h>
41 #include <oc_system_cfg.h>
42 #include <oc_pixel.h>
43 
44 /*==========================================================================================================================================
45 //
46 // LOCAL CONSTS
47 //
48 //========================================================================================================================================*/
49 
50 
51 /*==========================================================================================================================================
52 //
53 // LOCAL TYPES
54 //
55 //========================================================================================================================================*/
56 
57 typedef struct
58 {
59  const char * Function;
60  uint32_t LineNumber;
61  const char * Description;
62  oC_ErrorCode_t ErrorCode;
63 } SavedError_t;
64 
65 /*==========================================================================================================================================
66 //
67 // MACROS
68 //
69 //========================================================================================================================================*/
70 
71 #define _ADD_ERROR_TO_STRING_LIST( CODE_NAME , CODE_STR ) CODE_STR ,
72 
73 /*==========================================================================================================================================
74 //
75 // LOCAL VARIABLES
76 //
77 //========================================================================================================================================*/
78 
82 static const char* oC_ErrorsStrings[] = {
83  "Success" ,
84  oC_ERRORS_LIST(_ADD_ERROR_TO_STRING_LIST)
85  "Unknown error code"
86 };
87 
88 static SavedError_t SavedErrors[CFG_UINT8_MAXIMUM_NUMBER_OF_SAVED_ERRORS];
89 static uint8_t FreeIndex = 0;
90 static bool Locked = false;
91 
92 /*==========================================================================================================================================
93 //
94 // LOCAL FUNCTION PROTOTYPES
95 //
96 //========================================================================================================================================*/
97 
98 
99 
100 /*==========================================================================================================================================
101 //
102 // INTERFACE FUNCTIONS
103 //
104 //========================================================================================================================================*/
105 
106 //==========================================================================================================================================
114 //==========================================================================================================================================
115 const char * oC_GetErrorString( oC_ErrorCode_t ErrorCode )
116 {
117  const char * string = NULL;
118  if ( ErrorCode < oC_ErrorCode_NumberOfErrorsDefinitions )
119  {
120  string = oC_ErrorsStrings[ErrorCode];
121  }
122  else
123  {
124  string = oC_ARRAY_LAST_ELEMENT(oC_ErrorsStrings);
125  }
126  return string;
127 }
128 
129 //==========================================================================================================================================
138 //==========================================================================================================================================
139 bool oC_SaveErrorFunction( const char * Description , oC_ErrorCode_t ErrorCode , const char * Function, uint32_t LineNumber )
140 {
141  bool success = false;
142 
143  if(Locked == false && FreeIndex < CFG_UINT8_MAXIMUM_NUMBER_OF_SAVED_ERRORS)
144  {
145  SavedErrors[FreeIndex].Description = Description;
146  SavedErrors[FreeIndex].ErrorCode = ErrorCode;
147  SavedErrors[FreeIndex].Function = Function;
148  SavedErrors[FreeIndex].LineNumber = LineNumber;
149  FreeIndex++;
150 
151  success = true;
152  }
153 
154  return success;
155 }
156 
157 //==========================================================================================================================================
161 //==========================================================================================================================================
162 bool oC_ReadLastError( const char ** outDescription , oC_ErrorCode_t * outErrorCode , const char ** outFunction , uint32_t * outLineNumber )
163 {
164  bool read = false;
165 
166  if(FreeIndex > 0)
167  {
168  FreeIndex--;
169  *outDescription = SavedErrors[FreeIndex].Description;
170  *outErrorCode = SavedErrors[FreeIndex].ErrorCode;
171  *outFunction = SavedErrors[FreeIndex].Function;
172  *outLineNumber = SavedErrors[FreeIndex].LineNumber;
173 
174  read = true;
175  }
176 
177  return read;
178 }
179 
180 //==========================================================================================================================================
184 //==========================================================================================================================================
185 void oC_SetLockSavingErrors( bool Lock )
186 {
187  Locked = Lock;
188 }
189 
190 /*==========================================================================================================================================
191 //
192 // LOCAL FUNCTION
193 //
194 //========================================================================================================================================*/
void oC_SetLockSavingErrors(bool Lock)
locks or unlocks saving errors
Definition: oc_errors.c:185
static const char * oC_ErrorsStrings[]
Definition: oc_errors.c:82
The file with interface for the GPIO driver.
Static array definitions.
Definition of the null pointer.
bool oC_SaveErrorFunction(const char *Description, oC_ErrorCode_t ErrorCode, const char *Function, uint32_t LineNumber)
save error code with description for later
Definition: oc_errors.c:139
const char * oC_GetErrorString(oC_ErrorCode_t ErrorCode)
Definition: oc_errors.c:115
bool oC_ReadLastError(const char **outDescription, oC_ErrorCode_t *outErrorCode, const char **outFunction, uint32_t *outLineNumber)
reads error code with description from the errors stack
Definition: oc_errors.c:162
#define NULL
pointer to a zero
Definition: oc_null.h:37