cmsis_iccarm.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /**************************************************************************//**
  2. * @file cmsis_iccarm.h
  3. * @brief CMSIS compiler ICCARM (IAR Compiler for Arm) header file
  4. * @version V5.0.8
  5. * @date 13. November 2022
  6. ******************************************************************************/
  7. //------------------------------------------------------------------------------
  8. //
  9. // Copyright (c) 2017-2018 IAR Systems
  10. // Copyright (c) 2018-2019 Arm Limited
  11. //
  12. // SPDX-License-Identifier: Apache-2.0
  13. //
  14. // Licensed under the Apache License, Version 2.0 (the "License")
  15. // you may not use this file except in compliance with the License.
  16. // You may obtain a copy of the License at
  17. // http://www.apache.org/licenses/LICENSE-2.0
  18. //
  19. // Unless required by applicable law or agreed to in writing, software
  20. // distributed under the License is distributed on an "AS IS" BASIS,
  21. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. // See the License for the specific language governing permissions and
  23. // limitations under the License.
  24. //
  25. //------------------------------------------------------------------------------
  26. #ifndef __CMSIS_ICCARM_H__
  27. #define __CMSIS_ICCARM_H__
  28. #ifndef __ICCARM__
  29. #error This file should only be compiled by ICCARM
  30. #endif
  31. #pragma system_include
  32. #define __IAR_FT _Pragma("inline=forced") __intrinsic
  33. #if (__VER__ >= 8000000)
  34. #define __ICCARM_V8 1
  35. #else
  36. #define __ICCARM_V8 0
  37. #endif
  38. #pragma language=extended
  39. #ifndef __ALIGNED
  40. #if __ICCARM_V8
  41. #define __ALIGNED(x) __attribute__((aligned(x)))
  42. #elif (__VER__ >= 7080000)
  43. /* Needs IAR language extensions */
  44. #define __ALIGNED(x) __attribute__((aligned(x)))
  45. #else
  46. #warning No compiler specific solution for __ALIGNED.__ALIGNED is ignored.
  47. #define __ALIGNED(x)
  48. #endif
  49. #endif
  50. /* Define compiler macros for CPU architecture, used in CMSIS 5.
  51. */
  52. #if __ARM_ARCH_7A__
  53. /* Macro already defined */
  54. #else
  55. #if defined(__ARM7A__)
  56. #define __ARM_ARCH_7A__ 1
  57. #endif
  58. #endif
  59. #ifndef __ASM
  60. #define __ASM __asm
  61. #endif
  62. #ifndef __COMPILER_BARRIER
  63. #define __COMPILER_BARRIER() __ASM volatile("":::"memory")
  64. #endif
  65. #ifndef __INLINE
  66. #define __INLINE inline
  67. #endif
  68. #ifndef __NO_RETURN
  69. #if __ICCARM_V8
  70. #define __NO_RETURN __attribute__((__noreturn__))
  71. #else
  72. #define __NO_RETURN _Pragma("object_attribute=__noreturn")
  73. #endif
  74. #endif
  75. #ifndef __PACKED
  76. #if __ICCARM_V8
  77. #define __PACKED __attribute__((packed, aligned(1)))
  78. #else
  79. /* Needs IAR language extensions */
  80. #define __PACKED __packed
  81. #endif
  82. #endif
  83. #ifndef __PACKED_STRUCT
  84. #if __ICCARM_V8
  85. #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
  86. #else
  87. /* Needs IAR language extensions */
  88. #define __PACKED_STRUCT __packed struct
  89. #endif
  90. #endif
  91. #ifndef __PACKED_UNION
  92. #if __ICCARM_V8
  93. #define __PACKED_UNION union __attribute__((packed, aligned(1)))
  94. #else
  95. /* Needs IAR language extensions */
  96. #define __PACKED_UNION __packed union
  97. #endif
  98. #endif
  99. #ifndef __RESTRICT
  100. #if __ICCARM_V8
  101. #define __RESTRICT __restrict
  102. #else
  103. /* Needs IAR language extensions */
  104. #define __RESTRICT restrict
  105. #endif
  106. #endif
  107. #ifndef __STATIC_INLINE
  108. #define __STATIC_INLINE static inline
  109. #endif
  110. #ifndef __FORCEINLINE
  111. #define __FORCEINLINE _Pragma("inline=forced")
  112. #endif
  113. #ifndef __STATIC_FORCEINLINE
  114. #define __STATIC_FORCEINLINE __FORCEINLINE __STATIC_INLINE
  115. #endif
  116. #ifndef CMSIS_DEPRECATED
  117. #define CMSIS_DEPRECATED __attribute__((deprecated))
  118. #endif
  119. #ifndef __UNALIGNED_UINT16_READ
  120. #pragma language=save
  121. #pragma language=extended
  122. __IAR_FT uint16_t __iar_uint16_read(void const *ptr)
  123. {
  124. return *(__packed uint16_t*)(ptr);
  125. }
  126. #pragma language=restore
  127. #define __UNALIGNED_UINT16_READ(PTR) __iar_uint16_read(PTR)
  128. #endif
  129. #ifndef __UNALIGNED_UINT16_WRITE
  130. #pragma language=save
  131. #pragma language=extended
  132. __IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val)
  133. {
  134. *(__packed uint16_t*)(ptr) = val;;
  135. }
  136. #pragma language=restore
  137. #define __UNALIGNED_UINT16_WRITE(PTR,VAL) __iar_uint16_write(PTR,VAL)
  138. #endif
  139. #ifndef __UNALIGNED_UINT32_READ
  140. #pragma language=save
  141. #pragma language=extended
  142. __IAR_FT uint32_t __iar_uint32_read(void const *ptr)
  143. {
  144. return *(__packed uint32_t*)(ptr);
  145. }
  146. #pragma language=restore
  147. #define __UNALIGNED_UINT32_READ(PTR) __iar_uint32_read(PTR)
  148. #endif
  149. #ifndef __UNALIGNED_UINT32_WRITE
  150. #pragma language=save
  151. #pragma language=extended
  152. __IAR_FT void __iar_uint32_write(void const *ptr, uint32_t val)
  153. {
  154. *(__packed uint32_t*)(ptr) = val;;
  155. }
  156. #pragma language=restore
  157. #define __UNALIGNED_UINT32_WRITE(PTR,VAL) __iar_uint32_write(PTR,VAL)
  158. #endif
  159. #if 0
  160. #ifndef __UNALIGNED_UINT32 /* deprecated */
  161. #pragma language=save
  162. #pragma language=extended
  163. __packed struct __iar_u32 { uint32_t v; };
  164. #pragma language=restore
  165. #define __UNALIGNED_UINT32(PTR) (((struct __iar_u32 *)(PTR))->v)
  166. #endif
  167. #endif
  168. #ifndef __USED
  169. #if __ICCARM_V8
  170. #define __USED __attribute__((used))
  171. #else
  172. #define __USED _Pragma("__root")
  173. #endif
  174. #endif
  175. #ifndef __WEAK
  176. #if __ICCARM_V8
  177. #define __WEAK __attribute__((weak))
  178. #else
  179. #define __WEAK _Pragma("__weak")
  180. #endif
  181. #endif
  182. #ifndef __ICCARM_INTRINSICS_VERSION__
  183. #define __ICCARM_INTRINSICS_VERSION__ 0
  184. #endif
  185. #if __ICCARM_INTRINSICS_VERSION__ == 2
  186. #if defined(__CLZ)
  187. #undef __CLZ
  188. #endif
  189. #if defined(__REVSH)
  190. #undef __REVSH
  191. #endif
  192. #if defined(__RBIT)
  193. #undef __RBIT
  194. #endif
  195. #if defined(__SSAT)
  196. #undef __SSAT
  197. #endif
  198. #if defined(__USAT)
  199. #undef __USAT
  200. #endif
  201. #include "iccarm_builtin.h"
  202. #define __disable_fault_irq __iar_builtin_disable_fiq
  203. #define __disable_irq __iar_builtin_disable_interrupt
  204. #define __enable_fault_irq __iar_builtin_enable_fiq
  205. #define __enable_irq __iar_builtin_enable_interrupt
  206. #define __arm_rsr __iar_builtin_rsr
  207. #define __arm_wsr __iar_builtin_wsr
  208. #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)))
  209. #define __get_FPSCR() (__arm_rsr("FPSCR"))
  210. #define __set_FPSCR(VALUE) (__arm_wsr("FPSCR", (VALUE)))
  211. #else
  212. #define __get_FPSCR() ( 0 )
  213. #define __set_FPSCR(VALUE) ((void)VALUE)
  214. #endif
  215. #define __get_CPSR() (__arm_rsr("CPSR"))
  216. #define __get_mode() (__get_CPSR() & 0x1FU)
  217. #define __set_CPSR(VALUE) (__arm_wsr("CPSR", (VALUE)))
  218. #define __set_mode(VALUE) (__arm_wsr("CPSR_c", (VALUE)))
  219. #define __get_FPEXC() (__arm_rsr("FPEXC"))
  220. #define __set_FPEXC(VALUE) (__arm_wsr("FPEXC", VALUE))
  221. #define __get_CP(cp, op1, RT, CRn, CRm, op2) \
  222. ((RT) = __arm_rsr("p" # cp ":" # op1 ":c" # CRn ":c" # CRm ":" # op2))
  223. #define __set_CP(cp, op1, RT, CRn, CRm, op2) \
  224. (__arm_wsr("p" # cp ":" # op1 ":c" # CRn ":c" # CRm ":" # op2, (RT)))
  225. #define __get_CP64(cp, op1, Rt, CRm) \
  226. __ASM volatile("MRRC p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : "=r" (Rt) : : "memory" )
  227. #define __set_CP64(cp, op1, Rt, CRm) \
  228. __ASM volatile("MCRR p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : : "r" (Rt) : "memory" )
  229. #include "cmsis_cp15.h"
  230. #define __NOP __iar_builtin_no_operation
  231. #define __CLZ __iar_builtin_CLZ
  232. #define __CLREX __iar_builtin_CLREX
  233. #define __DMB __iar_builtin_DMB
  234. #define __DSB __iar_builtin_DSB
  235. #define __ISB __iar_builtin_ISB
  236. #define __LDREXB __iar_builtin_LDREXB
  237. #define __LDREXH __iar_builtin_LDREXH
  238. #define __LDREXW __iar_builtin_LDREX
  239. #define __RBIT __iar_builtin_RBIT
  240. #define __REV __iar_builtin_REV
  241. #define __REV16 __iar_builtin_REV16
  242. __IAR_FT int16_t __REVSH(int16_t val)
  243. {
  244. return (int16_t) __iar_builtin_REVSH(val);
  245. }
  246. #define __ROR __iar_builtin_ROR
  247. #define __RRX __iar_builtin_RRX
  248. #define __SEV __iar_builtin_SEV
  249. #define __SSAT __iar_builtin_SSAT
  250. #define __STREXB __iar_builtin_STREXB
  251. #define __STREXH __iar_builtin_STREXH
  252. #define __STREXW __iar_builtin_STREX
  253. #define __USAT __iar_builtin_USAT
  254. #define __WFE __iar_builtin_WFE
  255. #define __WFI __iar_builtin_WFI
  256. #define __SADD8 __iar_builtin_SADD8
  257. #define __QADD8 __iar_builtin_QADD8
  258. #define __SHADD8 __iar_builtin_SHADD8
  259. #define __UADD8 __iar_builtin_UADD8
  260. #define __UQADD8 __iar_builtin_UQADD8
  261. #define __UHADD8 __iar_builtin_UHADD8
  262. #define __SSUB8 __iar_builtin_SSUB8
  263. #define __QSUB8 __iar_builtin_QSUB8
  264. #define __SHSUB8 __iar_builtin_SHSUB8
  265. #define __USUB8 __iar_builtin_USUB8
  266. #define __UQSUB8 __iar_builtin_UQSUB8
  267. #define __UHSUB8 __iar_builtin_UHSUB8
  268. #define __SADD16 __iar_builtin_SADD16
  269. #define __QADD16 __iar_builtin_QADD16
  270. #define __SHADD16 __iar_builtin_SHADD16
  271. #define __UADD16 __iar_builtin_UADD16
  272. #define __UQADD16 __iar_builtin_UQADD16
  273. #define __UHADD16 __iar_builtin_UHADD16
  274. #define __SSUB16 __iar_builtin_SSUB16
  275. #define __QSUB16 __iar_builtin_QSUB16
  276. #define __SHSUB16 __iar_builtin_SHSUB16
  277. #define __USUB16 __iar_builtin_USUB16
  278. #define __UQSUB16 __iar_builtin_UQSUB16
  279. #define __UHSUB16 __iar_builtin_UHSUB16
  280. #define __SASX __iar_builtin_SASX
  281. #define __QASX __iar_builtin_QASX
  282. #define __SHASX __iar_builtin_SHASX
  283. #define __UASX __iar_builtin_UASX
  284. #define __UQASX __iar_builtin_UQASX
  285. #define __UHASX __iar_builtin_UHASX
  286. #define __SSAX __iar_builtin_SSAX
  287. #define __QSAX __iar_builtin_QSAX
  288. #define __SHSAX __iar_builtin_SHSAX
  289. #define __USAX __iar_builtin_USAX
  290. #define __UQSAX __iar_builtin_UQSAX
  291. #define __UHSAX __iar_builtin_UHSAX
  292. #define __USAD8 __iar_builtin_USAD8
  293. #define __USADA8 __iar_builtin_USADA8
  294. #define __SSAT16 __iar_builtin_SSAT16
  295. #define __USAT16 __iar_builtin_USAT16
  296. #define __UXTB16 __iar_builtin_UXTB16
  297. #define __UXTAB16 __iar_builtin_UXTAB16
  298. #define __SXTB16 __iar_builtin_SXTB16
  299. #define __SXTAB16 __iar_builtin_SXTAB16
  300. #define __SMUAD __iar_builtin_SMUAD
  301. #define __SMUADX __iar_builtin_SMUADX
  302. #define __SMMLA __iar_builtin_SMMLA
  303. #define __SMLAD __iar_builtin_SMLAD
  304. #define __SMLADX __iar_builtin_SMLADX
  305. #define __SMLALD __iar_builtin_SMLALD
  306. #define __SMLALDX __iar_builtin_SMLALDX
  307. #define __SMUSD __iar_builtin_SMUSD
  308. #define __SMUSDX __iar_builtin_SMUSDX
  309. #define __SMLSD __iar_builtin_SMLSD
  310. #define __SMLSDX __iar_builtin_SMLSDX
  311. #define __SMLSLD __iar_builtin_SMLSLD
  312. #define __SMLSLDX __iar_builtin_SMLSLDX
  313. #define __SEL __iar_builtin_SEL
  314. #define __QADD __iar_builtin_QADD
  315. #define __QSUB __iar_builtin_QSUB
  316. #define __PKHBT __iar_builtin_PKHBT
  317. #define __PKHTB __iar_builtin_PKHTB
  318. #else /* __ICCARM_INTRINSICS_VERSION__ == 2 */
  319. #if !((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)))
  320. #define __get_FPSCR __cmsis_iar_get_FPSR_not_active
  321. #endif
  322. #ifdef __INTRINSICS_INCLUDED
  323. #error intrinsics.h is already included previously!
  324. #endif
  325. #include <intrinsics.h>
  326. #if !((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)))
  327. #define __get_FPSCR() (0)
  328. #endif
  329. #pragma diag_suppress=Pe940
  330. #pragma diag_suppress=Pe177
  331. #define __enable_irq __enable_interrupt
  332. #define __disable_irq __disable_interrupt
  333. #define __enable_fault_irq __enable_fiq
  334. #define __disable_fault_irq __disable_fiq
  335. #define __NOP __no_operation
  336. #define __get_xPSR __get_PSR
  337. __IAR_FT void __set_mode(uint32_t mode)
  338. {
  339. __ASM volatile("MSR cpsr_c, %0" : : "r" (mode) : "memory");
  340. }
  341. __IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr)
  342. {
  343. return __LDREX((unsigned long *)ptr);
  344. }
  345. __IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr)
  346. {
  347. return __STREX(value, (unsigned long *)ptr);
  348. }
  349. __IAR_FT uint32_t __RRX(uint32_t value)
  350. {
  351. uint32_t result;
  352. __ASM("RRX %0, %1" : "=r"(result) : "r" (value) : "cc");
  353. return(result);
  354. }
  355. __IAR_FT uint32_t __ROR(uint32_t op1, uint32_t op2)
  356. {
  357. return (op1 >> op2) | (op1 << ((sizeof(op1)*8)-op2));
  358. }
  359. __IAR_FT uint32_t __get_FPEXC(void)
  360. {
  361. #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)))
  362. uint32_t result;
  363. __ASM volatile("VMRS %0, fpexc" : "=r" (result) : : "memory");
  364. return(result);
  365. #else
  366. return(0);
  367. #endif
  368. }
  369. __IAR_FT void __set_FPEXC(uint32_t fpexc)
  370. {
  371. #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)))
  372. __ASM volatile ("VMSR fpexc, %0" : : "r" (fpexc) : "memory");
  373. #endif
  374. }
  375. #define __get_CP(cp, op1, Rt, CRn, CRm, op2) \
  376. __ASM volatile("MRC p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : "=r" (Rt) : : "memory" )
  377. #define __set_CP(cp, op1, Rt, CRn, CRm, op2) \
  378. __ASM volatile("MCR p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : : "r" (Rt) : "memory" )
  379. #define __get_CP64(cp, op1, Rt, CRm) \
  380. __ASM volatile("MRRC p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : "=r" (Rt) : : "memory" )
  381. #define __set_CP64(cp, op1, Rt, CRm) \
  382. __ASM volatile("MCRR p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : : "r" (Rt) : "memory" )
  383. #include "cmsis_cp15.h"
  384. #endif /* __ICCARM_INTRINSICS_VERSION__ == 2 */
  385. #define __BKPT(value) __asm volatile ("BKPT %0" : : "i"(value))
  386. __IAR_FT uint32_t __get_SP_usr(void)
  387. {
  388. uint32_t cpsr;
  389. uint32_t result;
  390. __ASM volatile(
  391. "MRS %0, cpsr \n"
  392. "CPS #0x1F \n" // no effect in USR mode
  393. "MOV %1, sp \n"
  394. "MSR cpsr_c, %2 \n" // no effect in USR mode
  395. "ISB" : "=r"(cpsr), "=r"(result) : "r"(cpsr) : "memory"
  396. );
  397. return result;
  398. }
  399. __IAR_FT void __set_SP_usr(uint32_t topOfProcStack)
  400. {
  401. uint32_t cpsr;
  402. __ASM volatile(
  403. "MRS %0, cpsr \n"
  404. "CPS #0x1F \n" // no effect in USR mode
  405. "MOV sp, %1 \n"
  406. "MSR cpsr_c, %2 \n" // no effect in USR mode
  407. "ISB" : "=r"(cpsr) : "r" (topOfProcStack), "r"(cpsr) : "memory"
  408. );
  409. }
  410. #define __get_mode() (__get_CPSR() & 0x1FU)
  411. __STATIC_INLINE
  412. void __FPU_Enable(void)
  413. {
  414. __ASM volatile(
  415. //Permit access to VFP/NEON, registers by modifying CPACR
  416. " MRC p15,0,R1,c1,c0,2 \n"
  417. " ORR R1,R1,#0x00F00000 \n"
  418. " MCR p15,0,R1,c1,c0,2 \n"
  419. //Ensure that subsequent instructions occur in the context of VFP/NEON access permitted
  420. " ISB \n"
  421. //Enable VFP/NEON
  422. " VMRS R1,FPEXC \n"
  423. " ORR R1,R1,#0x40000000 \n"
  424. " VMSR FPEXC,R1 \n"
  425. //Initialise VFP/NEON registers to 0
  426. " MOV R2,#0 \n"
  427. //Initialise D16 registers to 0
  428. " VMOV D0, R2,R2 \n"
  429. " VMOV D1, R2,R2 \n"
  430. " VMOV D2, R2,R2 \n"
  431. " VMOV D3, R2,R2 \n"
  432. " VMOV D4, R2,R2 \n"
  433. " VMOV D5, R2,R2 \n"
  434. " VMOV D6, R2,R2 \n"
  435. " VMOV D7, R2,R2 \n"
  436. " VMOV D8, R2,R2 \n"
  437. " VMOV D9, R2,R2 \n"
  438. " VMOV D10,R2,R2 \n"
  439. " VMOV D11,R2,R2 \n"
  440. " VMOV D12,R2,R2 \n"
  441. " VMOV D13,R2,R2 \n"
  442. " VMOV D14,R2,R2 \n"
  443. " VMOV D15,R2,R2 \n"
  444. #ifdef __ARM_ADVANCED_SIMD__
  445. //Initialise D32 registers to 0
  446. " VMOV D16,R2,R2 \n"
  447. " VMOV D17,R2,R2 \n"
  448. " VMOV D18,R2,R2 \n"
  449. " VMOV D19,R2,R2 \n"
  450. " VMOV D20,R2,R2 \n"
  451. " VMOV D21,R2,R2 \n"
  452. " VMOV D22,R2,R2 \n"
  453. " VMOV D23,R2,R2 \n"
  454. " VMOV D24,R2,R2 \n"
  455. " VMOV D25,R2,R2 \n"
  456. " VMOV D26,R2,R2 \n"
  457. " VMOV D27,R2,R2 \n"
  458. " VMOV D28,R2,R2 \n"
  459. " VMOV D29,R2,R2 \n"
  460. " VMOV D30,R2,R2 \n"
  461. " VMOV D31,R2,R2 \n"
  462. #endif
  463. //Initialise FPSCR to a known state
  464. " VMRS R1,FPSCR \n"
  465. " MOV32 R2,#0x00086060 \n" //Mask off all bits that do not have to be preserved. Non-preserved bits can/should be zero.
  466. " AND R1,R1,R2 \n"
  467. " VMSR FPSCR,R1 \n"
  468. : : : "cc", "r1", "r2"
  469. );
  470. }
  471. #undef __IAR_FT
  472. #undef __ICCARM_V8
  473. #pragma diag_default=Pe940
  474. #pragma diag_default=Pe177
  475. #endif /* __CMSIS_ICCARM_H__ */