1 | /** |
---|
2 | * @file rtems/error.h |
---|
3 | * |
---|
4 | * @brief RTEMS Error Reporting |
---|
5 | * |
---|
6 | * Defines and externs for rtems error reporting |
---|
7 | * |
---|
8 | * These routines provide general purpose error reporting. |
---|
9 | * rtems_error reports an error to stderr and allows use of |
---|
10 | * printf style formatting. A newline is appended to all messages. |
---|
11 | * |
---|
12 | * error_flag can be specified as any of the following: |
---|
13 | * |
---|
14 | * RTEMS_ERROR_ERRNO -- include errno text in output |
---|
15 | * RTEMS_ERROR_PANIC -- halts local system after output |
---|
16 | * RTEMS_ERROR_ABORT -- abort after output |
---|
17 | * |
---|
18 | * It can also include a rtems_status value which can be OR'd |
---|
19 | * with the above flags. * |
---|
20 | * |
---|
21 | * Example 1: |
---|
22 | * @code |
---|
23 | * #include <rtems.h> |
---|
24 | * #include <rtems/error.h> |
---|
25 | * rtems_error(0, "stray interrupt %d", intr); |
---|
26 | * @endcode |
---|
27 | * |
---|
28 | * Example 2: |
---|
29 | * @code |
---|
30 | * if ((status = rtems_task_create(...)) != RTEMS_SUCCCESSFUL) |
---|
31 | * { |
---|
32 | * rtems_error(status | RTEMS_ERROR_ABORT, |
---|
33 | * "could not create task"); |
---|
34 | * } |
---|
35 | * @endcode |
---|
36 | * |
---|
37 | * Example 3: |
---|
38 | * @code |
---|
39 | * if ((fd = open(pathname, O_RDNLY)) < 0) |
---|
40 | * { |
---|
41 | * rtems_error(RTEMS_ERROR_ERRNO, "open of '%s' failed", pathname); |
---|
42 | * goto failed; |
---|
43 | * } |
---|
44 | * @endcode |
---|
45 | */ |
---|
46 | |
---|
47 | #ifndef _RTEMS_RTEMS_ERROR_H |
---|
48 | #define _RTEMS_RTEMS_ERROR_H |
---|
49 | |
---|
50 | #include <rtems/rtems/status.h> |
---|
51 | #include <rtems/fatal.h> |
---|
52 | |
---|
53 | #include <stdarg.h> |
---|
54 | |
---|
55 | #ifdef __cplusplus |
---|
56 | extern "C" { |
---|
57 | #endif |
---|
58 | |
---|
59 | /** |
---|
60 | * @defgroup ErrorPanicSupport Error And Panic Support |
---|
61 | * |
---|
62 | * @ingroup libcsupport |
---|
63 | * |
---|
64 | * @brief Defines and externs for rtems error reporting |
---|
65 | * |
---|
66 | */ |
---|
67 | typedef Internal_errors_t rtems_error_code_t; |
---|
68 | |
---|
69 | /* |
---|
70 | * rtems_error(), rtems_verror() and rtems_panic() support |
---|
71 | */ |
---|
72 | |
---|
73 | #if 0 |
---|
74 | /* not 16bit-int host clean */ |
---|
75 | #define RTEMS_ERROR_ERRNO (1<<((sizeof(rtems_error_code_t) * CHAR_BIT) - 2)) /* hi bit; use 'errno' */ |
---|
76 | #define RTEMS_ERROR_PANIC (RTEMS_ERROR_ERRNO / 2) /* err fatal; no return */ |
---|
77 | #define RTEMS_ERROR_ABORT (RTEMS_ERROR_ERRNO / 4) /* err is fatal; panic */ |
---|
78 | #else |
---|
79 | #define RTEMS_ERROR_ERRNO (0x40000000) /* hi bit; use 'errno' */ |
---|
80 | #define RTEMS_ERROR_PANIC (0x20000000) /* err fatal; no return */ |
---|
81 | #define RTEMS_ERROR_ABORT (0x10000000) /* err is fatal; panic */ |
---|
82 | #endif |
---|
83 | |
---|
84 | #define RTEMS_ERROR_MASK \ |
---|
85 | (RTEMS_ERROR_ERRNO | RTEMS_ERROR_ABORT | RTEMS_ERROR_PANIC) /* all */ |
---|
86 | |
---|
87 | /** |
---|
88 | * @brief Report an Error |
---|
89 | * |
---|
90 | * @param[in] error_code can be specified as any of the following: |
---|
91 | * RTEMS_ERROR_ERRNO -- include errno text in output |
---|
92 | * RTEMS_ERROR_PANIC -- halts local system after output |
---|
93 | * RTEMS_ERROR_ABORT -- abort after output |
---|
94 | * |
---|
95 | * @param[in] printf_format is a normal printf(3) format string, |
---|
96 | * with its concommitant arguments |
---|
97 | * |
---|
98 | * @return the number of characters written. |
---|
99 | */ |
---|
100 | int rtems_error( |
---|
101 | rtems_error_code_t error_code, |
---|
102 | const char *printf_format, |
---|
103 | ... |
---|
104 | ); |
---|
105 | |
---|
106 | /** |
---|
107 | * @brief Report an Error |
---|
108 | * |
---|
109 | * @param[in] error_code can be specified as any of the following: |
---|
110 | * RTEMS_ERROR_ERRNO -- include errno text in output |
---|
111 | * RTEMS_ERROR_PANIC -- halts local system after output |
---|
112 | * RTEMS_ERROR_ABORT -- abort after output |
---|
113 | * |
---|
114 | * @param[in] printf_format is a normal printf(3) format string, |
---|
115 | * with its concommitant arguments |
---|
116 | * @param[in] arglist is a varargs list corresponding to |
---|
117 | * printf_format |
---|
118 | * |
---|
119 | * @return the number of characters written. |
---|
120 | */ |
---|
121 | int rtems_verror( |
---|
122 | rtems_error_code_t error_code, |
---|
123 | const char *printf_format, |
---|
124 | va_list arglist |
---|
125 | ); |
---|
126 | |
---|
127 | extern int rtems_panic_in_progress; |
---|
128 | |
---|
129 | #ifdef __cplusplus |
---|
130 | } |
---|
131 | #endif |
---|
132 | |
---|
133 | |
---|
134 | #endif |
---|
135 | /* end of include file */ |
---|