1 /**************************************************************************//**
\r
3 * @brief CMSIS Cortex-M0 Core Peripheral Access Layer Header File
\r
8 * Copyright (C) 2009-2011 ARM Limited. All rights reserved.
\r
11 * ARM Limited (ARM) is supplying this software for use with Cortex-M
\r
12 * processor based microcontrollers. This file can be freely distributed
\r
13 * within development tools that are supporting such ARM based processors.
\r
16 * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
\r
17 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
\r
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
\r
19 * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
\r
20 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
\r
22 ******************************************************************************/
\r
23 #if defined ( __ICCARM__ )
\r
24 #pragma system_include /* treat file as system include file for MISRA check */
\r
31 #ifndef __CORE_CM0_H_GENERIC
\r
32 #define __CORE_CM0_H_GENERIC
\r
35 /** \mainpage CMSIS Cortex-M0
\r
37 This documentation describes the CMSIS Cortex-M Core Peripheral Access Layer.
\r
40 - Cortex-M Core Register Definitions
\r
41 - Cortex-M functions
\r
42 - Cortex-M instructions
\r
44 The CMSIS Cortex-M0 Core Peripheral Access Layer contains C and assembly functions that ease
\r
45 access to the Cortex-M Core
\r
48 /** \defgroup CMSIS_LintCinfiguration CMSIS Lint Configuration
\r
49 List of Lint messages which will be suppressed and not shown:
\r
52 Note: To re-enable a Message, insert a space before 'lint' *
\r
57 /*******************************************************************************
\r
59 ******************************************************************************/
\r
60 /** \defgroup CMSIS_core_definitions CMSIS Core Definitions
\r
61 This file defines all structures and symbols for CMSIS core:
\r
62 - CMSIS version number
\r
64 - Cortex-M core Revision Number
\r
68 /* CMSIS CM0 definitions */
\r
69 #define __CM0_CMSIS_VERSION_MAIN (0x02) /*!< [31:16] CMSIS HAL main version */
\r
70 #define __CM0_CMSIS_VERSION_SUB (0x00) /*!< [15:0] CMSIS HAL sub version */
\r
71 #define __CM0_CMSIS_VERSION ((__CM0_CMSIS_VERSION_MAIN << 16) | __CM0_CMSIS_VERSION_SUB) /*!< CMSIS HAL version number */
\r
73 #define __CORTEX_M (0x00) /*!< Cortex core */
\r
76 #if defined ( __CC_ARM )
\r
77 #define __ASM __asm /*!< asm keyword for ARM Compiler */
\r
78 #define __INLINE __inline /*!< inline keyword for ARM Compiler */
\r
80 #elif defined ( __ICCARM__ )
\r
81 #define __ASM __asm /*!< asm keyword for IAR Compiler */
\r
82 #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
\r
84 #elif defined ( __GNUC__ )
\r
85 #define __ASM __asm /*!< asm keyword for GNU Compiler */
\r
86 #define __INLINE inline /*!< inline keyword for GNU Compiler */
\r
88 #elif defined ( __TASKING__ )
\r
89 #define __ASM __asm /*!< asm keyword for TASKING Compiler */
\r
90 #define __INLINE inline /*!< inline keyword for TASKING Compiler */
\r
94 #include <stdint.h> /*!< standard types definitions */
\r
95 #include "core_cmInstr.h" /*!< Core Instruction Access */
\r
96 #include "core_cmFunc.h" /*!< Core Function Access */
\r
98 #endif /* __CORE_CM0_H_GENERIC */
\r
101 #ifndef __CMSIS_GENERIC
\r
103 #ifndef __CORE_CM0_H_DEPENDANT
\r
104 #define __CORE_CM0_H_DEPENDANT
\r
106 /* IO definitions (access restrictions to peripheral registers) */
\r
108 #define __I volatile /*!< defines 'read only' permissions */
\r
110 #define __I volatile const /*!< defines 'read only' permissions */
\r
112 #define __O volatile /*!< defines 'write only' permissions */
\r
113 #define __IO volatile /*!< defines 'read / write' permissions */
\r
115 /*@} end of group CMSIS_core_definitions */
\r
119 /*******************************************************************************
\r
120 * Register Abstraction
\r
121 ******************************************************************************/
\r
122 /** \defgroup CMSIS_core_register CMSIS Core Register
\r
123 Core Register contain:
\r
125 - Core NVIC Register
\r
126 - Core SCB Register
\r
127 - Core SysTick Register
\r
130 /** \ingroup CMSIS_core_register
\r
131 \defgroup CMSIS_CORE CMSIS Core
\r
132 Type definitions for the Cortex-M Core Registers
\r
136 /** \brief Union type to access the Application Program Status Register (APSR).
\r
142 #if (__CORTEX_M != 0x04)
\r
143 uint32_t _reserved0:27; /*!< bit: 0..26 Reserved */
\r
145 uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */
\r
146 uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
\r
147 uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */
\r
149 uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
\r
150 uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
\r
151 uint32_t C:1; /*!< bit: 29 Carry condition code flag */
\r
152 uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
\r
153 uint32_t N:1; /*!< bit: 31 Negative condition code flag */
\r
154 } b; /*!< Structure used for bit access */
\r
155 uint32_t w; /*!< Type used for word access */
\r
159 /** \brief Union type to access the Interrupt Program Status Register (IPSR).
\r
165 uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
\r
166 uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
\r
167 } b; /*!< Structure used for bit access */
\r
168 uint32_t w; /*!< Type used for word access */
\r
172 /** \brief Union type to access the Special-Purpose Program Status Registers (xPSR).
\r
178 uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
\r
179 #if (__CORTEX_M != 0x04)
\r
180 uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
\r
182 uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */
\r
183 uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
\r
184 uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */
\r
186 uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
\r
187 uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */
\r
188 uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
\r
189 uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
\r
190 uint32_t C:1; /*!< bit: 29 Carry condition code flag */
\r
191 uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
\r
192 uint32_t N:1; /*!< bit: 31 Negative condition code flag */
\r
193 } b; /*!< Structure used for bit access */
\r
194 uint32_t w; /*!< Type used for word access */
\r
198 /** \brief Union type to access the Control Registers (CONTROL).
\r
204 uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */
\r
205 uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
\r
206 uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */
\r
207 uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */
\r
208 } b; /*!< Structure used for bit access */
\r
209 uint32_t w; /*!< Type used for word access */
\r
212 /*@} end of group CMSIS_CORE */
\r
215 /** \ingroup CMSIS_core_register
\r
216 \defgroup CMSIS_NVIC CMSIS NVIC
\r
217 Type definitions for the Cortex-M NVIC Registers
\r
221 /** \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
\r
225 __IO uint32_t ISER[1]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
\r
226 uint32_t RESERVED0[31];
\r
227 __IO uint32_t ICER[1]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
\r
228 uint32_t RSERVED1[31];
\r
229 __IO uint32_t ISPR[1]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
\r
230 uint32_t RESERVED2[31];
\r
231 __IO uint32_t ICPR[1]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
\r
232 uint32_t RESERVED3[31];
\r
233 uint32_t RESERVED4[64];
\r
234 __IO uint32_t IPR[8]; /*!< Offset: 0x3EC (R/W) Interrupt Priority Register */
\r
237 /*@} end of group CMSIS_NVIC */
\r
240 /** \ingroup CMSIS_core_register
\r
241 \defgroup CMSIS_SCB CMSIS SCB
\r
242 Type definitions for the Cortex-M System Control Block Registers
\r
246 /** \brief Structure type to access the System Control Block (SCB).
\r
250 __I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPU ID Base Register */
\r
251 __IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control State Register */
\r
252 uint32_t RESERVED0;
\r
253 __IO uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt / Reset Control Register */
\r
254 __IO uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
\r
255 __IO uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
\r
256 uint32_t RESERVED1;
\r
257 __IO uint32_t SHP[2]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */
\r
260 /* SCB CPUID Register Definitions */
\r
261 #define SCB_CPUID_IMPLEMENTER_Pos 24 /*!< SCB CPUID: IMPLEMENTER Position */
\r
262 #define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
\r
264 #define SCB_CPUID_VARIANT_Pos 20 /*!< SCB CPUID: VARIANT Position */
\r
265 #define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
\r
267 #define SCB_CPUID_ARCHITECTURE_Pos 16 /*!< SCB CPUID: ARCHITECTURE Position */
\r
268 #define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
\r
270 #define SCB_CPUID_PARTNO_Pos 4 /*!< SCB CPUID: PARTNO Position */
\r
271 #define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
\r
273 #define SCB_CPUID_REVISION_Pos 0 /*!< SCB CPUID: REVISION Position */
\r
274 #define SCB_CPUID_REVISION_Msk (0xFUL << SCB_CPUID_REVISION_Pos) /*!< SCB CPUID: REVISION Mask */
\r
276 /* SCB Interrupt Control State Register Definitions */
\r
277 #define SCB_ICSR_NMIPENDSET_Pos 31 /*!< SCB ICSR: NMIPENDSET Position */
\r
278 #define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
\r
280 #define SCB_ICSR_PENDSVSET_Pos 28 /*!< SCB ICSR: PENDSVSET Position */
\r
281 #define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
\r
283 #define SCB_ICSR_PENDSVCLR_Pos 27 /*!< SCB ICSR: PENDSVCLR Position */
\r
284 #define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
\r
286 #define SCB_ICSR_PENDSTSET_Pos 26 /*!< SCB ICSR: PENDSTSET Position */
\r
287 #define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
\r
289 #define SCB_ICSR_PENDSTCLR_Pos 25 /*!< SCB ICSR: PENDSTCLR Position */
\r
290 #define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
\r
292 #define SCB_ICSR_ISRPREEMPT_Pos 23 /*!< SCB ICSR: ISRPREEMPT Position */
\r
293 #define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
\r
295 #define SCB_ICSR_ISRPENDING_Pos 22 /*!< SCB ICSR: ISRPENDING Position */
\r
296 #define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
\r
298 #define SCB_ICSR_VECTPENDING_Pos 12 /*!< SCB ICSR: VECTPENDING Position */
\r
299 #define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
\r
301 #define SCB_ICSR_VECTACTIVE_Pos 0 /*!< SCB ICSR: VECTACTIVE Position */
\r
302 #define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL << SCB_ICSR_VECTACTIVE_Pos) /*!< SCB ICSR: VECTACTIVE Mask */
\r
304 /* SCB Application Interrupt and Reset Control Register Definitions */
\r
305 #define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */
\r
306 #define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
\r
308 #define SCB_AIRCR_VECTKEYSTAT_Pos 16 /*!< SCB AIRCR: VECTKEYSTAT Position */
\r
309 #define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
\r
311 #define SCB_AIRCR_ENDIANESS_Pos 15 /*!< SCB AIRCR: ENDIANESS Position */
\r
312 #define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
\r
314 #define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */
\r
315 #define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
\r
317 #define SCB_AIRCR_VECTCLRACTIVE_Pos 1 /*!< SCB AIRCR: VECTCLRACTIVE Position */
\r
318 #define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
\r
320 /* SCB System Control Register Definitions */
\r
321 #define SCB_SCR_SEVONPEND_Pos 4 /*!< SCB SCR: SEVONPEND Position */
\r
322 #define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
\r
324 #define SCB_SCR_SLEEPDEEP_Pos 2 /*!< SCB SCR: SLEEPDEEP Position */
\r
325 #define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
\r
327 #define SCB_SCR_SLEEPONEXIT_Pos 1 /*!< SCB SCR: SLEEPONEXIT Position */
\r
328 #define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
\r
330 /* SCB Configuration Control Register Definitions */
\r
331 #define SCB_CCR_STKALIGN_Pos 9 /*!< SCB CCR: STKALIGN Position */
\r
332 #define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
\r
334 #define SCB_CCR_UNALIGN_TRP_Pos 3 /*!< SCB CCR: UNALIGN_TRP Position */
\r
335 #define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
\r
337 /*@} end of group CMSIS_SCB */
\r
340 /** \ingroup CMSIS_core_register
\r
341 \defgroup CMSIS_SysTick CMSIS SysTick
\r
342 Type definitions for the Cortex-M System Timer Registers
\r
346 /** \brief Structure type to access the System Timer (SysTick).
\r
350 __IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
\r
351 __IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
\r
352 __IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
\r
353 __I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
\r
356 /* SysTick Control / Status Register Definitions */
\r
357 #define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */
\r
358 #define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
\r
360 #define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */
\r
361 #define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
\r
363 #define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */
\r
364 #define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
\r
366 #define SysTick_CTRL_ENABLE_Pos 0 /*!< SysTick CTRL: ENABLE Position */
\r
367 #define SysTick_CTRL_ENABLE_Msk (1UL << SysTick_CTRL_ENABLE_Pos) /*!< SysTick CTRL: ENABLE Mask */
\r
369 /* SysTick Reload Register Definitions */
\r
370 #define SysTick_LOAD_RELOAD_Pos 0 /*!< SysTick LOAD: RELOAD Position */
\r
371 #define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL << SysTick_LOAD_RELOAD_Pos) /*!< SysTick LOAD: RELOAD Mask */
\r
373 /* SysTick Current Register Definitions */
\r
374 #define SysTick_VAL_CURRENT_Pos 0 /*!< SysTick VAL: CURRENT Position */
\r
375 #define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick VAL: CURRENT Mask */
\r
377 /* SysTick Calibration Register Definitions */
\r
378 #define SysTick_CALIB_NOREF_Pos 31 /*!< SysTick CALIB: NOREF Position */
\r
379 #define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
\r
381 #define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */
\r
382 #define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
\r
384 #define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */
\r
385 #define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick CALIB: TENMS Mask */
\r
387 /*@} end of group CMSIS_SysTick */
\r
390 /** \ingroup CMSIS_core_register
\r
391 \defgroup CMSIS_CoreDebug CMSIS Core Debug
\r
392 Cortex-M0 Core Debug Registers (DCB registers, SHCSR, and DFSR) are only accessible over DAP
\r
393 and not via processor. Therefore they are not covered by the Cortex-M0 header file.
\r
397 /*@} end of group CMSIS_CoreDebug */
\r
400 /** \ingroup CMSIS_core_register
\r
404 /* Memory mapping of Cortex-M0 Hardware */
\r
405 #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
\r
406 #define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */
\r
407 #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
\r
408 #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
\r
409 #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
\r
411 #define SCB ((SCB_Type *) SCB_BASE) /*!< SCB configuration struct */
\r
412 #define SysTick ((SysTick_Type *) SysTick_BASE) /*!< SysTick configuration struct */
\r
413 #define NVIC ((NVIC_Type *) NVIC_BASE) /*!< NVIC configuration struct */
\r
419 /*******************************************************************************
\r
420 * Hardware Abstraction Layer
\r
421 ******************************************************************************/
\r
422 /** \defgroup CMSIS_Core_FunctionInterface CMSIS Core Function Interface
\r
423 Core Function Interface contains:
\r
424 - Core NVIC Functions
\r
425 - Core SysTick Functions
\r
426 - Core Register Access Functions
\r
431 /* ########################## NVIC functions #################################### */
\r
432 /** \ingroup CMSIS_Core_FunctionInterface
\r
433 \defgroup CMSIS_Core_NVICFunctions CMSIS Core NVIC Functions
\r
437 /* Interrupt Priorities are WORD accessible only under ARMv6M */
\r
438 /* The following MACROS handle generation of the register offset and byte masks */
\r
439 #define _BIT_SHIFT(IRQn) ( (((uint32_t)(IRQn) ) & 0x03) * 8 )
\r
440 #define _SHP_IDX(IRQn) ( ((((uint32_t)(IRQn) & 0x0F)-8) >> 2) )
\r
441 #define _IP_IDX(IRQn) ( ((uint32_t)(IRQn) >> 2) )
\r
444 /** \brief Enable External Interrupt
\r
446 This function enables a device specific interrupt in the NVIC interrupt controller.
\r
447 The interrupt number cannot be a negative value.
\r
449 \param [in] IRQn Number of the external interrupt to enable
\r
451 static __INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
\r
453 NVIC->ISER[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
\r
457 /** \brief Disable External Interrupt
\r
459 This function disables a device specific interupt in the NVIC interrupt controller.
\r
460 The interrupt number cannot be a negative value.
\r
462 \param [in] IRQn Number of the external interrupt to disable
\r
464 static __INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
\r
466 NVIC->ICER[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
\r
470 /** \brief Get Pending Interrupt
\r
472 This function reads the pending register in the NVIC and returns the pending bit
\r
473 for the specified interrupt.
\r
475 \param [in] IRQn Number of the interrupt for get pending
\r
476 \return 0 Interrupt status is not pending
\r
477 \return 1 Interrupt status is pending
\r
479 static __INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
\r
481 return((uint32_t) ((NVIC->ISPR[0] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0));
\r
485 /** \brief Set Pending Interrupt
\r
487 This function sets the pending bit for the specified interrupt.
\r
488 The interrupt number cannot be a negative value.
\r
490 \param [in] IRQn Number of the interrupt for set pending
\r
492 static __INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
\r
494 NVIC->ISPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
\r
498 /** \brief Clear Pending Interrupt
\r
500 This function clears the pending bit for the specified interrupt.
\r
501 The interrupt number cannot be a negative value.
\r
503 \param [in] IRQn Number of the interrupt for clear pending
\r
505 static __INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
\r
507 NVIC->ICPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */
\r
511 /** \brief Set Interrupt Priority
\r
513 This function sets the priority for the specified interrupt. The interrupt
\r
514 number can be positive to specify an external (device specific)
\r
515 interrupt, or negative to specify an internal (core) interrupt.
\r
517 Note: The priority cannot be set for every core interrupt.
\r
519 \param [in] IRQn Number of the interrupt for set priority
\r
520 \param [in] priority Priority to set
\r
522 static __INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
\r
525 SCB->SHP[_SHP_IDX(IRQn)] = (SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |
\r
526 (((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }
\r
528 NVIC->IPR[_IP_IDX(IRQn)] = (NVIC->IPR[_IP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |
\r
529 (((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }
\r
533 /** \brief Get Interrupt Priority
\r
535 This function reads the priority for the specified interrupt. The interrupt
\r
536 number can be positive to specify an external (device specific)
\r
537 interrupt, or negative to specify an internal (core) interrupt.
\r
539 The returned priority value is automatically aligned to the implemented
\r
540 priority bits of the microcontroller.
\r
542 \param [in] IRQn Number of the interrupt for get priority
\r
543 \return Interrupt Priority
\r
545 static __INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
\r
549 return((uint32_t)((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M0 system interrupts */
\r
551 return((uint32_t)((NVIC->IPR[_IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */
\r
555 /** \brief System Reset
\r
557 This function initiate a system reset request to reset the MCU.
\r
559 static __INLINE void NVIC_SystemReset(void)
\r
561 __DSB(); /* Ensure all outstanding memory accesses included
\r
562 buffered write are completed before reset */
\r
563 SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) |
\r
564 SCB_AIRCR_SYSRESETREQ_Msk);
\r
565 __DSB(); /* Ensure completion of memory access */
\r
566 while(1); /* wait until reset */
\r
569 /*@} end of CMSIS_Core_NVICFunctions */
\r
573 /* ################################## SysTick function ############################################ */
\r
574 /** \ingroup CMSIS_Core_FunctionInterface
\r
575 \defgroup CMSIS_Core_SysTickFunctions CMSIS Core SysTick Functions
\r
579 #if (__Vendor_SysTickConfig == 0)
\r
581 /** \brief System Tick Configuration
\r
583 This function initialises the system tick timer and its interrupt and start the system tick timer.
\r
584 Counter is in free running mode to generate periodical interrupts.
\r
586 \param [in] ticks Number of ticks between two interrupts
\r
587 \return 0 Function succeeded
\r
588 \return 1 Function failed
\r
590 static __INLINE uint32_t SysTick_Config(uint32_t ticks)
\r
592 if (ticks > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */
\r
594 SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1; /* set reload register */
\r
595 NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Cortex-M0 System Interrupts */
\r
596 SysTick->VAL = 0; /* Load the SysTick Counter Value */
\r
597 SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
\r
598 SysTick_CTRL_TICKINT_Msk |
\r
599 SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
\r
600 return (0); /* Function successful */
\r
605 /*@} end of CMSIS_Core_SysTickFunctions */
\r
610 #endif /* __CORE_CM0_H_DEPENDANT */
\r
612 #endif /* __CMSIS_GENERIC */
\r