cmsis_iar.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /**************************************************
  2. *
  3. * This file shall be included in appropriate CMSIS header
  4. * files, to provide required functions and intrinsics when
  5. * building with the IAR C/C++ Compiler for ARM (iccarm).
  6. *
  7. * Copyright 2011 IAR Systems. All rights reserved.
  8. *
  9. * $Revision: 50409 $
  10. *
  11. **************************************************/
  12. #ifndef __CMSIS_IAR_H__
  13. #define __CMSIS_IAR_H__
  14. #ifndef __ICCARM__
  15. #error This file should only be compiled by ICCARM
  16. #endif
  17. #pragma system_include
  18. #include <intrinsics.h>
  19. #if (__CORE__ == __ARM6M__)
  20. /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */
  21. #define __CLZ __cmsis_iar_clz
  22. #define __SSAT __cmsis_iar_ssat
  23. #endif
  24. #pragma diag_suppress=Pe940
  25. #pragma diag_suppress=Pe177
  26. #define __enable_irq __enable_interrupt
  27. #define __disable_irq __disable_interrupt
  28. #define __NOP __no_operation
  29. #if (__VER__ < 6020000) /* If iccarm version is older than 6.20.0 ---------- */
  30. #if (__VER__ < 6010002) /* If iccarm version is older than 6.10.2 ---------- */
  31. static uint32_t __get_APSR(void)
  32. {
  33. __ASM("mrs r0, apsr");
  34. }
  35. static uint32_t __get_xPSR(void)
  36. {
  37. __ASM("mrs r0, psr"); /* assembler does not know "xpsr" */
  38. }
  39. #endif /* __VER__ < 6010002 */
  40. static uint32_t __get_IPSR(void)
  41. {
  42. __ASM("mrs r0, ipsr");
  43. }
  44. static uint32_t __get_PSR(void)
  45. {
  46. __ASM("mrs r0, psr");
  47. }
  48. static uint32_t __get_PSP(void)
  49. {
  50. __ASM("mrs r0, psp");
  51. }
  52. static void __set_PSP(uint32_t topOfProcStack)
  53. {
  54. __ASM("msr psp, r0");
  55. }
  56. static uint32_t __get_MSP(void)
  57. {
  58. __ASM("mrs r0, msp");
  59. }
  60. static void __set_MSP(uint32_t topOfMainStack)
  61. {
  62. __ASM("msr msp, r0");
  63. }
  64. static __INLINE void __WFI(void)
  65. {
  66. __ASM ("wfi");
  67. }
  68. static __INLINE void __WFE(void)
  69. {
  70. __ASM ("wfe");
  71. }
  72. static __INLINE void __SEV(void)
  73. {
  74. __ASM ("sev");
  75. }
  76. static uint32_t __REV16(uint32_t value)
  77. {
  78. __ASM("rev16 r0, r0");
  79. }
  80. #else /* __VER__ < 6020000 */
  81. static uint32_t __get_xPSR(void)
  82. {
  83. return __get_PSR(); /* __get_PSR() intrinsic introduced in iccarm 6.20 */
  84. }
  85. #endif /* __VER__ < 6020000 */
  86. #if (__CORTEX_M >= 0x03) /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
  87. #if (__VER__ < 6020000) /* If iccarm version is older than 6.20.0 ---------- */
  88. static __INLINE void __enable_fault_irq(void)
  89. {
  90. __ASM ("cpsie f");
  91. }
  92. static __INLINE void __disable_fault_irq(void)
  93. {
  94. __ASM ("cpsid f");
  95. }
  96. static uint32_t __RBIT(uint32_t value)
  97. {
  98. __ASM("rbit r0, r0");
  99. }
  100. static uint8_t __LDREXB(volatile uint8_t *addr)
  101. {
  102. __ASM("ldrexb r0, [r0]");
  103. }
  104. static uint16_t __LDREXH(volatile uint16_t *addr)
  105. {
  106. __ASM("ldrexh r0, [r0]");
  107. }
  108. static uint32_t __LDREXW(volatile uint32_t *addr)
  109. {
  110. __ASM("ldrex r0, [r0]");
  111. }
  112. static uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
  113. {
  114. __ASM("strexb r0, r0, [r1]");
  115. }
  116. static uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
  117. {
  118. __ASM("strexh r0, r0, [r1]");
  119. }
  120. static uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
  121. {
  122. __ASM("strex r0, r0, [r1]");
  123. }
  124. static __INLINE void __CLREX(void)
  125. {
  126. __ASM ("clrex");
  127. }
  128. #else /* __VER__ >= 6020000 --------------------- */
  129. #define __LDREXW __LDREX
  130. #define __STREXW __STREX
  131. #define __enable_fault_irq __enable_fiq
  132. #define __disable_fault_irq __disable_fiq
  133. #endif /* __VER__ < 6020000 */
  134. #endif /* (__CORTEX_M >= 0x03) */
  135. #if (__CORTEX_M == 0x04) /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
  136. #if (__VER__ < 6020000) /* If iccarm version is older than 6.20.0 ---------- */
  137. static uint32_t __get_FPSCR(void)
  138. {
  139. #if (__FPU_PRESENT == 1) /* __FPU_PRESENT is defined in the device header file, if present in current device. */
  140. __ASM("vmrs r0, fpscr");
  141. #else
  142. return(0);
  143. #endif
  144. }
  145. static void __set_FPSCR(uint32_t fpscr)
  146. {
  147. #if (__FPU_PRESENT == 1) /* __FPU_PRESENT is defined in the device header file, if present in current device. */
  148. __ASM("vmsr fpscr, r0");
  149. #endif
  150. }
  151. #endif /* __VER__ < 6020000 */
  152. #endif /* (__CORTEX_M == 0x04) */
  153. static __INLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
  154. {
  155. return (op1 >> op2) | (op1 << ((sizeof(op1)*8)-op2));
  156. }
  157. #pragma diag_default=Pe940
  158. #pragma diag_default=Pe177
  159. #endif /* __CMSIS_IAR_H__ */