iLLD_TC29x  1.0
Assert.h
Go to the documentation of this file.
1 /**
2  * \file Assert.h
3  * \brief Assert functions.
4  * \ingroup library_srvsw_sysse_bsp_assert
5  *
6  * \version iLLD_1_0_0_11_0
7  * \copyright Copyright (c) 2013 Infineon Technologies AG. All rights reserved.
8  *
9  *
10  * IMPORTANT NOTICE
11  *
12  *
13  * Infineon Technologies AG (Infineon) is supplying this file for use
14  * exclusively with Infineon's microcontroller products. This file can be freely
15  * distributed within development tools that are supporting such microcontroller
16  * products.
17  *
18  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21  * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
22  * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
23  *
24  * \defgroup library_srvsw_sysse_bsp_assert Assertion
25  * This module implements assertion functions.
26  * \ingroup library_srvsw_sysse_bsp
27  */
28 
29 #ifndef ASSERT_H
30 #define ASSERT_H 1
31 
32 #include "_Utilities/Ifx_Assert.h"
33 
34 /** \addtogroup library_srvsw_sysse_bsp_assert
35  * Global configuration settings (Ifx_Cfg.h) :
36  * - IFX_CFG_ASSERT_STDIO: if IFX_CFG_ASSERT_STDIO=1, the assertion is output to the io
37  * defined by \ref Ifx_Assert_setStandardIo (). if IFX_CFG_ASSERT_STDIO=0, no text
38  * output is done.
39  * Default is IFX_CFG_ASSERT_STDIO=0
40  * - IFX_CFG_ASSERT_USE_BREAKPOINT: if IFX_CFG_ASSERT_USE_BREAKPOINT=1, a debug instruction is
41  * inserted in case an assertion occurs with a level of
42  * \ref IFX_VERBOSE_LEVEL_FAILURE or \ref IFX_VERBOSE_LEVEL_ERROR. If IFX_CFG_ASSERT_USE_BREAKPOINT=0 then
43  * no debug instruction is inserted.
44  * Default is IFX_CFG_ASSERT_USE_BREAKPOINT=0.
45  * - IFX_CFG_ASSERT_VERBOSE_LEVEL_DEFAULT: Set the assertion limit,
46  * assertion with a level below or equal to the limit are taken in
47  * account, other are ignored. range=[\ref IFX_VERBOSE_LEVEL_OFF, \ref IFX_VERBOSE_LEVEL_FAILURE,
48  * \ref IFX_VERBOSE_LEVEL_ERROR, \ref IFX_VERBOSE_LEVEL_WARNING, \ref IFX_VERBOSE_LEVEL_INFO,
49  * \ref IFX_VERBOSE_LEVEL_DEBUG]
50  * Default is IFX_CFG_ASSERT_VERBOSE_LEVEL_DEFAULT=\ref IFX_VERBOSE_LEVEL_INFO.
51  *
52  * Do not include this file but use #include "_Utilities/Ifx_Assert.h" instead
53  * \{ */
54 
55 #ifndef IFX_CFG_ASSERT_STDIO
56 # define IFX_CFG_ASSERT_STDIO (0) /**< \brief If set to 1, the assert message is send to the Assert_io interface */
57 #endif
58 
59 #if IFX_CFG_ASSERT_STDIO == 1
60 # include "StdIf/IfxStdIf_DPipe.h"
61 #endif
62 
63 #ifndef IFX_CFG_ASSERT_USE_BREAKPOINT
64 # define IFX_CFG_ASSERT_USE_BREAKPOINT (0) /**< \brief If set to 1, the assert function will break the execution (breakpoint) */
65 #endif
66 
67 #ifndef IFX_CFG_ASSERT_VERBOSE_LEVEL_DEFAULT
68 /** \brief defines the assertion default level
69  *
70  * If not defined, the default assert level is set to IFX_VERBOSE_LEVEL_INFO
71  * */
72 #define IFX_CFG_ASSERT_VERBOSE_LEVEL_DEFAULT (IFX_VERBOSE_LEVEL_INFO)
73 #endif
74 
75 /** \brief Set the standard output used for \ref IFX_ASSERT and \ref IFX_VALIDATE
76  *
77  * For example the standard IO could redirect the output to a serial interface, CAN interface, ...
78  *
79  * \param standardIo Specifies the standard output used
80  *
81  * Enable only if (IFX_CFG_ASSERT_STDIO!=0)
82  *
83  * \return None.
84  */
85 #if IFX_CFG_ASSERT_STDIO == 1
87 #else
88 #define Ifx_Assert_setStandardIo(standardIo) ((void)0)
89 #endif
90 
91 /** \internal
92  * \brief Execute the assertion and display the assertion message
93  *
94  * Do not call this function directly, use IFX_ASSERT() instead
95  *
96  * \param level assertion level
97  * \param __assertion test as string, is displayed with the assertion message
98  * \param __file file in which the assertion occurred
99  * \param __line line number where the assertion occurred
100  * \param __function name of the function in which the assertion occurred
101  * \return void
102  */
103 IFX_EXTERN void Ifx_Assert_doLevel(uint8 level, pchar __assertion, pchar __file, unsigned int __line, pchar __function);
104 
105 /** \internal
106  * \brief Execute the assertion and display the assertion message.
107  *
108  * Do not call this function directly, use IFX_VALIDATE() instead
109  *
110  * \param expr expression value, assertion occurs if FALSE
111  * \param level assertion level
112  * \param __assertion test as string, is displayed with the assertion message
113  * \param __file file in which the assertion occurred
114  * \param __line line number where the assertion occurred
115  * \param __function name of the function in which the assertion occurred
116  * \return expr
117  */
118 IFX_EXTERN boolean Ifx_Assert_doValidate(boolean expr, uint8 level, pchar __assertion, pchar __file, unsigned int __line, pchar __function);
119 
120 #if IFX_CFG_ASSERT_VERBOSE_LEVEL_DEFAULT > IFX_VERBOSE_LEVEL_OFF
121 IFX_EXTERN uint32 Assert_verboseLevel; /**< \bri-ef Current verbose level, this value is initialised to IFX_CFG_ASSERT_VERBOSE_LEVEL_DEFAULT */
122 
123 #else
124 
125 # undef IFX_CFG_ASSERT_STDIO
126 # define IFX_CFG_ASSERT_STDIO (0)
127 
128 #endif
129 
130 #undef IFX_ASSERT
131 #undef IFX_VALIDATE
132 
133 /** \brief Assertion function (assert)
134  *
135  * If expr is FALSE, then an assertion message is displayed. The message
136  * indicates the assertion level, the file, line and function where the
137  * assertion occurred, and also display expr as text. In case the debug break
138  * point is enabled then a debug instruction will also be inserted so that the debugger stops
139  *
140  * If expr is true, nothing is additional done.
141  *
142  * The expr expression is ignored (code disabled) in case the assertion level set by IFX_CFG_ASSERT_VERBOSE_LEVEL_DEFAULT is \ref IFX_VERBOSE_LEVEL_OFF.
143  *
144  * The output needs to the be set with the function Ifx_Assert_setStandardIo() in order for the message to be displayed.
145  *
146  * \param level level of the assertion, range=[\ref IFX_VERBOSE_LEVEL_OFF, \ref IFX_VERBOSE_LEVEL_FAILURE,
147  * \ref IFX_VERBOSE_LEVEL_ERROR, \ref IFX_VERBOSE_LEVEL_WARNING, \ref IFX_VERBOSE_LEVEL_INFO,
148  * \ref IFX_VERBOSE_LEVEL_DEBUG]
149  * \param expr expression to be tested. If FALSE the assertion is executed else nothing is done
150  *
151  * \return void
152  */
153 #if IFX_CFG_ASSERT_VERBOSE_LEVEL_DEFAULT > IFX_VERBOSE_LEVEL_OFF
154 # define IFX_ASSERT(level, expr) (((expr) || (level > Assert_verboseLevel)) ? ((void)0) : Ifx_Assert_doLevel(level,#expr, __FILE__, __LINE__, __func__))
155 #else
156 # define IFX_ASSERT(level, expr) ((void)0)
157 #endif
158 
159 /** \brief Assertion function (validate)
160  *
161  * If expr is FALSE, then an assertion message is displayed. The message
162  * indicates the assertion level, the file, line and function where the
163  * assertion occurred, and also display expr as text. In case the debug
164  * break point is enabled then a debug instruction will also be inserted so
165  * that the debugger stops.
166  *
167  * \ref IFX_VALIDATE differs from \ref IFX_ASSERT in the way that the expr expression is
168  * evaluated whatever the assertion level set by IFX_CFG_ASSERT_VERBOSE_LEVEL_DEFAULT.
169  *
170  * The output needs to the be set with the function Ifx_Assert_setStandardIo() in order for the message to be displayed.
171  *
172  * \param level level of the assertion, range=[\ref IFX_VERBOSE_LEVEL_OFF, \ref IFX_VERBOSE_LEVEL_FAILURE,
173  * \ref IFX_VERBOSE_LEVEL_ERROR, \ref IFX_VERBOSE_LEVEL_WARNING, \ref IFX_VERBOSE_LEVEL_INFO,
174  * \ref IFX_VERBOSE_LEVEL_DEBUG]
175  * \param expr expression to be tested. If FALSE the assertion is executed else nothing is done
176  *
177  * \return void
178  */
179 #if IFX_CFG_ASSERT_VERBOSE_LEVEL_DEFAULT > IFX_VERBOSE_LEVEL_OFF
180 # define IFX_VALIDATE(level, expr) (Ifx_Assert_doValidate(expr, level,#expr, __FILE__, __LINE__, __func__))
181 #else
182 # define IFX_VALIDATE(level, expr) (expr)
183 #endif
184 
185 /** \} */
186 
187 //#include "_Utilities/Ifx_Assert.h" /* Needs to be at the end of the file */
188 
189 #endif