core_cm0.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /**************************************************************************//**
  2. * @file core_cm0.h
  3. * @brief CMSIS Cortex-M0 Core Peripheral Access Layer Header File
  4. * @version V2.10
  5. * @date 19. July 2011
  6. *
  7. * @note
  8. * Copyright (C) 2009-2011 ARM Limited. All rights reserved.
  9. *
  10. * @par
  11. * ARM Limited (ARM) is supplying this software for use with Cortex-M
  12. * processor based microcontrollers. This file can be freely distributed
  13. * within development tools that are supporting such ARM based processors.
  14. *
  15. * @par
  16. * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
  17. * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
  19. * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
  20. * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  21. *
  22. ******************************************************************************/
  23. #if defined ( __ICCARM__ )
  24. #pragma system_include /* treat file as system include file for MISRA check */
  25. #endif
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #ifndef __CORE_CM0_H_GENERIC
  30. #define __CORE_CM0_H_GENERIC
  31. /** \mainpage CMSIS Cortex-M0
  32. This documentation describes the CMSIS Cortex-M Core Peripheral Access Layer.
  33. It consists of:
  34. - Cortex-M Core Register Definitions
  35. - Cortex-M functions
  36. - Cortex-M instructions
  37. The CMSIS Cortex-M0 Core Peripheral Access Layer contains C and assembly functions that ease
  38. access to the Cortex-M Core
  39. */
  40. /** \defgroup CMSIS_MISRA_Exceptions CMSIS MISRA-C:2004 Compliance Exceptions
  41. CMSIS violates following MISRA-C2004 Rules:
  42. - Violates MISRA 2004 Required Rule 8.5, object/function definition in header file.<br>
  43. Function definitions in header files are used to allow 'inlining'.
  44. - Violates MISRA 2004 Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
  45. Unions are used for effective representation of core registers.
  46. - Violates MISRA 2004 Advisory Rule 19.7, Function-like macro defined.<br>
  47. Function-like macros are used to allow more efficient code.
  48. */
  49. /*******************************************************************************
  50. * CMSIS definitions
  51. ******************************************************************************/
  52. /** \defgroup CMSIS_core_definitions CMSIS Core Definitions
  53. This file defines all structures and symbols for CMSIS core:
  54. - CMSIS version number
  55. - Cortex-M core
  56. - Cortex-M core Revision Number
  57. @{
  58. */
  59. /* CMSIS CM0 definitions */
  60. #define __CM0_CMSIS_VERSION_MAIN (0x02) /*!< [31:16] CMSIS HAL main version */
  61. #define __CM0_CMSIS_VERSION_SUB (0x10) /*!< [15:0] CMSIS HAL sub version */
  62. #define __CM0_CMSIS_VERSION ((__CM0_CMSIS_VERSION_MAIN << 16) | __CM0_CMSIS_VERSION_SUB) /*!< CMSIS HAL version number */
  63. #define __CORTEX_M (0x00) /*!< Cortex core */
  64. #if defined ( __CC_ARM )
  65. #define __ASM __asm /*!< asm keyword for ARM Compiler */
  66. #define __INLINE __inline /*!< inline keyword for ARM Compiler */
  67. #elif defined ( __ICCARM__ )
  68. #define __ASM __asm /*!< asm keyword for IAR Compiler */
  69. #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
  70. #elif defined ( __GNUC__ )
  71. #define __ASM __asm /*!< asm keyword for GNU Compiler */
  72. #define __INLINE inline /*!< inline keyword for GNU Compiler */
  73. #elif defined ( __TASKING__ )
  74. #define __ASM __asm /*!< asm keyword for TASKING Compiler */
  75. #define __INLINE inline /*!< inline keyword for TASKING Compiler */
  76. #endif
  77. /*!< __FPU_USED to be checked prior to making use of FPU specific registers and functions */
  78. #define __FPU_USED 0
  79. #if defined ( __CC_ARM )
  80. #if defined __TARGET_FPU_VFP
  81. #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
  82. #endif
  83. #elif defined ( __ICCARM__ )
  84. #if defined __ARMVFP__
  85. #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
  86. #endif
  87. #elif defined ( __GNUC__ )
  88. #if defined (__VFP_FP__) && !defined(__SOFTFP__)
  89. #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
  90. #endif
  91. #elif defined ( __TASKING__ )
  92. /* add preprocessor checks */
  93. #endif
  94. #include <stdint.h> /*!< standard types definitions */
  95. #include "core_cmInstr.h" /*!< Core Instruction Access */
  96. #include "core_cmFunc.h" /*!< Core Function Access */
  97. #endif /* __CORE_CM0_H_GENERIC */
  98. #ifndef __CMSIS_GENERIC
  99. #ifndef __CORE_CM0_H_DEPENDANT
  100. #define __CORE_CM0_H_DEPENDANT
  101. /* check device defines and use defaults */
  102. #if defined __CHECK_DEVICE_DEFINES
  103. #ifndef __CM0_REV
  104. #define __CM0_REV 0x0000
  105. #warning "__CM0_REV not defined in device header file; using default!"
  106. #endif
  107. #ifndef __NVIC_PRIO_BITS
  108. #define __NVIC_PRIO_BITS 2
  109. #warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
  110. #endif
  111. #ifndef __Vendor_SysTickConfig
  112. #define __Vendor_SysTickConfig 0
  113. #warning "__Vendor_SysTickConfig not defined in device header file; using default!"
  114. #endif
  115. #endif
  116. /* IO definitions (access restrictions to peripheral registers) */
  117. #ifdef __cplusplus
  118. #define __I volatile /*!< defines 'read only' permissions */
  119. #else
  120. #define __I volatile const /*!< defines 'read only' permissions */
  121. #endif
  122. #define __O volatile /*!< defines 'write only' permissions */
  123. #define __IO volatile /*!< defines 'read / write' permissions */
  124. /*@} end of group CMSIS_core_definitions */
  125. /*******************************************************************************
  126. * Register Abstraction
  127. ******************************************************************************/
  128. /** \defgroup CMSIS_core_register CMSIS Core Register
  129. Core Register contain:
  130. - Core Register
  131. - Core NVIC Register
  132. - Core SCB Register
  133. - Core SysTick Register
  134. */
  135. /** \ingroup CMSIS_core_register
  136. \defgroup CMSIS_CORE CMSIS Core
  137. Type definitions for the Cortex-M Core Registers
  138. @{
  139. */
  140. /** \brief Union type to access the Application Program Status Register (APSR).
  141. */
  142. typedef union
  143. {
  144. struct
  145. {
  146. #if (__CORTEX_M != 0x04)
  147. uint32_t _reserved0:27; /*!< bit: 0..26 Reserved */
  148. #else
  149. uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */
  150. uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
  151. uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */
  152. #endif
  153. uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
  154. uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
  155. uint32_t C:1; /*!< bit: 29 Carry condition code flag */
  156. uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
  157. uint32_t N:1; /*!< bit: 31 Negative condition code flag */
  158. } b; /*!< Structure used for bit access */
  159. uint32_t w; /*!< Type used for word access */
  160. } APSR_Type;
  161. /** \brief Union type to access the Interrupt Program Status Register (IPSR).
  162. */
  163. typedef union
  164. {
  165. struct
  166. {
  167. uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
  168. uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
  169. } b; /*!< Structure used for bit access */
  170. uint32_t w; /*!< Type used for word access */
  171. } IPSR_Type;
  172. /** \brief Union type to access the Special-Purpose Program Status Registers (xPSR).
  173. */
  174. typedef union
  175. {
  176. struct
  177. {
  178. uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
  179. #if (__CORTEX_M != 0x04)
  180. uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
  181. #else
  182. uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */
  183. uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
  184. uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */
  185. #endif
  186. uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
  187. uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */
  188. uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
  189. uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
  190. uint32_t C:1; /*!< bit: 29 Carry condition code flag */
  191. uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
  192. uint32_t N:1; /*!< bit: 31 Negative condition code flag */
  193. } b; /*!< Structure used for bit access */
  194. uint32_t w; /*!< Type used for word access */
  195. } xPSR_Type;
  196. /** \brief Union type to access the Control Registers (CONTROL).
  197. */
  198. typedef union
  199. {
  200. struct
  201. {
  202. uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */
  203. uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
  204. uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */
  205. uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */
  206. } b; /*!< Structure used for bit access */
  207. uint32_t w; /*!< Type used for word access */
  208. } CONTROL_Type;
  209. /*@} end of group CMSIS_CORE */
  210. /** \ingroup CMSIS_core_register
  211. \defgroup CMSIS_NVIC CMSIS NVIC
  212. Type definitions for the Cortex-M NVIC Registers
  213. @{
  214. */
  215. /** \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
  216. */
  217. typedef struct
  218. {
  219. __IO uint32_t ISER[1]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
  220. uint32_t RESERVED0[31];
  221. __IO uint32_t ICER[1]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
  222. uint32_t RSERVED1[31];
  223. __IO uint32_t ISPR[1]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
  224. uint32_t RESERVED2[31];
  225. __IO uint32_t ICPR[1]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
  226. uint32_t RESERVED3[31];
  227. uint32_t RESERVED4[64];
  228. __IO uint32_t IP[8]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */
  229. } NVIC_Type;
  230. /*@} end of group CMSIS_NVIC */
  231. /** \ingroup CMSIS_core_register
  232. \defgroup CMSIS_SCB CMSIS SCB
  233. Type definitions for the Cortex-M System Control Block Registers
  234. @{
  235. */
  236. /** \brief Structure type to access the System Control Block (SCB).
  237. */
  238. typedef struct
  239. {
  240. __I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
  241. __IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
  242. uint32_t RESERVED0;
  243. __IO uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
  244. __IO uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
  245. __IO uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
  246. uint32_t RESERVED1;
  247. __IO uint32_t SHP[2]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */
  248. __IO uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
  249. } SCB_Type;
  250. /* SCB CPUID Register Definitions */
  251. #define SCB_CPUID_IMPLEMENTER_Pos 24 /*!< SCB CPUID: IMPLEMENTER Position */
  252. #define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
  253. #define SCB_CPUID_VARIANT_Pos 20 /*!< SCB CPUID: VARIANT Position */
  254. #define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
  255. #define SCB_CPUID_ARCHITECTURE_Pos 16 /*!< SCB CPUID: ARCHITECTURE Position */
  256. #define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
  257. #define SCB_CPUID_PARTNO_Pos 4 /*!< SCB CPUID: PARTNO Position */
  258. #define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
  259. #define SCB_CPUID_REVISION_Pos 0 /*!< SCB CPUID: REVISION Position */
  260. #define SCB_CPUID_REVISION_Msk (0xFUL << SCB_CPUID_REVISION_Pos) /*!< SCB CPUID: REVISION Mask */
  261. /* SCB Interrupt Control State Register Definitions */
  262. #define SCB_ICSR_NMIPENDSET_Pos 31 /*!< SCB ICSR: NMIPENDSET Position */
  263. #define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
  264. #define SCB_ICSR_PENDSVSET_Pos 28 /*!< SCB ICSR: PENDSVSET Position */
  265. #define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
  266. #define SCB_ICSR_PENDSVCLR_Pos 27 /*!< SCB ICSR: PENDSVCLR Position */
  267. #define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
  268. #define SCB_ICSR_PENDSTSET_Pos 26 /*!< SCB ICSR: PENDSTSET Position */
  269. #define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
  270. #define SCB_ICSR_PENDSTCLR_Pos 25 /*!< SCB ICSR: PENDSTCLR Position */
  271. #define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
  272. #define SCB_ICSR_ISRPREEMPT_Pos 23 /*!< SCB ICSR: ISRPREEMPT Position */
  273. #define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
  274. #define SCB_ICSR_ISRPENDING_Pos 22 /*!< SCB ICSR: ISRPENDING Position */
  275. #define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
  276. #define SCB_ICSR_VECTPENDING_Pos 12 /*!< SCB ICSR: VECTPENDING Position */
  277. #define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
  278. #define SCB_ICSR_VECTACTIVE_Pos 0 /*!< SCB ICSR: VECTACTIVE Position */
  279. #define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL << SCB_ICSR_VECTACTIVE_Pos) /*!< SCB ICSR: VECTACTIVE Mask */
  280. /* SCB Application Interrupt and Reset Control Register Definitions */
  281. #define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */
  282. #define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
  283. #define SCB_AIRCR_VECTKEYSTAT_Pos 16 /*!< SCB AIRCR: VECTKEYSTAT Position */
  284. #define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
  285. #define SCB_AIRCR_ENDIANESS_Pos 15 /*!< SCB AIRCR: ENDIANESS Position */
  286. #define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
  287. #define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */
  288. #define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
  289. #define SCB_AIRCR_VECTCLRACTIVE_Pos 1 /*!< SCB AIRCR: VECTCLRACTIVE Position */
  290. #define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
  291. /* SCB System Control Register Definitions */
  292. #define SCB_SCR_SEVONPEND_Pos 4 /*!< SCB SCR: SEVONPEND Position */
  293. #define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
  294. #define SCB_SCR_SLEEPDEEP_Pos 2 /*!< SCB SCR: SLEEPDEEP Position */
  295. #define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
  296. #define SCB_SCR_SLEEPONEXIT_Pos 1 /*!< SCB SCR: SLEEPONEXIT Position */
  297. #define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
  298. /* SCB Configuration Control Register Definitions */
  299. #define SCB_CCR_STKALIGN_Pos 9 /*!< SCB CCR: STKALIGN Position */
  300. #define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
  301. #define SCB_CCR_UNALIGN_TRP_Pos 3 /*!< SCB CCR: UNALIGN_TRP Position */
  302. #define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
  303. /* SCB System Handler Control and State Register Definitions */
  304. #define SCB_SHCSR_SVCALLPENDED_Pos 15 /*!< SCB SHCSR: SVCALLPENDED Position */
  305. #define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
  306. /*@} end of group CMSIS_SCB */
  307. /** \ingroup CMSIS_core_register
  308. \defgroup CMSIS_SysTick CMSIS SysTick
  309. Type definitions for the Cortex-M System Timer Registers
  310. @{
  311. */
  312. /** \brief Structure type to access the System Timer (SysTick).
  313. */
  314. typedef struct
  315. {
  316. __IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
  317. __IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
  318. __IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
  319. __I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
  320. } SysTick_Type;
  321. /* SysTick Control / Status Register Definitions */
  322. #define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */
  323. #define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
  324. #define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */
  325. #define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
  326. #define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */
  327. #define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
  328. #define SysTick_CTRL_ENABLE_Pos 0 /*!< SysTick CTRL: ENABLE Position */
  329. #define SysTick_CTRL_ENABLE_Msk (1UL << SysTick_CTRL_ENABLE_Pos) /*!< SysTick CTRL: ENABLE Mask */
  330. /* SysTick Reload Register Definitions */
  331. #define SysTick_LOAD_RELOAD_Pos 0 /*!< SysTick LOAD: RELOAD Position */
  332. #define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL << SysTick_LOAD_RELOAD_Pos) /*!< SysTick LOAD: RELOAD Mask */
  333. /* SysTick Current Register Definitions */
  334. #define SysTick_VAL_CURRENT_Pos 0 /*!< SysTick VAL: CURRENT Position */
  335. #define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick VAL: CURRENT Mask */
  336. /* SysTick Calibration Register Definitions */
  337. #define SysTick_CALIB_NOREF_Pos 31 /*!< SysTick CALIB: NOREF Position */
  338. #define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
  339. #define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */
  340. #define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
  341. #define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */
  342. #define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick CALIB: TENMS Mask */
  343. /*@} end of group CMSIS_SysTick */
  344. /** \ingroup CMSIS_core_register
  345. \defgroup CMSIS_CoreDebug CMSIS Core Debug
  346. Cortex-M0 Core Debug Registers (DCB registers, SHCSR, and DFSR) are only accessible over DAP
  347. and not via processor. Therefore they are not covered by the Cortex-M0 header file.
  348. @{
  349. */
  350. /*@} end of group CMSIS_CoreDebug */
  351. /** \ingroup CMSIS_core_register
  352. @{
  353. */
  354. /* Memory mapping of Cortex-M0 Hardware */
  355. #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
  356. #define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */
  357. #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
  358. #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
  359. #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
  360. #define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
  361. #define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
  362. #define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
  363. /*@} */
  364. /*******************************************************************************
  365. * Hardware Abstraction Layer
  366. ******************************************************************************/
  367. /** \defgroup CMSIS_Core_FunctionInterface CMSIS Core Function Interface
  368. Core Function Interface contains:
  369. - Core NVIC Functions
  370. - Core SysTick Functions
  371. - Core Register Access Functions
  372. */
  373. /* ########################## NVIC functions #################################### */
  374. /** \ingroup CMSIS_Core_FunctionInterface
  375. \defgroup CMSIS_Core_NVICFunctions CMSIS Core NVIC Functions
  376. @{
  377. */
  378. /* Interrupt Priorities are WORD accessible only under ARMv6M */
  379. /* The following MACROS handle generation of the register offset and byte masks */
  380. #define _BIT_SHIFT(IRQn) ( (((uint32_t)(IRQn) ) & 0x03) * 8 )
  381. #define _SHP_IDX(IRQn) ( ((((uint32_t)(IRQn) & 0x0F)-8) >> 2) )
  382. #define _IP_IDX(IRQn) ( ((uint32_t)(IRQn) >> 2) )
  383. /** \brief Enable External Interrupt
  384. This function enables a device specific interrupt in the NVIC interrupt controller.
  385. The interrupt number cannot be a negative value.
  386. \param [in] IRQn Number of the external interrupt to enable
  387. */
  388. static __INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
  389. {
  390. NVIC->ISER[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
  391. }
  392. /** \brief Disable External Interrupt
  393. This function disables a device specific interrupt in the NVIC interrupt controller.
  394. The interrupt number cannot be a negative value.
  395. \param [in] IRQn Number of the external interrupt to disable
  396. */
  397. static __INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
  398. {
  399. NVIC->ICER[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
  400. }
  401. /** \brief Get Pending Interrupt
  402. This function reads the pending register in the NVIC and returns the pending bit
  403. for the specified interrupt.
  404. \param [in] IRQn Number of the interrupt for get pending
  405. \return 0 Interrupt status is not pending
  406. \return 1 Interrupt status is pending
  407. */
  408. static __INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
  409. {
  410. return((uint32_t) ((NVIC->ISPR[0] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0));
  411. }
  412. /** \brief Set Pending Interrupt
  413. This function sets the pending bit for the specified interrupt.
  414. The interrupt number cannot be a negative value.
  415. \param [in] IRQn Number of the interrupt for set pending
  416. */
  417. static __INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
  418. {
  419. NVIC->ISPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
  420. }
  421. /** \brief Clear Pending Interrupt
  422. This function clears the pending bit for the specified interrupt.
  423. The interrupt number cannot be a negative value.
  424. \param [in] IRQn Number of the interrupt for clear pending
  425. */
  426. static __INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
  427. {
  428. NVIC->ICPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */
  429. }
  430. /** \brief Set Interrupt Priority
  431. This function sets the priority for the specified interrupt. The interrupt
  432. number can be positive to specify an external (device specific)
  433. interrupt, or negative to specify an internal (core) interrupt.
  434. Note: The priority cannot be set for every core interrupt.
  435. \param [in] IRQn Number of the interrupt for set priority
  436. \param [in] priority Priority to set
  437. */
  438. static __INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
  439. {
  440. if(IRQn < 0) {
  441. SCB->SHP[_SHP_IDX(IRQn)] = (SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |
  442. (((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }
  443. else {
  444. NVIC->IP[_IP_IDX(IRQn)] = (NVIC->IP[_IP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |
  445. (((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }
  446. }
  447. /** \brief Get Interrupt Priority
  448. This function reads the priority for the specified interrupt. The interrupt
  449. number can be positive to specify an external (device specific)
  450. interrupt, or negative to specify an internal (core) interrupt.
  451. The returned priority value is automatically aligned to the implemented
  452. priority bits of the microcontroller.
  453. \param [in] IRQn Number of the interrupt for get priority
  454. \return Interrupt Priority
  455. */
  456. static __INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
  457. {
  458. if(IRQn < 0) {
  459. return((uint32_t)((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M0 system interrupts */
  460. else {
  461. return((uint32_t)((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */
  462. }
  463. /** \brief System Reset
  464. This function initiate a system reset request to reset the MCU.
  465. */
  466. static __INLINE void NVIC_SystemReset(void)
  467. {
  468. __DSB(); /* Ensure all outstanding memory accesses included
  469. buffered write are completed before reset */
  470. SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) |
  471. SCB_AIRCR_SYSRESETREQ_Msk);
  472. __DSB(); /* Ensure completion of memory access */
  473. while(1); /* wait until reset */
  474. }
  475. /*@} end of CMSIS_Core_NVICFunctions */
  476. /* ################################## SysTick function ############################################ */
  477. /** \ingroup CMSIS_Core_FunctionInterface
  478. \defgroup CMSIS_Core_SysTickFunctions CMSIS Core SysTick Functions
  479. @{
  480. */
  481. #if (__Vendor_SysTickConfig == 0)
  482. /** \brief System Tick Configuration
  483. This function initialises the system tick timer and its interrupt and start the system tick timer.
  484. Counter is in free running mode to generate periodical interrupts.
  485. \param [in] ticks Number of ticks between two interrupts
  486. \return 0 Function succeeded
  487. \return 1 Function failed
  488. */
  489. static __INLINE uint32_t SysTick_Config(uint32_t ticks)
  490. {
  491. if (ticks > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */
  492. SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1; /* set reload register */
  493. NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Cortex-M0 System Interrupts */
  494. SysTick->VAL = 0; /* Load the SysTick Counter Value */
  495. SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
  496. SysTick_CTRL_TICKINT_Msk |
  497. SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
  498. return (0); /* Function successful */
  499. }
  500. #endif
  501. /*@} end of CMSIS_Core_SysTickFunctions */
  502. #endif /* __CORE_CM0_H_DEPENDANT */
  503. #endif /* __CMSIS_GENERIC */
  504. #ifdef __cplusplus
  505. }
  506. #endif