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