|
| 1 | +/* |
| 2 | +
|
| 3 | +Copyright (c) 2010 - 2021, 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 | + |
| 33 | +#ifndef _COMPILER_ABSTRACTION_H |
| 34 | +#define _COMPILER_ABSTRACTION_H |
| 35 | + |
| 36 | +/*lint ++flb "Enter library region" */ |
| 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 | + |
| 45 | +#if defined ( __CC_ARM ) |
| 46 | + |
| 47 | + #ifndef __ASM |
| 48 | + #define __ASM __asm |
| 49 | + #endif |
| 50 | + |
| 51 | + #ifndef __INLINE |
| 52 | + #define __INLINE __inline |
| 53 | + #endif |
| 54 | + |
| 55 | + #ifndef __WEAK |
| 56 | + #define __WEAK __weak |
| 57 | + #endif |
| 58 | + |
| 59 | + #ifndef __ALIGN |
| 60 | + #define __ALIGN(n) __align(n) |
| 61 | + #endif |
| 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 | + |
| 104 | + #define GET_SP() __current_sp() |
| 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 | + |
| 115 | +#elif defined ( __ICCARM__ ) |
| 116 | + |
| 117 | + #ifndef __ASM |
| 118 | + #define __ASM __asm |
| 119 | + #endif |
| 120 | + |
| 121 | + #ifndef __INLINE |
| 122 | + #define __INLINE inline |
| 123 | + #endif |
| 124 | + |
| 125 | + #ifndef __WEAK |
| 126 | + #define __WEAK __weak |
| 127 | + #endif |
| 128 | + |
| 129 | + #if (__VER__ >= 8000000) |
| 130 | + #ifndef __ALIGN |
| 131 | + #define __ALIGN(n) __attribute__((aligned(x))) |
| 132 | + #endif |
| 133 | + |
| 134 | + #ifndef __PACKED |
| 135 | + #define __PACKED __attribute__((packed, aligned(1))) |
| 136 | + #endif |
| 137 | + #else |
| 138 | + #ifndef __ALIGN |
| 139 | + #define STRING_PRAGMA(x) _Pragma(#x) |
| 140 | + #define __ALIGN(n) STRING_PRAGMA(data_alignment = n) |
| 141 | + #endif |
| 142 | + |
| 143 | + #ifndef __PACKED |
| 144 | + #define __PACKED __packed |
| 145 | + #endif |
| 146 | + #endif |
| 147 | + |
| 148 | + #ifndef __UNUSED |
| 149 | + #define __UNUSED |
| 150 | + #endif |
| 151 | + |
| 152 | + #define GET_SP() __get_SP() |
| 153 | + |
| 154 | + #ifndef NRF_STATIC_ASSERT |
| 155 | + #define NRF_STATIC_ASSERT(cond, msg) static_assert(cond, msg) |
| 156 | + #endif |
| 157 | + |
| 158 | +#elif defined ( __GNUC__ ) || defined ( __clang__ ) |
| 159 | + |
| 160 | + #ifndef __ASM |
| 161 | + #define __ASM __asm |
| 162 | + #endif |
| 163 | + |
| 164 | + #ifndef __INLINE |
| 165 | + #define __INLINE inline |
| 166 | + #endif |
| 167 | + |
| 168 | + #ifndef __WEAK |
| 169 | + #define __WEAK __attribute__((weak)) |
| 170 | + #endif |
| 171 | + |
| 172 | + #ifndef __ALIGN |
| 173 | + #define __ALIGN(n) __attribute__((aligned(n))) |
| 174 | + #endif |
| 175 | + |
| 176 | + #ifndef __PACKED |
| 177 | + #define __PACKED __attribute__((packed)) |
| 178 | + #endif |
| 179 | + |
| 180 | + #ifndef __UNUSED |
| 181 | + #define __UNUSED __attribute__((unused)) |
| 182 | + #endif |
| 183 | + |
| 184 | + #define GET_SP() gcc_current_sp() |
| 185 | + |
| 186 | + static inline unsigned int gcc_current_sp(void) |
| 187 | + { |
| 188 | + unsigned int stack_pointer = 0; |
| 189 | + __asm__ __volatile__ ("mov %0, sp" : "=r"(stack_pointer)); |
| 190 | + return stack_pointer; |
| 191 | + } |
| 192 | + |
| 193 | + #ifndef NRF_STATIC_ASSERT |
| 194 | + #ifdef __cplusplus |
| 195 | + #ifndef _Static_assert |
| 196 | + #define _Static_assert static_assert |
| 197 | + #endif |
| 198 | + #endif |
| 199 | + #define NRF_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg) |
| 200 | + #endif |
| 201 | + |
| 202 | +#elif defined ( __TASKING__ ) |
| 203 | + |
| 204 | + #ifndef __ASM |
| 205 | + #define __ASM __asm |
| 206 | + #endif |
| 207 | + |
| 208 | + #ifndef __INLINE |
| 209 | + #define __INLINE inline |
| 210 | + #endif |
| 211 | + |
| 212 | + #ifndef __WEAK |
| 213 | + #define __WEAK __attribute__((weak)) |
| 214 | + #endif |
| 215 | + |
| 216 | + #ifndef __ALIGN |
| 217 | + #define __ALIGN(n) __align(n) |
| 218 | + #endif |
| 219 | + |
| 220 | + /* Not defined for TASKING. */ |
| 221 | + #ifndef __PACKED |
| 222 | + #define __PACKED |
| 223 | + #endif |
| 224 | + |
| 225 | + #ifndef __UNUSED |
| 226 | + #define __UNUSED __attribute__((unused)) |
| 227 | + #endif |
| 228 | + |
| 229 | + #define GET_SP() __get_MSP() |
| 230 | + |
| 231 | + #ifndef NRF_STATIC_ASSERT |
| 232 | + #define NRF_STATIC_ASSERT(cond, msg) static_assert(cond, msg) |
| 233 | + #endif |
| 234 | + |
| 235 | +#endif |
| 236 | + |
| 237 | +#define NRF_MDK_VERSION_ASSERT_AT_LEAST(major, minor, micro) \ |
| 238 | + NRF_STATIC_ASSERT( \ |
| 239 | + ( \ |
| 240 | + (major < MDK_MAJOR_VERSION) || \ |
| 241 | + (major == MDK_MAJOR_VERSION && minor < MDK_MINOR_VERSION) || \ |
| 242 | + (major == MDK_MAJOR_VERSION && minor == MDK_MINOR_VERSION && micro < MDK_MICRO_VERSION) \ |
| 243 | + ), "MDK version mismatch.") |
| 244 | + |
| 245 | +#define NRF_MDK_VERSION_ASSERT_EXACT(major, minor, micro) \ |
| 246 | + NRF_STATIC_ASSERT( \ |
| 247 | + ( \ |
| 248 | + (major != MDK_MAJOR_VERSION) || \ |
| 249 | + (major != MDK_MAJOR_VERSION) || \ |
| 250 | + (major != MDK_MAJOR_VERSION) \ |
| 251 | + ), "MDK version mismatch.") |
| 252 | + |
| 253 | +/*lint --flb "Leave library region" */ |
| 254 | + |
| 255 | +#endif |
0 commit comments