cmsis_iccarm.h 28 KB

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