SYS/BIOS  7.00
Error.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-2021, Texas Instruments Incorporated - http://www.ti.com
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
122 /*
123  * ======== Error.h ========
124  */
125 
126 #ifndef ti_sysbios_runtime_Error__include
127 #define ti_sysbios_runtime_Error__include
128 
129 #include <stdbool.h>
130 #include <stddef.h>
131 #include <stdint.h>
132 
133 /* @cond NODOC */
134 /* BIOS 6.x compatibility, use -Dxdc_std__include to disable */
135 #include <xdc/std.h>
136 
137 #define ti_sysbios_runtime_Error_long_names
138 #include "Error_defs.h"
139 /* @endcond */
140 
141 #ifdef __cplusplus
142 extern "C" {
143 #endif
144 
152 typedef struct Error_Block {
153  const char * id;
154  intptr_t a0;
155  intptr_t a1;
156 } Error_Block;
157 
158 typedef void (*Error_HookFxn)(Error_Block *eb);
159 
160 /* @cond NODOC */
161 extern Error_Block Error_ignore;
162 
163 #define Error_UNWIND 0
164 #define Error_TERMINATE 1
165 #define Error_SPIN 2
166 /* @endcond */
167 
174 #define Error_E_memory "out of memory: heap=0x%x, size=%u"
175 
190 #define Error_E_generic "error %s"
191 
202 #define Error_IGNORE (&Error_ignore)
203 
213 #define Error_ABORT NULL
214 
226 extern bool Error_check(Error_Block *eb);
227 
235 extern void Error_init(Error_Block *eb);
236 
263 extern void Error_print(Error_Block *eb);
264 
265 /* @cond NODOC */
266 
267 extern void Error_raiseX(Error_Block *eb, int prefix, const char * id, intptr_t a0, intptr_t a1);
268 
269 #if Error_retainStrings_D
270 #define Error_PLACE_STR_IN_SECTION(name, str) static const char name[] = (str);
271 #else
272 #if defined(__IAR_SYSTEMS_ICC__)
273 #define Error_PLACE_STR_IN_SECTION(name, str) \
274  __root static const char name[] @ ".error_str" = str;
275 #elif defined(__TI_COMPILER_VERSION__) || (defined(__clang__) && defined(__ti_version__)) || defined(__GNUC__)
276 #define Error_PLACE_STR_IN_SECTION(name, str) \
277  static const char name[] __attribute__((used,section(".error_str"))) = str;
278 #else
279 #error Incompatible compiler: Error/Assert is currently supported by the following \
280 compilers: TI ARM Compiler, TI CLANG Compiler, GCC, IAR. Please migrate to a \
281 a supported compiler.
282 #endif
283 #endif
284 
285 #define Error_STR_NX(l) #l
286 #define Error_STR(l) Error_STR_NX(l)
287 
288 #if Error_addFileLine_D
289 #define Error_raise(eb, id, a0, a1) do { \
290  Error_PLACE_STR_IN_SECTION(err, id " (" __FILE__ ":" Error_STR(__LINE__) ")"); \
291  Error_raiseX((eb), 0, err, (intptr_t)(a0), (intptr_t)(a1)); } while (0);
292 #else
293 #define Error_raise(eb, id, a0, a1) do { \
294  Error_PLACE_STR_IN_SECTION(err, id); \
295  Error_raiseX((eb), 0, err, (intptr_t)(a0), (intptr_t)(a1)); } while (0);
296 #endif
297 
298 #define Error_assert(id, a0, a1) do { \
299  Error_PLACE_STR_IN_SECTION(err, id); \
300  Error_raiseX(NULL, 1, err, (intptr_t)(a0), (intptr_t)(a1)); } while (0);
301 
302 /* @endcond */
303 
304 #ifdef __cplusplus
305 }
306 #endif
307 
308 #endif /* ti_sysbios_runtime_Error__include */
309 
310 /* @cond NODOC */
311 #undef ti_sysbios_runtime_Error_long_names
312 #include "Error_defs.h"
313 /* @endcond */
bool Error_check(Error_Block *eb)
Return true if an error was raised.
void Error_init(Error_Block *eb)
Initialize an error block.
const char * id
Definition: Error.h:153
Error block.
Definition: Error.h:152
intptr_t a1
Definition: Error.h:155
void Error_print(Error_Block *eb)
Print error using System.printf()
void(* Error_HookFxn)(Error_Block *eb)
Definition: Error.h:158
intptr_t a0
Definition: Error.h:154
struct Error_Block Error_Block
Error block.
© Copyright 1995-2022, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale