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