cmsis_iccarm.h 26 KB

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