]> begriffs open source - cmsis/blob - CMSIS/Core/Include/cmsis_armclang.h
Core(M): Introduced provisions for compiler-independent C startup code.
[cmsis] / CMSIS / Core / Include / cmsis_armclang.h
1 /**************************************************************************//**
2  * @file     cmsis_armclang.h
3  * @brief    CMSIS compiler armclang (Arm Compiler 6) header file
4  * @version  V5.1.0
5  * @date     14. March 2019
6  ******************************************************************************/
7 /*
8  * Copyright (c) 2009-2019 Arm Limited. All rights reserved.
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  *
12  * Licensed under the Apache License, Version 2.0 (the License); you may
13  * not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  * www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  */
24
25 /*lint -esym(9058, IRQn)*/ /* disable MISRA 2012 Rule 2.4 for IRQn */
26
27 #ifndef __CMSIS_ARMCLANG_H
28 #define __CMSIS_ARMCLANG_H
29
30 #pragma clang system_header   /* treat file as system include file */
31
32 #ifndef __ARM_COMPAT_H
33 #include <arm_compat.h>    /* Compatibility header for Arm Compiler 5 intrinsics */
34 #endif
35
36 /* CMSIS compiler specific defines */
37 #ifndef   __ASM
38   #define __ASM                                  __asm
39 #endif
40 #ifndef   __INLINE
41   #define __INLINE                               __inline
42 #endif
43 #ifndef   __STATIC_INLINE
44   #define __STATIC_INLINE                        static __inline
45 #endif
46 #ifndef   __STATIC_FORCEINLINE
47   #define __STATIC_FORCEINLINE                   __attribute__((always_inline)) static __inline
48 #endif
49 #ifndef   __NO_RETURN
50   #define __NO_RETURN                            __attribute__((__noreturn__))
51 #endif
52 #ifndef   __USED
53   #define __USED                                 __attribute__((used))
54 #endif
55 #ifndef   __WEAK
56   #define __WEAK                                 __attribute__((weak))
57 #endif
58 #ifndef   __PACKED
59   #define __PACKED                               __attribute__((packed, aligned(1)))
60 #endif
61 #ifndef   __PACKED_STRUCT
62   #define __PACKED_STRUCT                        struct __attribute__((packed, aligned(1)))
63 #endif
64 #ifndef   __PACKED_UNION
65   #define __PACKED_UNION                         union __attribute__((packed, aligned(1)))
66 #endif
67 #ifndef   __UNALIGNED_UINT32        /* deprecated */
68   #pragma clang diagnostic push
69   #pragma clang diagnostic ignored "-Wpacked"
70 /*lint -esym(9058, T_UINT32)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32 */
71   struct __attribute__((packed)) T_UINT32 { uint32_t v; };
72   #pragma clang diagnostic pop
73   #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
74 #endif
75 #ifndef   __UNALIGNED_UINT16_WRITE
76   #pragma clang diagnostic push
77   #pragma clang diagnostic ignored "-Wpacked"
78 /*lint -esym(9058, T_UINT16_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_WRITE */
79   __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
80   #pragma clang diagnostic pop
81   #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
82 #endif
83 #ifndef   __UNALIGNED_UINT16_READ
84   #pragma clang diagnostic push
85   #pragma clang diagnostic ignored "-Wpacked"
86 /*lint -esym(9058, T_UINT16_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_READ */
87   __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
88   #pragma clang diagnostic pop
89   #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
90 #endif
91 #ifndef   __UNALIGNED_UINT32_WRITE
92   #pragma clang diagnostic push
93   #pragma clang diagnostic ignored "-Wpacked"
94 /*lint -esym(9058, T_UINT32_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_WRITE */
95   __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
96   #pragma clang diagnostic pop
97   #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
98 #endif
99 #ifndef   __UNALIGNED_UINT32_READ
100   #pragma clang diagnostic push
101   #pragma clang diagnostic ignored "-Wpacked"
102 /*lint -esym(9058, T_UINT32_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_READ */
103   __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
104   #pragma clang diagnostic pop
105   #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
106 #endif
107 #ifndef   __ALIGNED
108   #define __ALIGNED(x)                           __attribute__((aligned(x)))
109 #endif
110 #ifndef   __RESTRICT
111   #define __RESTRICT                             __restrict
112 #endif
113
114 /* #########################  Startup and Lowlevel Init  ######################## */
115
116 extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Limit;
117 extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Base;
118
119 #define __PROGRAM_START   __main
120 #define __INITIAL_SP      Image$$ARM_LIB_STACK$$ZI$$Limit
121 #define __STACK_LIMIT     Image$$ARM_LIB_STACK$$ZI$$Base
122 #define __VECTOR_ATTR     __attribute((section("RESET")))
123
124 /* ###########################  Core Function Access  ########################### */
125 /** \ingroup  CMSIS_Core_FunctionInterface
126     \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
127   @{
128  */
129
130 /**
131   \brief   Enable IRQ Interrupts
132   \details Enables IRQ interrupts by clearing the I-bit in the CPSR.
133            Can only be executed in Privileged modes.
134  */
135 /* intrinsic void __enable_irq();  see arm_compat.h */
136
137
138 /**
139   \brief   Disable IRQ Interrupts
140   \details Disables IRQ interrupts by setting the I-bit in the CPSR.
141            Can only be executed in Privileged modes.
142  */
143 /* intrinsic void __disable_irq();  see arm_compat.h */
144
145
146 /**
147   \brief   Get Control Register
148   \details Returns the content of the Control Register.
149   \return               Control Register value
150  */
151 __STATIC_FORCEINLINE uint32_t __get_CONTROL(void)
152 {
153   uint32_t result;
154
155   __ASM volatile ("MRS %0, control" : "=r" (result) );
156   return(result);
157 }
158
159
160 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
161 /**
162   \brief   Get Control Register (non-secure)
163   \details Returns the content of the non-secure Control Register when in secure mode.
164   \return               non-secure Control Register value
165  */
166 __STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void)
167 {
168   uint32_t result;
169
170   __ASM volatile ("MRS %0, control_ns" : "=r" (result) );
171   return(result);
172 }
173 #endif
174
175
176 /**
177   \brief   Set Control Register
178   \details Writes the given value to the Control Register.
179   \param [in]    control  Control Register value to set
180  */
181 __STATIC_FORCEINLINE void __set_CONTROL(uint32_t control)
182 {
183   __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
184 }
185
186
187 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
188 /**
189   \brief   Set Control Register (non-secure)
190   \details Writes the given value to the non-secure Control Register when in secure state.
191   \param [in]    control  Control Register value to set
192  */
193 __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
194 {
195   __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory");
196 }
197 #endif
198
199
200 /**
201   \brief   Get IPSR Register
202   \details Returns the content of the IPSR Register.
203   \return               IPSR Register value
204  */
205 __STATIC_FORCEINLINE uint32_t __get_IPSR(void)
206 {
207   uint32_t result;
208
209   __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
210   return(result);
211 }
212
213
214 /**
215   \brief   Get APSR Register
216   \details Returns the content of the APSR Register.
217   \return               APSR Register value
218  */
219 __STATIC_FORCEINLINE uint32_t __get_APSR(void)
220 {
221   uint32_t result;
222
223   __ASM volatile ("MRS %0, apsr" : "=r" (result) );
224   return(result);
225 }
226
227
228 /**
229   \brief   Get xPSR Register
230   \details Returns the content of the xPSR Register.
231   \return               xPSR Register value
232  */
233 __STATIC_FORCEINLINE uint32_t __get_xPSR(void)
234 {
235   uint32_t result;
236
237   __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
238   return(result);
239 }
240
241
242 /**
243   \brief   Get Process Stack Pointer
244   \details Returns the current value of the Process Stack Pointer (PSP).
245   \return               PSP Register value
246  */
247 __STATIC_FORCEINLINE uint32_t __get_PSP(void)
248 {
249   uint32_t result;
250
251   __ASM volatile ("MRS %0, psp"  : "=r" (result) );
252   return(result);
253 }
254
255
256 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
257 /**
258   \brief   Get Process Stack Pointer (non-secure)
259   \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.
260   \return               PSP Register value
261  */
262 __STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void)
263 {
264   uint32_t result;
265
266   __ASM volatile ("MRS %0, psp_ns"  : "=r" (result) );
267   return(result);
268 }
269 #endif
270
271
272 /**
273   \brief   Set Process Stack Pointer
274   \details Assigns the given value to the Process Stack Pointer (PSP).
275   \param [in]    topOfProcStack  Process Stack Pointer value to set
276  */
277 __STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack)
278 {
279   __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : );
280 }
281
282
283 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
284 /**
285   \brief   Set Process Stack Pointer (non-secure)
286   \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.
287   \param [in]    topOfProcStack  Process Stack Pointer value to set
288  */
289 __STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack)
290 {
291   __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : );
292 }
293 #endif
294
295
296 /**
297   \brief   Get Main Stack Pointer
298   \details Returns the current value of the Main Stack Pointer (MSP).
299   \return               MSP Register value
300  */
301 __STATIC_FORCEINLINE uint32_t __get_MSP(void)
302 {
303   uint32_t result;
304
305   __ASM volatile ("MRS %0, msp" : "=r" (result) );
306   return(result);
307 }
308
309
310 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
311 /**
312   \brief   Get Main Stack Pointer (non-secure)
313   \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.
314   \return               MSP Register value
315  */
316 __STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void)
317 {
318   uint32_t result;
319
320   __ASM volatile ("MRS %0, msp_ns" : "=r" (result) );
321   return(result);
322 }
323 #endif
324
325
326 /**
327   \brief   Set Main Stack Pointer
328   \details Assigns the given value to the Main Stack Pointer (MSP).
329   \param [in]    topOfMainStack  Main Stack Pointer value to set
330  */
331 __STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack)
332 {
333   __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : );
334 }
335
336
337 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
338 /**
339   \brief   Set Main Stack Pointer (non-secure)
340   \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.
341   \param [in]    topOfMainStack  Main Stack Pointer value to set
342  */
343 __STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack)
344 {
345   __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : );
346 }
347 #endif
348
349
350 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
351 /**
352   \brief   Get Stack Pointer (non-secure)
353   \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state.
354   \return               SP Register value
355  */
356 __STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void)
357 {
358   uint32_t result;
359
360   __ASM volatile ("MRS %0, sp_ns" : "=r" (result) );
361   return(result);
362 }
363
364
365 /**
366   \brief   Set Stack Pointer (non-secure)
367   \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state.
368   \param [in]    topOfStack  Stack Pointer value to set
369  */
370 __STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack)
371 {
372   __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : );
373 }
374 #endif
375
376
377 /**
378   \brief   Get Priority Mask
379   \details Returns the current state of the priority mask bit from the Priority Mask Register.
380   \return               Priority Mask value
381  */
382 __STATIC_FORCEINLINE uint32_t __get_PRIMASK(void)
383 {
384   uint32_t result;
385
386   __ASM volatile ("MRS %0, primask" : "=r" (result) );
387   return(result);
388 }
389
390
391 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
392 /**
393   \brief   Get Priority Mask (non-secure)
394   \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.
395   \return               Priority Mask value
396  */
397 __STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void)
398 {
399   uint32_t result;
400
401   __ASM volatile ("MRS %0, primask_ns" : "=r" (result) );
402   return(result);
403 }
404 #endif
405
406
407 /**
408   \brief   Set Priority Mask
409   \details Assigns the given value to the Priority Mask Register.
410   \param [in]    priMask  Priority Mask
411  */
412 __STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask)
413 {
414   __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
415 }
416
417
418 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
419 /**
420   \brief   Set Priority Mask (non-secure)
421   \details Assigns the given value to the non-secure Priority Mask Register when in secure state.
422   \param [in]    priMask  Priority Mask
423  */
424 __STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask)
425 {
426   __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory");
427 }
428 #endif
429
430
431 #if ((defined (__ARM_ARCH_7M__      ) && (__ARM_ARCH_7M__      == 1)) || \
432      (defined (__ARM_ARCH_7EM__     ) && (__ARM_ARCH_7EM__     == 1)) || \
433      (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))    )
434 /**
435   \brief   Enable FIQ
436   \details Enables FIQ interrupts by clearing the F-bit in the CPSR.
437            Can only be executed in Privileged modes.
438  */
439 #define __enable_fault_irq                __enable_fiq   /* see arm_compat.h */
440
441
442 /**
443   \brief   Disable FIQ
444   \details Disables FIQ interrupts by setting the F-bit in the CPSR.
445            Can only be executed in Privileged modes.
446  */
447 #define __disable_fault_irq               __disable_fiq   /* see arm_compat.h */
448
449
450 /**
451   \brief   Get Base Priority
452   \details Returns the current value of the Base Priority register.
453   \return               Base Priority register value
454  */
455 __STATIC_FORCEINLINE uint32_t __get_BASEPRI(void)
456 {
457   uint32_t result;
458
459   __ASM volatile ("MRS %0, basepri" : "=r" (result) );
460   return(result);
461 }
462
463
464 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
465 /**
466   \brief   Get Base Priority (non-secure)
467   \details Returns the current value of the non-secure Base Priority register when in secure state.
468   \return               Base Priority register value
469  */
470 __STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void)
471 {
472   uint32_t result;
473
474   __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) );
475   return(result);
476 }
477 #endif
478
479
480 /**
481   \brief   Set Base Priority
482   \details Assigns the given value to the Base Priority register.
483   \param [in]    basePri  Base Priority value to set
484  */
485 __STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri)
486 {
487   __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory");
488 }
489
490
491 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
492 /**
493   \brief   Set Base Priority (non-secure)
494   \details Assigns the given value to the non-secure Base Priority register when in secure state.
495   \param [in]    basePri  Base Priority value to set
496  */
497 __STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri)
498 {
499   __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory");
500 }
501 #endif
502
503
504 /**
505   \brief   Set Base Priority with condition
506   \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
507            or the new value increases the BASEPRI priority level.
508   \param [in]    basePri  Base Priority value to set
509  */
510 __STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri)
511 {
512   __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory");
513 }
514
515
516 /**
517   \brief   Get Fault Mask
518   \details Returns the current value of the Fault Mask register.
519   \return               Fault Mask register value
520  */
521 __STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void)
522 {
523   uint32_t result;
524
525   __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
526   return(result);
527 }
528
529
530 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
531 /**
532   \brief   Get Fault Mask (non-secure)
533   \details Returns the current value of the non-secure Fault Mask register when in secure state.
534   \return               Fault Mask register value
535  */
536 __STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void)
537 {
538   uint32_t result;
539
540   __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) );
541   return(result);
542 }
543 #endif
544
545
546 /**
547   \brief   Set Fault Mask
548   \details Assigns the given value to the Fault Mask register.
549   \param [in]    faultMask  Fault Mask value to set
550  */
551 __STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask)
552 {
553   __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
554 }
555
556
557 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
558 /**
559   \brief   Set Fault Mask (non-secure)
560   \details Assigns the given value to the non-secure Fault Mask register when in secure state.
561   \param [in]    faultMask  Fault Mask value to set
562  */
563 __STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask)
564 {
565   __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory");
566 }
567 #endif
568
569 #endif /* ((defined (__ARM_ARCH_7M__      ) && (__ARM_ARCH_7M__      == 1)) || \
570            (defined (__ARM_ARCH_7EM__     ) && (__ARM_ARCH_7EM__     == 1)) || \
571            (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))    ) */
572
573
574 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
575      (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    )
576
577 /**
578   \brief   Get Process Stack Pointer Limit
579   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
580   Stack Pointer Limit register hence zero is returned always in non-secure
581   mode.
582   
583   \details Returns the current value of the Process Stack Pointer Limit (PSPLIM).
584   \return               PSPLIM Register value
585  */
586 __STATIC_FORCEINLINE uint32_t __get_PSPLIM(void)
587 {
588 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
589     (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
590     // without main extensions, the non-secure PSPLIM is RAZ/WI
591   return 0U;
592 #else
593   uint32_t result;
594   __ASM volatile ("MRS %0, psplim"  : "=r" (result) );
595   return result;
596 #endif
597 }
598
599 #if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3))
600 /**
601   \brief   Get Process Stack Pointer Limit (non-secure)
602   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
603   Stack Pointer Limit register hence zero is returned always in non-secure
604   mode.
605
606   \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
607   \return               PSPLIM Register value
608  */
609 __STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void)
610 {
611 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
612   // without main extensions, the non-secure PSPLIM is RAZ/WI
613   return 0U;
614 #else
615   uint32_t result;
616   __ASM volatile ("MRS %0, psplim_ns"  : "=r" (result) );
617   return result;
618 #endif
619 }
620 #endif
621
622
623 /**
624   \brief   Set Process Stack Pointer Limit
625   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
626   Stack Pointer Limit register hence the write is silently ignored in non-secure
627   mode.
628   
629   \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM).
630   \param [in]    ProcStackPtrLimit  Process Stack Pointer Limit value to set
631  */
632 __STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit)
633 {
634 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
635     (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
636   // without main extensions, the non-secure PSPLIM is RAZ/WI
637   (void)ProcStackPtrLimit;
638 #else
639   __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit));
640 #endif
641 }
642
643
644 #if (defined (__ARM_FEATURE_CMSE  ) && (__ARM_FEATURE_CMSE   == 3))
645 /**
646   \brief   Set Process Stack Pointer (non-secure)
647   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
648   Stack Pointer Limit register hence the write is silently ignored in non-secure
649   mode.
650
651   \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
652   \param [in]    ProcStackPtrLimit  Process Stack Pointer Limit value to set
653  */
654 __STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit)
655 {
656 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
657   // without main extensions, the non-secure PSPLIM is RAZ/WI
658   (void)ProcStackPtrLimit;
659 #else
660   __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit));
661 #endif
662 }
663 #endif
664
665
666 /**
667   \brief   Get Main Stack Pointer Limit
668   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
669   Stack Pointer Limit register hence zero is returned always.
670
671   \details Returns the current value of the Main Stack Pointer Limit (MSPLIM).
672   \return               MSPLIM Register value
673  */
674 __STATIC_FORCEINLINE uint32_t __get_MSPLIM(void)
675 {
676 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
677     (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
678   // without main extensions, the non-secure MSPLIM is RAZ/WI
679   return 0U;
680 #else
681   uint32_t result;
682   __ASM volatile ("MRS %0, msplim" : "=r" (result) );
683   return result;
684 #endif
685 }
686
687
688 #if (defined (__ARM_FEATURE_CMSE  ) && (__ARM_FEATURE_CMSE   == 3))
689 /**
690   \brief   Get Main Stack Pointer Limit (non-secure)
691   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
692   Stack Pointer Limit register hence zero is returned always.
693
694   \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state.
695   \return               MSPLIM Register value
696  */
697 __STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void)
698 {
699 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
700   // without main extensions, the non-secure MSPLIM is RAZ/WI
701   return 0U;
702 #else
703   uint32_t result;
704   __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) );
705   return result;
706 #endif
707 }
708 #endif
709
710
711 /**
712   \brief   Set Main Stack Pointer Limit
713   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
714   Stack Pointer Limit register hence the write is silently ignored.
715
716   \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM).
717   \param [in]    MainStackPtrLimit  Main Stack Pointer Limit value to set
718  */
719 __STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit)
720 {
721 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
722     (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
723   // without main extensions, the non-secure MSPLIM is RAZ/WI
724   (void)MainStackPtrLimit;
725 #else
726   __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit));
727 #endif
728 }
729
730
731 #if (defined (__ARM_FEATURE_CMSE  ) && (__ARM_FEATURE_CMSE   == 3))
732 /**
733   \brief   Set Main Stack Pointer Limit (non-secure)
734   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
735   Stack Pointer Limit register hence the write is silently ignored.
736
737   \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state.
738   \param [in]    MainStackPtrLimit  Main Stack Pointer value to set
739  */
740 __STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit)
741 {
742 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
743   // without main extensions, the non-secure MSPLIM is RAZ/WI
744   (void)MainStackPtrLimit;
745 #else
746   __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit));
747 #endif
748 }
749 #endif
750
751 #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
752            (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    ) */
753
754 /**
755   \brief   Get FPSCR
756   \details Returns the current value of the Floating Point Status/Control register.
757   \return               Floating Point Status/Control register value
758  */
759 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
760      (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     )
761 #define __get_FPSCR      (uint32_t)__builtin_arm_get_fpscr
762 #else
763 #define __get_FPSCR()      ((uint32_t)0U)
764 #endif
765
766 /**
767   \brief   Set FPSCR
768   \details Assigns the given value to the Floating Point Status/Control register.
769   \param [in]    fpscr  Floating Point Status/Control value to set
770  */
771 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
772      (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     )
773 #define __set_FPSCR      __builtin_arm_set_fpscr
774 #else
775 #define __set_FPSCR(x)      ((void)(x))
776 #endif
777
778
779 /*@} end of CMSIS_Core_RegAccFunctions */
780
781
782 /* ##########################  Core Instruction Access  ######################### */
783 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
784   Access to dedicated instructions
785   @{
786 */
787
788 /* Define macros for porting to both thumb1 and thumb2.
789  * For thumb1, use low register (r0-r7), specified by constraint "l"
790  * Otherwise, use general registers, specified by constraint "r" */
791 #if defined (__thumb__) && !defined (__thumb2__)
792 #define __CMSIS_GCC_OUT_REG(r) "=l" (r)
793 #define __CMSIS_GCC_RW_REG(r) "+l" (r)
794 #define __CMSIS_GCC_USE_REG(r) "l" (r)
795 #else
796 #define __CMSIS_GCC_OUT_REG(r) "=r" (r)
797 #define __CMSIS_GCC_RW_REG(r) "+r" (r)
798 #define __CMSIS_GCC_USE_REG(r) "r" (r)
799 #endif
800
801 /**
802   \brief   No Operation
803   \details No Operation does nothing. This instruction can be used for code alignment purposes.
804  */
805 #define __NOP          __builtin_arm_nop
806
807 /**
808   \brief   Wait For Interrupt
809   \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
810  */
811 #define __WFI          __builtin_arm_wfi
812
813
814 /**
815   \brief   Wait For Event
816   \details Wait For Event is a hint instruction that permits the processor to enter
817            a low-power state until one of a number of events occurs.
818  */
819 #define __WFE          __builtin_arm_wfe
820
821
822 /**
823   \brief   Send Event
824   \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
825  */
826 #define __SEV          __builtin_arm_sev
827
828
829 /**
830   \brief   Instruction Synchronization Barrier
831   \details Instruction Synchronization Barrier flushes the pipeline in the processor,
832            so that all instructions following the ISB are fetched from cache or memory,
833            after the instruction has been completed.
834  */
835 #define __ISB()        __builtin_arm_isb(0xF)
836
837 /**
838   \brief   Data Synchronization Barrier
839   \details Acts as a special kind of Data Memory Barrier.
840            It completes when all explicit memory accesses before this instruction complete.
841  */
842 #define __DSB()        __builtin_arm_dsb(0xF)
843
844
845 /**
846   \brief   Data Memory Barrier
847   \details Ensures the apparent order of the explicit memory operations before
848            and after the instruction, without ensuring their completion.
849  */
850 #define __DMB()        __builtin_arm_dmb(0xF)
851
852
853 /**
854   \brief   Reverse byte order (32 bit)
855   \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
856   \param [in]    value  Value to reverse
857   \return               Reversed value
858  */
859 #define __REV(value)   __builtin_bswap32(value)
860
861
862 /**
863   \brief   Reverse byte order (16 bit)
864   \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
865   \param [in]    value  Value to reverse
866   \return               Reversed value
867  */
868 #define __REV16(value) __ROR(__REV(value), 16)
869
870
871 /**
872   \brief   Reverse byte order (16 bit)
873   \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
874   \param [in]    value  Value to reverse
875   \return               Reversed value
876  */
877 #define __REVSH(value) (int16_t)__builtin_bswap16(value)
878
879
880 /**
881   \brief   Rotate Right in unsigned value (32 bit)
882   \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
883   \param [in]    op1  Value to rotate
884   \param [in]    op2  Number of Bits to rotate
885   \return               Rotated value
886  */
887 __STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
888 {
889   op2 %= 32U;
890   if (op2 == 0U)
891   {
892     return op1;
893   }
894   return (op1 >> op2) | (op1 << (32U - op2));
895 }
896
897
898 /**
899   \brief   Breakpoint
900   \details Causes the processor to enter Debug state.
901            Debug tools can use this to investigate system state when the instruction at a particular address is reached.
902   \param [in]    value  is ignored by the processor.
903                  If required, a debugger can use it to store additional information about the breakpoint.
904  */
905 #define __BKPT(value)     __ASM volatile ("bkpt "#value)
906
907
908 /**
909   \brief   Reverse bit order of value
910   \details Reverses the bit order of the given value.
911   \param [in]    value  Value to reverse
912   \return               Reversed value
913  */
914 #define __RBIT            __builtin_arm_rbit
915
916 /**
917   \brief   Count leading zeros
918   \details Counts the number of leading zeros of a data value.
919   \param [in]  value  Value to count the leading zeros
920   \return             number of leading zeros in value
921  */
922 __STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value)
923 {
924   /* Even though __builtin_clz produces a CLZ instruction on ARM, formally
925      __builtin_clz(0) is undefined behaviour, so handle this case specially.
926      This guarantees ARM-compatible results if happening to compile on a non-ARM
927      target, and ensures the compiler doesn't decide to activate any
928      optimisations using the logic "value was passed to __builtin_clz, so it
929      is non-zero".
930      ARM Compiler 6.10 and possibly earlier will optimise this test away, leaving a
931      single CLZ instruction.
932    */
933   if (value == 0U)
934   {
935     return 32U;
936   }
937   return __builtin_clz(value);
938 }
939
940
941 #if ((defined (__ARM_ARCH_7M__      ) && (__ARM_ARCH_7M__      == 1)) || \
942      (defined (__ARM_ARCH_7EM__     ) && (__ARM_ARCH_7EM__     == 1)) || \
943      (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
944      (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    )
945 /**
946   \brief   LDR Exclusive (8 bit)
947   \details Executes a exclusive LDR instruction for 8 bit value.
948   \param [in]    ptr  Pointer to data
949   \return             value of type uint8_t at (*ptr)
950  */
951 #define __LDREXB        (uint8_t)__builtin_arm_ldrex
952
953
954 /**
955   \brief   LDR Exclusive (16 bit)
956   \details Executes a exclusive LDR instruction for 16 bit values.
957   \param [in]    ptr  Pointer to data
958   \return        value of type uint16_t at (*ptr)
959  */
960 #define __LDREXH        (uint16_t)__builtin_arm_ldrex
961
962
963 /**
964   \brief   LDR Exclusive (32 bit)
965   \details Executes a exclusive LDR instruction for 32 bit values.
966   \param [in]    ptr  Pointer to data
967   \return        value of type uint32_t at (*ptr)
968  */
969 #define __LDREXW        (uint32_t)__builtin_arm_ldrex
970
971
972 /**
973   \brief   STR Exclusive (8 bit)
974   \details Executes a exclusive STR instruction for 8 bit values.
975   \param [in]  value  Value to store
976   \param [in]    ptr  Pointer to location
977   \return          0  Function succeeded
978   \return          1  Function failed
979  */
980 #define __STREXB        (uint32_t)__builtin_arm_strex
981
982
983 /**
984   \brief   STR Exclusive (16 bit)
985   \details Executes a exclusive STR instruction for 16 bit values.
986   \param [in]  value  Value to store
987   \param [in]    ptr  Pointer to location
988   \return          0  Function succeeded
989   \return          1  Function failed
990  */
991 #define __STREXH        (uint32_t)__builtin_arm_strex
992
993
994 /**
995   \brief   STR Exclusive (32 bit)
996   \details Executes a exclusive STR instruction for 32 bit values.
997   \param [in]  value  Value to store
998   \param [in]    ptr  Pointer to location
999   \return          0  Function succeeded
1000   \return          1  Function failed
1001  */
1002 #define __STREXW        (uint32_t)__builtin_arm_strex
1003
1004
1005 /**
1006   \brief   Remove the exclusive lock
1007   \details Removes the exclusive lock which is created by LDREX.
1008  */
1009 #define __CLREX             __builtin_arm_clrex
1010
1011 #endif /* ((defined (__ARM_ARCH_7M__      ) && (__ARM_ARCH_7M__      == 1)) || \
1012            (defined (__ARM_ARCH_7EM__     ) && (__ARM_ARCH_7EM__     == 1)) || \
1013            (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1014            (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    ) */
1015
1016
1017 #if ((defined (__ARM_ARCH_7M__      ) && (__ARM_ARCH_7M__      == 1)) || \
1018      (defined (__ARM_ARCH_7EM__     ) && (__ARM_ARCH_7EM__     == 1)) || \
1019      (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))    )
1020
1021 /**
1022   \brief   Signed Saturate
1023   \details Saturates a signed value.
1024   \param [in]  value  Value to be saturated
1025   \param [in]    sat  Bit position to saturate to (1..32)
1026   \return             Saturated value
1027  */
1028 #define __SSAT             __builtin_arm_ssat
1029
1030
1031 /**
1032   \brief   Unsigned Saturate
1033   \details Saturates an unsigned value.
1034   \param [in]  value  Value to be saturated
1035   \param [in]    sat  Bit position to saturate to (0..31)
1036   \return             Saturated value
1037  */
1038 #define __USAT             __builtin_arm_usat
1039
1040
1041 /**
1042   \brief   Rotate Right with Extend (32 bit)
1043   \details Moves each bit of a bitstring right by one bit.
1044            The carry input is shifted in at the left end of the bitstring.
1045   \param [in]    value  Value to rotate
1046   \return               Rotated value
1047  */
1048 __STATIC_FORCEINLINE uint32_t __RRX(uint32_t value)
1049 {
1050   uint32_t result;
1051
1052   __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
1053   return(result);
1054 }
1055
1056
1057 /**
1058   \brief   LDRT Unprivileged (8 bit)
1059   \details Executes a Unprivileged LDRT instruction for 8 bit value.
1060   \param [in]    ptr  Pointer to data
1061   \return             value of type uint8_t at (*ptr)
1062  */
1063 __STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr)
1064 {
1065   uint32_t result;
1066
1067   __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) );
1068   return ((uint8_t) result);    /* Add explicit type cast here */
1069 }
1070
1071
1072 /**
1073   \brief   LDRT Unprivileged (16 bit)
1074   \details Executes a Unprivileged LDRT instruction for 16 bit values.
1075   \param [in]    ptr  Pointer to data
1076   \return        value of type uint16_t at (*ptr)
1077  */
1078 __STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr)
1079 {
1080   uint32_t result;
1081
1082   __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) );
1083   return ((uint16_t) result);    /* Add explicit type cast here */
1084 }
1085
1086
1087 /**
1088   \brief   LDRT Unprivileged (32 bit)
1089   \details Executes a Unprivileged LDRT instruction for 32 bit values.
1090   \param [in]    ptr  Pointer to data
1091   \return        value of type uint32_t at (*ptr)
1092  */
1093 __STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr)
1094 {
1095   uint32_t result;
1096
1097   __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) );
1098   return(result);
1099 }
1100
1101
1102 /**
1103   \brief   STRT Unprivileged (8 bit)
1104   \details Executes a Unprivileged STRT instruction for 8 bit values.
1105   \param [in]  value  Value to store
1106   \param [in]    ptr  Pointer to location
1107  */
1108 __STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr)
1109 {
1110   __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1111 }
1112
1113
1114 /**
1115   \brief   STRT Unprivileged (16 bit)
1116   \details Executes a Unprivileged STRT instruction for 16 bit values.
1117   \param [in]  value  Value to store
1118   \param [in]    ptr  Pointer to location
1119  */
1120 __STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr)
1121 {
1122   __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1123 }
1124
1125
1126 /**
1127   \brief   STRT Unprivileged (32 bit)
1128   \details Executes a Unprivileged STRT instruction for 32 bit values.
1129   \param [in]  value  Value to store
1130   \param [in]    ptr  Pointer to location
1131  */
1132 __STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr)
1133 {
1134   __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) );
1135 }
1136
1137 #else  /* ((defined (__ARM_ARCH_7M__      ) && (__ARM_ARCH_7M__      == 1)) || \
1138            (defined (__ARM_ARCH_7EM__     ) && (__ARM_ARCH_7EM__     == 1)) || \
1139            (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))    ) */
1140
1141 /**
1142   \brief   Signed Saturate
1143   \details Saturates a signed value.
1144   \param [in]  value  Value to be saturated
1145   \param [in]    sat  Bit position to saturate to (1..32)
1146   \return             Saturated value
1147  */
1148 __STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat)
1149 {
1150   if ((sat >= 1U) && (sat <= 32U))
1151   {
1152     const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
1153     const int32_t min = -1 - max ;
1154     if (val > max)
1155     {
1156       return max;
1157     }
1158     else if (val < min)
1159     {
1160       return min;
1161     }
1162   }
1163   return val;
1164 }
1165
1166 /**
1167   \brief   Unsigned Saturate
1168   \details Saturates an unsigned value.
1169   \param [in]  value  Value to be saturated
1170   \param [in]    sat  Bit position to saturate to (0..31)
1171   \return             Saturated value
1172  */
1173 __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat)
1174 {
1175   if (sat <= 31U)
1176   {
1177     const uint32_t max = ((1U << sat) - 1U);
1178     if (val > (int32_t)max)
1179     {
1180       return max;
1181     }
1182     else if (val < 0)
1183     {
1184       return 0U;
1185     }
1186   }
1187   return (uint32_t)val;
1188 }
1189
1190 #endif /* ((defined (__ARM_ARCH_7M__      ) && (__ARM_ARCH_7M__      == 1)) || \
1191            (defined (__ARM_ARCH_7EM__     ) && (__ARM_ARCH_7EM__     == 1)) || \
1192            (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))    ) */
1193
1194
1195 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1196      (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    )
1197 /**
1198   \brief   Load-Acquire (8 bit)
1199   \details Executes a LDAB instruction for 8 bit value.
1200   \param [in]    ptr  Pointer to data
1201   \return             value of type uint8_t at (*ptr)
1202  */
1203 __STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr)
1204 {
1205   uint32_t result;
1206
1207   __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) );
1208   return ((uint8_t) result);
1209 }
1210
1211
1212 /**
1213   \brief   Load-Acquire (16 bit)
1214   \details Executes a LDAH instruction for 16 bit values.
1215   \param [in]    ptr  Pointer to data
1216   \return        value of type uint16_t at (*ptr)
1217  */
1218 __STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr)
1219 {
1220   uint32_t result;
1221
1222   __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) );
1223   return ((uint16_t) result);
1224 }
1225
1226
1227 /**
1228   \brief   Load-Acquire (32 bit)
1229   \details Executes a LDA instruction for 32 bit values.
1230   \param [in]    ptr  Pointer to data
1231   \return        value of type uint32_t at (*ptr)
1232  */
1233 __STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr)
1234 {
1235   uint32_t result;
1236
1237   __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) );
1238   return(result);
1239 }
1240
1241
1242 /**
1243   \brief   Store-Release (8 bit)
1244   \details Executes a STLB instruction for 8 bit values.
1245   \param [in]  value  Value to store
1246   \param [in]    ptr  Pointer to location
1247  */
1248 __STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr)
1249 {
1250   __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1251 }
1252
1253
1254 /**
1255   \brief   Store-Release (16 bit)
1256   \details Executes a STLH instruction for 16 bit values.
1257   \param [in]  value  Value to store
1258   \param [in]    ptr  Pointer to location
1259  */
1260 __STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr)
1261 {
1262   __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1263 }
1264
1265
1266 /**
1267   \brief   Store-Release (32 bit)
1268   \details Executes a STL instruction for 32 bit values.
1269   \param [in]  value  Value to store
1270   \param [in]    ptr  Pointer to location
1271  */
1272 __STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr)
1273 {
1274   __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1275 }
1276
1277
1278 /**
1279   \brief   Load-Acquire Exclusive (8 bit)
1280   \details Executes a LDAB exclusive instruction for 8 bit value.
1281   \param [in]    ptr  Pointer to data
1282   \return             value of type uint8_t at (*ptr)
1283  */
1284 #define     __LDAEXB                 (uint8_t)__builtin_arm_ldaex
1285
1286
1287 /**
1288   \brief   Load-Acquire Exclusive (16 bit)
1289   \details Executes a LDAH exclusive instruction for 16 bit values.
1290   \param [in]    ptr  Pointer to data
1291   \return        value of type uint16_t at (*ptr)
1292  */
1293 #define     __LDAEXH                 (uint16_t)__builtin_arm_ldaex
1294
1295
1296 /**
1297   \brief   Load-Acquire Exclusive (32 bit)
1298   \details Executes a LDA exclusive instruction for 32 bit values.
1299   \param [in]    ptr  Pointer to data
1300   \return        value of type uint32_t at (*ptr)
1301  */
1302 #define     __LDAEX                  (uint32_t)__builtin_arm_ldaex
1303
1304
1305 /**
1306   \brief   Store-Release Exclusive (8 bit)
1307   \details Executes a STLB exclusive instruction for 8 bit values.
1308   \param [in]  value  Value to store
1309   \param [in]    ptr  Pointer to location
1310   \return          0  Function succeeded
1311   \return          1  Function failed
1312  */
1313 #define     __STLEXB                 (uint32_t)__builtin_arm_stlex
1314
1315
1316 /**
1317   \brief   Store-Release Exclusive (16 bit)
1318   \details Executes a STLH exclusive instruction for 16 bit values.
1319   \param [in]  value  Value to store
1320   \param [in]    ptr  Pointer to location
1321   \return          0  Function succeeded
1322   \return          1  Function failed
1323  */
1324 #define     __STLEXH                 (uint32_t)__builtin_arm_stlex
1325
1326
1327 /**
1328   \brief   Store-Release Exclusive (32 bit)
1329   \details Executes a STL exclusive instruction for 32 bit values.
1330   \param [in]  value  Value to store
1331   \param [in]    ptr  Pointer to location
1332   \return          0  Function succeeded
1333   \return          1  Function failed
1334  */
1335 #define     __STLEX                  (uint32_t)__builtin_arm_stlex
1336
1337 #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1338            (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    ) */
1339
1340 /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
1341
1342
1343 /* ###################  Compiler specific Intrinsics  ########################### */
1344 /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
1345   Access to dedicated SIMD instructions
1346   @{
1347 */
1348
1349 #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
1350
1351 #define     __SADD8                 __builtin_arm_sadd8
1352 #define     __QADD8                 __builtin_arm_qadd8
1353 #define     __SHADD8                __builtin_arm_shadd8
1354 #define     __UADD8                 __builtin_arm_uadd8
1355 #define     __UQADD8                __builtin_arm_uqadd8
1356 #define     __UHADD8                __builtin_arm_uhadd8
1357 #define     __SSUB8                 __builtin_arm_ssub8
1358 #define     __QSUB8                 __builtin_arm_qsub8
1359 #define     __SHSUB8                __builtin_arm_shsub8
1360 #define     __USUB8                 __builtin_arm_usub8
1361 #define     __UQSUB8                __builtin_arm_uqsub8
1362 #define     __UHSUB8                __builtin_arm_uhsub8
1363 #define     __SADD16                __builtin_arm_sadd16
1364 #define     __QADD16                __builtin_arm_qadd16
1365 #define     __SHADD16               __builtin_arm_shadd16
1366 #define     __UADD16                __builtin_arm_uadd16
1367 #define     __UQADD16               __builtin_arm_uqadd16
1368 #define     __UHADD16               __builtin_arm_uhadd16
1369 #define     __SSUB16                __builtin_arm_ssub16
1370 #define     __QSUB16                __builtin_arm_qsub16
1371 #define     __SHSUB16               __builtin_arm_shsub16
1372 #define     __USUB16                __builtin_arm_usub16
1373 #define     __UQSUB16               __builtin_arm_uqsub16
1374 #define     __UHSUB16               __builtin_arm_uhsub16
1375 #define     __SASX                  __builtin_arm_sasx
1376 #define     __QASX                  __builtin_arm_qasx
1377 #define     __SHASX                 __builtin_arm_shasx
1378 #define     __UASX                  __builtin_arm_uasx
1379 #define     __UQASX                 __builtin_arm_uqasx
1380 #define     __UHASX                 __builtin_arm_uhasx
1381 #define     __SSAX                  __builtin_arm_ssax
1382 #define     __QSAX                  __builtin_arm_qsax
1383 #define     __SHSAX                 __builtin_arm_shsax
1384 #define     __USAX                  __builtin_arm_usax
1385 #define     __UQSAX                 __builtin_arm_uqsax
1386 #define     __UHSAX                 __builtin_arm_uhsax
1387 #define     __USAD8                 __builtin_arm_usad8
1388 #define     __USADA8                __builtin_arm_usada8
1389 #define     __SSAT16                __builtin_arm_ssat16
1390 #define     __USAT16                __builtin_arm_usat16
1391 #define     __UXTB16                __builtin_arm_uxtb16
1392 #define     __UXTAB16               __builtin_arm_uxtab16
1393 #define     __SXTB16                __builtin_arm_sxtb16
1394 #define     __SXTAB16               __builtin_arm_sxtab16
1395 #define     __SMUAD                 __builtin_arm_smuad
1396 #define     __SMUADX                __builtin_arm_smuadx
1397 #define     __SMLAD                 __builtin_arm_smlad
1398 #define     __SMLADX                __builtin_arm_smladx
1399 #define     __SMLALD                __builtin_arm_smlald
1400 #define     __SMLALDX               __builtin_arm_smlaldx
1401 #define     __SMUSD                 __builtin_arm_smusd
1402 #define     __SMUSDX                __builtin_arm_smusdx
1403 #define     __SMLSD                 __builtin_arm_smlsd
1404 #define     __SMLSDX                __builtin_arm_smlsdx
1405 #define     __SMLSLD                __builtin_arm_smlsld
1406 #define     __SMLSLDX               __builtin_arm_smlsldx
1407 #define     __SEL                   __builtin_arm_sel
1408 #define     __QADD                  __builtin_arm_qadd
1409 #define     __QSUB                  __builtin_arm_qsub
1410
1411 #define __PKHBT(ARG1,ARG2,ARG3)          ( ((((uint32_t)(ARG1))          ) & 0x0000FFFFUL) |  \
1412                                            ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL)  )
1413
1414 #define __PKHTB(ARG1,ARG2,ARG3)          ( ((((uint32_t)(ARG1))          ) & 0xFFFF0000UL) |  \
1415                                            ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL)  )
1416
1417 __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
1418 {
1419   int32_t result;
1420
1421   __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r"  (op1), "r" (op2), "r" (op3) );
1422   return(result);
1423 }
1424
1425 #endif /* (__ARM_FEATURE_DSP == 1) */
1426 /*@} end of group CMSIS_SIMD_intrinsics */
1427
1428
1429 #endif /* __CMSIS_ARMCLANG_H */