]> begriffs open source - cmsis/blob - CMSIS/Core/Include/cmsis_armcc.h
NVIC_SetVector: Add DSB to newer cores
[cmsis] / CMSIS / Core / Include / cmsis_armcc.h
1 /**************************************************************************//**
2  * @file     cmsis_armcc.h
3  * @brief    CMSIS compiler ARMCC (Arm Compiler 5) header file
4  * @version  V5.1.0
5  * @date     08. May 2019
6  ******************************************************************************/
7 /*
8  * Copyright (c) 2009-2019 Arm Limited. All rights reserved.
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  *
12  * Licensed under the Apache License, Version 2.0 (the License); you may
13  * not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  * www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  */
24
25 #ifndef __CMSIS_ARMCC_H
26 #define __CMSIS_ARMCC_H
27
28
29 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 400677)
30   #error "Please use Arm Compiler Toolchain V4.0.677 or later!"
31 #endif
32
33 /* CMSIS compiler control architecture macros */
34 #if ((defined (__TARGET_ARCH_6_M  ) && (__TARGET_ARCH_6_M   == 1)) || \
35      (defined (__TARGET_ARCH_6S_M ) && (__TARGET_ARCH_6S_M  == 1))   )
36   #define __ARM_ARCH_6M__           1
37 #endif
38
39 #if (defined (__TARGET_ARCH_7_M ) && (__TARGET_ARCH_7_M  == 1))
40   #define __ARM_ARCH_7M__           1
41 #endif
42
43 #if (defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1))
44   #define __ARM_ARCH_7EM__          1
45 #endif
46
47   /* __ARM_ARCH_8M_BASE__  not applicable */
48   /* __ARM_ARCH_8M_MAIN__  not applicable */
49
50 /* CMSIS compiler control DSP macros */
51 #if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1))     )
52   #define __ARM_FEATURE_DSP         1
53 #endif
54
55 /* CMSIS compiler specific defines */
56 #ifndef   __ASM
57   #define __ASM                                  __asm
58 #endif
59 #ifndef   __INLINE
60   #define __INLINE                               __inline
61 #endif
62 #ifndef   __STATIC_INLINE
63   #define __STATIC_INLINE                        static __inline
64 #endif
65 #ifndef   __STATIC_FORCEINLINE                 
66   #define __STATIC_FORCEINLINE                   static __forceinline
67 #endif           
68 #ifndef   __NO_RETURN
69   #define __NO_RETURN                            __declspec(noreturn)
70 #endif
71 #ifndef   __USED
72   #define __USED                                 __attribute__((used))
73 #endif
74 #ifndef   __WEAK
75   #define __WEAK                                 __attribute__((weak))
76 #endif
77 #ifndef   __PACKED
78   #define __PACKED                               __attribute__((packed))
79 #endif
80 #ifndef   __PACKED_STRUCT
81   #define __PACKED_STRUCT                        __packed struct
82 #endif
83 #ifndef   __PACKED_UNION
84   #define __PACKED_UNION                         __packed union
85 #endif
86 #ifndef   __UNALIGNED_UINT32        /* deprecated */
87   #define __UNALIGNED_UINT32(x)                  (*((__packed uint32_t *)(x)))
88 #endif
89 #ifndef   __UNALIGNED_UINT16_WRITE
90   #define __UNALIGNED_UINT16_WRITE(addr, val)    ((*((__packed uint16_t *)(addr))) = (val))
91 #endif
92 #ifndef   __UNALIGNED_UINT16_READ
93   #define __UNALIGNED_UINT16_READ(addr)          (*((const __packed uint16_t *)(addr)))
94 #endif
95 #ifndef   __UNALIGNED_UINT32_WRITE
96   #define __UNALIGNED_UINT32_WRITE(addr, val)    ((*((__packed uint32_t *)(addr))) = (val))
97 #endif
98 #ifndef   __UNALIGNED_UINT32_READ
99   #define __UNALIGNED_UINT32_READ(addr)          (*((const __packed uint32_t *)(addr)))
100 #endif
101 #ifndef   __ALIGNED
102   #define __ALIGNED(x)                           __attribute__((aligned(x)))
103 #endif
104 #ifndef   __RESTRICT
105   #define __RESTRICT                             __restrict
106 #endif
107
108 /* #########################  Startup and Lowlevel Init  ######################## */
109
110 #ifndef __PROGRAM_START
111 #define __PROGRAM_START           __main
112 #endif
113
114 #ifndef __INITIAL_SP
115 #define __INITIAL_SP              Image$$ARM_LIB_STACK$$ZI$$Limit
116 #endif
117
118 #ifndef __STACK_LIMIT
119 #define __STACK_LIMIT             Image$$ARM_LIB_STACK$$ZI$$Base
120 #endif
121
122 #ifndef __VECTOR_TABLE
123 #define __VECTOR_TABLE            __Vectors
124 #endif
125
126 #ifndef __VECTOR_TABLE_ATTRIBUTE
127 #define __VECTOR_TABLE_ATTRIBUTE  __attribute((used, section("RESET")))
128 #endif
129
130 /* ###########################  Core Function Access  ########################### */
131 /** \ingroup  CMSIS_Core_FunctionInterface
132     \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
133   @{
134  */
135
136 /**
137   \brief   Enable IRQ Interrupts
138   \details Enables IRQ interrupts by clearing the I-bit in the CPSR.
139            Can only be executed in Privileged modes.
140  */
141 /* intrinsic void __enable_irq();     */
142
143
144 /**
145   \brief   Disable IRQ Interrupts
146   \details Disables IRQ interrupts by setting the I-bit in the CPSR.
147            Can only be executed in Privileged modes.
148  */
149 /* intrinsic void __disable_irq();    */
150
151 /**
152   \brief   Get Control Register
153   \details Returns the content of the Control Register.
154   \return               Control Register value
155  */
156 __STATIC_INLINE uint32_t __get_CONTROL(void)
157 {
158   register uint32_t __regControl         __ASM("control");
159   return(__regControl);
160 }
161
162
163 /**
164   \brief   Set Control Register
165   \details Writes the given value to the Control Register.
166   \param [in]    control  Control Register value to set
167  */
168 __STATIC_INLINE void __set_CONTROL(uint32_t control)
169 {
170   register uint32_t __regControl         __ASM("control");
171   __regControl = control;
172 }
173
174
175 /**
176   \brief   Get IPSR Register
177   \details Returns the content of the IPSR Register.
178   \return               IPSR Register value
179  */
180 __STATIC_INLINE uint32_t __get_IPSR(void)
181 {
182   register uint32_t __regIPSR          __ASM("ipsr");
183   return(__regIPSR);
184 }
185
186
187 /**
188   \brief   Get APSR Register
189   \details Returns the content of the APSR Register.
190   \return               APSR Register value
191  */
192 __STATIC_INLINE uint32_t __get_APSR(void)
193 {
194   register uint32_t __regAPSR          __ASM("apsr");
195   return(__regAPSR);
196 }
197
198
199 /**
200   \brief   Get xPSR Register
201   \details Returns the content of the xPSR Register.
202   \return               xPSR Register value
203  */
204 __STATIC_INLINE uint32_t __get_xPSR(void)
205 {
206   register uint32_t __regXPSR          __ASM("xpsr");
207   return(__regXPSR);
208 }
209
210
211 /**
212   \brief   Get Process Stack Pointer
213   \details Returns the current value of the Process Stack Pointer (PSP).
214   \return               PSP Register value
215  */
216 __STATIC_INLINE uint32_t __get_PSP(void)
217 {
218   register uint32_t __regProcessStackPointer  __ASM("psp");
219   return(__regProcessStackPointer);
220 }
221
222
223 /**
224   \brief   Set Process Stack Pointer
225   \details Assigns the given value to the Process Stack Pointer (PSP).
226   \param [in]    topOfProcStack  Process Stack Pointer value to set
227  */
228 __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
229 {
230   register uint32_t __regProcessStackPointer  __ASM("psp");
231   __regProcessStackPointer = topOfProcStack;
232 }
233
234
235 /**
236   \brief   Get Main Stack Pointer
237   \details Returns the current value of the Main Stack Pointer (MSP).
238   \return               MSP Register value
239  */
240 __STATIC_INLINE uint32_t __get_MSP(void)
241 {
242   register uint32_t __regMainStackPointer     __ASM("msp");
243   return(__regMainStackPointer);
244 }
245
246
247 /**
248   \brief   Set Main Stack Pointer
249   \details Assigns the given value to the Main Stack Pointer (MSP).
250   \param [in]    topOfMainStack  Main Stack Pointer value to set
251  */
252 __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
253 {
254   register uint32_t __regMainStackPointer     __ASM("msp");
255   __regMainStackPointer = topOfMainStack;
256 }
257
258
259 /**
260   \brief   Get Priority Mask
261   \details Returns the current state of the priority mask bit from the Priority Mask Register.
262   \return               Priority Mask value
263  */
264 __STATIC_INLINE uint32_t __get_PRIMASK(void)
265 {
266   register uint32_t __regPriMask         __ASM("primask");
267   return(__regPriMask);
268 }
269
270
271 /**
272   \brief   Set Priority Mask
273   \details Assigns the given value to the Priority Mask Register.
274   \param [in]    priMask  Priority Mask
275  */
276 __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
277 {
278   register uint32_t __regPriMask         __ASM("primask");
279   __regPriMask = (priMask);
280 }
281
282
283 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__  == 1)) || \
284      (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1))     )
285
286 /**
287   \brief   Enable FIQ
288   \details Enables FIQ interrupts by clearing the F-bit in the CPSR.
289            Can only be executed in Privileged modes.
290  */
291 #define __enable_fault_irq                __enable_fiq
292
293
294 /**
295   \brief   Disable FIQ
296   \details Disables FIQ interrupts by setting the F-bit in the CPSR.
297            Can only be executed in Privileged modes.
298  */
299 #define __disable_fault_irq               __disable_fiq
300
301
302 /**
303   \brief   Get Base Priority
304   \details Returns the current value of the Base Priority register.
305   \return               Base Priority register value
306  */
307 __STATIC_INLINE uint32_t  __get_BASEPRI(void)
308 {
309   register uint32_t __regBasePri         __ASM("basepri");
310   return(__regBasePri);
311 }
312
313
314 /**
315   \brief   Set Base Priority
316   \details Assigns the given value to the Base Priority register.
317   \param [in]    basePri  Base Priority value to set
318  */
319 __STATIC_INLINE void __set_BASEPRI(uint32_t basePri)
320 {
321   register uint32_t __regBasePri         __ASM("basepri");
322   __regBasePri = (basePri & 0xFFU);
323 }
324
325
326 /**
327   \brief   Set Base Priority with condition
328   \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
329            or the new value increases the BASEPRI priority level.
330   \param [in]    basePri  Base Priority value to set
331  */
332 __STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri)
333 {
334   register uint32_t __regBasePriMax      __ASM("basepri_max");
335   __regBasePriMax = (basePri & 0xFFU);
336 }
337
338
339 /**
340   \brief   Get Fault Mask
341   \details Returns the current value of the Fault Mask register.
342   \return               Fault Mask register value
343  */
344 __STATIC_INLINE uint32_t __get_FAULTMASK(void)
345 {
346   register uint32_t __regFaultMask       __ASM("faultmask");
347   return(__regFaultMask);
348 }
349
350
351 /**
352   \brief   Set Fault Mask
353   \details Assigns the given value to the Fault Mask register.
354   \param [in]    faultMask  Fault Mask value to set
355  */
356 __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
357 {
358   register uint32_t __regFaultMask       __ASM("faultmask");
359   __regFaultMask = (faultMask & (uint32_t)1U);
360 }
361
362 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__  == 1)) || \
363            (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1))     ) */
364
365
366 /**
367   \brief   Get FPSCR
368   \details Returns the current value of the Floating Point Status/Control register.
369   \return               Floating Point Status/Control register value
370  */
371 __STATIC_INLINE uint32_t __get_FPSCR(void)
372 {
373 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
374      (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     )
375   register uint32_t __regfpscr         __ASM("fpscr");
376   return(__regfpscr);
377 #else
378    return(0U);
379 #endif
380 }
381
382
383 /**
384   \brief   Set FPSCR
385   \details Assigns the given value to the Floating Point Status/Control register.
386   \param [in]    fpscr  Floating Point Status/Control value to set
387  */
388 __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
389 {
390 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
391      (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     )
392   register uint32_t __regfpscr         __ASM("fpscr");
393   __regfpscr = (fpscr);
394 #else
395   (void)fpscr;
396 #endif
397 }
398
399
400 /*@} end of CMSIS_Core_RegAccFunctions */
401
402
403 /* ##########################  Core Instruction Access  ######################### */
404 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
405   Access to dedicated instructions
406   @{
407 */
408
409 /**
410   \brief   No Operation
411   \details No Operation does nothing. This instruction can be used for code alignment purposes.
412  */
413 #define __NOP                             __nop
414
415
416 /**
417   \brief   Wait For Interrupt
418   \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
419  */
420 #define __WFI                             __wfi
421
422
423 /**
424   \brief   Wait For Event
425   \details Wait For Event is a hint instruction that permits the processor to enter
426            a low-power state until one of a number of events occurs.
427  */
428 #define __WFE                             __wfe
429
430
431 /**
432   \brief   Send Event
433   \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
434  */
435 #define __SEV                             __sev
436
437
438 /**
439   \brief   Instruction Synchronization Barrier
440   \details Instruction Synchronization Barrier flushes the pipeline in the processor,
441            so that all instructions following the ISB are fetched from cache or memory,
442            after the instruction has been completed.
443  */
444 #define __ISB() do {\
445                    __schedule_barrier();\
446                    __isb(0xF);\
447                    __schedule_barrier();\
448                 } while (0U)
449
450 /**
451   \brief   Data Synchronization Barrier
452   \details Acts as a special kind of Data Memory Barrier.
453            It completes when all explicit memory accesses before this instruction complete.
454  */
455 #define __DSB() do {\
456                    __schedule_barrier();\
457                    __dsb(0xF);\
458                    __schedule_barrier();\
459                 } while (0U)
460
461 /**
462   \brief   Data Memory Barrier
463   \details Ensures the apparent order of the explicit memory operations before
464            and after the instruction, without ensuring their completion.
465  */
466 #define __DMB() do {\
467                    __schedule_barrier();\
468                    __dmb(0xF);\
469                    __schedule_barrier();\
470                 } while (0U)
471
472                   
473 /**
474   \brief   Reverse byte order (32 bit)
475   \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
476   \param [in]    value  Value to reverse
477   \return               Reversed value
478  */
479 #define __REV                             __rev
480
481
482 /**
483   \brief   Reverse byte order (16 bit)
484   \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
485   \param [in]    value  Value to reverse
486   \return               Reversed value
487  */
488 #ifndef __NO_EMBEDDED_ASM
489 __attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
490 {
491   rev16 r0, r0
492   bx lr
493 }
494 #endif
495
496
497 /**
498   \brief   Reverse byte order (16 bit)
499   \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
500   \param [in]    value  Value to reverse
501   \return               Reversed value
502  */
503 #ifndef __NO_EMBEDDED_ASM
504 __attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int16_t __REVSH(int16_t value)
505 {
506   revsh r0, r0
507   bx lr
508 }
509 #endif
510
511
512 /**
513   \brief   Rotate Right in unsigned value (32 bit)
514   \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
515   \param [in]    op1  Value to rotate
516   \param [in]    op2  Number of Bits to rotate
517   \return               Rotated value
518  */
519 #define __ROR                             __ror
520
521
522 /**
523   \brief   Breakpoint
524   \details Causes the processor to enter Debug state.
525            Debug tools can use this to investigate system state when the instruction at a particular address is reached.
526   \param [in]    value  is ignored by the processor.
527                  If required, a debugger can use it to store additional information about the breakpoint.
528  */
529 #define __BKPT(value)                       __breakpoint(value)
530
531
532 /**
533   \brief   Reverse bit order of value
534   \details Reverses the bit order of the given value.
535   \param [in]    value  Value to reverse
536   \return               Reversed value
537  */
538 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__  == 1)) || \
539      (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1))     )
540   #define __RBIT                          __rbit
541 #else
542 __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
543 {
544   uint32_t result;
545   uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */
546
547   result = value;                      /* r will be reversed bits of v; first get LSB of v */
548   for (value >>= 1U; value != 0U; value >>= 1U)
549   {
550     result <<= 1U;
551     result |= value & 1U;
552     s--;
553   }
554   result <<= s;                        /* shift when v's highest bits are zero */
555   return result;
556 }
557 #endif
558
559
560 /**
561   \brief   Count leading zeros
562   \details Counts the number of leading zeros of a data value.
563   \param [in]  value  Value to count the leading zeros
564   \return             number of leading zeros in value
565  */
566 #define __CLZ                             __clz
567
568
569 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__  == 1)) || \
570      (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1))     )
571
572 /**
573   \brief   LDR Exclusive (8 bit)
574   \details Executes a exclusive LDR instruction for 8 bit value.
575   \param [in]    ptr  Pointer to data
576   \return             value of type uint8_t at (*ptr)
577  */
578 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
579   #define __LDREXB(ptr)                                                        ((uint8_t ) __ldrex(ptr))
580 #else
581   #define __LDREXB(ptr)          _Pragma("push") _Pragma("diag_suppress 3731") ((uint8_t ) __ldrex(ptr))  _Pragma("pop")
582 #endif
583
584
585 /**
586   \brief   LDR Exclusive (16 bit)
587   \details Executes a exclusive LDR instruction for 16 bit values.
588   \param [in]    ptr  Pointer to data
589   \return        value of type uint16_t at (*ptr)
590  */
591 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
592   #define __LDREXH(ptr)                                                        ((uint16_t) __ldrex(ptr))
593 #else
594   #define __LDREXH(ptr)          _Pragma("push") _Pragma("diag_suppress 3731") ((uint16_t) __ldrex(ptr))  _Pragma("pop")
595 #endif
596
597
598 /**
599   \brief   LDR Exclusive (32 bit)
600   \details Executes a exclusive LDR instruction for 32 bit values.
601   \param [in]    ptr  Pointer to data
602   \return        value of type uint32_t at (*ptr)
603  */
604 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
605   #define __LDREXW(ptr)                                                        ((uint32_t ) __ldrex(ptr))
606 #else
607   #define __LDREXW(ptr)          _Pragma("push") _Pragma("diag_suppress 3731") ((uint32_t ) __ldrex(ptr))  _Pragma("pop")
608 #endif
609
610
611 /**
612   \brief   STR Exclusive (8 bit)
613   \details Executes a exclusive STR instruction for 8 bit values.
614   \param [in]  value  Value to store
615   \param [in]    ptr  Pointer to location
616   \return          0  Function succeeded
617   \return          1  Function failed
618  */
619 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
620   #define __STREXB(value, ptr)                                                 __strex(value, ptr)
621 #else
622   #define __STREXB(value, ptr)   _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr)        _Pragma("pop")
623 #endif
624
625
626 /**
627   \brief   STR Exclusive (16 bit)
628   \details Executes a exclusive STR instruction for 16 bit values.
629   \param [in]  value  Value to store
630   \param [in]    ptr  Pointer to location
631   \return          0  Function succeeded
632   \return          1  Function failed
633  */
634 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
635   #define __STREXH(value, ptr)                                                 __strex(value, ptr)
636 #else
637   #define __STREXH(value, ptr)   _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr)        _Pragma("pop")
638 #endif
639
640
641 /**
642   \brief   STR Exclusive (32 bit)
643   \details Executes a exclusive STR instruction for 32 bit values.
644   \param [in]  value  Value to store
645   \param [in]    ptr  Pointer to location
646   \return          0  Function succeeded
647   \return          1  Function failed
648  */
649 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
650   #define __STREXW(value, ptr)                                                 __strex(value, ptr)
651 #else
652   #define __STREXW(value, ptr)   _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr)        _Pragma("pop")
653 #endif
654
655
656 /**
657   \brief   Remove the exclusive lock
658   \details Removes the exclusive lock which is created by LDREX.
659  */
660 #define __CLREX                           __clrex
661
662
663 /**
664   \brief   Signed Saturate
665   \details Saturates a signed value.
666   \param [in]  value  Value to be saturated
667   \param [in]    sat  Bit position to saturate to (1..32)
668   \return             Saturated value
669  */
670 #define __SSAT                            __ssat
671
672
673 /**
674   \brief   Unsigned Saturate
675   \details Saturates an unsigned value.
676   \param [in]  value  Value to be saturated
677   \param [in]    sat  Bit position to saturate to (0..31)
678   \return             Saturated value
679  */
680 #define __USAT                            __usat
681
682
683 /**
684   \brief   Rotate Right with Extend (32 bit)
685   \details Moves each bit of a bitstring right by one bit.
686            The carry input is shifted in at the left end of the bitstring.
687   \param [in]    value  Value to rotate
688   \return               Rotated value
689  */
690 #ifndef __NO_EMBEDDED_ASM
691 __attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value)
692 {
693   rrx r0, r0
694   bx lr
695 }
696 #endif
697
698
699 /**
700   \brief   LDRT Unprivileged (8 bit)
701   \details Executes a Unprivileged LDRT instruction for 8 bit value.
702   \param [in]    ptr  Pointer to data
703   \return             value of type uint8_t at (*ptr)
704  */
705 #define __LDRBT(ptr)                      ((uint8_t )  __ldrt(ptr))
706
707
708 /**
709   \brief   LDRT Unprivileged (16 bit)
710   \details Executes a Unprivileged LDRT instruction for 16 bit values.
711   \param [in]    ptr  Pointer to data
712   \return        value of type uint16_t at (*ptr)
713  */
714 #define __LDRHT(ptr)                      ((uint16_t)  __ldrt(ptr))
715
716
717 /**
718   \brief   LDRT Unprivileged (32 bit)
719   \details Executes a Unprivileged LDRT instruction for 32 bit values.
720   \param [in]    ptr  Pointer to data
721   \return        value of type uint32_t at (*ptr)
722  */
723 #define __LDRT(ptr)                       ((uint32_t ) __ldrt(ptr))
724
725
726 /**
727   \brief   STRT Unprivileged (8 bit)
728   \details Executes a Unprivileged STRT instruction for 8 bit values.
729   \param [in]  value  Value to store
730   \param [in]    ptr  Pointer to location
731  */
732 #define __STRBT(value, ptr)               __strt(value, ptr)
733
734
735 /**
736   \brief   STRT Unprivileged (16 bit)
737   \details Executes a Unprivileged STRT instruction for 16 bit values.
738   \param [in]  value  Value to store
739   \param [in]    ptr  Pointer to location
740  */
741 #define __STRHT(value, ptr)               __strt(value, ptr)
742
743
744 /**
745   \brief   STRT Unprivileged (32 bit)
746   \details Executes a Unprivileged STRT instruction for 32 bit values.
747   \param [in]  value  Value to store
748   \param [in]    ptr  Pointer to location
749  */
750 #define __STRT(value, ptr)                __strt(value, ptr)
751
752 #else  /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__  == 1)) || \
753            (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1))     ) */
754
755 /**
756   \brief   Signed Saturate
757   \details Saturates a signed value.
758   \param [in]  value  Value to be saturated
759   \param [in]    sat  Bit position to saturate to (1..32)
760   \return             Saturated value
761  */
762 __attribute__((always_inline)) __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat)
763 {
764   if ((sat >= 1U) && (sat <= 32U))
765   {
766     const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
767     const int32_t min = -1 - max ;
768     if (val > max)
769     {
770       return max;
771     }
772     else if (val < min)
773     {
774       return min;
775     }
776   }
777   return val;
778 }
779
780 /**
781   \brief   Unsigned Saturate
782   \details Saturates an unsigned value.
783   \param [in]  value  Value to be saturated
784   \param [in]    sat  Bit position to saturate to (0..31)
785   \return             Saturated value
786  */
787 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat)
788 {
789   if (sat <= 31U)
790   {
791     const uint32_t max = ((1U << sat) - 1U);
792     if (val > (int32_t)max)
793     {
794       return max;
795     }
796     else if (val < 0)
797     {
798       return 0U;
799     }
800   }
801   return (uint32_t)val;
802 }
803
804 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__  == 1)) || \
805            (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1))     ) */
806
807 /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
808
809
810 /* ###################  Compiler specific Intrinsics  ########################### */
811 /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
812   Access to dedicated SIMD instructions
813   @{
814 */
815
816 #if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1))     )
817
818 #define __SADD8                           __sadd8
819 #define __QADD8                           __qadd8
820 #define __SHADD8                          __shadd8
821 #define __UADD8                           __uadd8
822 #define __UQADD8                          __uqadd8
823 #define __UHADD8                          __uhadd8
824 #define __SSUB8                           __ssub8
825 #define __QSUB8                           __qsub8
826 #define __SHSUB8                          __shsub8
827 #define __USUB8                           __usub8
828 #define __UQSUB8                          __uqsub8
829 #define __UHSUB8                          __uhsub8
830 #define __SADD16                          __sadd16
831 #define __QADD16                          __qadd16
832 #define __SHADD16                         __shadd16
833 #define __UADD16                          __uadd16
834 #define __UQADD16                         __uqadd16
835 #define __UHADD16                         __uhadd16
836 #define __SSUB16                          __ssub16
837 #define __QSUB16                          __qsub16
838 #define __SHSUB16                         __shsub16
839 #define __USUB16                          __usub16
840 #define __UQSUB16                         __uqsub16
841 #define __UHSUB16                         __uhsub16
842 #define __SASX                            __sasx
843 #define __QASX                            __qasx
844 #define __SHASX                           __shasx
845 #define __UASX                            __uasx
846 #define __UQASX                           __uqasx
847 #define __UHASX                           __uhasx
848 #define __SSAX                            __ssax
849 #define __QSAX                            __qsax
850 #define __SHSAX                           __shsax
851 #define __USAX                            __usax
852 #define __UQSAX                           __uqsax
853 #define __UHSAX                           __uhsax
854 #define __USAD8                           __usad8
855 #define __USADA8                          __usada8
856 #define __SSAT16                          __ssat16
857 #define __USAT16                          __usat16
858 #define __UXTB16                          __uxtb16
859 #define __UXTAB16                         __uxtab16
860 #define __SXTB16                          __sxtb16
861 #define __SXTAB16                         __sxtab16
862 #define __SMUAD                           __smuad
863 #define __SMUADX                          __smuadx
864 #define __SMLAD                           __smlad
865 #define __SMLADX                          __smladx
866 #define __SMLALD                          __smlald
867 #define __SMLALDX                         __smlaldx
868 #define __SMUSD                           __smusd
869 #define __SMUSDX                          __smusdx
870 #define __SMLSD                           __smlsd
871 #define __SMLSDX                          __smlsdx
872 #define __SMLSLD                          __smlsld
873 #define __SMLSLDX                         __smlsldx
874 #define __SEL                             __sel
875 #define __QADD                            __qadd
876 #define __QSUB                            __qsub
877
878 #define __PKHBT(ARG1,ARG2,ARG3)          ( ((((uint32_t)(ARG1))          ) & 0x0000FFFFUL) |  \
879                                            ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL)  )
880
881 #define __PKHTB(ARG1,ARG2,ARG3)          ( ((((uint32_t)(ARG1))          ) & 0xFFFF0000UL) |  \
882                                            ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL)  )
883
884 #define __SMMLA(ARG1,ARG2,ARG3)          ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \
885                                                       ((int64_t)(ARG3) << 32U)     ) >> 32U))
886
887 #endif /* ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1))     ) */
888 /*@} end of group CMSIS_SIMD_intrinsics */
889
890
891 #endif /* __CMSIS_ARMCC_H */