xref: /freebsd-src/sys/contrib/ncsw/inc/error_ext.h (revision c2c014f24c10f90d85126ac5fbd4d8524de32b1c)
1*852ba100SJustin Hibbits /* Copyright (c) 2008-2012 Freescale Semiconductor, Inc
20aeed3e9SJustin Hibbits  * All rights reserved.
30aeed3e9SJustin Hibbits  *
40aeed3e9SJustin Hibbits  * Redistribution and use in source and binary forms, with or without
50aeed3e9SJustin Hibbits  * modification, are permitted provided that the following conditions are met:
60aeed3e9SJustin Hibbits  *     * Redistributions of source code must retain the above copyright
70aeed3e9SJustin Hibbits  *       notice, this list of conditions and the following disclaimer.
80aeed3e9SJustin Hibbits  *     * Redistributions in binary form must reproduce the above copyright
90aeed3e9SJustin Hibbits  *       notice, this list of conditions and the following disclaimer in the
100aeed3e9SJustin Hibbits  *       documentation and/or other materials provided with the distribution.
110aeed3e9SJustin Hibbits  *     * Neither the name of Freescale Semiconductor nor the
120aeed3e9SJustin Hibbits  *       names of its contributors may be used to endorse or promote products
130aeed3e9SJustin Hibbits  *       derived from this software without specific prior written permission.
140aeed3e9SJustin Hibbits  *
150aeed3e9SJustin Hibbits  *
160aeed3e9SJustin Hibbits  * ALTERNATIVELY, this software may be distributed under the terms of the
170aeed3e9SJustin Hibbits  * GNU General Public License ("GPL") as published by the Free Software
180aeed3e9SJustin Hibbits  * Foundation, either version 2 of that License or (at your option) any
190aeed3e9SJustin Hibbits  * later version.
200aeed3e9SJustin Hibbits  *
210aeed3e9SJustin Hibbits  * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
220aeed3e9SJustin Hibbits  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
230aeed3e9SJustin Hibbits  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
240aeed3e9SJustin Hibbits  * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
250aeed3e9SJustin Hibbits  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
260aeed3e9SJustin Hibbits  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
270aeed3e9SJustin Hibbits  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
280aeed3e9SJustin Hibbits  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
290aeed3e9SJustin Hibbits  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
300aeed3e9SJustin Hibbits  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
310aeed3e9SJustin Hibbits  */
320aeed3e9SJustin Hibbits 
33*852ba100SJustin Hibbits 
34*852ba100SJustin Hibbits /**************************************************************************//**
350aeed3e9SJustin Hibbits  @File          error_ext.h
360aeed3e9SJustin Hibbits 
370aeed3e9SJustin Hibbits  @Description   Error definitions.
380aeed3e9SJustin Hibbits *//***************************************************************************/
390aeed3e9SJustin Hibbits 
400aeed3e9SJustin Hibbits #ifndef __ERROR_EXT_H
410aeed3e9SJustin Hibbits #define __ERROR_EXT_H
420aeed3e9SJustin Hibbits 
43*852ba100SJustin Hibbits #if defined(NCSW_FREEBSD)
44*852ba100SJustin Hibbits #include <sys/param.h>
45*852ba100SJustin Hibbits #include <sys/errno.h>
46*852ba100SJustin Hibbits #include <sys/pcpu.h>
47*852ba100SJustin Hibbits #endif
48*852ba100SJustin Hibbits 
490aeed3e9SJustin Hibbits #include "std_ext.h"
500aeed3e9SJustin Hibbits #include "xx_ext.h"
510aeed3e9SJustin Hibbits #include "core_ext.h"
520aeed3e9SJustin Hibbits 
53*852ba100SJustin Hibbits 
54*852ba100SJustin Hibbits 
55*852ba100SJustin Hibbits 
560aeed3e9SJustin Hibbits /**************************************************************************//**
570aeed3e9SJustin Hibbits  @Group         gen_id  General Drivers Utilities
580aeed3e9SJustin Hibbits 
590aeed3e9SJustin Hibbits  @Description   External routines.
600aeed3e9SJustin Hibbits 
610aeed3e9SJustin Hibbits  @{
620aeed3e9SJustin Hibbits *//***************************************************************************/
630aeed3e9SJustin Hibbits 
640aeed3e9SJustin Hibbits /**************************************************************************//**
650aeed3e9SJustin Hibbits  @Group         gen_error_id  Errors, Events and Debug
660aeed3e9SJustin Hibbits 
670aeed3e9SJustin Hibbits  @Description   External routines.
680aeed3e9SJustin Hibbits 
690aeed3e9SJustin Hibbits  @{
700aeed3e9SJustin Hibbits *//***************************************************************************/
710aeed3e9SJustin Hibbits 
720aeed3e9SJustin Hibbits /******************************************************************************
730aeed3e9SJustin Hibbits The scheme below provides the bits description for error codes:
740aeed3e9SJustin Hibbits 
750aeed3e9SJustin Hibbits  0    1    2    3    4    5    6    7    8    9    10   11   12   13   14   15
760aeed3e9SJustin Hibbits |       Reserved (should be zero)      |              Module ID               |
770aeed3e9SJustin Hibbits 
780aeed3e9SJustin Hibbits  16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31
790aeed3e9SJustin Hibbits |                               Error Type                                    |
800aeed3e9SJustin Hibbits ******************************************************************************/
810aeed3e9SJustin Hibbits 
820aeed3e9SJustin Hibbits #define ERROR_CODE(_err)            ((((uint32_t)_err) & 0x0000FFFF) | __ERR_MODULE__)
830aeed3e9SJustin Hibbits 
840aeed3e9SJustin Hibbits #define GET_ERROR_TYPE(_errcode)    ((_errcode) & 0x0000FFFF)
850aeed3e9SJustin Hibbits                                 /**< Extract module code from error code (#t_Error) */
860aeed3e9SJustin Hibbits 
870aeed3e9SJustin Hibbits #define GET_ERROR_MODULE(_errcode)  ((_errcode) & 0x00FF0000)
880aeed3e9SJustin Hibbits                                 /**< Extract error type (#e_ErrorType) from
890aeed3e9SJustin Hibbits                                      error code (#t_Error) */
900aeed3e9SJustin Hibbits 
910aeed3e9SJustin Hibbits 
920aeed3e9SJustin Hibbits /**************************************************************************//**
930aeed3e9SJustin Hibbits  @Description    Error Type Enumeration
940aeed3e9SJustin Hibbits *//***************************************************************************/
950aeed3e9SJustin Hibbits typedef enum e_ErrorType    /*   Comments / Associated Message Strings                      */
960aeed3e9SJustin Hibbits {                           /* ------------------------------------------------------------ */
970aeed3e9SJustin Hibbits     E_OK = 0                /*   Never use "RETURN_ERROR" with E_OK; Use "return E_OK;"     */
98*852ba100SJustin Hibbits     ,E_WRITE_FAILED = EIO   /**< Write access failed on memory/device.                      */
99*852ba100SJustin Hibbits                             /*   String: none, or device name.                              */
100*852ba100SJustin Hibbits     ,E_NO_DEVICE = ENXIO    /**< The associated device is not initialized.                  */
101*852ba100SJustin Hibbits                             /*   String: none.                                              */
102*852ba100SJustin Hibbits     ,E_NOT_AVAILABLE = EAGAIN
103*852ba100SJustin Hibbits                             /**< Resource is unavailable.                                   */
104*852ba100SJustin Hibbits                             /*   String: none, unless the operation is not the main goal
105*852ba100SJustin Hibbits                                  of the function (in this case add resource description).   */
106*852ba100SJustin Hibbits     ,E_NO_MEMORY = ENOMEM   /**< External memory allocation failed.                         */
107*852ba100SJustin Hibbits                             /*   String: description of item for which allocation failed.   */
108*852ba100SJustin Hibbits     ,E_INVALID_ADDRESS = EFAULT
109*852ba100SJustin Hibbits                             /**< Invalid address.                                           */
110*852ba100SJustin Hibbits                             /*   String: description of the specific violation.             */
111*852ba100SJustin Hibbits     ,E_BUSY = EBUSY         /**< Resource or module is busy.                                */
112*852ba100SJustin Hibbits                             /*   String: none, unless the operation is not the main goal
113*852ba100SJustin Hibbits                                  of the function (in this case add resource description).   */
114*852ba100SJustin Hibbits     ,E_ALREADY_EXISTS = EEXIST
115*852ba100SJustin Hibbits                             /**< Requested resource or item already exists.                 */
116*852ba100SJustin Hibbits                             /*   Use when resource duplication or sharing are not allowed.
117*852ba100SJustin Hibbits                                  String: none, unless the operation is not the main goal
118*852ba100SJustin Hibbits                                  of the function (in this case add item description).       */
119*852ba100SJustin Hibbits     ,E_INVALID_OPERATION = ENODEV
120*852ba100SJustin Hibbits                             /**< The operation/command is invalid (unrecognized).           */
121*852ba100SJustin Hibbits                             /*   String: none.                                              */
122*852ba100SJustin Hibbits     ,E_INVALID_VALUE = EDOM /**< Invalid value.                                             */
123*852ba100SJustin Hibbits                             /*   Use for non-enumeration parameters, and
124*852ba100SJustin Hibbits                                  only when other error types are not suitable.
125*852ba100SJustin Hibbits                                  String: parameter description + "(should be <attribute>)",
126*852ba100SJustin Hibbits                                  e.g: "Maximum Rx buffer length (should be divisible by 8)",
127*852ba100SJustin Hibbits                                       "Channel number (should be even)".                    */
128*852ba100SJustin Hibbits     ,E_NOT_IN_RANGE = ERANGE/**< Parameter value is out of range.                           */
129*852ba100SJustin Hibbits                             /*   Don't use this error for enumeration parameters.
130*852ba100SJustin Hibbits                                  String: parameter description + "(should be %d-%d)",
131*852ba100SJustin Hibbits                                  e.g: "Number of pad characters (should be 0-15)".          */
132*852ba100SJustin Hibbits     ,E_NOT_SUPPORTED = ENOSYS
133*852ba100SJustin Hibbits                             /**< The function is not supported or not implemented.          */
134*852ba100SJustin Hibbits                             /*   String: none.                                              */
1350aeed3e9SJustin Hibbits     ,E_INVALID_STATE        /**< The operation is not allowed in current module state.      */
1360aeed3e9SJustin Hibbits                             /*   String: none.                                              */
1370aeed3e9SJustin Hibbits     ,E_INVALID_HANDLE       /**< Invalid handle of module or object.                        */
1380aeed3e9SJustin Hibbits                             /*   String: none, unless the function takes in more than one
1390aeed3e9SJustin Hibbits                                  handle (in this case add the handle description)           */
1400aeed3e9SJustin Hibbits     ,E_INVALID_ID           /**< Invalid module ID (usually enumeration or index).          */
1410aeed3e9SJustin Hibbits                             /*   String: none, unless the function takes in more than one
1420aeed3e9SJustin Hibbits                                  ID (in this case add the ID description)                   */
1430aeed3e9SJustin Hibbits     ,E_NULL_POINTER         /**< Unexpected NULL pointer.                                   */
1440aeed3e9SJustin Hibbits                             /*   String: pointer description.                               */
1450aeed3e9SJustin Hibbits     ,E_INVALID_SELECTION    /**< Invalid selection or mode.                                 */
1460aeed3e9SJustin Hibbits                             /*   Use for enumeration values, only when other error types
1470aeed3e9SJustin Hibbits                                  are not suitable.
1480aeed3e9SJustin Hibbits                                  String: parameter description.                             */
1490aeed3e9SJustin Hibbits     ,E_INVALID_COMM_MODE    /**< Invalid communication mode.                                */
1500aeed3e9SJustin Hibbits                             /*   String: none, unless the function takes in more than one
1510aeed3e9SJustin Hibbits                                  communication mode indications (in this case add
1520aeed3e9SJustin Hibbits                                  parameter description).                                    */
1530aeed3e9SJustin Hibbits     ,E_INVALID_MEMORY_TYPE  /**< Invalid memory type.                                       */
1540aeed3e9SJustin Hibbits                             /*   String: none, unless the function takes in more than one
1550aeed3e9SJustin Hibbits                                  memory types (in this case add memory description,
1560aeed3e9SJustin Hibbits                                  e.g: "Data memory", "Buffer descriptors memory").          */
1570aeed3e9SJustin Hibbits     ,E_INVALID_CLOCK        /**< Invalid clock.                                             */
1580aeed3e9SJustin Hibbits                             /*   String: none, unless the function takes in more than one
1590aeed3e9SJustin Hibbits                                  clocks (in this case add clock description,
1600aeed3e9SJustin Hibbits                                  e.g: "Rx clock", "Tx clock").                              */
1610aeed3e9SJustin Hibbits     ,E_CONFLICT             /**< Some setting conflicts with another setting.               */
1620aeed3e9SJustin Hibbits                             /*   String: description of the conflicting settings.           */
1630aeed3e9SJustin Hibbits     ,E_NOT_ALIGNED          /**< Non-aligned address.                                       */
1640aeed3e9SJustin Hibbits                             /*   String: parameter description + "(should be %d-bytes aligned)",
1650aeed3e9SJustin Hibbits                                  e.g: "Rx data buffer (should be 32-bytes aligned)".        */
1660aeed3e9SJustin Hibbits     ,E_NOT_FOUND            /**< Requested resource or item was not found.                  */
1670aeed3e9SJustin Hibbits                             /*   Use only when the resource/item is uniquely identified.
1680aeed3e9SJustin Hibbits                                  String: none, unless the operation is not the main goal
1690aeed3e9SJustin Hibbits                                  of the function (in this case add item description).       */
1700aeed3e9SJustin Hibbits     ,E_FULL                 /**< Resource is full.                                          */
1710aeed3e9SJustin Hibbits                             /*   String: none, unless the operation is not the main goal
1720aeed3e9SJustin Hibbits                                  of the function (in this case add resource description).   */
1730aeed3e9SJustin Hibbits     ,E_EMPTY                /**< Resource is empty.                                         */
1740aeed3e9SJustin Hibbits                             /*   String: none, unless the operation is not the main goal
1750aeed3e9SJustin Hibbits                                  of the function (in this case add resource description).   */
1760aeed3e9SJustin Hibbits     ,E_ALREADY_FREE         /**< Specified resource or item is already free or deleted.     */
1770aeed3e9SJustin Hibbits                             /*   String: none, unless the operation is not the main goal
1780aeed3e9SJustin Hibbits                                  of the function (in this case add item description).       */
1790aeed3e9SJustin Hibbits     ,E_READ_FAILED          /**< Read access failed on memory/device.                       */
1800aeed3e9SJustin Hibbits                             /*   String: none, or device name.                              */
181*852ba100SJustin Hibbits     ,E_INVALID_FRAME        /**< Invalid frame object (NULL handle or missing buffers).     */
182*852ba100SJustin Hibbits                             /*   String: none.                                              */
1830aeed3e9SJustin Hibbits     ,E_SEND_FAILED          /**< Send operation failed on device.                           */
1840aeed3e9SJustin Hibbits                             /*   String: none, or device name.                              */
1850aeed3e9SJustin Hibbits     ,E_RECEIVE_FAILED       /**< Receive operation failed on device.                        */
1860aeed3e9SJustin Hibbits                             /*   String: none, or device name.                              */
187*852ba100SJustin Hibbits     ,E_TIMEOUT/* = ETIMEDOUT*/  /**< The operation timed out.                                   */
1880aeed3e9SJustin Hibbits                             /*   String: none.                                              */
1890aeed3e9SJustin Hibbits 
1900aeed3e9SJustin Hibbits     ,E_DUMMY_LAST           /* NEVER USED */
1910aeed3e9SJustin Hibbits 
1920aeed3e9SJustin Hibbits } e_ErrorType;
1930aeed3e9SJustin Hibbits 
1940aeed3e9SJustin Hibbits /**************************************************************************//**
1950aeed3e9SJustin Hibbits  @Description    Event Type Enumeration
1960aeed3e9SJustin Hibbits *//***************************************************************************/
1970aeed3e9SJustin Hibbits typedef enum e_Event        /*   Comments / Associated Flags and Message Strings            */
1980aeed3e9SJustin Hibbits {                           /* ------------------------------------------------------------ */
1990aeed3e9SJustin Hibbits     EV_NO_EVENT = 0         /**< No event; Never used.                                      */
2000aeed3e9SJustin Hibbits 
2010aeed3e9SJustin Hibbits     ,EV_RX_DISCARD          /**< Received packet discarded (by the driver, and only for
2020aeed3e9SJustin Hibbits                                  complete packets);
2030aeed3e9SJustin Hibbits                                  Flags: error flags in case of error, zero otherwise.       */
2040aeed3e9SJustin Hibbits                             /*   String: reason for discard, e.g: "Error in frame",
2050aeed3e9SJustin Hibbits                                  "Disordered frame", "Incomplete frame", "No frame object". */
2060aeed3e9SJustin Hibbits     ,EV_RX_ERROR            /**< Receive error (by hardware/firmware);
2070aeed3e9SJustin Hibbits                                  Flags: usually status flags from the buffer descriptor.    */
2080aeed3e9SJustin Hibbits                             /*   String: none.                                              */
2090aeed3e9SJustin Hibbits     ,EV_TX_ERROR            /**< Transmit error (by hardware/firmware);
2100aeed3e9SJustin Hibbits                                  Flags: usually status flags from the buffer descriptor.    */
2110aeed3e9SJustin Hibbits                             /*   String: none.                                              */
2120aeed3e9SJustin Hibbits     ,EV_NO_BUFFERS          /**< System ran out of buffer objects;
2130aeed3e9SJustin Hibbits                                  Flags: zero.                                               */
2140aeed3e9SJustin Hibbits                             /*   String: none.                                              */
2150aeed3e9SJustin Hibbits     ,EV_NO_MB_FRAMES        /**< System ran out of multi-buffer frame objects;
2160aeed3e9SJustin Hibbits                                  Flags: zero.                                               */
2170aeed3e9SJustin Hibbits                             /*   String: none.                                              */
2180aeed3e9SJustin Hibbits     ,EV_NO_SB_FRAMES        /**< System ran out of single-buffer frame objects;
2190aeed3e9SJustin Hibbits                                  Flags: zero.                                               */
2200aeed3e9SJustin Hibbits                             /*   String: none.                                              */
2210aeed3e9SJustin Hibbits     ,EV_TX_QUEUE_FULL       /**< Transmit queue is full;
2220aeed3e9SJustin Hibbits                                  Flags: zero.                                               */
2230aeed3e9SJustin Hibbits                             /*   String: none.                                              */
2240aeed3e9SJustin Hibbits     ,EV_RX_QUEUE_FULL       /**< Receive queue is full;
2250aeed3e9SJustin Hibbits                                  Flags: zero.                                               */
2260aeed3e9SJustin Hibbits                             /*   String: none.                                              */
2270aeed3e9SJustin Hibbits     ,EV_INTR_QUEUE_FULL     /**< Interrupt queue overflow;
2280aeed3e9SJustin Hibbits                                  Flags: zero.                                               */
2290aeed3e9SJustin Hibbits                             /*   String: none.                                              */
2300aeed3e9SJustin Hibbits     ,EV_NO_DATA_BUFFER      /**< Data buffer allocation (from higher layer) failed;
2310aeed3e9SJustin Hibbits                                  Flags: zero.                                               */
2320aeed3e9SJustin Hibbits                             /*   String: none.                                              */
2330aeed3e9SJustin Hibbits     ,EV_OBJ_POOL_EMPTY      /**< Objects pool is empty;
2340aeed3e9SJustin Hibbits                                  Flags: zero.                                               */
2350aeed3e9SJustin Hibbits                             /*   String: object description (name).                         */
2360aeed3e9SJustin Hibbits     ,EV_BUS_ERROR           /**< Illegal access on bus;
2370aeed3e9SJustin Hibbits                                  Flags: the address (if available) or bus identifier        */
2380aeed3e9SJustin Hibbits                             /*   String: bus/address/module description.                    */
2390aeed3e9SJustin Hibbits     ,EV_PTP_TXTS_QUEUE_FULL /**< PTP Tx timestamps queue is full;
2400aeed3e9SJustin Hibbits                                  Flags: zero.                                               */
2410aeed3e9SJustin Hibbits                             /*   String: none.                                              */
2420aeed3e9SJustin Hibbits     ,EV_PTP_RXTS_QUEUE_FULL /**< PTP Rx timestamps queue is full;
2430aeed3e9SJustin Hibbits                                  Flags: zero.                                               */
2440aeed3e9SJustin Hibbits                             /*   String: none.                                              */
2450aeed3e9SJustin Hibbits     ,EV_DUMMY_LAST
2460aeed3e9SJustin Hibbits 
2470aeed3e9SJustin Hibbits } e_Event;
2480aeed3e9SJustin Hibbits 
2490aeed3e9SJustin Hibbits 
2500aeed3e9SJustin Hibbits /**************************************************************************//**
2510aeed3e9SJustin Hibbits  @Collection    Debug Levels for Errors and Events
2520aeed3e9SJustin Hibbits 
2530aeed3e9SJustin Hibbits                 The level description refers to errors only.
2540aeed3e9SJustin Hibbits                 For events, classification is done by the user.
2550aeed3e9SJustin Hibbits 
2560aeed3e9SJustin Hibbits                 The TRACE, INFO and WARNING levels are allowed only when using
2570aeed3e9SJustin Hibbits                 the DBG macro, and are not allowed when using the error macros
2580aeed3e9SJustin Hibbits                 (RETURN_ERROR or REPORT_ERROR).
2590aeed3e9SJustin Hibbits  @{
2600aeed3e9SJustin Hibbits *//***************************************************************************/
2610aeed3e9SJustin Hibbits #define REPORT_LEVEL_CRITICAL   1       /**< Crasher: Incorrect flow, NULL pointers/handles. */
2620aeed3e9SJustin Hibbits #define REPORT_LEVEL_MAJOR      2       /**< Cannot proceed: Invalid operation, parameters or
2630aeed3e9SJustin Hibbits                                              configuration. */
2640aeed3e9SJustin Hibbits #define REPORT_LEVEL_MINOR      3       /**< Recoverable problem: a repeating call with the same
2650aeed3e9SJustin Hibbits                                              parameters may be successful. */
2660aeed3e9SJustin Hibbits #define REPORT_LEVEL_WARNING    4       /**< Something is not exactly right, yet it is not an error. */
2670aeed3e9SJustin Hibbits #define REPORT_LEVEL_INFO       5       /**< Messages which may be of interest to user/programmer. */
2680aeed3e9SJustin Hibbits #define REPORT_LEVEL_TRACE      6       /**< Program flow messages. */
2690aeed3e9SJustin Hibbits 
2700aeed3e9SJustin Hibbits #define EVENT_DISABLED          0xFF    /**< Disabled event (not reported at all) */
2710aeed3e9SJustin Hibbits 
2720aeed3e9SJustin Hibbits /* @} */
2730aeed3e9SJustin Hibbits 
2740aeed3e9SJustin Hibbits 
2750aeed3e9SJustin Hibbits 
2760aeed3e9SJustin Hibbits #define NO_MSG      ("")
2770aeed3e9SJustin Hibbits 
2780aeed3e9SJustin Hibbits #ifndef DEBUG_GLOBAL_LEVEL
2790aeed3e9SJustin Hibbits #define DEBUG_GLOBAL_LEVEL  REPORT_LEVEL_WARNING
2800aeed3e9SJustin Hibbits #endif /* DEBUG_GLOBAL_LEVEL */
2810aeed3e9SJustin Hibbits 
2820aeed3e9SJustin Hibbits #ifndef ERROR_GLOBAL_LEVEL
2830aeed3e9SJustin Hibbits #define ERROR_GLOBAL_LEVEL  DEBUG_GLOBAL_LEVEL
2840aeed3e9SJustin Hibbits #endif /* ERROR_GLOBAL_LEVEL */
2850aeed3e9SJustin Hibbits 
2860aeed3e9SJustin Hibbits #ifndef EVENT_GLOBAL_LEVEL
2870aeed3e9SJustin Hibbits #define EVENT_GLOBAL_LEVEL  REPORT_LEVEL_MINOR
2880aeed3e9SJustin Hibbits #endif /* EVENT_GLOBAL_LEVEL */
2890aeed3e9SJustin Hibbits 
2900aeed3e9SJustin Hibbits #ifdef EVENT_LOCAL_LEVEL
2910aeed3e9SJustin Hibbits #define EVENT_DYNAMIC_LEVEL EVENT_LOCAL_LEVEL
2920aeed3e9SJustin Hibbits #else
2930aeed3e9SJustin Hibbits #define EVENT_DYNAMIC_LEVEL EVENT_GLOBAL_LEVEL
2940aeed3e9SJustin Hibbits #endif /* EVENT_LOCAL_LEVEL */
2950aeed3e9SJustin Hibbits 
2960aeed3e9SJustin Hibbits 
2970aeed3e9SJustin Hibbits #ifndef DEBUG_DYNAMIC_LEVEL
2980aeed3e9SJustin Hibbits #define DEBUG_USING_STATIC_LEVEL
2990aeed3e9SJustin Hibbits 
3000aeed3e9SJustin Hibbits #ifdef DEBUG_STATIC_LEVEL
3010aeed3e9SJustin Hibbits #define DEBUG_DYNAMIC_LEVEL DEBUG_STATIC_LEVEL
3020aeed3e9SJustin Hibbits #else
3030aeed3e9SJustin Hibbits #define DEBUG_DYNAMIC_LEVEL DEBUG_GLOBAL_LEVEL
3040aeed3e9SJustin Hibbits #endif /* DEBUG_STATIC_LEVEL */
3050aeed3e9SJustin Hibbits 
3060aeed3e9SJustin Hibbits #else /* DEBUG_DYNAMIC_LEVEL */
3070aeed3e9SJustin Hibbits #ifdef DEBUG_STATIC_LEVEL
3080aeed3e9SJustin Hibbits #error "Please use either DEBUG_STATIC_LEVEL or DEBUG_DYNAMIC_LEVEL (not both)"
3090aeed3e9SJustin Hibbits #else
3100aeed3e9SJustin Hibbits int DEBUG_DYNAMIC_LEVEL = DEBUG_GLOBAL_LEVEL;
3110aeed3e9SJustin Hibbits #endif /* DEBUG_STATIC_LEVEL */
3120aeed3e9SJustin Hibbits #endif /* !DEBUG_DYNAMIC_LEVEL */
3130aeed3e9SJustin Hibbits 
3140aeed3e9SJustin Hibbits 
3150aeed3e9SJustin Hibbits #ifndef ERROR_DYNAMIC_LEVEL
3160aeed3e9SJustin Hibbits 
3170aeed3e9SJustin Hibbits #ifdef ERROR_STATIC_LEVEL
3180aeed3e9SJustin Hibbits #define ERROR_DYNAMIC_LEVEL ERROR_STATIC_LEVEL
3190aeed3e9SJustin Hibbits #else
3200aeed3e9SJustin Hibbits #define ERROR_DYNAMIC_LEVEL ERROR_GLOBAL_LEVEL
3210aeed3e9SJustin Hibbits #endif /* ERROR_STATIC_LEVEL */
3220aeed3e9SJustin Hibbits 
3230aeed3e9SJustin Hibbits #else /* ERROR_DYNAMIC_LEVEL */
3240aeed3e9SJustin Hibbits #ifdef ERROR_STATIC_LEVEL
3250aeed3e9SJustin Hibbits #error "Please use either ERROR_STATIC_LEVEL or ERROR_DYNAMIC_LEVEL (not both)"
3260aeed3e9SJustin Hibbits #else
3270aeed3e9SJustin Hibbits int ERROR_DYNAMIC_LEVEL = ERROR_GLOBAL_LEVEL;
3280aeed3e9SJustin Hibbits #endif /* ERROR_STATIC_LEVEL */
3290aeed3e9SJustin Hibbits #endif /* !ERROR_DYNAMIC_LEVEL */
3300aeed3e9SJustin Hibbits 
3310aeed3e9SJustin Hibbits #define PRINT_FORMAT        "[CPU%02d, %s:%d %s]"
332*852ba100SJustin Hibbits #define PRINT_FMT_PARAMS    PCPU_GET(cpuid), __FILE__, __LINE__, __FUNCTION__
3330aeed3e9SJustin Hibbits 
3340aeed3e9SJustin Hibbits #if (!(defined(DEBUG_ERRORS)) || (DEBUG_ERRORS == 0))
3350aeed3e9SJustin Hibbits /* No debug/error/event messages at all */
3360aeed3e9SJustin Hibbits #define DBG(_level, _vmsg)
3370aeed3e9SJustin Hibbits 
3380aeed3e9SJustin Hibbits #define REPORT_ERROR(_level, _err, _vmsg)
3390aeed3e9SJustin Hibbits 
3400aeed3e9SJustin Hibbits #define RETURN_ERROR(_level, _err, _vmsg) \
3410aeed3e9SJustin Hibbits         return ERROR_CODE(_err)
3420aeed3e9SJustin Hibbits 
3430aeed3e9SJustin Hibbits #if (REPORT_EVENTS > 0)
3440aeed3e9SJustin Hibbits 
3450aeed3e9SJustin Hibbits #define REPORT_EVENT(_ev, _appId, _flg, _vmsg) \
3460aeed3e9SJustin Hibbits     do { \
3470aeed3e9SJustin Hibbits         if (_ev##_LEVEL <= EVENT_DYNAMIC_LEVEL) { \
3480aeed3e9SJustin Hibbits             XX_EventById((uint32_t)(_ev), (t_Handle)(_appId), (uint16_t)(_flg), NO_MSG); \
3490aeed3e9SJustin Hibbits         } \
3500aeed3e9SJustin Hibbits     } while (0)
3510aeed3e9SJustin Hibbits 
3520aeed3e9SJustin Hibbits #else
3530aeed3e9SJustin Hibbits 
3540aeed3e9SJustin Hibbits #define REPORT_EVENT(_ev, _appId, _flg, _vmsg)
3550aeed3e9SJustin Hibbits 
3560aeed3e9SJustin Hibbits #endif /* (REPORT_EVENTS > 0) */
3570aeed3e9SJustin Hibbits 
3580aeed3e9SJustin Hibbits 
3590aeed3e9SJustin Hibbits #else /* DEBUG_ERRORS > 0 */
3600aeed3e9SJustin Hibbits 
3610aeed3e9SJustin Hibbits extern const char *dbgLevelStrings[];
3620aeed3e9SJustin Hibbits #if (REPORT_EVENTS > 0)
3630aeed3e9SJustin Hibbits extern const char *eventStrings[];
3640aeed3e9SJustin Hibbits #endif /* (REPORT_EVENTS > 0) */
3650aeed3e9SJustin Hibbits 
366*852ba100SJustin Hibbits char * ErrTypeStrings (e_ErrorType err);
367*852ba100SJustin Hibbits 
3680aeed3e9SJustin Hibbits 
3690aeed3e9SJustin Hibbits #if ((defined(DEBUG_USING_STATIC_LEVEL)) && (DEBUG_DYNAMIC_LEVEL < REPORT_LEVEL_WARNING))
3700aeed3e9SJustin Hibbits /* No need for DBG macro - debug level is higher anyway */
3710aeed3e9SJustin Hibbits #define DBG(_level, _vmsg)
3720aeed3e9SJustin Hibbits #else
3730aeed3e9SJustin Hibbits #define DBG(_level, _vmsg) \
3740aeed3e9SJustin Hibbits     do { \
3750aeed3e9SJustin Hibbits         if (REPORT_LEVEL_##_level <= DEBUG_DYNAMIC_LEVEL) { \
3760aeed3e9SJustin Hibbits             XX_Print("> %s (%s) " PRINT_FORMAT ": ", \
3770aeed3e9SJustin Hibbits                      dbgLevelStrings[REPORT_LEVEL_##_level - 1], \
378*852ba100SJustin Hibbits                      __STRING(__ERR_MODULE__), \
3790aeed3e9SJustin Hibbits                      PRINT_FMT_PARAMS); \
3800aeed3e9SJustin Hibbits             XX_Print _vmsg; \
3810aeed3e9SJustin Hibbits             XX_Print("\r\n"); \
3820aeed3e9SJustin Hibbits         } \
3830aeed3e9SJustin Hibbits     } while (0)
3840aeed3e9SJustin Hibbits #endif /* (defined(DEBUG_USING_STATIC_LEVEL) && (DEBUG_DYNAMIC_LEVEL < WARNING)) */
3850aeed3e9SJustin Hibbits 
3860aeed3e9SJustin Hibbits 
3870aeed3e9SJustin Hibbits #define REPORT_ERROR(_level, _err, _vmsg) \
3880aeed3e9SJustin Hibbits     do { \
3890aeed3e9SJustin Hibbits         if (REPORT_LEVEL_##_level <= ERROR_DYNAMIC_LEVEL) { \
3900aeed3e9SJustin Hibbits             XX_Print("! %s %s Error " PRINT_FORMAT ": %s; ", \
3910aeed3e9SJustin Hibbits                      dbgLevelStrings[REPORT_LEVEL_##_level - 1], \
392*852ba100SJustin Hibbits                      __STRING(__ERR_MODULE__), \
3930aeed3e9SJustin Hibbits                      PRINT_FMT_PARAMS, \
394*852ba100SJustin Hibbits                      ErrTypeStrings((e_ErrorType)GET_ERROR_TYPE(_err))); \
3950aeed3e9SJustin Hibbits             XX_Print _vmsg; \
3960aeed3e9SJustin Hibbits             XX_Print("\r\n"); \
3970aeed3e9SJustin Hibbits         } \
3980aeed3e9SJustin Hibbits     } while (0)
3990aeed3e9SJustin Hibbits 
4000aeed3e9SJustin Hibbits 
4010aeed3e9SJustin Hibbits #define RETURN_ERROR(_level, _err, _vmsg) \
4020aeed3e9SJustin Hibbits     do { \
4030aeed3e9SJustin Hibbits         REPORT_ERROR(_level, (_err), _vmsg); \
4040aeed3e9SJustin Hibbits         return ERROR_CODE(_err); \
4050aeed3e9SJustin Hibbits     } while (0)
4060aeed3e9SJustin Hibbits 
4070aeed3e9SJustin Hibbits 
4080aeed3e9SJustin Hibbits #if (REPORT_EVENTS > 0)
4090aeed3e9SJustin Hibbits 
4100aeed3e9SJustin Hibbits #define REPORT_EVENT(_ev, _appId, _flg, _vmsg) \
4110aeed3e9SJustin Hibbits     do { \
4120aeed3e9SJustin Hibbits         if (_ev##_LEVEL <= EVENT_DYNAMIC_LEVEL) { \
4130aeed3e9SJustin Hibbits             XX_Print("~ %s %s Event " PRINT_FORMAT ": %s (flags: 0x%04x); ", \
4140aeed3e9SJustin Hibbits                      dbgLevelStrings[_ev##_LEVEL - 1], \
415*852ba100SJustin Hibbits                      __STRING(__ERR_MODULE__), \
4160aeed3e9SJustin Hibbits                      PRINT_FMT_PARAMS, \
4170aeed3e9SJustin Hibbits                      eventStrings[((_ev) - EV_NO_EVENT - 1)], \
4180aeed3e9SJustin Hibbits                      (uint16_t)(_flg)); \
4190aeed3e9SJustin Hibbits             XX_Print _vmsg; \
4200aeed3e9SJustin Hibbits             XX_Print("\r\n"); \
4210aeed3e9SJustin Hibbits             XX_EventById((uint32_t)(_ev), (t_Handle)(_appId), (uint16_t)(_flg), NO_MSG); \
4220aeed3e9SJustin Hibbits         } \
4230aeed3e9SJustin Hibbits     } while (0)
4240aeed3e9SJustin Hibbits 
4250aeed3e9SJustin Hibbits #else /* not REPORT_EVENTS */
4260aeed3e9SJustin Hibbits 
4270aeed3e9SJustin Hibbits #define REPORT_EVENT(_ev, _appId, _flg, _vmsg)
4280aeed3e9SJustin Hibbits 
4290aeed3e9SJustin Hibbits #endif /* (REPORT_EVENTS > 0) */
4300aeed3e9SJustin Hibbits 
4310aeed3e9SJustin Hibbits #endif /* (DEBUG_ERRORS > 0) */
4320aeed3e9SJustin Hibbits 
4330aeed3e9SJustin Hibbits 
4340aeed3e9SJustin Hibbits /**************************************************************************//**
4350aeed3e9SJustin Hibbits  @Function      ASSERT_COND
4360aeed3e9SJustin Hibbits 
4370aeed3e9SJustin Hibbits  @Description   Assertion macro.
4380aeed3e9SJustin Hibbits 
4390aeed3e9SJustin Hibbits  @Param[in]     _cond - The condition being checked, in positive form;
4400aeed3e9SJustin Hibbits                         Failure of the condition triggers the assert.
4410aeed3e9SJustin Hibbits *//***************************************************************************/
4420aeed3e9SJustin Hibbits #ifdef DISABLE_ASSERTIONS
4430aeed3e9SJustin Hibbits #define ASSERT_COND(_cond)
4440aeed3e9SJustin Hibbits #else
4450aeed3e9SJustin Hibbits #define ASSERT_COND(_cond) \
4460aeed3e9SJustin Hibbits     do { \
4470aeed3e9SJustin Hibbits         if (!(_cond)) { \
4480aeed3e9SJustin Hibbits             XX_Print("*** ASSERT_COND failed " PRINT_FORMAT "\r\n", \
4490aeed3e9SJustin Hibbits                     PRINT_FMT_PARAMS); \
4500aeed3e9SJustin Hibbits             XX_Exit(1); \
4510aeed3e9SJustin Hibbits         } \
4520aeed3e9SJustin Hibbits     } while (0)
4530aeed3e9SJustin Hibbits #endif /* DISABLE_ASSERTIONS */
4540aeed3e9SJustin Hibbits 
4550aeed3e9SJustin Hibbits 
4560aeed3e9SJustin Hibbits #ifdef DISABLE_INIT_PARAMETERS_CHECK
4570aeed3e9SJustin Hibbits 
4580aeed3e9SJustin Hibbits #define CHECK_INIT_PARAMETERS(handle, f_check)
4590aeed3e9SJustin Hibbits #define CHECK_INIT_PARAMETERS_RETURN_VALUE(handle, f_check, retval)
4600aeed3e9SJustin Hibbits 
4610aeed3e9SJustin Hibbits #else
4620aeed3e9SJustin Hibbits 
4630aeed3e9SJustin Hibbits #define CHECK_INIT_PARAMETERS(handle, f_check) \
4640aeed3e9SJustin Hibbits     do { \
4650aeed3e9SJustin Hibbits         t_Error err = f_check(handle); \
4660aeed3e9SJustin Hibbits         if (err != E_OK) { \
4670aeed3e9SJustin Hibbits             RETURN_ERROR(MAJOR, err, NO_MSG); \
4680aeed3e9SJustin Hibbits         } \
4690aeed3e9SJustin Hibbits     } while (0)
4700aeed3e9SJustin Hibbits 
4710aeed3e9SJustin Hibbits #define CHECK_INIT_PARAMETERS_RETURN_VALUE(handle, f_check, retval) \
4720aeed3e9SJustin Hibbits     do { \
4730aeed3e9SJustin Hibbits         t_Error err = f_check(handle); \
4740aeed3e9SJustin Hibbits         if (err != E_OK) { \
4750aeed3e9SJustin Hibbits             REPORT_ERROR(MAJOR, err, NO_MSG); \
4760aeed3e9SJustin Hibbits             return (retval); \
4770aeed3e9SJustin Hibbits         } \
4780aeed3e9SJustin Hibbits     } while (0)
4790aeed3e9SJustin Hibbits 
4800aeed3e9SJustin Hibbits #endif /* DISABLE_INIT_PARAMETERS_CHECK */
4810aeed3e9SJustin Hibbits 
4820aeed3e9SJustin Hibbits #ifdef DISABLE_SANITY_CHECKS
4830aeed3e9SJustin Hibbits 
4840aeed3e9SJustin Hibbits #define SANITY_CHECK_RETURN_ERROR(_cond, _err)
4850aeed3e9SJustin Hibbits #define SANITY_CHECK_RETURN_VALUE(_cond, _err, retval)
4860aeed3e9SJustin Hibbits #define SANITY_CHECK_RETURN(_cond, _err)
4870aeed3e9SJustin Hibbits #define SANITY_CHECK_EXIT(_cond, _err)
4880aeed3e9SJustin Hibbits 
4890aeed3e9SJustin Hibbits #else /* DISABLE_SANITY_CHECKS */
4900aeed3e9SJustin Hibbits 
4910aeed3e9SJustin Hibbits #define SANITY_CHECK_RETURN_ERROR(_cond, _err) \
4920aeed3e9SJustin Hibbits     do { \
4930aeed3e9SJustin Hibbits         if (!(_cond)) { \
4940aeed3e9SJustin Hibbits             RETURN_ERROR(CRITICAL, (_err), NO_MSG); \
4950aeed3e9SJustin Hibbits         } \
4960aeed3e9SJustin Hibbits     } while (0)
4970aeed3e9SJustin Hibbits 
4980aeed3e9SJustin Hibbits #define SANITY_CHECK_RETURN_VALUE(_cond, _err, retval) \
4990aeed3e9SJustin Hibbits     do { \
5000aeed3e9SJustin Hibbits         if (!(_cond)) { \
5010aeed3e9SJustin Hibbits             REPORT_ERROR(CRITICAL, (_err), NO_MSG); \
5020aeed3e9SJustin Hibbits             return (retval); \
5030aeed3e9SJustin Hibbits         } \
5040aeed3e9SJustin Hibbits     } while (0)
5050aeed3e9SJustin Hibbits 
5060aeed3e9SJustin Hibbits #define SANITY_CHECK_RETURN(_cond, _err) \
5070aeed3e9SJustin Hibbits     do { \
5080aeed3e9SJustin Hibbits         if (!(_cond)) { \
5090aeed3e9SJustin Hibbits             REPORT_ERROR(CRITICAL, (_err), NO_MSG); \
5100aeed3e9SJustin Hibbits             return; \
5110aeed3e9SJustin Hibbits         } \
5120aeed3e9SJustin Hibbits     } while (0)
5130aeed3e9SJustin Hibbits 
5140aeed3e9SJustin Hibbits #define SANITY_CHECK_EXIT(_cond, _err) \
5150aeed3e9SJustin Hibbits     do { \
5160aeed3e9SJustin Hibbits         if (!(_cond)) { \
5170aeed3e9SJustin Hibbits             REPORT_ERROR(CRITICAL, (_err), NO_MSG); \
5180aeed3e9SJustin Hibbits             XX_Exit(1); \
5190aeed3e9SJustin Hibbits         } \
5200aeed3e9SJustin Hibbits     } while (0)
5210aeed3e9SJustin Hibbits 
5220aeed3e9SJustin Hibbits #endif /* DISABLE_SANITY_CHECKS */
5230aeed3e9SJustin Hibbits 
5240aeed3e9SJustin Hibbits /** @} */ /* end of Debug/error Utils group */
5250aeed3e9SJustin Hibbits 
5260aeed3e9SJustin Hibbits /** @} */ /* end of General Utils group */
5270aeed3e9SJustin Hibbits 
5280aeed3e9SJustin Hibbits #endif /* __ERROR_EXT_H */
5290aeed3e9SJustin Hibbits 
5300aeed3e9SJustin Hibbits 
531