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