NMSIS-Core  Version 1.0.0-HummingBird
NMSIS-Core support for HummingBird RISC-V processor-based devices
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
nmsis_gcc.h
1 /*
2  * Copyright (c) 2019 Nuclei Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the License); you may
7  * not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef __NMSIS_GCC_H__
20 #define __NMSIS_GCC_H__
21 
25 #include <stdint.h>
26 #include "riscv_encoding.h"
27 
28 #ifdef __cplusplus
29  extern "C" {
30 #endif
31 
32 /* ######################### Startup and Lowlevel Init ######################## */
45 /* ignore some GCC warnings */
46 #pragma GCC diagnostic push
47 #pragma GCC diagnostic ignored "-Wsign-conversion"
48 #pragma GCC diagnostic ignored "-Wconversion"
49 #pragma GCC diagnostic ignored "-Wunused-parameter"
50 
51 /* Fallback for __has_builtin */
52 #ifndef __has_builtin
53  #define __has_builtin(x) (0)
54 #endif
55 
56 /* NMSIS compiler specific defines */
58 #ifndef __ASM
59  #define __ASM __asm
60 #endif
61 
63 #ifndef __INLINE
64  #define __INLINE inline
65 #endif
66 
68 #ifndef __STATIC_INLINE
69  #define __STATIC_INLINE static inline
70 #endif
71 
73 #ifndef __STATIC_FORCEINLINE
74  #define __STATIC_FORCEINLINE __attribute__((always_inline)) static inline
75 #endif
76 
78 #ifndef __NO_RETURN
79  #define __NO_RETURN __attribute__((__noreturn__))
80 #endif
81 
83 #ifndef __USED
84  #define __USED __attribute__((used))
85 #endif
86 
88 #ifndef __WEAK
89  #define __WEAK __attribute__((weak))
90 #endif
91 
93 #ifndef __VECTOR_SIZE
94  #define __VECTOR_SIZE(x) __attribute__((vector_size(x)))
95 #endif
96 
98 #ifndef __PACKED
99  #define __PACKED __attribute__((packed, aligned(1)))
100 #endif
101 
103 #ifndef __PACKED_STRUCT
104  #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
105 #endif
106 
108 #ifndef __PACKED_UNION
109  #define __PACKED_UNION union __attribute__((packed, aligned(1)))
110 #endif
111 
112 #ifndef __UNALIGNED_UINT16_WRITE
113  #pragma GCC diagnostic push
114  #pragma GCC diagnostic ignored "-Wpacked"
115  #pragma GCC diagnostic ignored "-Wattributes"
116 
118  uint16_t v;
119  };
120  #pragma GCC diagnostic pop
121 
122  #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
123 #endif
124 
125 #ifndef __UNALIGNED_UINT16_READ
126  #pragma GCC diagnostic push
127  #pragma GCC diagnostic ignored "-Wpacked"
128  #pragma GCC diagnostic ignored "-Wattributes"
129 
131  uint16_t v;
132  };
133  #pragma GCC diagnostic pop
134 
135  #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
136 #endif
137 
138 #ifndef __UNALIGNED_UINT32_WRITE
139  #pragma GCC diagnostic push
140  #pragma GCC diagnostic ignored "-Wpacked"
141  #pragma GCC diagnostic ignored "-Wattributes"
142 
144  uint32_t v;
145  };
146  #pragma GCC diagnostic pop
147 
148  #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
149 #endif
150 
151 #ifndef __UNALIGNED_UINT32_READ
152  #pragma GCC diagnostic push
153  #pragma GCC diagnostic ignored "-Wpacked"
154  #pragma GCC diagnostic ignored "-Wattributes"
155 
157  uint32_t v;
158  };
159  #pragma GCC diagnostic pop
160 
161  #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
162 #endif
163 
165 #ifndef __ALIGNED
166  #define __ALIGNED(x) __attribute__((aligned(x)))
167 #endif
168 
170 #ifndef __RESTRICT
171  #define __RESTRICT __restrict
172 #endif
173 
175 #ifndef __COMPILER_BARRIER
176  #define __COMPILER_BARRIER() __ASM volatile("":::"memory")
177 #endif
178 
180 #ifndef __USUALLY
181  #define __USUALLY(exp) __builtin_expect((exp), 1)
182 #endif
183 
185 #ifndef __RARELY
186  #define __RARELY(exp) __builtin_expect((exp), 0)
187 #endif
188 
190 #ifndef __INTERRUPT
191  #define __INTERRUPT
192 #endif
193  /* End of Doxygen Group NMSIS_Core_CompilerControl */
195 
196 /* IO definitions (access restrictions to peripheral registers) */
211 #ifdef __cplusplus
212  #define __I volatile
213 #else
214  #define __I volatile const
215 #endif
216 
217 #define __O volatile
218 
219 #define __IO volatile
220 
221 /* following defines should be used for structure members */
223 #define __IM volatile const
224 
225 #define __OM volatile
226 
227 #define __IOM volatile
228 
242 #define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk)
243 
257 #define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos)
258  /* end of group NMSIS_Core_PeriphAccess */
260 
261 
262 #ifdef __cplusplus
263 }
264 #endif
265 #endif /* __NMSIS_GCC_H__ */
__PACKED_STRUCT
#define __PACKED_STRUCT
Request smallest possible alignment for a structure.
Definition: nmsis_gcc.h:104
T_UINT32_WRITE
__PACKED_STRUCT T_UINT32_WRITE
Packed struct for unaligned uint32_t write access.
Definition: nmsis_gcc.h:143
T_UINT32_READ
__PACKED_STRUCT T_UINT32_READ
Packed struct for unaligned uint32_t read access.
Definition: nmsis_gcc.h:156
T_UINT16_WRITE
__PACKED_STRUCT T_UINT16_WRITE
Packed struct for unaligned uint16_t write access.
Definition: nmsis_gcc.h:117
T_UINT16_READ
__PACKED_STRUCT T_UINT16_READ
Packed struct for unaligned uint16_t read access.
Definition: nmsis_gcc.h:130