core_cm0.h 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. /**************************************************************************//**
  2. * @file core_cm0.h
  3. * @brief CMSIS Cortex-M0 Core Peripheral Access Layer Header File
  4. * @version V5.00
  5. * @date 29. June 2016
  6. ******************************************************************************/
  7. /*
  8. * Copyright (c) 2009-2016 ARM Limited. All rights reserved.
  9. *
  10. * SPDX-License-Identifier: Apache-2.0
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the License); you may
  13. * not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * http://www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  20. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. #if defined ( __ICCARM__ )
  25. #pragma system_include /* treat file as system include file for MISRA check */
  26. #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
  27. #pragma clang system_header /* treat file as system include file */
  28. #endif
  29. #ifndef __CORE_CM0_H_GENERIC
  30. #define __CORE_CM0_H_GENERIC
  31. #include <stdint.h>
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. /**
  36. \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
  37. CMSIS violates the following MISRA-C:2004 rules:
  38. \li Required Rule 8.5, object/function definition in header file.<br>
  39. Function definitions in header files are used to allow 'inlining'.
  40. \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
  41. Unions are used for effective representation of core registers.
  42. \li Advisory Rule 19.7, Function-like macro defined.<br>
  43. Function-like macros are used to allow more efficient code.
  44. */
  45. /*******************************************************************************
  46. * CMSIS definitions
  47. ******************************************************************************/
  48. /**
  49. \ingroup Cortex_M0
  50. @{
  51. */
  52. /* CMSIS CM0 definitions */
  53. #define __CM0_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS HAL main version */
  54. #define __CM0_CMSIS_VERSION_SUB ( 0U) /*!< [15:0] CMSIS HAL sub version */
  55. #define __CM0_CMSIS_VERSION ((__CM0_CMSIS_VERSION_MAIN << 16U) | \
  56. __CM0_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */
  57. #define __CORTEX_M (0U) /*!< Cortex-M Core */
  58. /* Common defines in core_*.h files
  59. - #define __ASM Compiler keyword for asm
  60. - #define __INLINE Compiler keyword for inline
  61. - #define __STATIC_INLINE Compiler keyword for static inline
  62. - #define __NO_RETURN function that never returns
  63. - #define __USED function or variable that is not optimized away
  64. - #define __WEAK weak function or variable
  65. - #define __UNALIGNED_UINT32 pointer to unaligned uint32_t variable
  66. - #define __ALIGNED(x) compiler keyword to align a variable
  67. */
  68. #if defined ( __CC_ARM ) /* ARM Compiler 4/5 */
  69. #define __ASM __asm
  70. #define __INLINE __inline
  71. #define __STATIC_INLINE static __inline
  72. #define __NO_RETURN __declspec(noreturn)
  73. #define __USED __attribute__((used))
  74. #define __WEAK __attribute__((weak))
  75. #define __UNALIGNED_UINT32(x) (*((__packed uint32_t *)(x)))
  76. #define __ALIGNED(x) __attribute__((aligned(x)))
  77. #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler 6 */
  78. #define __ASM __asm
  79. #define __INLINE __inline
  80. #define __STATIC_INLINE static __inline
  81. #define __NO_RETURN __attribute__((noreturn))
  82. #define __USED __attribute__((used))
  83. #define __WEAK __attribute__((weak))
  84. #pragma clang diagnostic push
  85. #pragma clang diagnostic ignored "-Wpacked"
  86. struct __attribute__((packed)) T_UINT32 { uint32_t v; };
  87. #pragma clang diagnostic pop
  88. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  89. #define __ALIGNED(x) __attribute__((aligned(x)))
  90. #elif defined ( __GNUC__ ) /* GNU Compiler */
  91. #define __ASM __asm
  92. #define __INLINE inline
  93. #define __STATIC_INLINE static inline
  94. #define __NO_RETURN __attribute__((noreturn))
  95. #define __USED __attribute__((used))
  96. #define __WEAK __attribute__((weak))
  97. struct __attribute__((packed)) T_UINT32 { uint32_t v; };
  98. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  99. #define __ALIGNED(x) __attribute__((aligned(x)))
  100. #elif defined ( __ICCARM__ ) /* IAR Compiler */
  101. #define __ASM __asm
  102. #define __INLINE inline
  103. #define __STATIC_INLINE static inline
  104. #define __NO_RETURN __noreturn
  105. #define __USED
  106. #define __WEAK __weak
  107. struct __packed T_UINT32 { uint32_t v; };
  108. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  109. #define __ALIGNED(x)
  110. #elif defined ( __TI_ARM__ ) /* TI ARM Compiler */
  111. #define __ASM __asm
  112. #define __INLINE inline
  113. #define __STATIC_INLINE static inline
  114. #define __NO_RETURN __attribute__((noreturn))
  115. #define __USED __attribute__((used))
  116. #define __WEAK __attribute__((weak))
  117. struct __attribute__((packed)) T_UINT32 { uint32_t v; };
  118. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  119. #define __ALIGNED(x)
  120. #elif defined ( __TASKING__ ) /* TASKING Compiler */
  121. #define __ASM __asm
  122. #define __INLINE inline
  123. #define __STATIC_INLINE static inline
  124. #define __NO_RETURN __attribute__((noreturn))
  125. #define __USED __attribute__((used))
  126. #define __WEAK __attribute__((weak))
  127. struct __packed__ T_UINT32 { uint32_t v; };
  128. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  129. #define __ALIGNED(x) __align(x)
  130. #elif defined ( __CSMC__ ) /* COSMIC Compiler */
  131. #define __packed
  132. #define __ASM _asm
  133. #define __INLINE inline
  134. #define __STATIC_INLINE static inline
  135. #define __NO_RETURN
  136. #define __USED
  137. #define __WEAK
  138. #define __UNALIGNED_UINT32(x) (*x)
  139. #define __ALIGNED(x)
  140. #else
  141. #error Unknown compiler
  142. #endif
  143. /** __FPU_USED indicates whether an FPU is used or not.
  144. This core does not support an FPU at all
  145. */
  146. #define __FPU_USED 0U
  147. #if defined ( __CC_ARM )
  148. #if defined __TARGET_FPU_VFP
  149. #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
  150. #endif
  151. #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
  152. #if defined __ARM_PCS_VFP
  153. #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
  154. #endif
  155. #elif defined ( __GNUC__ )
  156. #if defined (__VFP_FP__) && !defined(__SOFTFP__)
  157. #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
  158. #endif
  159. #elif defined ( __ICCARM__ )
  160. #if defined __ARMVFP__
  161. #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
  162. #endif
  163. #elif defined ( __TI_ARM__ )
  164. #if defined __TI_VFP_SUPPORT__
  165. #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
  166. #endif
  167. #elif defined ( __TASKING__ )
  168. #if defined __FPU_VFP__
  169. #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
  170. #endif
  171. #elif defined ( __CSMC__ )
  172. #if ( __CSMC__ & 0x400U)
  173. #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
  174. #endif
  175. #endif
  176. #include "core_cminstr.h" /* Core Instruction Access */
  177. #include "core_cmfunc.h" /* Core Function Access */
  178. #ifdef __cplusplus
  179. }
  180. #endif
  181. #endif /* __CORE_CM0_H_GENERIC */
  182. #ifndef __CMSIS_GENERIC
  183. #ifndef __CORE_CM0_H_DEPENDANT
  184. #define __CORE_CM0_H_DEPENDANT
  185. #ifdef __cplusplus
  186. extern "C" {
  187. #endif
  188. /* check device defines and use defaults */
  189. #if defined __CHECK_DEVICE_DEFINES
  190. #ifndef __CM0_REV
  191. #define __CM0_REV 0x0000U
  192. #warning "__CM0_REV not defined in device header file; using default!"
  193. #endif
  194. #ifndef __NVIC_PRIO_BITS
  195. #define __NVIC_PRIO_BITS 2U
  196. #warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
  197. #endif
  198. #ifndef __Vendor_SysTickConfig
  199. #define __Vendor_SysTickConfig 0U
  200. #warning "__Vendor_SysTickConfig not defined in device header file; using default!"
  201. #endif
  202. #endif
  203. /* IO definitions (access restrictions to peripheral registers) */
  204. /**
  205. \defgroup CMSIS_glob_defs CMSIS Global Defines
  206. <strong>IO Type Qualifiers</strong> are used
  207. \li to specify the access to peripheral variables.
  208. \li for automatic generation of peripheral register debug information.
  209. */
  210. #ifdef __cplusplus
  211. #define __I volatile /*!< Defines 'read only' permissions */
  212. #else
  213. #define __I volatile const /*!< Defines 'read only' permissions */
  214. #endif
  215. #define __O volatile /*!< Defines 'write only' permissions */
  216. #define __IO volatile /*!< Defines 'read / write' permissions */
  217. /* following defines should be used for structure members */
  218. #define __IM volatile const /*! Defines 'read only' structure member permissions */
  219. #define __OM volatile /*! Defines 'write only' structure member permissions */
  220. #define __IOM volatile /*! Defines 'read / write' structure member permissions */
  221. /*@} end of group Cortex_M0 */
  222. /*******************************************************************************
  223. * Register Abstraction
  224. Core Register contain:
  225. - Core Register
  226. - Core NVIC Register
  227. - Core SCB Register
  228. - Core SysTick Register
  229. ******************************************************************************/
  230. /**
  231. \defgroup CMSIS_core_register Defines and Type Definitions
  232. \brief Type definitions and defines for Cortex-M processor based devices.
  233. */
  234. /**
  235. \ingroup CMSIS_core_register
  236. \defgroup CMSIS_CORE Status and Control Registers
  237. \brief Core Register type definitions.
  238. @{
  239. */
  240. /**
  241. \brief Union type to access the Application Program Status Register (APSR).
  242. */
  243. typedef union
  244. {
  245. struct
  246. {
  247. uint32_t _reserved0:28; /*!< bit: 0..27 Reserved */
  248. uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
  249. uint32_t C:1; /*!< bit: 29 Carry condition code flag */
  250. uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
  251. uint32_t N:1; /*!< bit: 31 Negative condition code flag */
  252. } b; /*!< Structure used for bit access */
  253. uint32_t w; /*!< Type used for word access */
  254. } APSR_Type;
  255. /* APSR Register Definitions */
  256. #define APSR_N_Pos 31U /*!< APSR: N Position */
  257. #define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */
  258. #define APSR_Z_Pos 30U /*!< APSR: Z Position */
  259. #define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */
  260. #define APSR_C_Pos 29U /*!< APSR: C Position */
  261. #define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */
  262. #define APSR_V_Pos 28U /*!< APSR: V Position */
  263. #define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */
  264. /**
  265. \brief Union type to access the Interrupt Program Status Register (IPSR).
  266. */
  267. typedef union
  268. {
  269. struct
  270. {
  271. uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
  272. uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
  273. } b; /*!< Structure used for bit access */
  274. uint32_t w; /*!< Type used for word access */
  275. } IPSR_Type;
  276. /* IPSR Register Definitions */
  277. #define IPSR_ISR_Pos 0U /*!< IPSR: ISR Position */
  278. #define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */
  279. /**
  280. \brief Union type to access the Special-Purpose Program Status Registers (xPSR).
  281. */
  282. typedef union
  283. {
  284. struct
  285. {
  286. uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
  287. uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
  288. uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
  289. uint32_t _reserved1:3; /*!< bit: 25..27 Reserved */
  290. uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
  291. uint32_t C:1; /*!< bit: 29 Carry condition code flag */
  292. uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
  293. uint32_t N:1; /*!< bit: 31 Negative condition code flag */
  294. } b; /*!< Structure used for bit access */
  295. uint32_t w; /*!< Type used for word access */
  296. } xPSR_Type;
  297. /* xPSR Register Definitions */
  298. #define xPSR_N_Pos 31U /*!< xPSR: N Position */
  299. #define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */
  300. #define xPSR_Z_Pos 30U /*!< xPSR: Z Position */
  301. #define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */
  302. #define xPSR_C_Pos 29U /*!< xPSR: C Position */
  303. #define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */
  304. #define xPSR_V_Pos 28U /*!< xPSR: V Position */
  305. #define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */
  306. #define xPSR_T_Pos 24U /*!< xPSR: T Position */
  307. #define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */
  308. #define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */
  309. #define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */
  310. /**
  311. \brief Union type to access the Control Registers (CONTROL).
  312. */
  313. typedef union
  314. {
  315. struct
  316. {
  317. uint32_t _reserved0:1; /*!< bit: 0 Reserved */
  318. uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
  319. uint32_t _reserved1:30; /*!< bit: 2..31 Reserved */
  320. } b; /*!< Structure used for bit access */
  321. uint32_t w; /*!< Type used for word access */
  322. } CONTROL_Type;
  323. /* CONTROL Register Definitions */
  324. #define CONTROL_SPSEL_Pos 1U /*!< CONTROL: SPSEL Position */
  325. #define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */
  326. /*@} end of group CMSIS_CORE */
  327. /**
  328. \ingroup CMSIS_core_register
  329. \defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC)
  330. \brief Type definitions for the NVIC Registers
  331. @{
  332. */
  333. /**
  334. \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
  335. */
  336. typedef struct
  337. {
  338. __IOM uint32_t ISER[1U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
  339. uint32_t RESERVED0[31U];
  340. __IOM uint32_t ICER[1U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
  341. uint32_t RSERVED1[31U];
  342. __IOM uint32_t ISPR[1U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
  343. uint32_t RESERVED2[31U];
  344. __IOM uint32_t ICPR[1U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
  345. uint32_t RESERVED3[31U];
  346. uint32_t RESERVED4[64U];
  347. __IOM uint32_t IP[8U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */
  348. } NVIC_Type;
  349. /*@} end of group CMSIS_NVIC */
  350. /**
  351. \ingroup CMSIS_core_register
  352. \defgroup CMSIS_SCB System Control Block (SCB)
  353. \brief Type definitions for the System Control Block Registers
  354. @{
  355. */
  356. /**
  357. \brief Structure type to access the System Control Block (SCB).
  358. */
  359. typedef struct
  360. {
  361. __IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
  362. __IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
  363. uint32_t RESERVED0;
  364. __IOM uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
  365. __IOM uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
  366. __IOM uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
  367. uint32_t RESERVED1;
  368. __IOM uint32_t SHP[2U]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */
  369. __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
  370. } SCB_Type;
  371. /* SCB CPUID Register Definitions */
  372. #define SCB_CPUID_IMPLEMENTER_Pos 24U /*!< SCB CPUID: IMPLEMENTER Position */
  373. #define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
  374. #define SCB_CPUID_VARIANT_Pos 20U /*!< SCB CPUID: VARIANT Position */
  375. #define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
  376. #define SCB_CPUID_ARCHITECTURE_Pos 16U /*!< SCB CPUID: ARCHITECTURE Position */
  377. #define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
  378. #define SCB_CPUID_PARTNO_Pos 4U /*!< SCB CPUID: PARTNO Position */
  379. #define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
  380. #define SCB_CPUID_REVISION_Pos 0U /*!< SCB CPUID: REVISION Position */
  381. #define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */
  382. /* SCB Interrupt Control State Register Definitions */
  383. #define SCB_ICSR_NMIPENDSET_Pos 31U /*!< SCB ICSR: NMIPENDSET Position */
  384. #define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
  385. #define SCB_ICSR_PENDSVSET_Pos 28U /*!< SCB ICSR: PENDSVSET Position */
  386. #define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
  387. #define SCB_ICSR_PENDSVCLR_Pos 27U /*!< SCB ICSR: PENDSVCLR Position */
  388. #define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
  389. #define SCB_ICSR_PENDSTSET_Pos 26U /*!< SCB ICSR: PENDSTSET Position */
  390. #define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
  391. #define SCB_ICSR_PENDSTCLR_Pos 25U /*!< SCB ICSR: PENDSTCLR Position */
  392. #define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
  393. #define SCB_ICSR_ISRPREEMPT_Pos 23U /*!< SCB ICSR: ISRPREEMPT Position */
  394. #define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
  395. #define SCB_ICSR_ISRPENDING_Pos 22U /*!< SCB ICSR: ISRPENDING Position */
  396. #define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
  397. #define SCB_ICSR_VECTPENDING_Pos 12U /*!< SCB ICSR: VECTPENDING Position */
  398. #define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
  399. #define SCB_ICSR_VECTACTIVE_Pos 0U /*!< SCB ICSR: VECTACTIVE Position */
  400. #define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */
  401. /* SCB Application Interrupt and Reset Control Register Definitions */
  402. #define SCB_AIRCR_VECTKEY_Pos 16U /*!< SCB AIRCR: VECTKEY Position */
  403. #define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
  404. #define SCB_AIRCR_VECTKEYSTAT_Pos 16U /*!< SCB AIRCR: VECTKEYSTAT Position */
  405. #define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
  406. #define SCB_AIRCR_ENDIANESS_Pos 15U /*!< SCB AIRCR: ENDIANESS Position */
  407. #define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
  408. #define SCB_AIRCR_SYSRESETREQ_Pos 2U /*!< SCB AIRCR: SYSRESETREQ Position */
  409. #define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
  410. #define SCB_AIRCR_VECTCLRACTIVE_Pos 1U /*!< SCB AIRCR: VECTCLRACTIVE Position */
  411. #define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
  412. /* SCB System Control Register Definitions */
  413. #define SCB_SCR_SEVONPEND_Pos 4U /*!< SCB SCR: SEVONPEND Position */
  414. #define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
  415. #define SCB_SCR_SLEEPDEEP_Pos 2U /*!< SCB SCR: SLEEPDEEP Position */
  416. #define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
  417. #define SCB_SCR_SLEEPONEXIT_Pos 1U /*!< SCB SCR: SLEEPONEXIT Position */
  418. #define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
  419. /* SCB Configuration Control Register Definitions */
  420. #define SCB_CCR_STKALIGN_Pos 9U /*!< SCB CCR: STKALIGN Position */
  421. #define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
  422. #define SCB_CCR_UNALIGN_TRP_Pos 3U /*!< SCB CCR: UNALIGN_TRP Position */
  423. #define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
  424. /* SCB System Handler Control and State Register Definitions */
  425. #define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */
  426. #define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
  427. /*@} end of group CMSIS_SCB */
  428. /**
  429. \ingroup CMSIS_core_register
  430. \defgroup CMSIS_SysTick System Tick Timer (SysTick)
  431. \brief Type definitions for the System Timer Registers.
  432. @{
  433. */
  434. /**
  435. \brief Structure type to access the System Timer (SysTick).
  436. */
  437. typedef struct
  438. {
  439. __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
  440. __IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
  441. __IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
  442. __IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
  443. } SysTick_Type;
  444. /* SysTick Control / Status Register Definitions */
  445. #define SysTick_CTRL_COUNTFLAG_Pos 16U /*!< SysTick CTRL: COUNTFLAG Position */
  446. #define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
  447. #define SysTick_CTRL_CLKSOURCE_Pos 2U /*!< SysTick CTRL: CLKSOURCE Position */
  448. #define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
  449. #define SysTick_CTRL_TICKINT_Pos 1U /*!< SysTick CTRL: TICKINT Position */
  450. #define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
  451. #define SysTick_CTRL_ENABLE_Pos 0U /*!< SysTick CTRL: ENABLE Position */
  452. #define SysTick_CTRL_ENABLE_Msk (1UL /*<< SysTick_CTRL_ENABLE_Pos*/) /*!< SysTick CTRL: ENABLE Mask */
  453. /* SysTick Reload Register Definitions */
  454. #define SysTick_LOAD_RELOAD_Pos 0U /*!< SysTick LOAD: RELOAD Position */
  455. #define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/) /*!< SysTick LOAD: RELOAD Mask */
  456. /* SysTick Current Register Definitions */
  457. #define SysTick_VAL_CURRENT_Pos 0U /*!< SysTick VAL: CURRENT Position */
  458. #define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/) /*!< SysTick VAL: CURRENT Mask */
  459. /* SysTick Calibration Register Definitions */
  460. #define SysTick_CALIB_NOREF_Pos 31U /*!< SysTick CALIB: NOREF Position */
  461. #define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
  462. #define SysTick_CALIB_SKEW_Pos 30U /*!< SysTick CALIB: SKEW Position */
  463. #define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
  464. #define SysTick_CALIB_TENMS_Pos 0U /*!< SysTick CALIB: TENMS Position */
  465. #define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/) /*!< SysTick CALIB: TENMS Mask */
  466. /*@} end of group CMSIS_SysTick */
  467. /**
  468. \ingroup CMSIS_core_register
  469. \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug)
  470. \brief Cortex-M0 Core Debug Registers (DCB registers, SHCSR, and DFSR) are only accessible over DAP and not via processor.
  471. Therefore they are not covered by the Cortex-M0 header file.
  472. @{
  473. */
  474. /*@} end of group CMSIS_CoreDebug */
  475. /**
  476. \ingroup CMSIS_core_register
  477. \defgroup CMSIS_core_bitfield Core register bit field macros
  478. \brief Macros for use with bit field definitions (xxx_Pos, xxx_Msk).
  479. @{
  480. */
  481. /**
  482. \brief Mask and shift a bit field value for use in a register bit range.
  483. \param[in] field Name of the register bit field.
  484. \param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type.
  485. \return Masked and shifted value.
  486. */
  487. #define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk)
  488. /**
  489. \brief Mask and shift a register value to extract a bit filed value.
  490. \param[in] field Name of the register bit field.
  491. \param[in] value Value of register. This parameter is interpreted as an uint32_t type.
  492. \return Masked and shifted bit field value.
  493. */
  494. #define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos)
  495. /*@} end of group CMSIS_core_bitfield */
  496. /**
  497. \ingroup CMSIS_core_register
  498. \defgroup CMSIS_core_base Core Definitions
  499. \brief Definitions for base addresses, unions, and structures.
  500. @{
  501. */
  502. /* Memory mapping of Cortex-M0 Hardware */
  503. #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
  504. #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
  505. #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
  506. #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
  507. #define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
  508. #define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
  509. #define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
  510. /*@} */
  511. /*******************************************************************************
  512. * Hardware Abstraction Layer
  513. Core Function Interface contains:
  514. - Core NVIC Functions
  515. - Core SysTick Functions
  516. - Core Register Access Functions
  517. ******************************************************************************/
  518. /**
  519. \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
  520. */
  521. /* ########################## NVIC functions #################################### */
  522. /**
  523. \ingroup CMSIS_Core_FunctionInterface
  524. \defgroup CMSIS_Core_NVICFunctions NVIC Functions
  525. \brief Functions that manage interrupts and exceptions via the NVIC.
  526. @{
  527. */
  528. /* Interrupt Priorities are WORD accessible only under ARMv6M */
  529. /* The following MACROS handle generation of the register offset and byte masks */
  530. #define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL)
  531. #define _SHP_IDX(IRQn) ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >> 2UL) )
  532. #define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) )
  533. /**
  534. \brief Enable Interrupt
  535. \details Enables a device specific interrupt in the NVIC interrupt controller.
  536. \param [in] IRQn Device specific interrupt number.
  537. \note IRQn must not be negative.
  538. */
  539. __STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
  540. {
  541. if ((int32_t)(IRQn) >= 0)
  542. {
  543. NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
  544. }
  545. }
  546. /**
  547. \brief Get Interrupt Enable status
  548. \details Returns a device specific interrupt enable status from the NVIC interrupt controller.
  549. \param [in] IRQn Device specific interrupt number.
  550. \return 0 Interrupt is not enabled.
  551. \return 1 Interrupt is enabled.
  552. \note IRQn must not be negative.
  553. */
  554. __STATIC_INLINE uint32_t NVIC_GetEnableIRQ(IRQn_Type IRQn)
  555. {
  556. if ((int32_t)(IRQn) >= 0)
  557. {
  558. return((uint32_t)(((NVIC->ISER[0U] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
  559. }
  560. else
  561. {
  562. return(0U);
  563. }
  564. }
  565. /**
  566. \brief Disable Interrupt
  567. \details Disables a device specific interrupt in the NVIC interrupt controller.
  568. \param [in] IRQn Device specific interrupt number.
  569. \note IRQn must not be negative.
  570. */
  571. __STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
  572. {
  573. if ((int32_t)(IRQn) >= 0)
  574. {
  575. NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
  576. }
  577. }
  578. /**
  579. \brief Get Pending Interrupt
  580. \details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt.
  581. \param [in] IRQn Device specific interrupt number.
  582. \return 0 Interrupt status is not pending.
  583. \return 1 Interrupt status is pending.
  584. \note IRQn must not be negative.
  585. */
  586. __STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
  587. {
  588. if ((int32_t)(IRQn) >= 0)
  589. {
  590. return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
  591. }
  592. else
  593. {
  594. return(0U);
  595. }
  596. }
  597. /**
  598. \brief Set Pending Interrupt
  599. \details Sets the pending bit of a device specific interrupt in the NVIC pending register.
  600. \param [in] IRQn Device specific interrupt number.
  601. \note IRQn must not be negative.
  602. */
  603. __STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
  604. {
  605. if ((int32_t)(IRQn) >= 0)
  606. {
  607. NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
  608. }
  609. }
  610. /**
  611. \brief Clear Pending Interrupt
  612. \details Clears the pending bit of a device specific interrupt in the NVIC pending register.
  613. \param [in] IRQn Device specific interrupt number.
  614. \note IRQn must not be negative.
  615. */
  616. __STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
  617. {
  618. if ((int32_t)(IRQn) >= 0)
  619. {
  620. NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
  621. }
  622. }
  623. /**
  624. \brief Set Interrupt Priority
  625. \details Sets the priority of a device specific interrupt or a processor exception.
  626. The interrupt number can be positive to specify a device specific interrupt,
  627. or negative to specify a processor exception.
  628. \param [in] IRQn Interrupt number.
  629. \param [in] priority Priority to set.
  630. \note The priority cannot be set for every processor exception.
  631. */
  632. __STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
  633. {
  634. if ((int32_t)(IRQn) >= 0)
  635. {
  636. NVIC->IP[_IP_IDX(IRQn)] = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
  637. (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
  638. }
  639. else
  640. {
  641. SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
  642. (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
  643. }
  644. }
  645. /**
  646. \brief Get Interrupt Priority
  647. \details Reads the priority of a device specific interrupt or a processor exception.
  648. The interrupt number can be positive to specify a device specific interrupt,
  649. or negative to specify a processor exception.
  650. \param [in] IRQn Interrupt number.
  651. \return Interrupt Priority.
  652. Value is aligned automatically to the implemented priority bits of the microcontroller.
  653. */
  654. __STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
  655. {
  656. if ((int32_t)(IRQn) >= 0)
  657. {
  658. return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
  659. }
  660. else
  661. {
  662. return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
  663. }
  664. }
  665. /**
  666. \brief System Reset
  667. \details Initiates a system reset request to reset the MCU.
  668. */
  669. __STATIC_INLINE void NVIC_SystemReset(void)
  670. {
  671. __DSB(); /* Ensure all outstanding memory accesses included
  672. buffered write are completed before reset */
  673. SCB->AIRCR = ((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
  674. SCB_AIRCR_SYSRESETREQ_Msk);
  675. __DSB(); /* Ensure completion of memory access */
  676. for(;;) /* wait until reset */
  677. {
  678. __NOP();
  679. }
  680. }
  681. /*@} end of CMSIS_Core_NVICFunctions */
  682. /* ########################## FPU functions #################################### */
  683. /**
  684. \ingroup CMSIS_Core_FunctionInterface
  685. \defgroup CMSIS_Core_FpuFunctions FPU Functions
  686. \brief Function that provides FPU type.
  687. @{
  688. */
  689. /**
  690. \brief get FPU type
  691. \details returns the FPU type
  692. \returns
  693. - \b 0: No FPU
  694. - \b 1: Single precision FPU
  695. - \b 2: Double + Single precision FPU
  696. */
  697. __STATIC_INLINE uint32_t SCB_GetFPUType(void)
  698. {
  699. return 0U; /* No FPU */
  700. }
  701. /*@} end of CMSIS_Core_FpuFunctions */
  702. /* ################################## SysTick function ############################################ */
  703. /**
  704. \ingroup CMSIS_Core_FunctionInterface
  705. \defgroup CMSIS_Core_SysTickFunctions SysTick Functions
  706. \brief Functions that configure the System.
  707. @{
  708. */
  709. #if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U)
  710. /**
  711. \brief System Tick Configuration
  712. \details Initializes the System Timer and its interrupt, and starts the System Tick Timer.
  713. Counter is in free running mode to generate periodic interrupts.
  714. \param [in] ticks Number of ticks between two interrupts.
  715. \return 0 Function succeeded.
  716. \return 1 Function failed.
  717. \note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
  718. function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
  719. must contain a vendor-specific implementation of this function.
  720. */
  721. __STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
  722. {
  723. if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)
  724. {
  725. return (1UL); /* Reload value impossible */
  726. }
  727. SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
  728. NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
  729. SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
  730. SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
  731. SysTick_CTRL_TICKINT_Msk |
  732. SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
  733. return (0UL); /* Function successful */
  734. }
  735. #endif
  736. /*@} end of CMSIS_Core_SysTickFunctions */
  737. #ifdef __cplusplus
  738. }
  739. #endif
  740. #endif /* __CORE_CM0_H_DEPENDANT */
  741. #endif /* __CMSIS_GENERIC */