source: rtems/cpukit/include/rtems/error.h

Last change on this file was 17c92ad, checked in by Ryan Long <ryan.long@…>, on 04/29/22 at 18:49:57

cpukit/include/rtems: Add file headers and licenses

These files had no header, copyright, or licenses. Based on git history,
added appropriate copyright and license.

  • Property mode set to 100644
File size: 4.8 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @brief RTEMS Error Reporting
7 *
8 * Defines and externs for rtems error reporting
9 *
10 * These routines provide general purpose error reporting.
11 * rtems_error reports an error to stderr and allows use of
12 * printf style formatting.  A newline is appended to all messages.
13 *
14 * error_flag can be specified as any of the following:
15 *
16 *  RTEMS_ERROR_ERRNO       -- include errno text in output
17 *  RTEMS_ERROR_PANIC       -- halts local system after output
18 *  RTEMS_ERROR_ABORT       -- abort after output
19 *
20 * It can also include a rtems_status value which can be OR'd
21 * with the above flags. *
22 *
23 * Example 1:
24 * @code
25 *  #include <rtems.h>
26 *  #include <rtems/error.h>
27 *  rtems_error(0, "stray interrupt %d", intr);
28 * @endcode
29 *
30 * Example 2:
31 * @code
32 *        if ((status = rtems_task_create(...)) != RTEMS_SUCCCESSFUL)
33 *        {
34 *            rtems_error(status | RTEMS_ERROR_ABORT,
35 *                        "could not create task");
36 *        }
37 * @endcode
38 *
39 * Example 3:
40 * @code
41 *        if ((fd = open(pathname, O_RDNLY)) < 0)
42 *        {
43 *            rtems_error(RTEMS_ERROR_ERRNO, "open of '%s' failed", pathname);
44 *            goto failed;
45 *        }
46 * @endcode
47 */
48
49/*
50 * Copyright (C) 1995 Tony Bennett <tbennett@divnc.com>
51 *
52 * Redistribution and use in source and binary forms, with or without
53 * modification, are permitted provided that the following conditions
54 * are met:
55 * 1. Redistributions of source code must retain the above copyright
56 *    notice, this list of conditions and the following disclaimer.
57 * 2. Redistributions in binary form must reproduce the above copyright
58 *    notice, this list of conditions and the following disclaimer in the
59 *    documentation and/or other materials provided with the distribution.
60 *
61 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
62 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
63 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
64 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
65 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
66 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
67 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
68 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
69 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
70 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
71 * POSSIBILITY OF SUCH DAMAGE.
72 */
73
74#ifndef _RTEMS_RTEMS_ERROR_H
75#define _RTEMS_RTEMS_ERROR_H
76
77#include <rtems/rtems/status.h>
78#include <rtems/fatal.h>
79
80#include <stdarg.h>
81
82#ifdef __cplusplus
83extern "C" {
84#endif
85
86/**
87 *  @defgroup ErrorPanicSupport Error And Panic Support
88 *
89 *  @ingroup libcsupport
90 *
91 *  @brief Defines and externs for rtems error reporting
92 *
93 */
94typedef Internal_errors_t rtems_error_code_t;
95
96/*
97 * rtems_error(), rtems_verror() and rtems_panic() support
98 */
99
100#if 0
101/* not 16bit-int host clean */
102#define RTEMS_ERROR_ERRNO  (1<<((sizeof(rtems_error_code_t) * CHAR_BIT) - 2)) /* hi bit; use 'errno' */
103#define RTEMS_ERROR_PANIC  (RTEMS_ERROR_ERRNO / 2)       /* err fatal; no return */
104#define RTEMS_ERROR_ABORT  (RTEMS_ERROR_ERRNO / 4)       /* err is fatal; panic */
105#else
106#define RTEMS_ERROR_ERRNO  (0x40000000) /* hi bit; use 'errno' */
107#define RTEMS_ERROR_PANIC  (0x20000000) /* err fatal; no return */
108#define RTEMS_ERROR_ABORT  (0x10000000) /* err is fatal; panic */
109#endif
110
111#define RTEMS_ERROR_MASK \
112  (RTEMS_ERROR_ERRNO | RTEMS_ERROR_ABORT | RTEMS_ERROR_PANIC) /* all */
113
114/**
115 *  @brief Report an Error
116 *
117 *  @param[in] error_code can be specified as any of the following:
118 *  RTEMS_ERROR_ERRNO       -- include errno text in output
119 *  RTEMS_ERROR_PANIC       -- halts local system after output
120 *  RTEMS_ERROR_ABORT       -- abort after output
121 *
122 *  @param[in] printf_format is a normal printf(3) format string,
123 *  with its concommitant arguments
124 *
125 *  @return the number of characters written.
126 */
127int   rtems_error(
128  rtems_error_code_t error_code,
129  const char *printf_format,
130  ...
131);
132
133/**
134 *  @brief Report an Error
135 *
136 *  @param[in] error_code can be specified as any of the following:
137 *  RTEMS_ERROR_ERRNO       -- include errno text in output
138 *  RTEMS_ERROR_PANIC       -- halts local system after output
139 *  RTEMS_ERROR_ABORT       -- abort after output
140 *
141 *  @param[in] printf_format is a normal printf(3) format string,
142 *  with its concommitant arguments
143 *  @param[in] arglist is a varargs list corresponding to
144 *  printf_format
145 *
146 *  @return the number of characters written.
147 */
148int rtems_verror(
149  rtems_error_code_t  error_code,
150  const char         *printf_format,
151  va_list             arglist
152);
153
154extern int rtems_panic_in_progress;
155
156#ifdef __cplusplus
157}
158#endif
159
160
161#endif
162/* end of include file */
Note: See TracBrowser for help on using the repository browser.