source: rtems/cpukit/include/rtems/status-checks.h @ 255fe43

Last change on this file since 255fe43 was 255fe43, checked in by Joel Sherrill <joel@…>, on 03/01/22 at 20:40:44

cpukit/: Scripted embedded brains header file clean up

Updates #4625.

  • Property mode set to 100644
File size: 8.4 KB
Line 
1/**
2 * @file
3 *
4 * @brief Header File for Status Checks
5 *
6 * @warning Do not include this file in other header files.  Use it only in
7 * source files.
8 */
9
10/*
11 * Copyright (c) 2008 embedded brains GmbH.  All rights reserved.
12 * The license and distribution terms for this file may be
13 * found in the file LICENSE in this distribution or at
14 * http://www.rtems.org/license/LICENSE.
15 */
16
17#ifndef RTEMS_STATUS_CHECKS_H
18#define RTEMS_STATUS_CHECKS_H
19
20#include <rtems/bspIo.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif /* __cplusplus */
25
26/**
27 * @defgroup rtems_status_checks Status Checks
28 *
29 * @ingroup RTEMSAPI
30 */
31/**@{**/
32
33/**
34 * @name Print Macros
35 */
36/**@{**/
37
38/**
39 * @brief General purpose debug print macro.
40 */
41#ifdef DEBUG
42  #ifndef RTEMS_DEBUG_PRINT
43    #ifdef RTEMS_STATUS_CHECKS_USE_PRINTK
44      #define RTEMS_DEBUG_PRINT( fmt, ...) \
45        printk( "%s: " fmt, __func__, ##__VA_ARGS__)
46    #else /* RTEMS_STATUS_CHECKS_USE_PRINTK */
47      #include <stdio.h>
48      #define RTEMS_DEBUG_PRINT( fmt, ...) \
49        printf( "%s: " fmt, __func__, ##__VA_ARGS__)
50    #endif /* RTEMS_STATUS_CHECKS_USE_PRINTK */
51  #endif /* RTEMS_DEBUG_PRINT */
52#else /* DEBUG */
53  #ifdef RTEMS_DEBUG_PRINT
54    #warning RTEMS_DEBUG_PRINT was defined, but DEBUG was undefined
55    #undef RTEMS_DEBUG_PRINT
56  #endif /* RTEMS_DEBUG_PRINT */
57  #define RTEMS_DEBUG_PRINT( fmt, ...)
58#endif /* DEBUG */
59
60/**
61 * @brief Macro to print debug messages for successful operations.
62 */
63#define RTEMS_DEBUG_OK( msg) \
64  RTEMS_DEBUG_PRINT( "Ok: %s\n", msg)
65
66/**
67 * @brief General purpose system log print macro.
68 */
69#ifndef RTEMS_SYSLOG_PRINT
70  #ifdef RTEMS_STATUS_CHECKS_USE_PRINTK
71    #define RTEMS_SYSLOG_PRINT( fmt, ...) \
72      printk( fmt, ##__VA_ARGS__)
73  #else /* RTEMS_STATUS_CHECKS_USE_PRINTK */
74    #include <stdio.h>
75    #define RTEMS_SYSLOG_PRINT( fmt, ...) \
76      printf( fmt, ##__VA_ARGS__)
77  #endif /* RTEMS_STATUS_CHECKS_USE_PRINTK */
78#endif /* RTEMS_SYSLOG_PRINT */
79
80/**
81 * @brief General purpose system log macro.
82 */
83#define RTEMS_SYSLOG( fmt, ...) \
84  RTEMS_SYSLOG_PRINT( "%s: " fmt, __func__, ##__VA_ARGS__)
85
86/**
87 * @brief General purpose system log macro for warnings.
88 */
89#define RTEMS_SYSLOG_WARNING( fmt, ...) \
90  RTEMS_SYSLOG( "Warning: " fmt, ##__VA_ARGS__)
91
92/**
93 * @brief Macro to generate a system log warning message if the status code @a
94 * sc is not equal to @ref RTEMS_SUCCESSFUL.
95 */
96#define RTEMS_SYSLOG_WARNING_SC( sc, msg) \
97  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
98    RTEMS_SYSLOG_WARNING( "SC = %i: %s\n", (int) sc, msg); \
99  }
100
101/**
102 * @brief General purpose system log macro for errors.
103 */
104#define RTEMS_SYSLOG_ERROR( fmt, ...) \
105  RTEMS_SYSLOG( "Error: " fmt, ##__VA_ARGS__)
106
107/**
108 * @brief Macro for system log error messages with status code.
109 */
110#define RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg) \
111  RTEMS_SYSLOG_ERROR( "SC = %i: %s\n", (int) sc, msg);
112
113/**
114 * @brief Macro for system log error messages with return value.
115 */
116#define RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg) \
117  RTEMS_SYSLOG_ERROR( "RV = %i: %s\n", (int) rv, msg);
118
119/**
120 * @brief Macro to generate a system log error message if the status code @a
121 * sc is not equal to @ref RTEMS_SUCCESSFUL.
122 */
123#define RTEMS_SYSLOG_ERROR_SC( sc, msg) \
124  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
125    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
126  }
127
128/**
129 * @brief Macro to generate a system log error message if the return value @a
130 * rv is less than zero.
131 */
132#define RTEMS_SYSLOG_ERROR_RV( rv, msg) \
133  if ((int) (rv) < 0) { \
134    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
135  }
136
137/** @} */
138
139/**
140 * @name Check Macros
141 */
142/**@{**/
143
144/**
145 * @brief Prints message @a msg and returns with status code @a sc if the status
146 * code @a sc is not equal to @ref RTEMS_SUCCESSFUL.
147 */
148#define RTEMS_CHECK_SC( sc, msg) \
149  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
150    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
151    return (rtems_status_code) sc; \
152  } else { \
153    RTEMS_DEBUG_OK( msg); \
154  }
155
156/**
157 * @brief Prints message @a msg and returns with a return value of negative @a sc
158 * if the status code @a sc is not equal to @ref RTEMS_SUCCESSFUL.
159 */
160#define RTEMS_CHECK_SC_RV( sc, msg) \
161  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
162    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
163    return -((int) (sc)); \
164  } else { \
165    RTEMS_DEBUG_OK( msg); \
166  }
167
168/**
169 * @brief Prints message @a msg and returns if the status code @a sc is not equal
170 * to @ref RTEMS_SUCCESSFUL.
171 */
172#define RTEMS_CHECK_SC_VOID( sc, msg) \
173  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
174    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
175    return; \
176  } else { \
177    RTEMS_DEBUG_OK( msg); \
178  }
179
180/**
181 * @brief Prints message @a msg and delete the current task if the status code
182 * @a sc is not equal to @ref RTEMS_SUCCESSFUL.
183 */
184#define RTEMS_CHECK_SC_TASK( sc, msg) \
185  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
186    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
187    rtems_task_exit(); \
188    return; \
189  } else { \
190    RTEMS_DEBUG_OK( msg); \
191  }
192
193/**
194 * @brief Prints message @a msg and returns with a return value @a rv if the
195 * return value @a rv is less than zero.
196 */
197#define RTEMS_CHECK_RV( rv, msg) \
198  if ((int) (rv) < 0) { \
199    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
200    return (int) rv; \
201  } else { \
202    RTEMS_DEBUG_OK( msg); \
203  }
204
205/**
206 * @brief Prints message @a msg and returns with status code @ref RTEMS_IO_ERROR
207 * if the return value @a rv is less than zero.
208 */
209#define RTEMS_CHECK_RV_SC( rv, msg) \
210  if ((int) (rv) < 0) { \
211    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
212    return RTEMS_IO_ERROR; \
213  } else { \
214    RTEMS_DEBUG_OK( msg); \
215  }
216
217/**
218 * @brief Prints message @a msg and returns if the return value @a rv is less
219 * than zero.
220 */
221#define RTEMS_CHECK_RV_VOID( rv, msg) \
222  if ((int) (rv) < 0) { \
223    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
224    return; \
225  } else { \
226    RTEMS_DEBUG_OK( msg); \
227  }
228
229/**
230 * @brief Prints message @a msg and delete the current task if the return value
231 * @a rv is less than zero.
232 */
233#define RTEMS_CHECK_RV_TASK( rv, msg) \
234  if ((int) (rv) < 0) { \
235    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
236    rtems_task_exit(); \
237    return; \
238  } else { \
239    RTEMS_DEBUG_OK( msg); \
240  }
241
242/** @} */
243
244/**
245 * @name Cleanup Macros
246 */
247/**@{**/
248
249/**
250 * @brief Prints message @a msg and jumps to @a label if the status code @a sc
251 * is not equal to @ref RTEMS_SUCCESSFUL.
252 */
253#define RTEMS_CLEANUP_SC( sc, label, msg) \
254  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
255    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
256    goto label; \
257  } else { \
258    RTEMS_DEBUG_OK( msg); \
259  }
260
261/**
262 * @brief Prints message @a msg and jumps to @a label if the status code @a sc
263 * is not equal to @ref RTEMS_SUCCESSFUL.  The return value variable @a rv will
264 * be set to a negative @a sc in this case.
265 */
266#define RTEMS_CLEANUP_SC_RV( sc, rv, label, msg) \
267  if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
268    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
269    rv = -((int) (sc)); \
270    goto label; \
271  } else { \
272    RTEMS_DEBUG_OK( msg); \
273  }
274
275/**
276 * @brief Prints message @a msg and jumps to @a label if the return value @a rv
277 * is less than zero.
278 */
279#define RTEMS_CLEANUP_RV( rv, label, msg) \
280  if ((int) (rv) < 0) { \
281    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
282    goto label; \
283  } else { \
284    RTEMS_DEBUG_OK( msg); \
285  }
286
287/**
288 * @brief Prints message @a msg and jumps to @a label if the return value @a rv
289 * is less than zero.  The status code variable @a sc will be set to @ref
290 * RTEMS_IO_ERROR in this case.
291 */
292#define RTEMS_CLEANUP_RV_SC( rv, sc, label, msg) \
293  if ((int) (rv) < 0) { \
294    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
295    sc = RTEMS_IO_ERROR; \
296    goto label; \
297  } else { \
298    RTEMS_DEBUG_OK( msg); \
299  }
300
301/**
302 * @brief Prints message @a msg and jumps to @a label.
303 */
304#define RTEMS_DO_CLEANUP( label, msg) \
305  do { \
306    RTEMS_SYSLOG_ERROR( msg); \
307    goto label; \
308  } while (0)
309
310/**
311 * @brief Prints message @a msg, sets the status code variable @a sc to @a val
312 * and jumps to @a label.
313 */
314#define RTEMS_DO_CLEANUP_SC( val, sc, label, msg) \
315  do { \
316    sc = (rtems_status_code) val; \
317    RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
318    goto label; \
319  } while (0)
320
321/**
322 * @brief Prints message @a msg, sets the return value variable @a rv to @a val
323 * and jumps to @a label.
324 */
325#define RTEMS_DO_CLEANUP_RV( val, rv, label, msg) \
326  do { \
327    rv = (int) val; \
328    RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
329    goto label; \
330  } while (0)
331
332/** @} */
333
334/** @} */
335
336#ifdef __cplusplus
337}
338#endif /* __cplusplus */
339
340#endif /* RTEMS_STATUS_CHECKS_H */
Note: See TracBrowser for help on using the repository browser.