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