cmsis_iccarm.h 28 KB

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