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