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