|
1 |
| -/* Copyright (c) 2015, Nordic Semiconductor ASA |
2 |
| - * All rights reserved. |
3 |
| - * |
4 |
| - * Redistribution and use in source and binary forms, with or without |
5 |
| - * modification, are permitted provided that the following conditions are met: |
6 |
| - * |
7 |
| - * * Redistributions of source code must retain the above copyright notice, this |
8 |
| - * list of conditions and the following disclaimer. |
9 |
| - * |
10 |
| - * * Redistributions in binary form must reproduce the above copyright notice, |
11 |
| - * this list of conditions and the following disclaimer in the documentation |
12 |
| - * and/or other materials provided with the distribution. |
13 |
| - * |
14 |
| - * * Neither the name of Nordic Semiconductor ASA nor the names of its |
15 |
| - * contributors may be used to endorse or promote products derived from |
16 |
| - * this software without specific prior written permission. |
17 |
| - * |
18 |
| - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 |
| - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 |
| - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
21 |
| - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
22 |
| - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
23 |
| - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
24 |
| - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
25 |
| - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
26 |
| - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 |
| - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 |
| - * |
29 |
| - */ |
| 1 | +/* |
| 2 | +
|
| 3 | +Copyright (c) 2010 - 2020, Nordic Semiconductor ASA 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 are met: |
| 7 | +
|
| 8 | +1. Redistributions of source code must retain the above copyright notice, this |
| 9 | + list of conditions and the following disclaimer. |
| 10 | +
|
| 11 | +2. Redistributions in binary form must reproduce the above copyright |
| 12 | + notice, this list of conditions and the following disclaimer in the |
| 13 | + documentation and/or other materials provided with the distribution. |
| 14 | +
|
| 15 | +3. Neither the name of Nordic Semiconductor ASA nor the names of its |
| 16 | + contributors may be used to endorse or promote products derived from this |
| 17 | + software without specific prior written permission. |
| 18 | +
|
| 19 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 | +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | +IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 | +ARE DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE |
| 23 | +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 | +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 | +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 | +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 | +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 | +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 | +POSSIBILITY OF SUCH DAMAGE. |
| 30 | +
|
| 31 | +*/ |
| 32 | + |
30 | 33 | #ifndef _COMPILER_ABSTRACTION_H
|
31 | 34 | #define _COMPILER_ABSTRACTION_H
|
32 | 35 |
|
33 | 36 | /*lint ++flb "Enter library region" */
|
34 | 37 |
|
| 38 | +#ifndef NRF_STRING_CONCATENATE_IMPL |
| 39 | + #define NRF_STRING_CONCATENATE_IMPL(lhs, rhs) lhs ## rhs |
| 40 | +#endif |
| 41 | +#ifndef NRF_STRING_CONCATENATE |
| 42 | + #define NRF_STRING_CONCATENATE(lhs, rhs) NRF_STRING_CONCATENATE_IMPL(lhs, rhs) |
| 43 | +#endif |
| 44 | + |
35 | 45 | #if defined ( __CC_ARM )
|
36 | 46 |
|
37 | 47 | #ifndef __ASM
|
|
50 | 60 | #define __ALIGN(n) __align(n)
|
51 | 61 | #endif
|
52 | 62 |
|
| 63 | + #ifndef __PACKED |
| 64 | + #define __PACKED __packed |
| 65 | + #endif |
| 66 | + |
| 67 | + #ifndef __UNUSED |
| 68 | + #define __UNUSED __attribute__((unused)) |
| 69 | + #endif |
| 70 | + |
| 71 | + #define GET_SP() __current_sp() |
| 72 | + |
| 73 | + #ifndef NRF_STATIC_ASSERT |
| 74 | + #define NRF_STATIC_ASSERT(cond, msg) \ |
| 75 | + ;enum { NRF_STRING_CONCATENATE(static_assert_on_line_, __LINE__) = 1 / (!!(cond)) } |
| 76 | + #endif |
| 77 | + |
| 78 | +#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) |
| 79 | + |
| 80 | + #ifndef __ASM |
| 81 | + #define __ASM __asm |
| 82 | + #endif |
| 83 | + |
| 84 | + #ifndef __INLINE |
| 85 | + #define __INLINE __inline |
| 86 | + #endif |
| 87 | + |
| 88 | + #ifndef __WEAK |
| 89 | + #define __WEAK __attribute__((weak)) |
| 90 | + #endif |
| 91 | + |
| 92 | + #ifndef __ALIGN |
| 93 | + #define __ALIGN(n) __attribute__((aligned(n))) |
| 94 | + #endif |
| 95 | + |
| 96 | + #ifndef __PACKED |
| 97 | + #define __PACKED __attribute__((packed, aligned(1))) |
| 98 | + #endif |
| 99 | + |
| 100 | + #ifndef __UNUSED |
| 101 | + #define __UNUSED __attribute__((unused)) |
| 102 | + #endif |
| 103 | + |
53 | 104 | #define GET_SP() __current_sp()
|
54 | 105 |
|
| 106 | + #ifndef NRF_STATIC_ASSERT |
| 107 | + #ifdef __cplusplus |
| 108 | + #ifndef _Static_assert |
| 109 | + #define _Static_assert static_assert |
| 110 | + #endif |
| 111 | + #endif |
| 112 | + #define NRF_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg) |
| 113 | + #endif |
| 114 | + |
55 | 115 | #elif defined ( __ICCARM__ )
|
56 | 116 |
|
57 | 117 | #ifndef __ASM
|
|
66 | 126 | #define __WEAK __weak
|
67 | 127 | #endif
|
68 | 128 |
|
69 |
| - /* Not defined for IAR since it requires a new line to work, and C preprocessor does not allow that. */ |
70 | 129 | #ifndef __ALIGN
|
71 |
| - #define __ALIGN(n) |
| 130 | + #define STRING_PRAGMA(x) _Pragma(#x) |
| 131 | + #define __ALIGN(n) STRING_PRAGMA(data_alignment = n) |
72 | 132 | #endif
|
73 | 133 |
|
| 134 | + #ifndef __PACKED |
| 135 | + #define __PACKED __packed |
| 136 | + #endif |
| 137 | + |
| 138 | + #ifndef __UNUSED |
| 139 | + #define __UNUSED |
| 140 | + #endif |
| 141 | + |
74 | 142 | #define GET_SP() __get_SP()
|
75 | 143 |
|
76 |
| -#elif defined ( __GNUC__ ) |
| 144 | + #ifndef NRF_STATIC_ASSERT |
| 145 | + #define NRF_STATIC_ASSERT(cond, msg) static_assert(cond, msg) |
| 146 | + #endif |
| 147 | + |
| 148 | +#elif defined ( __GNUC__ ) || defined ( __clang__ ) |
77 | 149 |
|
78 | 150 | #ifndef __ASM
|
79 | 151 | #define __ASM __asm
|
|
91 | 163 | #define __ALIGN(n) __attribute__((aligned(n)))
|
92 | 164 | #endif
|
93 | 165 |
|
| 166 | + #ifndef __PACKED |
| 167 | + #define __PACKED __attribute__((packed)) |
| 168 | + #endif |
| 169 | + |
| 170 | + #ifndef __UNUSED |
| 171 | + #define __UNUSED __attribute__((unused)) |
| 172 | + #endif |
| 173 | + |
94 | 174 | #define GET_SP() gcc_current_sp()
|
95 | 175 |
|
96 | 176 | static inline unsigned int gcc_current_sp(void)
|
97 | 177 | {
|
98 |
| - register unsigned sp __ASM("sp"); |
99 |
| - return sp; |
| 178 | + unsigned int stack_pointer = 0; |
| 179 | + __asm__ __volatile__ ("mov %0, sp" : "=r"(stack_pointer)); |
| 180 | + return stack_pointer; |
100 | 181 | }
|
101 | 182 |
|
| 183 | + #ifndef NRF_STATIC_ASSERT |
| 184 | + #ifdef __cplusplus |
| 185 | + #ifndef _Static_assert |
| 186 | + #define _Static_assert static_assert |
| 187 | + #endif |
| 188 | + #endif |
| 189 | + #define NRF_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg) |
| 190 | + #endif |
| 191 | + |
102 | 192 | #elif defined ( __TASKING__ )
|
103 | 193 |
|
104 | 194 | #ifndef __ASM
|
|
116 | 206 | #ifndef __ALIGN
|
117 | 207 | #define __ALIGN(n) __align(n)
|
118 | 208 | #endif
|
| 209 | + |
| 210 | + /* Not defined for TASKING. */ |
| 211 | + #ifndef __PACKED |
| 212 | + #define __PACKED |
| 213 | + #endif |
| 214 | + |
| 215 | + #ifndef __UNUSED |
| 216 | + #define __UNUSED __attribute__((unused)) |
| 217 | + #endif |
119 | 218 |
|
120 | 219 | #define GET_SP() __get_MSP()
|
121 | 220 |
|
| 221 | + #ifndef NRF_STATIC_ASSERT |
| 222 | + #define NRF_STATIC_ASSERT(cond, msg) static_assert(cond, msg) |
| 223 | + #endif |
| 224 | + |
122 | 225 | #endif
|
123 | 226 |
|
| 227 | +#define NRF_MDK_VERSION_ASSERT_AT_LEAST(major, minor, micro) \ |
| 228 | + NRF_STATIC_ASSERT( \ |
| 229 | + ( \ |
| 230 | + (major < MDK_MAJOR_VERSION) || \ |
| 231 | + (major == MDK_MAJOR_VERSION && minor < MDK_MINOR_VERSION) || \ |
| 232 | + (major == MDK_MAJOR_VERSION && minor == MDK_MINOR_VERSION && micro < MDK_MICRO_VERSION) \ |
| 233 | + ), "MDK version mismatch.") |
| 234 | + |
| 235 | +#define NRF_MDK_VERSION_ASSERT_EXACT(major, minor, micro) \ |
| 236 | + NRF_STATIC_ASSERT( \ |
| 237 | + ( \ |
<
5AE5
code> | 238 | + (major != MDK_MAJOR_VERSION) || \ |
| 239 | + (major != MDK_MAJOR_VERSION) || \ |
| 240 | + (major != MDK_MAJOR_VERSION) \ |
| 241 | + ), "MDK version mismatch.") |
| 242 | + |
124 | 243 | /*lint --flb "Leave library region" */
|
125 | 244 |
|
126 | 245 | #endif
|
0 commit comments