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