xref: /nrf52832-nimble/nordic/nrfx/mdk/compiler_abstraction.h (revision 150812a83cab50279bd772ef6db1bfaf255f2c5b)
1 /*
2 
3 Copyright (c) 2010 - 2018, 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 #if defined ( __CC_ARM )
39 
40     #ifndef __ASM
41         #define __ASM               __asm
42     #endif
43 
44     #ifndef __INLINE
45         #define __INLINE            __inline
46     #endif
47 
48     #ifndef __WEAK
49         #define __WEAK              __weak
50     #endif
51 
52     #ifndef __ALIGN
53         #define __ALIGN(n)          __align(n)
54     #endif
55 
56     #ifndef __PACKED
57         #define __PACKED            __packed
58     #endif
59 
60     #define GET_SP()                __current_sp()
61 
62 #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
63 
64     #ifndef __ASM
65         #define __ASM               __asm
66     #endif
67 
68     #ifndef __INLINE
69         #define __INLINE            __inline
70     #endif
71 
72     #ifndef __WEAK
73         #define __WEAK              __attribute__((weak))
74     #endif
75 
76     #ifndef __ALIGN
77         #define __ALIGN(n)          __attribute__((aligned(n)))
78     #endif
79 
80     #ifndef __PACKED
81         #define __PACKED            __attribute__((packed, aligned(1)))
82     #endif
83 
84     #define GET_SP()                __current_sp()
85 
86 #elif defined ( __ICCARM__ )
87 
88     #ifndef __ASM
89         #define __ASM               __asm
90     #endif
91 
92     #ifndef __INLINE
93         #define __INLINE            inline
94     #endif
95 
96     #ifndef __WEAK
97         #define __WEAK              __weak
98     #endif
99 
100     #ifndef __ALIGN
101         #define STRING_PRAGMA(x) _Pragma(#x)
102         #define __ALIGN(n) STRING_PRAGMA(data_alignment = n)
103     #endif
104 
105     #ifndef __PACKED
106         #define __PACKED            __packed
107     #endif
108 
109     #define GET_SP()                __get_SP()
110 
111 #elif defined   ( __GNUC__ )
112 
113     #ifndef __ASM
114         #define __ASM               __asm
115     #endif
116 
117     #ifndef __INLINE
118         #define __INLINE            inline
119     #endif
120 
121     #ifndef __WEAK
122         #define __WEAK              __attribute__((weak))
123     #endif
124 
125     #ifndef __ALIGN
126         #define __ALIGN(n)          __attribute__((aligned(n)))
127     #endif
128 
129     #ifndef __PACKED
130         #define __PACKED           __attribute__((packed))
131     #endif
132 
133     #define GET_SP()                gcc_current_sp()
134 
gcc_current_sp(void)135     static inline unsigned int gcc_current_sp(void)
136     {
137         register unsigned sp __ASM("sp");
138         return sp;
139     }
140 
141 #elif defined   ( __TASKING__ )
142 
143     #ifndef __ASM
144         #define __ASM               __asm
145     #endif
146 
147     #ifndef __INLINE
148         #define __INLINE            inline
149     #endif
150 
151     #ifndef __WEAK
152         #define __WEAK              __attribute__((weak))
153     #endif
154 
155     #ifndef __ALIGN
156         #define __ALIGN(n)          __align(n)
157     #endif
158 
159     /* Not defined for TASKING. */
160     #ifndef __PACKED
161         #define __PACKED
162     #endif
163 
164     #define GET_SP()                __get_MSP()
165 
166 #endif
167 
168 /*lint --flb "Leave library region" */
169 
170 #endif
171