1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup RTEMSScoreAssert |
---|
5 | * |
---|
6 | * @brief Information for the Assert Handler |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2013-2014 embedded brains GmbH. All rights reserved. |
---|
11 | * |
---|
12 | * embedded brains GmbH |
---|
13 | * Dornierstr. 4 |
---|
14 | * 82178 Puchheim |
---|
15 | * Germany |
---|
16 | * <rtems@embedded-brains.de> |
---|
17 | * |
---|
18 | * The license and distribution terms for this file may be |
---|
19 | * found in the file LICENSE in this distribution or at |
---|
20 | * http://www.rtems.org/license/LICENSE. |
---|
21 | */ |
---|
22 | |
---|
23 | #ifndef _RTEMS_SCORE_ASSERT_H |
---|
24 | #define _RTEMS_SCORE_ASSERT_H |
---|
25 | |
---|
26 | #include <rtems/score/basedefs.h> |
---|
27 | |
---|
28 | /** |
---|
29 | * @defgroup RTEMSScoreAssert Assert Handler |
---|
30 | * |
---|
31 | * @ingroup RTEMSScore |
---|
32 | * |
---|
33 | * @brief Support for Assert Statements |
---|
34 | * |
---|
35 | * @{ |
---|
36 | */ |
---|
37 | |
---|
38 | #if defined( RTEMS_DEBUG ) |
---|
39 | #include <assert.h> |
---|
40 | #endif |
---|
41 | |
---|
42 | #ifdef __cplusplus |
---|
43 | extern "C" { |
---|
44 | #endif /* __cplusplus */ |
---|
45 | |
---|
46 | /** |
---|
47 | * @brief Assertion similar to assert() controlled via RTEMS_DEBUG instead of |
---|
48 | * NDEBUG. |
---|
49 | */ |
---|
50 | #if defined( RTEMS_DEBUG ) |
---|
51 | |
---|
52 | /** |
---|
53 | * @brief Macro with method name used in assert output |
---|
54 | * |
---|
55 | * Given the variations in compilers and standards, we have to poke a bit. |
---|
56 | * |
---|
57 | * @note This is based on the code in newlib's assert.h. |
---|
58 | */ |
---|
59 | #ifndef __RTEMS_ASSERT_FUNCTION |
---|
60 | /* Use g++'s demangled names in C++. */ |
---|
61 | #if defined __cplusplus && defined __GNUC__ |
---|
62 | #define __RTEMS_ASSERT_FUNCTION __PRETTY_FUNCTION__ |
---|
63 | |
---|
64 | /* C99 requires the use of __func__. */ |
---|
65 | #elif __STDC_VERSION__ >= 199901L |
---|
66 | #define __RTEMS_ASSERT_FUNCTION __func__ |
---|
67 | |
---|
68 | /* Older versions of gcc don't have __func__ but can use __FUNCTION__. */ |
---|
69 | #elif __GNUC__ >= 2 |
---|
70 | #define __RTEMS_ASSERT_FUNCTION __FUNCTION__ |
---|
71 | |
---|
72 | /* failed to detect __func__ support. */ |
---|
73 | #else |
---|
74 | #define __RTEMS_ASSERT_FUNCTION ((char *) 0) |
---|
75 | #endif |
---|
76 | #endif /* !__RTEMS_ASSERT_FUNCTION */ |
---|
77 | |
---|
78 | #if !defined( RTEMS_SCHEDSIM ) |
---|
79 | /* normal build is newlib. */ |
---|
80 | |
---|
81 | #define _Assert( _e ) \ |
---|
82 | ( ( _e ) ? \ |
---|
83 | ( void ) 0 : \ |
---|
84 | __assert_func( __FILE__, __LINE__, __RTEMS_ASSERT_FUNCTION, #_e ) ) |
---|
85 | |
---|
86 | #elif defined(__linux__) |
---|
87 | /* Scheduler simulator has only beed tested on glibc. */ |
---|
88 | #define _Assert( _e ) \ |
---|
89 | ( ( _e ) ? \ |
---|
90 | ( void ) 0 : \ |
---|
91 | __assert_fail( #_e, __FILE__, __LINE__, __RTEMS_ASSERT_FUNCTION ) ) |
---|
92 | #else |
---|
93 | #error "Implement RTEMS assert support for this C Library" |
---|
94 | #endif |
---|
95 | |
---|
96 | #else |
---|
97 | #define _Assert( _e ) ( ( void ) 0 ) |
---|
98 | #endif |
---|
99 | |
---|
100 | /** |
---|
101 | * @brief Like _Assert(), but only armed if RTEMS_SMP is defined. |
---|
102 | */ |
---|
103 | #if defined( RTEMS_SMP ) |
---|
104 | #define _SMP_Assert( _e ) _Assert( _e ) |
---|
105 | #else |
---|
106 | #define _SMP_Assert( _e ) ( ( void ) 0 ) |
---|
107 | #endif |
---|
108 | |
---|
109 | /** |
---|
110 | * @brief Returns true if thread dispatching is allowed. |
---|
111 | * |
---|
112 | * Thread dispatching can be repressed via _Thread_Disable_dispatch() or |
---|
113 | * _ISR_Local_disable(). |
---|
114 | */ |
---|
115 | #if defined( RTEMS_DEBUG ) |
---|
116 | bool _Debug_Is_thread_dispatching_allowed( void ); |
---|
117 | #endif |
---|
118 | |
---|
119 | #ifdef __cplusplus |
---|
120 | } |
---|
121 | #endif /* __cplusplus */ |
---|
122 | |
---|
123 | /** @} */ |
---|
124 | |
---|
125 | #endif /* _RTEMS_SCORE_ASSERT_H */ |
---|