KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
errorcode.h
Go to the documentation of this file.
1 /*
2  * KM3NeT CLB v2 Firmware
3  *
4  * Copyright 2013 KM3NeT Collaboration
5  *
6  * All Rights Reserved.
7  *
8  *
9  * File : errorcode.h
10  * Created : 25 jan 2013
11  * Author : Vincent van Beveren
12  */
13 
14 #ifndef ERRORCODE_H_
15 #define ERRORCODE_H_
16 
17 /**
18  * @file
19  *
20  * @ingroup platform
21  *
22  * This module is responsible for distributing error codes. It does not contain all error codes
23  * itself.
24  *
25  * To add error codes, first add a module entry with a short name. Each module has 256 possible
26  * errors:
27  *
28  * @code
29  * #define E_MYMOD ( E_PLAFORM + 0x0700 )
30  * @endcode
31  *
32  * Note that there should be no other modules with the same error code range.
33  *
34  * Then in your header file define each error with the specified module offset, in this case
35  * E_MYMOD. Note that you have 256 possible codes, so never go beyond 0xFF.
36  * Also a text-description should be provided using the '_DESCR' postfix.
37  * @code
38  * #define E_MYMOD_TIMEOUT ( E_MYMOD + 0x01 ) ///< MyMod timed out.
39  * #define E_MYMOD_TIMEOUT_DESCR "MyMod transmission timeout"
40  * @endcode
41  *
42  * When creating an error in the err module, do this as follows:
43  *
44  * @code
45  * // ...
46  * if (t > tout) {
47  * errSet(ERROR(E_MYMOD_TIMEOUT));
48  * return false;
49  * }
50  * // ...
51  * @endcode
52  *
53  * When ERROR_W_DESCR is enabled, all error codes will also create a text representation of this
54  * error, which will be displayed with errPrint or can be retrieved with errGetStr().
55  * If ERROR_W_DESCR is not defined, all descriptions will not be included into the compile unit
56  * and only the error code is displayed.
57  */
58 
59 #define CAT(A, B) A ## B
60 
61 /// When defined includes the error description in the compilation unit.
62 #define ERROR_WITH_DESCR
63 
64 #ifdef ERROR_WITH_DESCR
65 
66 #define ERROR(CODE, ...) CODE, CODE ## _DESCR, 0
67 #define ERROR_INFO(CODE, INFO) CODE, CODE ## _DESCR " (" INFO ")", 0
68 
69 #define ERROR_CTX(CODE, ...) CODE, CODE ## _DESCR, _logModInfo.name
70 #define ERROR_CTX_INFO(CODE, INFO) CODE, CODE ## _DESCR " (" INFO ")", _logModInfo.name
71 
72 
73 #else
74 
75 #define ERROR(CODE) CODE, 0, 0
76 #define ERROR_INFO(CODE, INFO) CODE, 0, 0
77 #define ERROR_CTX(CODE, ...) CODE, 0, _logModInfo.name
78 #define ERROR_CTX_INFO(CODE, INFO) CODE, 0, _logModInfo.name
79 
80 #endif
81 
82 /**
83  * @def ERROR(CODE)
84  *
85  * Expands an error code to an error code with a description (if ERROR_W_DESCR is declared). Used
86  * with errSet(), like this:
87  *
88  * @code
89  * errSet(ERROR(E_MYMOD_TIMEOUT));
90  * @endcode
91  *
92  * @param CODE The E_* constant.
93  */
94 #define E_NONE 0x00 ///< Zero is no error.
95 #define E_NONE_DESCR "No error"
96 
97 #define E_UNKNOWN 0x01 ///< Generic error: Unknown error
98 #define E_UNKNOWN_DESCR "Unknown error"
99 
100 #define E_TIMEOUT 0x02 ///< Generic error: Timeout error
101 #define E_TIMEOUT_DESCR "Timeout"
102 
103 #define E_INVSTATE 0x03 ///< Generic error: Module is in a state in which
104  ///< it can not service your request.
105 #define E_INVSTATE_DESCR "Invalid state"
106 
107 #define E_OUTOFMEMORY 0x04 ///< Generic error: There is no more memory
108  ///< available for this operation.
109 #define E_OUTOFMEMORY_DESCR "Out of memory"
110 
111 
112 #define E_INVARGUMENT 0x05 ///< Generic error: invalid argument
113 #define E_INVARGUMENT_DESCR "Invalid argument"
114 
115 #define E_NOTSUPPORTED 0x06 ///< Generic error: not supported
116 #define E_NOTSUPPORTED_DESCR "Not supported"
117 
118 #define E_NOTIMPLEMENTED 0x07 ///< Generic error: not implemented
119 #define E_NOTIMPLEMENTED_DESCR "Not implemented"
120 
121 #define E_NOTFOUND 0x08 ///< Generic error: not found (ID or resource
122  ///< does not exist)
123 #define E_NOTFOUND_DESCR "Element not found"
124 
125 
126 #define E_PLATFORM 0x010000 ///< Error codes platform offset
127 
128 
129 
130 #define E_SUART ( E_PLATFORM + 0x1100 ) ///< WhiteRabbit Simple UART
131 #define E_I2C ( E_PLATFORM + 0x1200 ) ///< OpenCores I2C
132 #define E_SPI ( E_PLATFORM + 0x1300 ) ///< OpenCores SPI
133 #define E_SDB ( E_PLATFORM + 0x1400 ) ///< Self Describing Bus
134 #define E_DPB ( E_PLATFORM + 0x2100 ) ///< DigitPicco Basic
135 #define E_SFLASH ( E_PLATFORM + 0x2200 ) ///< Serial flash driver error
136 #define E_AHRS ( E_PLATFORM + 0x2300 ) ///< AHRS
137 
138 // I2C devices
139 #define E_PRMS ( E_I2C + 0x10 ) ///< OpenCores I2C
140 
141 #ifdef BASE
142 #define E_EDFA ( E_PLATFORM + 0x2400 ) ///< EDFA
143 #define E_ACDC ( E_PLATFORM + 0x2500 ) ///< Ac/Dc
144 #define E_BPS ( E_PLATFORM + 0x2600 ) ///< BPS
145 #endif
146 
147 #define E_SCHD ( E_PLATFORM + 0x0100 ) ///< Scheduler.
148 #define E_MSG ( E_PLATFORM + 0x0200 ) ///< Error in message processing
149 #define E_UPD ( E_PLATFORM + 0x0300 ) ///< Update module.
150 #define E_PREC ( E_PLATFORM + 0x0400 ) ///< Persistent Record module.
151 #define E_WRX ( E_PLATFORM + 0x0500 ) ///< WhiteRabbit eXchange'
152 #define E_NET ( E_PLATFORM + 0x0600 ) ///< Networking
153 #define E_BLOCK ( E_PLATFORM + 0x0700 ) ///< Block Store
154 
155 #define E_OCTO ( E_PLATFORM + 0x8700 ) ///< Octopus board module
156 
157 #define E_APP 0x020000 ///< Error codes application offset
158 
159 
160 #endif /* ERRORCODE_H_ */