cmsis_iccarm.h 26 KB

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