Choco OS  V.0.16.9.0
Join to the chocolate world
oc_diag.h
1 /*
2  * oc_diag.h
3  *
4  * Created on: 13.08.2016
5  * Author: pkubiak
6  */
7 
8 #ifndef SYSTEM_LIBRARIES_INC_OC_DIAG_H_
9 #define SYSTEM_LIBRARIES_INC_OC_DIAG_H_
10 
11 #include <oc_errors.h>
12 #include <oc_memory.h>
13 #include <string.h>
14 #include <oc_array.h>
15 
16 typedef enum
17 {
18  oC_Diag_State_NotStarted ,
19  oC_Diag_State_Prepared ,
20  oC_Diag_State_InProgress ,
21  oC_Diag_State_Finished ,
22  oC_Diag_State_NumberOfStates
23 } oC_Diag_State_t;
24 
25 typedef struct oC_Diag_t
26 {
27  const char * Name;
28  const char * SubName;
29  const char * ResultDescription;
30  oC_ErrorCode_t Result;
31  oC_Diag_State_t State;
32 
33  //==============================================================
37  //==============================================================
38  void (*PrintFunction)( struct oC_Diag_t * Diag );
39 } oC_Diag_t;
40 
41 typedef oC_ErrorCode_t (*oC_Diag_PerformFunction_t)(oC_Diag_t * Diag , void * Context );
42 
43 typedef struct
44 {
45  const char * Name;
46  oC_Diag_PerformFunction_t PerformFunction;
48 
49 #define oC_Diag_GetNumberOfSupportedDiagnostics( SupportedDiagArray ) oC_ARRAY_SIZE(SupportedDiagArray)
50 
51 //==========================================================================================================================================
52 //==========================================================================================================================================
53 static inline oC_ErrorCode_t oC_Diag_PerformDiagnostic( oC_Diag_t * Diag, const char * Name , const char * SubName , oC_Diag_PerformFunction_t PerformFunction , void * Context )
54 {
55  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
56 
57  if(
58  ErrorCondition( Diag != NULL, oC_ErrorCode_WrongAddress )
59  && ErrorCondition( Name != NULL, oC_ErrorCode_WrongAddress )
60  && ErrorCondition( PerformFunction != NULL, oC_ErrorCode_WrongAddress )
61  )
62  {
63  Diag->Name = Name;
64  Diag->SubName = SubName;
65  Diag->ResultDescription = NULL;
66  Diag->State = oC_Diag_State_InProgress;
67 
68  if(Diag->PrintFunction)
69  {
70  Diag->PrintFunction(Diag);
71  }
72 
73  Diag->Result = PerformFunction(Diag,Context);
74  Diag->State = oC_Diag_State_Finished;
75 
76  if(Diag->PrintFunction)
77  {
78  Diag->PrintFunction(Diag);
79  }
80 
81  errorCode = oC_ErrorCode_None;
82  }
83 
84  return errorCode;
85 }
86 
87 #define oC_Diag_PerformDiagnostics(SupportedArray,DiagsArray,DiagsSize,SubName,Context) oC_Diag_PerformDiagnosticsFunction((SupportedArray),oC_ARRAY_SIZE(SupportedArray),(DiagsArray),(DiagsSize),(SubName),(Context))
88 
89 //==========================================================================================================================================
90 //==========================================================================================================================================
91 static inline oC_ErrorCode_t oC_Diag_PerformDiagnosticsFunction( const oC_Diag_SupportedDiagData_t * SupportedArray , uint32_t NumberOfSupportedDiags , oC_Diag_t * DiagsArray, uint32_t DiagsSize , const char * SubName , void * Context )
92 {
93  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
94 
95  if(
96  ErrorCondition( SupportedArray != NULL , oC_ErrorCode_WrongAddress )
97  )
98  {
99  errorCode = oC_ErrorCode_None;
100 
101  for(uint32_t i = 0; i < NumberOfSupportedDiags && i < DiagsSize && !oC_ErrorOccur(errorCode) ; i++)
102  {
103  errorCode = oC_Diag_PerformDiagnostic(&DiagsArray[i],SupportedArray->Name,SubName,SupportedArray->PerformFunction,Context);
104  }
105  }
106 
107  return errorCode;
108 }
109 
110 #endif /* SYSTEM_LIBRARIES_INC_OC_DIAG_H_ */
The file with interface for the GPIO driver.
void(* PrintFunction)(struct oC_Diag_t *Diag)
prints state of the diagnostic
Definition: oc_diag.h:38
Static array definitions.
#define NULL
pointer to a zero
Definition: oc_null.h:37