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