Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:13

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @brief RTEMS Error Reporting
0007  *
0008  * Defines and externs for rtems error reporting
0009  *
0010  * These routines provide general purpose error reporting.
0011  * rtems_error reports an error to stderr and allows use of
0012  * printf style formatting.  A newline is appended to all messages.
0013  *
0014  * error_flag can be specified as any of the following:
0015  *
0016  *  RTEMS_ERROR_ERRNO       -- include errno text in output
0017  *  RTEMS_ERROR_PANIC       -- halts local system after output
0018  *  RTEMS_ERROR_ABORT       -- abort after output
0019  *
0020  * It can also include a rtems_status value which can be OR'd
0021  * with the above flags. *
0022  *
0023  * Example 1:
0024  * @code
0025  *  #include <rtems.h>
0026  *  #include <rtems/error.h>
0027  *  rtems_error(0, "stray interrupt %d", intr);
0028  * @endcode
0029  *
0030  * Example 2:
0031  * @code
0032  *        if ((status = rtems_task_create(...)) != RTEMS_SUCCCESSFUL)
0033  *        {
0034  *            rtems_error(status | RTEMS_ERROR_ABORT,
0035  *                        "could not create task");
0036  *        }
0037  * @endcode
0038  *
0039  * Example 3:
0040  * @code
0041  *        if ((fd = open(pathname, O_RDNLY)) < 0)
0042  *        {
0043  *            rtems_error(RTEMS_ERROR_ERRNO, "open of '%s' failed", pathname);
0044  *            goto failed;
0045  *        }
0046  * @endcode
0047  */
0048 
0049 /*
0050  * Copyright (C) 1995 Tony Bennett <tbennett@divnc.com>
0051  *
0052  * Redistribution and use in source and binary forms, with or without
0053  * modification, are permitted provided that the following conditions
0054  * are met:
0055  * 1. Redistributions of source code must retain the above copyright
0056  *    notice, this list of conditions and the following disclaimer.
0057  * 2. Redistributions in binary form must reproduce the above copyright
0058  *    notice, this list of conditions and the following disclaimer in the
0059  *    documentation and/or other materials provided with the distribution.
0060  *
0061  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0062  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0063  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0064  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0065  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0066  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0067  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0068  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0069  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0070  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0071  * POSSIBILITY OF SUCH DAMAGE.
0072  */
0073 
0074 #ifndef _RTEMS_RTEMS_ERROR_H
0075 #define _RTEMS_RTEMS_ERROR_H
0076 
0077 #include <rtems/rtems/status.h>
0078 #include <rtems/fatal.h>
0079 
0080 #include <stdarg.h>
0081 
0082 #ifdef __cplusplus
0083 extern "C" {
0084 #endif
0085 
0086 /**
0087  *  @defgroup ErrorPanicSupport Error And Panic Support
0088  *
0089  *  @ingroup libcsupport
0090  *
0091  *  @brief Defines and externs for rtems error reporting
0092  *
0093  */
0094 typedef Internal_errors_t rtems_error_code_t;
0095 
0096 /*
0097  * rtems_error(), rtems_verror() and rtems_panic() support
0098  */
0099 
0100 #if 0
0101 /* not 16bit-int host clean */
0102 #define RTEMS_ERROR_ERRNO  (1<<((sizeof(rtems_error_code_t) * CHAR_BIT) - 2)) /* hi bit; use 'errno' */
0103 #define RTEMS_ERROR_PANIC  (RTEMS_ERROR_ERRNO / 2)       /* err fatal; no return */
0104 #define RTEMS_ERROR_ABORT  (RTEMS_ERROR_ERRNO / 4)       /* err is fatal; panic */
0105 #else
0106 #define RTEMS_ERROR_ERRNO  (0x40000000) /* hi bit; use 'errno' */
0107 #define RTEMS_ERROR_PANIC  (0x20000000) /* err fatal; no return */
0108 #define RTEMS_ERROR_ABORT  (0x10000000) /* err is fatal; panic */
0109 #endif
0110 
0111 #define RTEMS_ERROR_MASK \
0112   (RTEMS_ERROR_ERRNO | RTEMS_ERROR_ABORT | RTEMS_ERROR_PANIC) /* all */
0113 
0114 /**
0115  *  @brief Report an Error
0116  *
0117  *  @param[in] error_code can be specified as any of the following:
0118  *  RTEMS_ERROR_ERRNO       -- include errno text in output
0119  *  RTEMS_ERROR_PANIC       -- halts local system after output
0120  *  RTEMS_ERROR_ABORT       -- abort after output
0121  *
0122  *  @param[in] printf_format is a normal printf(3) format string,
0123  *  with its concommitant arguments
0124  *
0125  *  @return the number of characters written.
0126  */
0127 int   rtems_error(
0128   rtems_error_code_t error_code,
0129   const char *printf_format,
0130   ...
0131 );
0132 
0133 /**
0134  *  @brief Report an Error
0135  *
0136  *  @param[in] error_code can be specified as any of the following:
0137  *  RTEMS_ERROR_ERRNO       -- include errno text in output
0138  *  RTEMS_ERROR_PANIC       -- halts local system after output
0139  *  RTEMS_ERROR_ABORT       -- abort after output
0140  *
0141  *  @param[in] printf_format is a normal printf(3) format string,
0142  *  with its concommitant arguments
0143  *  @param[in] arglist is a varargs list corresponding to
0144  *  printf_format
0145  *
0146  *  @return the number of characters written.
0147  */
0148 int rtems_verror(
0149   rtems_error_code_t  error_code,
0150   const char         *printf_format,
0151   va_list             arglist
0152 );
0153 
0154 extern int rtems_panic_in_progress;
0155 
0156 #ifdef __cplusplus
0157 }
0158 #endif
0159 
0160 
0161 #endif
0162 /* end of include file */