cmsis_iccarm.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  1. /**************************************************************************//**
  2. * @file cmsis_iccarm.h
  3. * @brief CMSIS compiler ICCARM (IAR Compiler for Arm) header file
  4. * @version V5.4.0
  5. * @date 20. January 2023
  6. ******************************************************************************/
  7. //------------------------------------------------------------------------------
  8. //
  9. // Copyright (c) 2017-2021 IAR Systems
  10. // Copyright (c) 2017-2023 Arm Limited. All rights reserved.
  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. #ifndef __ALIGNED
  39. #if __ICCARM_V8
  40. #define __ALIGNED(x) __attribute__((aligned(x)))
  41. #elif (__VER__ >= 7080000)
  42. /* Needs IAR language extensions */
  43. #define __ALIGNED(x) __attribute__((aligned(x)))
  44. #else
  45. #warning No compiler specific solution for __ALIGNED.__ALIGNED is ignored.
  46. #define __ALIGNED(x)
  47. #endif
  48. #endif
  49. /* Define compiler macros for CPU architecture, used in CMSIS 5.
  50. */
  51. #if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__ || __ARM_ARCH_8M_BASE__ || __ARM_ARCH_8M_MAIN__
  52. /* Macros already defined */
  53. #else
  54. #if defined(__ARM8M_MAINLINE__) || defined(__ARM8EM_MAINLINE__)
  55. #define __ARM_ARCH_8M_MAIN__ 1
  56. #elif defined(__ARM8M_BASELINE__)
  57. #define __ARM_ARCH_8M_BASE__ 1
  58. #elif defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M'
  59. #if __ARM_ARCH == 6
  60. #define __ARM_ARCH_6M__ 1
  61. #elif __ARM_ARCH == 7
  62. #if __ARM_FEATURE_DSP
  63. #define __ARM_ARCH_7EM__ 1
  64. #else
  65. #define __ARM_ARCH_7M__ 1
  66. #endif
  67. #endif /* __ARM_ARCH */
  68. #endif /* __ARM_ARCH_PROFILE == 'M' */
  69. #endif
  70. /* Alternativ core deduction for older ICCARM's */
  71. #if !defined(__ARM_ARCH_6M__) && !defined(__ARM_ARCH_7M__) && !defined(__ARM_ARCH_7EM__) && \
  72. !defined(__ARM_ARCH_8M_BASE__) && !defined(__ARM_ARCH_8M_MAIN__)
  73. #if defined(__ARM6M__) && (__CORE__ == __ARM6M__)
  74. #define __ARM_ARCH_6M__ 1
  75. #elif defined(__ARM7M__) && (__CORE__ == __ARM7M__)
  76. #define __ARM_ARCH_7M__ 1
  77. #elif defined(__ARM7EM__) && (__CORE__ == __ARM7EM__)
  78. #define __ARM_ARCH_7EM__ 1
  79. #elif defined(__ARM8M_BASELINE__) && (__CORE == __ARM8M_BASELINE__)
  80. #define __ARM_ARCH_8M_BASE__ 1
  81. #elif defined(__ARM8M_MAINLINE__) && (__CORE == __ARM8M_MAINLINE__)
  82. #define __ARM_ARCH_8M_MAIN__ 1
  83. #elif defined(__ARM8EM_MAINLINE__) && (__CORE == __ARM8EM_MAINLINE__)
  84. #define __ARM_ARCH_8M_MAIN__ 1
  85. #else
  86. #error "Unknown target."
  87. #endif
  88. #endif
  89. #if defined(__ARM_ARCH_6M__) && __ARM_ARCH_6M__==1
  90. #define __IAR_M0_FAMILY 1
  91. #elif defined(__ARM_ARCH_8M_BASE__) && __ARM_ARCH_8M_BASE__==1
  92. #define __IAR_M0_FAMILY 1
  93. #else
  94. #define __IAR_M0_FAMILY 0
  95. #endif
  96. #ifndef __NO_INIT
  97. #define __NO_INIT __attribute__ ((section (".noinit")))
  98. #endif
  99. #ifndef __ALIAS
  100. #define __ALIAS(x) __attribute__ ((alias(x)))
  101. #endif
  102. #ifndef __ASM
  103. #define __ASM __asm
  104. #endif
  105. #ifndef __COMPILER_BARRIER
  106. #define __COMPILER_BARRIER() __ASM volatile("":::"memory")
  107. #endif
  108. #ifndef __INLINE
  109. #define __INLINE inline
  110. #endif
  111. #ifndef __NO_RETURN
  112. #if __ICCARM_V8
  113. #define __NO_RETURN __attribute__((__noreturn__))
  114. #else
  115. #define __NO_RETURN _Pragma("object_attribute=__noreturn")
  116. #endif
  117. #endif
  118. #ifndef __PACKED
  119. #if __ICCARM_V8
  120. #define __PACKED __attribute__((packed, aligned(1)))
  121. #else
  122. /* Needs IAR language extensions */
  123. #define __PACKED __packed
  124. #endif
  125. #endif
  126. #ifndef __PACKED_STRUCT
  127. #if __ICCARM_V8
  128. #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
  129. #else
  130. /* Needs IAR language extensions */
  131. #define __PACKED_STRUCT __packed struct
  132. #endif
  133. #endif
  134. #ifndef __PACKED_UNION
  135. #if __ICCARM_V8
  136. #define __PACKED_UNION union __attribute__((packed, aligned(1)))
  137. #else
  138. /* Needs IAR language extensions */
  139. #define __PACKED_UNION __packed union
  140. #endif
  141. #endif
  142. #ifndef __RESTRICT
  143. #if __ICCARM_V8
  144. #define __RESTRICT __restrict
  145. #else
  146. /* Needs IAR language extensions */
  147. #define __RESTRICT restrict
  148. #endif
  149. #endif
  150. #ifndef __STATIC_INLINE
  151. #define __STATIC_INLINE static inline
  152. #endif
  153. #ifndef __FORCEINLINE
  154. #define __FORCEINLINE _Pragma("inline=forced")
  155. #endif
  156. #ifndef __STATIC_FORCEINLINE
  157. #define __STATIC_FORCEINLINE __FORCEINLINE __STATIC_INLINE
  158. #endif
  159. #ifndef __UNALIGNED_UINT16_READ
  160. #pragma language=save
  161. #pragma language=extended
  162. __IAR_FT uint16_t __iar_uint16_read(void const *ptr)
  163. {
  164. return *(__packed uint16_t*)(ptr);
  165. }
  166. #pragma language=restore
  167. #define __UNALIGNED_UINT16_READ(PTR) __iar_uint16_read(PTR)
  168. #endif
  169. #ifndef __UNALIGNED_UINT16_WRITE
  170. #pragma language=save
  171. #pragma language=extended
  172. __IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val)
  173. {
  174. *(__packed uint16_t*)(ptr) = val;;
  175. }
  176. #pragma language=restore
  177. #define __UNALIGNED_UINT16_WRITE(PTR,VAL) __iar_uint16_write(PTR,VAL)
  178. #endif
  179. #ifndef __UNALIGNED_UINT32_READ
  180. #pragma language=save
  181. #pragma language=extended
  182. __IAR_FT uint32_t __iar_uint32_read(void const *ptr)
  183. {
  184. return *(__packed uint32_t*)(ptr);
  185. }
  186. #pragma language=restore
  187. #define __UNALIGNED_UINT32_READ(PTR) __iar_uint32_read(PTR)
  188. #endif
  189. #ifndef __UNALIGNED_UINT32_WRITE
  190. #pragma language=save
  191. #pragma language=extended
  192. __IAR_FT void __iar_uint32_write(void const *ptr, uint32_t val)
  193. {
  194. *(__packed uint32_t*)(ptr) = val;;
  195. }
  196. #pragma language=restore
  197. #define __UNALIGNED_UINT32_WRITE(PTR,VAL) __iar_uint32_write(PTR,VAL)
  198. #endif
  199. #ifndef __UNALIGNED_UINT32 /* deprecated */
  200. #pragma language=save
  201. #pragma language=extended
  202. __packed struct __iar_u32 { uint32_t v; };
  203. #pragma language=restore
  204. #define __UNALIGNED_UINT32(PTR) (((struct __iar_u32 *)(PTR))->v)
  205. #endif
  206. #ifndef __USED
  207. #if __ICCARM_V8
  208. #define __USED __attribute__((used))
  209. #else
  210. #define __USED _Pragma("__root")
  211. #endif
  212. #endif
  213. #undef __WEAK /* undo the definition from DLib_Defaults.h */
  214. #ifndef __WEAK
  215. #if __ICCARM_V8
  216. #define __WEAK __attribute__((weak))
  217. #else
  218. #define __WEAK _Pragma("__weak")
  219. #endif
  220. #endif
  221. #ifndef __PROGRAM_START
  222. #define __PROGRAM_START __iar_program_start
  223. #endif
  224. #ifndef __INITIAL_SP
  225. #define __INITIAL_SP CSTACK$$Limit
  226. #endif
  227. #ifndef __STACK_LIMIT
  228. #define __STACK_LIMIT CSTACK$$Base
  229. #endif
  230. #ifndef __VECTOR_TABLE
  231. #define __VECTOR_TABLE __vector_table
  232. #endif
  233. #ifndef __VECTOR_TABLE_ATTRIBUTE
  234. #define __VECTOR_TABLE_ATTRIBUTE @".intvec"
  235. #endif
  236. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
  237. #ifndef __STACK_SEAL
  238. #define __STACK_SEAL STACKSEAL$$Base
  239. #endif
  240. #ifndef __TZ_STACK_SEAL_SIZE
  241. #define __TZ_STACK_SEAL_SIZE 8U
  242. #endif
  243. #ifndef __TZ_STACK_SEAL_VALUE
  244. #define __TZ_STACK_SEAL_VALUE 0xFEF5EDA5FEF5EDA5ULL
  245. #endif
  246. __STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) {
  247. *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE;
  248. }
  249. #endif
  250. #ifndef __ICCARM_INTRINSICS_VERSION__
  251. #define __ICCARM_INTRINSICS_VERSION__ 0
  252. #endif
  253. #if __ICCARM_INTRINSICS_VERSION__ == 2
  254. #if defined(__CLZ)
  255. #undef __CLZ
  256. #endif
  257. #if defined(__REVSH)
  258. #undef __REVSH
  259. #endif
  260. #if defined(__RBIT)
  261. #undef __RBIT
  262. #endif
  263. #if defined(__SSAT)
  264. #undef __SSAT
  265. #endif
  266. #if defined(__USAT)
  267. #undef __USAT
  268. #endif
  269. #include "iccarm_builtin.h"
  270. #define __disable_fault_irq __iar_builtin_disable_fiq
  271. #define __disable_irq __iar_builtin_disable_interrupt
  272. #define __enable_fault_irq __iar_builtin_enable_fiq
  273. #define __enable_irq __iar_builtin_enable_interrupt
  274. #define __arm_rsr __iar_builtin_rsr
  275. #define __arm_wsr __iar_builtin_wsr
  276. #define __get_APSR() (__arm_rsr("APSR"))
  277. #define __get_BASEPRI() (__arm_rsr("BASEPRI"))
  278. #define __get_CONTROL() (__arm_rsr("CONTROL"))
  279. #define __get_FAULTMASK() (__arm_rsr("FAULTMASK"))
  280. #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
  281. (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
  282. #define __get_FPSCR() (__arm_rsr("FPSCR"))
  283. #define __set_FPSCR(VALUE) (__arm_wsr("FPSCR", (VALUE)))
  284. #else
  285. #define __get_FPSCR() ( 0 )
  286. #define __set_FPSCR(VALUE) ((void)VALUE)
  287. #endif
  288. #define __get_IPSR() (__arm_rsr("IPSR"))
  289. #define __get_MSP() (__arm_rsr("MSP"))
  290. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  291. (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
  292. // without main extensions, the non-secure MSPLIM is RAZ/WI
  293. #define __get_MSPLIM() (0U)
  294. #else
  295. #define __get_MSPLIM() (__arm_rsr("MSPLIM"))
  296. #endif
  297. #define __get_PRIMASK() (__arm_rsr("PRIMASK"))
  298. #define __get_PSP() (__arm_rsr("PSP"))
  299. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  300. (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
  301. // without main extensions, the non-secure PSPLIM is RAZ/WI
  302. #define __get_PSPLIM() (0U)
  303. #else
  304. #define __get_PSPLIM() (__arm_rsr("PSPLIM"))
  305. #endif
  306. #define __get_xPSR() (__arm_rsr("xPSR"))
  307. #define __set_BASEPRI(VALUE) (__arm_wsr("BASEPRI", (VALUE)))
  308. #define __set_BASEPRI_MAX(VALUE) (__arm_wsr("BASEPRI_MAX", (VALUE)))
  309. __STATIC_FORCEINLINE void __set_CONTROL(uint32_t control)
  310. {
  311. __arm_wsr("CONTROL", control);
  312. __iar_builtin_ISB();
  313. }
  314. #define __set_FAULTMASK(VALUE) (__arm_wsr("FAULTMASK", (VALUE)))
  315. #define __set_MSP(VALUE) (__arm_wsr("MSP", (VALUE)))
  316. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  317. (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
  318. // without main extensions, the non-secure MSPLIM is RAZ/WI
  319. #define __set_MSPLIM(VALUE) ((void)(VALUE))
  320. #else
  321. #define __set_MSPLIM(VALUE) (__arm_wsr("MSPLIM", (VALUE)))
  322. #endif
  323. #define __set_PRIMASK(VALUE) (__arm_wsr("PRIMASK", (VALUE)))
  324. #define __set_PSP(VALUE) (__arm_wsr("PSP", (VALUE)))
  325. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  326. (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
  327. // without main extensions, the non-secure PSPLIM is RAZ/WI
  328. #define __set_PSPLIM(VALUE) ((void)(VALUE))
  329. #else
  330. #define __set_PSPLIM(VALUE) (__arm_wsr("PSPLIM", (VALUE)))
  331. #endif
  332. #define __TZ_get_CONTROL_NS() (__arm_rsr("CONTROL_NS"))
  333. __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
  334. {
  335. __arm_wsr("CONTROL_NS", control);
  336. __iar_builtin_ISB();
  337. }
  338. #define __TZ_get_PSP_NS() (__arm_rsr("PSP_NS"))
  339. #define __TZ_set_PSP_NS(VALUE) (__arm_wsr("PSP_NS", (VALUE)))
  340. #define __TZ_get_MSP_NS() (__arm_rsr("MSP_NS"))
  341. #define __TZ_set_MSP_NS(VALUE) (__arm_wsr("MSP_NS", (VALUE)))
  342. #define __TZ_get_SP_NS() (__arm_rsr("SP_NS"))
  343. #define __TZ_set_SP_NS(VALUE) (__arm_wsr("SP_NS", (VALUE)))
  344. #define __TZ_get_PRIMASK_NS() (__arm_rsr("PRIMASK_NS"))
  345. #define __TZ_set_PRIMASK_NS(VALUE) (__arm_wsr("PRIMASK_NS", (VALUE)))
  346. #define __TZ_get_BASEPRI_NS() (__arm_rsr("BASEPRI_NS"))
  347. #define __TZ_set_BASEPRI_NS(VALUE) (__arm_wsr("BASEPRI_NS", (VALUE)))
  348. #define __TZ_get_FAULTMASK_NS() (__arm_rsr("FAULTMASK_NS"))
  349. #define __TZ_set_FAULTMASK_NS(VALUE)(__arm_wsr("FAULTMASK_NS", (VALUE)))
  350. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  351. (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
  352. // without main extensions, the non-secure PSPLIM is RAZ/WI
  353. #define __TZ_get_PSPLIM_NS() (0U)
  354. #define __TZ_set_PSPLIM_NS(VALUE) ((void)(VALUE))
  355. #else
  356. #define __TZ_get_PSPLIM_NS() (__arm_rsr("PSPLIM_NS"))
  357. #define __TZ_set_PSPLIM_NS(VALUE) (__arm_wsr("PSPLIM_NS", (VALUE)))
  358. #endif
  359. #define __TZ_get_MSPLIM_NS() (__arm_rsr("MSPLIM_NS"))
  360. #define __TZ_set_MSPLIM_NS(VALUE) (__arm_wsr("MSPLIM_NS", (VALUE)))
  361. #define __NOP __iar_builtin_no_operation
  362. #define __CLZ __iar_builtin_CLZ
  363. #define __CLREX __iar_builtin_CLREX
  364. #define __DMB __iar_builtin_DMB
  365. #define __DSB __iar_builtin_DSB
  366. #define __ISB __iar_builtin_ISB
  367. #define __LDREXB __iar_builtin_LDREXB
  368. #define __LDREXH __iar_builtin_LDREXH
  369. #define __LDREXW __iar_builtin_LDREX
  370. #define __RBIT __iar_builtin_RBIT
  371. #define __REV __iar_builtin_REV
  372. #define __REV16 __iar_builtin_REV16
  373. __IAR_FT int16_t __REVSH(int16_t val)
  374. {
  375. return (int16_t) __iar_builtin_REVSH(val);
  376. }
  377. #define __ROR __iar_builtin_ROR
  378. #define __RRX __iar_builtin_RRX
  379. #define __SEV __iar_builtin_SEV
  380. #if !__IAR_M0_FAMILY
  381. #define __SSAT __iar_builtin_SSAT
  382. #endif
  383. #define __STREXB __iar_builtin_STREXB
  384. #define __STREXH __iar_builtin_STREXH
  385. #define __STREXW __iar_builtin_STREX
  386. #if !__IAR_M0_FAMILY
  387. #define __USAT __iar_builtin_USAT
  388. #endif
  389. #define __WFE __iar_builtin_WFE
  390. #define __WFI __iar_builtin_WFI
  391. #if __ARM_MEDIA__
  392. #define __SADD8 __iar_builtin_SADD8
  393. #define __QADD8 __iar_builtin_QADD8
  394. #define __SHADD8 __iar_builtin_SHADD8
  395. #define __UADD8 __iar_builtin_UADD8
  396. #define __UQADD8 __iar_builtin_UQADD8
  397. #define __UHADD8 __iar_builtin_UHADD8
  398. #define __SSUB8 __iar_builtin_SSUB8
  399. #define __QSUB8 __iar_builtin_QSUB8
  400. #define __SHSUB8 __iar_builtin_SHSUB8
  401. #define __USUB8 __iar_builtin_USUB8
  402. #define __UQSUB8 __iar_builtin_UQSUB8
  403. #define __UHSUB8 __iar_builtin_UHSUB8
  404. #define __SADD16 __iar_builtin_SADD16
  405. #define __QADD16 __iar_builtin_QADD16
  406. #define __SHADD16 __iar_builtin_SHADD16
  407. #define __UADD16 __iar_builtin_UADD16
  408. #define __UQADD16 __iar_builtin_UQADD16
  409. #define __UHADD16 __iar_builtin_UHADD16
  410. #define __SSUB16 __iar_builtin_SSUB16
  411. #define __QSUB16 __iar_builtin_QSUB16
  412. #define __SHSUB16 __iar_builtin_SHSUB16
  413. #define __USUB16 __iar_builtin_USUB16
  414. #define __UQSUB16 __iar_builtin_UQSUB16
  415. #define __UHSUB16 __iar_builtin_UHSUB16
  416. #define __SASX __iar_builtin_SASX
  417. #define __QASX __iar_builtin_QASX
  418. #define __SHASX __iar_builtin_SHASX
  419. #define __UASX __iar_builtin_UASX
  420. #define __UQASX __iar_builtin_UQASX
  421. #define __UHASX __iar_builtin_UHASX
  422. #define __SSAX __iar_builtin_SSAX
  423. #define __QSAX __iar_builtin_QSAX
  424. #define __SHSAX __iar_builtin_SHSAX
  425. #define __USAX __iar_builtin_USAX
  426. #define __UQSAX __iar_builtin_UQSAX
  427. #define __UHSAX __iar_builtin_UHSAX
  428. #define __USAD8 __iar_builtin_USAD8
  429. #define __USADA8 __iar_builtin_USADA8
  430. #define __SSAT16 __iar_builtin_SSAT16
  431. #define __USAT16 __iar_builtin_USAT16
  432. #define __UXTB16 __iar_builtin_UXTB16
  433. #define __UXTAB16 __iar_builtin_UXTAB16
  434. #define __SXTB16 __iar_builtin_SXTB16
  435. #define __SXTAB16 __iar_builtin_SXTAB16
  436. #define __SMUAD __iar_builtin_SMUAD
  437. #define __SMUADX __iar_builtin_SMUADX
  438. #define __SMMLA __iar_builtin_SMMLA
  439. #define __SMLAD __iar_builtin_SMLAD
  440. #define __SMLADX __iar_builtin_SMLADX
  441. #define __SMLALD __iar_builtin_SMLALD
  442. #define __SMLALDX __iar_builtin_SMLALDX
  443. #define __SMUSD __iar_builtin_SMUSD
  444. #define __SMUSDX __iar_builtin_SMUSDX
  445. #define __SMLSD __iar_builtin_SMLSD
  446. #define __SMLSDX __iar_builtin_SMLSDX
  447. #define __SMLSLD __iar_builtin_SMLSLD
  448. #define __SMLSLDX __iar_builtin_SMLSLDX
  449. #define __SEL __iar_builtin_SEL
  450. #define __QADD __iar_builtin_QADD
  451. #define __QSUB __iar_builtin_QSUB
  452. #define __PKHBT __iar_builtin_PKHBT
  453. #define __PKHTB __iar_builtin_PKHTB
  454. #endif
  455. #else /* __ICCARM_INTRINSICS_VERSION__ == 2 */
  456. #if __IAR_M0_FAMILY
  457. /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */
  458. #define __CLZ __cmsis_iar_clz_not_active
  459. #define __SSAT __cmsis_iar_ssat_not_active
  460. #define __USAT __cmsis_iar_usat_not_active
  461. #define __RBIT __cmsis_iar_rbit_not_active
  462. #define __get_APSR __cmsis_iar_get_APSR_not_active
  463. #endif
  464. #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
  465. (defined (__FPU_USED ) && (__FPU_USED == 1U)) ))
  466. #define __get_FPSCR __cmsis_iar_get_FPSR_not_active
  467. #define __set_FPSCR __cmsis_iar_set_FPSR_not_active
  468. #endif
  469. #ifdef __INTRINSICS_INCLUDED
  470. #error intrinsics.h is already included previously!
  471. #endif
  472. #include <intrinsics.h>
  473. #if __IAR_M0_FAMILY
  474. /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */
  475. #undef __CLZ
  476. #undef __SSAT
  477. #undef __USAT
  478. #undef __RBIT
  479. #undef __get_APSR
  480. __STATIC_INLINE uint8_t __CLZ(uint32_t data)
  481. {
  482. if (data == 0U) { return 32U; }
  483. uint32_t count = 0U;
  484. uint32_t mask = 0x80000000U;
  485. while ((data & mask) == 0U)
  486. {
  487. count += 1U;
  488. mask = mask >> 1U;
  489. }
  490. return count;
  491. }
  492. __STATIC_INLINE uint32_t __RBIT(uint32_t v)
  493. {
  494. uint8_t sc = 31U;
  495. uint32_t r = v;
  496. for (v >>= 1U; v; v >>= 1U)
  497. {
  498. r <<= 1U;
  499. r |= v & 1U;
  500. sc--;
  501. }
  502. return (r << sc);
  503. }
  504. __STATIC_INLINE uint32_t __get_APSR(void)
  505. {
  506. uint32_t res;
  507. __asm("MRS %0,APSR" : "=r" (res));
  508. return res;
  509. }
  510. #endif
  511. #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
  512. (defined (__FPU_USED ) && (__FPU_USED == 1U)) ))
  513. #undef __get_FPSCR
  514. #undef __set_FPSCR
  515. #define __get_FPSCR() (0)
  516. #define __set_FPSCR(VALUE) ((void)VALUE)
  517. #endif
  518. #pragma diag_suppress=Pe940
  519. #pragma diag_suppress=Pe177
  520. #define __enable_irq __enable_interrupt
  521. #define __disable_irq __disable_interrupt
  522. #define __NOP __no_operation
  523. #define __get_xPSR __get_PSR
  524. #if (!defined(__ARM_ARCH_6M__) || __ARM_ARCH_6M__==0)
  525. __IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr)
  526. {
  527. return __LDREX((unsigned long *)ptr);
  528. }
  529. __IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr)
  530. {
  531. return __STREX(value, (unsigned long *)ptr);
  532. }
  533. #endif
  534. /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
  535. #if (__CORTEX_M >= 0x03)
  536. __IAR_FT uint32_t __RRX(uint32_t value)
  537. {
  538. uint32_t result;
  539. __ASM volatile("RRX %0, %1" : "=r"(result) : "r" (value));
  540. return(result);
  541. }
  542. __IAR_FT void __set_BASEPRI_MAX(uint32_t value)
  543. {
  544. __asm volatile("MSR BASEPRI_MAX,%0"::"r" (value));
  545. }
  546. #define __enable_fault_irq __enable_fiq
  547. #define __disable_fault_irq __disable_fiq
  548. #endif /* (__CORTEX_M >= 0x03) */
  549. __IAR_FT uint32_t __ROR(uint32_t op1, uint32_t op2)
  550. {
  551. return (op1 >> op2) | (op1 << ((sizeof(op1)*8)-op2));
  552. }
  553. #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
  554. (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
  555. __IAR_FT uint32_t __get_MSPLIM(void)
  556. {
  557. uint32_t res;
  558. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  559. (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
  560. // without main extensions, the non-secure MSPLIM is RAZ/WI
  561. res = 0U;
  562. #else
  563. __asm volatile("MRS %0,MSPLIM" : "=r" (res));
  564. #endif
  565. return res;
  566. }
  567. __IAR_FT void __set_MSPLIM(uint32_t value)
  568. {
  569. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  570. (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
  571. // without main extensions, the non-secure MSPLIM is RAZ/WI
  572. (void)value;
  573. #else
  574. __asm volatile("MSR MSPLIM,%0" :: "r" (value));
  575. #endif
  576. }
  577. __IAR_FT uint32_t __get_PSPLIM(void)
  578. {
  579. uint32_t res;
  580. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  581. (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
  582. // without main extensions, the non-secure PSPLIM is RAZ/WI
  583. res = 0U;
  584. #else
  585. __asm volatile("MRS %0,PSPLIM" : "=r" (res));
  586. #endif
  587. return res;
  588. }
  589. __IAR_FT void __set_PSPLIM(uint32_t value)
  590. {
  591. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  592. (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
  593. // without main extensions, the non-secure PSPLIM is RAZ/WI
  594. (void)value;
  595. #else
  596. __asm volatile("MSR PSPLIM,%0" :: "r" (value));
  597. #endif
  598. }
  599. __IAR_FT uint32_t __TZ_get_CONTROL_NS(void)
  600. {
  601. uint32_t res;
  602. __asm volatile("MRS %0,CONTROL_NS" : "=r" (res));
  603. return res;
  604. }
  605. __IAR_FT void __TZ_set_CONTROL_NS(uint32_t value)
  606. {
  607. __asm volatile("MSR CONTROL_NS,%0" :: "r" (value));
  608. __iar_builtin_ISB();
  609. }
  610. __IAR_FT uint32_t __TZ_get_PSP_NS(void)
  611. {
  612. uint32_t res;
  613. __asm volatile("MRS %0,PSP_NS" : "=r" (res));
  614. return res;
  615. }
  616. __IAR_FT void __TZ_set_PSP_NS(uint32_t value)
  617. {
  618. __asm volatile("MSR PSP_NS,%0" :: "r" (value));
  619. }
  620. __IAR_FT uint32_t __TZ_get_MSP_NS(void)
  621. {
  622. uint32_t res;
  623. __asm volatile("MRS %0,MSP_NS" : "=r" (res));
  624. return res;
  625. }
  626. __IAR_FT void __TZ_set_MSP_NS(uint32_t value)
  627. {
  628. __asm volatile("MSR MSP_NS,%0" :: "r" (value));
  629. }
  630. __IAR_FT uint32_t __TZ_get_SP_NS(void)
  631. {
  632. uint32_t res;
  633. __asm volatile("MRS %0,SP_NS" : "=r" (res));
  634. return res;
  635. }
  636. __IAR_FT void __TZ_set_SP_NS(uint32_t value)
  637. {
  638. __asm volatile("MSR SP_NS,%0" :: "r" (value));
  639. }
  640. __IAR_FT uint32_t __TZ_get_PRIMASK_NS(void)
  641. {
  642. uint32_t res;
  643. __asm volatile("MRS %0,PRIMASK_NS" : "=r" (res));
  644. return res;
  645. }
  646. __IAR_FT void __TZ_set_PRIMASK_NS(uint32_t value)
  647. {
  648. __asm volatile("MSR PRIMASK_NS,%0" :: "r" (value));
  649. }
  650. __IAR_FT uint32_t __TZ_get_BASEPRI_NS(void)
  651. {
  652. uint32_t res;
  653. __asm volatile("MRS %0,BASEPRI_NS" : "=r" (res));
  654. return res;
  655. }
  656. __IAR_FT void __TZ_set_BASEPRI_NS(uint32_t value)
  657. {
  658. __asm volatile("MSR BASEPRI_NS,%0" :: "r" (value));
  659. }
  660. __IAR_FT uint32_t __TZ_get_FAULTMASK_NS(void)
  661. {
  662. uint32_t res;
  663. __asm volatile("MRS %0,FAULTMASK_NS" : "=r" (res));
  664. return res;
  665. }
  666. __IAR_FT void __TZ_set_FAULTMASK_NS(uint32_t value)
  667. {
  668. __asm volatile("MSR FAULTMASK_NS,%0" :: "r" (value));
  669. }
  670. __IAR_FT uint32_t __TZ_get_PSPLIM_NS(void)
  671. {
  672. uint32_t res;
  673. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  674. (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
  675. // without main extensions, the non-secure PSPLIM is RAZ/WI
  676. res = 0U;
  677. #else
  678. __asm volatile("MRS %0,PSPLIM_NS" : "=r" (res));
  679. #endif
  680. return res;
  681. }
  682. __IAR_FT void __TZ_set_PSPLIM_NS(uint32_t value)
  683. {
  684. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  685. (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
  686. // without main extensions, the non-secure PSPLIM is RAZ/WI
  687. (void)value;
  688. #else
  689. __asm volatile("MSR PSPLIM_NS,%0" :: "r" (value));
  690. #endif
  691. }
  692. __IAR_FT uint32_t __TZ_get_MSPLIM_NS(void)
  693. {
  694. uint32_t res;
  695. __asm volatile("MRS %0,MSPLIM_NS" : "=r" (res));
  696. return res;
  697. }
  698. __IAR_FT void __TZ_set_MSPLIM_NS(uint32_t value)
  699. {
  700. __asm volatile("MSR MSPLIM_NS,%0" :: "r" (value));
  701. }
  702. #endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */
  703. #endif /* __ICCARM_INTRINSICS_VERSION__ == 2 */
  704. #define __BKPT(value) __asm volatile ("BKPT %0" : : "i"(value))
  705. #if __IAR_M0_FAMILY
  706. __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat)
  707. {
  708. if ((sat >= 1U) && (sat <= 32U))
  709. {
  710. const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
  711. const int32_t min = -1 - max ;
  712. if (val > max)
  713. {
  714. return max;
  715. }
  716. else if (val < min)
  717. {
  718. return min;
  719. }
  720. }
  721. return val;
  722. }
  723. __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat)
  724. {
  725. if (sat <= 31U)
  726. {
  727. const uint32_t max = ((1U << sat) - 1U);
  728. if (val > (int32_t)max)
  729. {
  730. return max;
  731. }
  732. else if (val < 0)
  733. {
  734. return 0U;
  735. }
  736. }
  737. return (uint32_t)val;
  738. }
  739. #endif
  740. #if (__CORTEX_M >= 0x03) /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
  741. __IAR_FT uint8_t __LDRBT(volatile uint8_t *addr)
  742. {
  743. uint32_t res;
  744. __ASM volatile ("LDRBT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
  745. return ((uint8_t)res);
  746. }
  747. __IAR_FT uint16_t __LDRHT(volatile uint16_t *addr)
  748. {
  749. uint32_t res;
  750. __ASM volatile ("LDRHT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
  751. return ((uint16_t)res);
  752. }
  753. __IAR_FT uint32_t __LDRT(volatile uint32_t *addr)
  754. {
  755. uint32_t res;
  756. __ASM volatile ("LDRT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
  757. return res;
  758. }
  759. __IAR_FT void __STRBT(uint8_t value, volatile uint8_t *addr)
  760. {
  761. __ASM volatile ("STRBT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory");
  762. }
  763. __IAR_FT void __STRHT(uint16_t value, volatile uint16_t *addr)
  764. {
  765. __ASM volatile ("STRHT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory");
  766. }
  767. __IAR_FT void __STRT(uint32_t value, volatile uint32_t *addr)
  768. {
  769. __ASM volatile ("STRT %1, [%0]" : : "r" (addr), "r" (value) : "memory");
  770. }
  771. #endif /* (__CORTEX_M >= 0x03) */
  772. #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
  773. (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
  774. __IAR_FT uint8_t __LDAB(volatile uint8_t *ptr)
  775. {
  776. uint32_t res;
  777. __ASM volatile ("LDAB %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
  778. return ((uint8_t)res);
  779. }
  780. __IAR_FT uint16_t __LDAH(volatile uint16_t *ptr)
  781. {
  782. uint32_t res;
  783. __ASM volatile ("LDAH %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
  784. return ((uint16_t)res);
  785. }
  786. __IAR_FT uint32_t __LDA(volatile uint32_t *ptr)
  787. {
  788. uint32_t res;
  789. __ASM volatile ("LDA %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
  790. return res;
  791. }
  792. __IAR_FT void __STLB(uint8_t value, volatile uint8_t *ptr)
  793. {
  794. __ASM volatile ("STLB %1, [%0]" :: "r" (ptr), "r" (value) : "memory");
  795. }
  796. __IAR_FT void __STLH(uint16_t value, volatile uint16_t *ptr)
  797. {
  798. __ASM volatile ("STLH %1, [%0]" :: "r" (ptr), "r" (value) : "memory");
  799. }
  800. __IAR_FT void __STL(uint32_t value, volatile uint32_t *ptr)
  801. {
  802. __ASM volatile ("STL %1, [%0]" :: "r" (ptr), "r" (value) : "memory");
  803. }
  804. __IAR_FT uint8_t __LDAEXB(volatile uint8_t *ptr)
  805. {
  806. uint32_t res;
  807. __ASM volatile ("LDAEXB %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
  808. return ((uint8_t)res);
  809. }
  810. __IAR_FT uint16_t __LDAEXH(volatile uint16_t *ptr)
  811. {
  812. uint32_t res;
  813. __ASM volatile ("LDAEXH %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
  814. return ((uint16_t)res);
  815. }
  816. __IAR_FT uint32_t __LDAEX(volatile uint32_t *ptr)
  817. {
  818. uint32_t res;
  819. __ASM volatile ("LDAEX %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
  820. return res;
  821. }
  822. __IAR_FT uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr)
  823. {
  824. uint32_t res;
  825. __ASM volatile ("STLEXB %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory");
  826. return res;
  827. }
  828. __IAR_FT uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr)
  829. {
  830. uint32_t res;
  831. __ASM volatile ("STLEXH %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory");
  832. return res;
  833. }
  834. __IAR_FT uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr)
  835. {
  836. uint32_t res;
  837. __ASM volatile ("STLEX %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory");
  838. return res;
  839. }
  840. #endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */
  841. #undef __IAR_FT
  842. #undef __IAR_M0_FAMILY
  843. #undef __ICCARM_V8
  844. #pragma diag_default=Pe940
  845. #pragma diag_default=Pe177
  846. #define __SXTB16_RORn(ARG1, ARG2) __SXTB16(__ROR(ARG1, ARG2))
  847. #define __SXTAB16_RORn(ARG1, ARG2, ARG3) __SXTAB16(ARG1, __ROR(ARG2, ARG3))
  848. #endif /* __CMSIS_ICCARM_H__ */