new cmsis
[rapper.git] / new_cmsis / core_cm3.h
1 /******************************************************************************\r
2  * @file:    core_cm3.h\r
3  * @purpose: CMSIS Cortex-M3 Core Peripheral Access Layer Header File\r
4  * @version: V1.20\r
5  * @date:    22. May 2009\r
6  *----------------------------------------------------------------------------\r
7  *\r
8  * Copyright (C) 2009 ARM Limited. All rights reserved.\r
9  *\r
10  * ARM Limited (ARM) is supplying this software for use with Cortex-Mx \r
11  * processor based microcontrollers.  This file can be freely distributed \r
12  * within development tools that are supporting such ARM based processors. \r
13  *\r
14  * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
15  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
16  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
17  * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR\r
18  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.\r
19  *\r
20  ******************************************************************************/\r
21 \r
22 #ifndef __CM3_CORE_H__\r
23 #define __CM3_CORE_H__\r
24 \r
25 #ifdef __cplusplus\r
26  extern "C" {\r
27 #endif \r
28 \r
29 #define __CM3_CMSIS_VERSION_MAIN  (0x01)                                                       /*!< [31:16] CMSIS HAL main version */\r
30 #define __CM3_CMSIS_VERSION_SUB   (0x20)                                                       /*!< [15:0]  CMSIS HAL sub version  */\r
31 #define __CM3_CMSIS_VERSION       ((__CM3_CMSIS_VERSION_MAIN << 16) | __CM3_CMSIS_VERSION_SUB) /*!< CMSIS HAL version number       */\r
32 \r
33 #define __CORTEX_M                (0x03)                                                       /*!< Cortex core                    */\r
34 \r
35 /**\r
36  *  Lint configuration \n\r
37  *  ----------------------- \n\r
38  *\r
39  *  The following Lint messages will be suppressed and not shown: \n\r
40  *  \n\r
41  *    --- Error 10: --- \n\r
42  *    register uint32_t __regBasePri         __asm("basepri"); \n\r
43  *    Error 10: Expecting ';' \n\r
44  *     \n\r
45  *    --- Error 530: --- \n\r
46  *    return(__regBasePri); \n\r
47  *    Warning 530: Symbol '__regBasePri' (line 264) not initialized \n\r
48  *     \n\r
49  *    --- Error 550: --- \n\r
50  *      __regBasePri = (basePri & 0x1ff); \n\r
51  *    } \n\r
52  *    Warning 550: Symbol '__regBasePri' (line 271) not accessed \n\r
53  *     \n\r
54  *    --- Error 754: --- \n\r
55  *    uint32_t RESERVED0[24]; \n\r
56  *    Info 754: local structure member '<some, not used in the HAL>' (line 109, file ./cm3_core.h) not referenced \n\r
57  *     \n\r
58  *    --- Error 750: --- \n\r
59  *    #define __CM3_CORE_H__ \n\r
60  *    Info 750: local macro '__CM3_CORE_H__' (line 43, file./cm3_core.h) not referenced \n\r
61  *     \n\r
62  *    --- Error 528: --- \n\r
63  *    static __INLINE void NVIC_DisableIRQ(uint32_t IRQn) \n\r
64  *    Warning 528: Symbol 'NVIC_DisableIRQ(unsigned int)' (line 419, file ./cm3_core.h) not referenced \n\r
65  *     \n\r
66  *    --- Error 751: --- \n\r
67  *    } InterruptType_Type; \n\r
68  *    Info 751: local typedef 'InterruptType_Type' (line 170, file ./cm3_core.h) not referenced \n\r
69  * \n\r
70  * \n\r
71  *    Note:  To re-enable a Message, insert a space before 'lint' * \n\r
72  *\r
73  */\r
74 \r
75 /*lint -save */\r
76 /*lint -e10  */\r
77 /*lint -e530 */\r
78 /*lint -e550 */\r
79 /*lint -e754 */\r
80 /*lint -e750 */\r
81 /*lint -e528 */\r
82 /*lint -e751 */\r
83 \r
84 \r
85 #include <stdint.h>                           /* Include standard types */\r
86 \r
87 #if defined (__ICCARM__)\r
88   #include <intrinsics.h>                     /* IAR Intrinsics   */\r
89 #endif\r
90 \r
91 \r
92 #ifndef __NVIC_PRIO_BITS\r
93   #define __NVIC_PRIO_BITS    4               /*!< standard definition for NVIC Priority Bits */\r
94 #endif\r
95 \r
96 \r
97 \r
98 \r
99 /**\r
100  * IO definitions\r
101  *\r
102  * define access restrictions to peripheral registers\r
103  */\r
104 \r
105 #ifdef __cplusplus\r
106 #define     __I     volatile                  /*!< defines 'read only' permissions      */\r
107 #else\r
108 #define     __I     volatile const            /*!< defines 'read only' permissions      */\r
109 #endif\r
110 #define     __O     volatile                  /*!< defines 'write only' permissions     */\r
111 #define     __IO    volatile                  /*!< defines 'read / write' permissions   */\r
112 \r
113 \r
114 \r
115 /*******************************************************************************\r
116  *                 Register Abstraction\r
117  ******************************************************************************/\r
118 \r
119 \r
120 /* System Reset */\r
121 #define NVIC_VECTRESET              0         /*!< Vector Reset Bit             */\r
122 #define NVIC_SYSRESETREQ            2         /*!< System Reset Request         */\r
123 #define NVIC_AIRCR_VECTKEY    (0x5FA << 16)   /*!< AIRCR Key for write access   */\r
124 #define NVIC_AIRCR_ENDIANESS        15        /*!< Endianess                    */\r
125 \r
126 /* Core Debug */\r
127 #define CoreDebug_DEMCR_TRCENA (1 << 24)      /*!< DEMCR TRCENA enable          */\r
128 #define ITM_TCR_ITMENA              1         /*!< ITM enable                   */\r
129 \r
130 \r
131 \r
132 \r
133 /* memory mapping struct for Nested Vectored Interrupt Controller (NVIC) */\r
134 typedef struct\r
135 {\r
136   __IO uint32_t ISER[8];                      /*!< Interrupt Set Enable Register            */\r
137        uint32_t RESERVED0[24];\r
138   __IO uint32_t ICER[8];                      /*!< Interrupt Clear Enable Register          */\r
139        uint32_t RSERVED1[24];\r
140   __IO uint32_t ISPR[8];                      /*!< Interrupt Set Pending Register           */\r
141        uint32_t RESERVED2[24];\r
142   __IO uint32_t ICPR[8];                      /*!< Interrupt Clear Pending Register         */\r
143        uint32_t RESERVED3[24];\r
144   __IO uint32_t IABR[8];                      /*!< Interrupt Active bit Register            */\r
145        uint32_t RESERVED4[56];\r
146   __IO uint8_t  IP[240];                      /*!< Interrupt Priority Register, 8Bit wide   */\r
147        uint32_t RESERVED5[644];\r
148   __O  uint32_t STIR;                         /*!< Software Trigger Interrupt Register      */\r
149 }  NVIC_Type;\r
150 \r
151 \r
152 /* memory mapping struct for System Control Block */\r
153 typedef struct\r
154 {\r
155   __I  uint32_t CPUID;                        /*!< CPU ID Base Register                                     */\r
156   __IO uint32_t ICSR;                         /*!< Interrupt Control State Register                         */\r
157   __IO uint32_t VTOR;                         /*!< Vector Table Offset Register                             */\r
158   __IO uint32_t AIRCR;                        /*!< Application Interrupt / Reset Control Register           */\r
159   __IO uint32_t SCR;                          /*!< System Control Register                                  */\r
160   __IO uint32_t CCR;                          /*!< Configuration Control Register                           */\r
161   __IO uint8_t  SHP[12];                      /*!< System Handlers Priority Registers (4-7, 8-11, 12-15)    */\r
162   __IO uint32_t SHCSR;                        /*!< System Handler Control and State Register                */\r
163   __IO uint32_t CFSR;                         /*!< Configurable Fault Status Register                       */\r
164   __IO uint32_t HFSR;                         /*!< Hard Fault Status Register                               */\r
165   __IO uint32_t DFSR;                         /*!< Debug Fault Status Register                              */\r
166   __IO uint32_t MMFAR;                        /*!< Mem Manage Address Register                              */\r
167   __IO uint32_t BFAR;                         /*!< Bus Fault Address Register                               */\r
168   __IO uint32_t AFSR;                         /*!< Auxiliary Fault Status Register                          */\r
169   __I  uint32_t PFR[2];                       /*!< Processor Feature Register                               */\r
170   __I  uint32_t DFR;                          /*!< Debug Feature Register                                   */\r
171   __I  uint32_t ADR;                          /*!< Auxiliary Feature Register                               */\r
172   __I  uint32_t MMFR[4];                      /*!< Memory Model Feature Register                            */\r
173   __I  uint32_t ISAR[5];                      /*!< ISA Feature Register                                     */\r
174 } SCB_Type;\r
175 \r
176 \r
177 /* memory mapping struct for SysTick */\r
178 typedef struct\r
179 {\r
180   __IO uint32_t CTRL;                         /*!< SysTick Control and Status Register */\r
181   __IO uint32_t LOAD;                         /*!< SysTick Reload Value Register       */\r
182   __IO uint32_t VAL;                          /*!< SysTick Current Value Register      */\r
183   __I  uint32_t CALIB;                        /*!< SysTick Calibration Register        */\r
184 } SysTick_Type;\r
185 \r
186 \r
187 /* memory mapping structur for ITM */\r
188 typedef struct\r
189 {\r
190   __O  union  \r
191   {\r
192     __O  uint8_t    u8;                       /*!< ITM Stimulus Port 8-bit               */\r
193     __O  uint16_t   u16;                      /*!< ITM Stimulus Port 16-bit              */\r
194     __O  uint32_t   u32;                      /*!< ITM Stimulus Port 32-bit              */\r
195   }  PORT [32];                               /*!< ITM Stimulus Port Registers           */\r
196        uint32_t RESERVED0[864];\r
197   __IO uint32_t TER;                          /*!< ITM Trace Enable Register             */\r
198        uint32_t RESERVED1[15];\r
199   __IO uint32_t TPR;                          /*!< ITM Trace Privilege Register          */\r
200        uint32_t RESERVED2[15];\r
201   __IO uint32_t TCR;                          /*!< ITM Trace Control Register            */\r
202        uint32_t RESERVED3[29];\r
203   __IO uint32_t IWR;                          /*!< ITM Integration Write Register        */\r
204   __IO uint32_t IRR;                          /*!< ITM Integration Read Register         */\r
205   __IO uint32_t IMCR;                         /*!< ITM Integration Mode Control Register */\r
206        uint32_t RESERVED4[43];\r
207   __IO uint32_t LAR;                          /*!< ITM Lock Access Register              */\r
208   __IO uint32_t LSR;                          /*!< ITM Lock Status Register              */\r
209        uint32_t RESERVED5[6];\r
210   __I  uint32_t PID4;                         /*!< ITM Product ID Registers              */\r
211   __I  uint32_t PID5;\r
212   __I  uint32_t PID6;\r
213   __I  uint32_t PID7;\r
214   __I  uint32_t PID0;\r
215   __I  uint32_t PID1;\r
216   __I  uint32_t PID2;\r
217   __I  uint32_t PID3;\r
218   __I  uint32_t CID0;\r
219   __I  uint32_t CID1;\r
220   __I  uint32_t CID2;\r
221   __I  uint32_t CID3;\r
222 } ITM_Type;\r
223 \r
224 \r
225 /* memory mapped struct for Interrupt Type */\r
226 typedef struct\r
227 {\r
228        uint32_t RESERVED0;\r
229   __I  uint32_t ICTR;                         /*!< Interrupt Control Type Register  */\r
230 #if ((defined __CM3_REV) && (__CM3_REV >= 0x200))\r
231   __IO uint32_t ACTLR;                        /*!< Auxiliary Control Register       */\r
232 #else\r
233        uint32_t RESERVED1;\r
234 #endif\r
235 } InterruptType_Type;\r
236 \r
237 \r
238 /* Memory Protection Unit */\r
239 #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1)\r
240 typedef struct\r
241 {\r
242   __I  uint32_t TYPE;                         /*!< MPU Type Register                               */\r
243   __IO uint32_t CTRL;                         /*!< MPU Control Register                            */\r
244   __IO uint32_t RNR;                          /*!< MPU Region RNRber Register                      */\r
245   __IO uint32_t RBAR;                         /*!< MPU Region Base Address Register                */\r
246   __IO uint32_t RASR;                         /*!< MPU Region Attribute and Size Register          */\r
247   __IO uint32_t RBAR_A1;                      /*!< MPU Alias 1 Region Base Address Register        */\r
248   __IO uint32_t RASR_A1;                      /*!< MPU Alias 1 Region Attribute and Size Register  */\r
249   __IO uint32_t RBAR_A2;                      /*!< MPU Alias 2 Region Base Address Register        */\r
250   __IO uint32_t RASR_A2;                      /*!< MPU Alias 2 Region Attribute and Size Register  */\r
251   __IO uint32_t RBAR_A3;                      /*!< MPU Alias 3 Region Base Address Register        */\r
252   __IO uint32_t RASR_A3;                      /*!< MPU Alias 3 Region Attribute and Size Register  */\r
253 } MPU_Type;\r
254 #endif\r
255 \r
256 \r
257 /* Core Debug Register */\r
258 typedef struct\r
259 {\r
260   __IO uint32_t DHCSR;                        /*!< Debug Halting Control and Status Register       */\r
261   __O  uint32_t DCRSR;                        /*!< Debug Core Register Selector Register           */\r
262   __IO uint32_t DCRDR;                        /*!< Debug Core Register Data Register               */\r
263   __IO uint32_t DEMCR;                        /*!< Debug Exception and Monitor Control Register    */\r
264 } CoreDebug_Type;\r
265 \r
266 \r
267 /* Memory mapping of Cortex-M3 Hardware */\r
268 #define SCS_BASE            (0xE000E000)                              /*!< System Control Space Base Address    */\r
269 #define ITM_BASE            (0xE0000000)                              /*!< ITM Base Address                     */\r
270 #define CoreDebug_BASE      (0xE000EDF0)                              /*!< Core Debug Base Address              */\r
271 #define SysTick_BASE        (SCS_BASE +  0x0010)                      /*!< SysTick Base Address                 */\r
272 #define NVIC_BASE           (SCS_BASE +  0x0100)                      /*!< NVIC Base Address                    */\r
273 #define SCB_BASE            (SCS_BASE +  0x0D00)                      /*!< System Control Block Base Address    */\r
274 \r
275 #define InterruptType       ((InterruptType_Type *) SCS_BASE)         /*!< Interrupt Type Register              */\r
276 #define SCB                 ((SCB_Type *)           SCB_BASE)         /*!< SCB configuration struct             */\r
277 #define SysTick             ((SysTick_Type *)       SysTick_BASE)     /*!< SysTick configuration struct         */\r
278 #define NVIC                ((NVIC_Type *)          NVIC_BASE)        /*!< NVIC configuration struct            */\r
279 #define ITM                 ((ITM_Type *)           ITM_BASE)         /*!< ITM configuration struct             */\r
280 #define CoreDebug           ((CoreDebug_Type *)     CoreDebug_BASE)   /*!< Core Debug configuration struct      */\r
281 \r
282 #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1)\r
283   #define MPU_BASE          (SCS_BASE +  0x0D90)                      /*!< Memory Protection Unit               */\r
284   #define MPU               ((MPU_Type*)            MPU_BASE)         /*!< Memory Protection Unit               */\r
285 #endif\r
286 \r
287 \r
288 \r
289 /*******************************************************************************\r
290  *                Hardware Abstraction Layer\r
291  ******************************************************************************/\r
292 \r
293 \r
294 #if defined ( __CC_ARM   )\r
295   #define __ASM            __asm                                      /*!< asm keyword for ARM Compiler          */\r
296   #define __INLINE         __inline                                   /*!< inline keyword for ARM Compiler       */\r
297 \r
298 #elif defined ( __ICCARM__ )\r
299   #define __ASM           __asm                                       /*!< asm keyword for IAR Compiler           */\r
300   #define __INLINE        inline                                      /*!< inline keyword for IAR Compiler. Only avaiable in High optimization mode! */\r
301 \r
302 #elif defined   (  __GNUC__  )\r
303   #define __ASM            __asm                                      /*!< asm keyword for GNU Compiler          */\r
304   #define __INLINE         inline                                     /*!< inline keyword for GNU Compiler       */\r
305 \r
306 #elif defined   (  __TASKING__  )\r
307   #define __ASM            __asm                                      /*!< asm keyword for TASKING Compiler          */\r
308   #define __INLINE         inline                                     /*!< inline keyword for TASKING Compiler       */\r
309 \r
310 #endif\r
311 \r
312 \r
313 /* ###################  Compiler specific Intrinsics  ########################### */\r
314 \r
315 #if defined ( __CC_ARM   ) /*------------------RealView Compiler -----------------*/\r
316 /* ARM armcc specific functions */\r
317 \r
318 #define __enable_fault_irq                __enable_fiq\r
319 #define __disable_fault_irq               __disable_fiq\r
320 \r
321 #define __NOP                             __nop\r
322 #define __WFI                             __wfi\r
323 #define __WFE                             __wfe\r
324 #define __SEV                             __sev\r
325 #define __ISB()                           __isb(0)\r
326 #define __DSB()                           __dsb(0)\r
327 #define __DMB()                           __dmb(0)\r
328 #define __REV                             __rev\r
329 #define __RBIT                            __rbit\r
330 #define __LDREXB(ptr)                     ((unsigned char ) __ldrex(ptr))\r
331 #define __LDREXH(ptr)                     ((unsigned short) __ldrex(ptr))\r
332 #define __LDREXW(ptr)                     ((unsigned int  ) __ldrex(ptr))\r
333 #define __STREXB(value, ptr)              __strex(value, ptr)\r
334 #define __STREXH(value, ptr)              __strex(value, ptr)\r
335 #define __STREXW(value, ptr)              __strex(value, ptr)\r
336 \r
337 \r
338 /* intrinsic unsigned long long __ldrexd(volatile void *ptr) */\r
339 /* intrinsic int __strexd(unsigned long long val, volatile void *ptr) */\r
340 /* intrinsic void __enable_irq();     */\r
341 /* intrinsic void __disable_irq();    */\r
342 \r
343 \r
344 /**\r
345  * @brief  Return the Process Stack Pointer\r
346  *\r
347  * @param  none\r
348  * @return uint32_t ProcessStackPointer\r
349  *\r
350  * Return the actual process stack pointer\r
351  */\r
352 extern uint32_t __get_PSP(void);\r
353 \r
354 /**\r
355  * @brief  Set the Process Stack Pointer\r
356  *\r
357  * @param  uint32_t Process Stack Pointer\r
358  * @return none\r
359  *\r
360  * Assign the value ProcessStackPointer to the MSP \r
361  * (process stack pointer) Cortex processor register\r
362  */\r
363 extern void __set_PSP(uint32_t topOfProcStack);\r
364 \r
365 /**\r
366  * @brief  Return the Main Stack Pointer\r
367  *\r
368  * @param  none\r
369  * @return uint32_t Main Stack Pointer\r
370  *\r
371  * Return the current value of the MSP (main stack pointer)\r
372  * Cortex processor register\r
373  */\r
374 extern uint32_t __get_MSP(void);\r
375 \r
376 /**\r
377  * @brief  Set the Main Stack Pointer\r
378  *\r
379  * @param  uint32_t Main Stack Pointer\r
380  * @return none\r
381  *\r
382  * Assign the value mainStackPointer to the MSP \r
383  * (main stack pointer) Cortex processor register\r
384  */\r
385 extern void __set_MSP(uint32_t topOfMainStack);\r
386 \r
387 /**\r
388  * @brief  Reverse byte order in unsigned short value\r
389  *\r
390  * @param  uint16_t value to reverse\r
391  * @return uint32_t reversed value\r
392  *\r
393  * Reverse byte order in unsigned short value\r
394  */\r
395 extern uint32_t __REV16(uint16_t value);\r
396 \r
397 /*\r
398  * @brief  Reverse byte order in signed short value with sign extension to integer\r
399  *\r
400  * @param  int16_t value to reverse\r
401  * @return int32_t reversed value\r
402  *\r
403  * Reverse byte order in signed short value with sign extension to integer\r
404  */\r
405 extern int32_t __REVSH(int16_t value);\r
406 \r
407 \r
408 #if (__ARMCC_VERSION < 400000)\r
409 \r
410 /**\r
411  * @brief  Remove the exclusive lock created by ldrex\r
412  *\r
413  * @param  none\r
414  * @return none\r
415  *\r
416  * Removes the exclusive lock which is created by ldrex.\r
417  */\r
418 extern void __CLREX(void);\r
419 \r
420 /**\r
421  * @brief  Return the Base Priority value\r
422  *\r
423  * @param  none\r
424  * @return uint32_t BasePriority\r
425  *\r
426  * Return the content of the base priority register\r
427  */\r
428 extern uint32_t __get_BASEPRI(void);\r
429 \r
430 /**\r
431  * @brief  Set the Base Priority value\r
432  *\r
433  * @param  uint32_t BasePriority\r
434  * @return none\r
435  *\r
436  * Set the base priority register\r
437  */\r
438 extern void __set_BASEPRI(uint32_t basePri);\r
439 \r
440 /**\r
441  * @brief  Return the Priority Mask value\r
442  *\r
443  * @param  none\r
444  * @return uint32_t PriMask\r
445  *\r
446  * Return the state of the priority mask bit from the priority mask\r
447  * register\r
448  */\r
449 extern uint32_t __get_PRIMASK(void);\r
450 \r
451 /**\r
452  * @brief  Set the Priority Mask value\r
453  *\r
454  * @param  uint32_t PriMask\r
455  * @return none\r
456  *\r
457  * Set the priority mask bit in the priority mask register\r
458  */\r
459 extern void __set_PRIMASK(uint32_t priMask);\r
460 \r
461 /**\r
462  * @brief  Return the Fault Mask value\r
463  *\r
464  * @param  none\r
465  * @return uint32_t FaultMask\r
466  *\r
467  * Return the content of the fault mask register\r
468  */\r
469 extern uint32_t __get_FAULTMASK(void);\r
470 \r
471 /**\r
472  * @brief  Set the Fault Mask value\r
473  *\r
474  * @param  uint32_t faultMask value\r
475  * @return none\r
476  *\r
477  * Set the fault mask register\r
478  */\r
479 extern void __set_FAULTMASK(uint32_t faultMask);\r
480 \r
481 /**\r
482  * @brief  Return the Control Register value\r
483  * \r
484  * @param  none\r
485  * @return uint32_t Control value\r
486  *\r
487  * Return the content of the control register\r
488  */\r
489 extern uint32_t __get_CONTROL(void);\r
490 \r
491 /**\r
492  * @brief  Set the Control Register value\r
493  *\r
494  * @param  uint32_t Control value\r
495  * @return none\r
496  *\r
497  * Set the control register\r
498  */\r
499 extern void __set_CONTROL(uint32_t control);\r
500 \r
501 #else  /* (__ARMCC_VERSION >= 400000)  */\r
502 \r
503 \r
504 /**\r
505  * @brief  Remove the exclusive lock created by ldrex\r
506  *\r
507  * @param  none\r
508  * @return none\r
509  *\r
510  * Removes the exclusive lock which is created by ldrex.\r
511  */\r
512 #define __CLREX                           __clrex\r
513 \r
514 /**\r
515  * @brief  Return the Base Priority value\r
516  *\r
517  * @param  none\r
518  * @return uint32_t BasePriority\r
519  *\r
520  * Return the content of the base priority register\r
521  */\r
522 static __INLINE uint32_t  __get_BASEPRI(void)\r
523 {\r
524   register uint32_t __regBasePri         __ASM("basepri");\r
525   return(__regBasePri);\r
526 }\r
527 \r
528 /**\r
529  * @brief  Set the Base Priority value\r
530  *\r
531  * @param  uint32_t BasePriority\r
532  * @return none\r
533  *\r
534  * Set the base priority register\r
535  */\r
536 static __INLINE void __set_BASEPRI(uint32_t basePri)\r
537 {\r
538   register uint32_t __regBasePri         __ASM("basepri");\r
539   __regBasePri = (basePri & 0x1ff);\r
540 }\r
541 \r
542 /**\r
543  * @brief  Return the Priority Mask value\r
544  *\r
545  * @param  none\r
546  * @return uint32_t PriMask\r
547  *\r
548  * Return the state of the priority mask bit from the priority mask\r
549  * register\r
550  */\r
551 static __INLINE uint32_t __get_PRIMASK(void)\r
552 {\r
553   register uint32_t __regPriMask         __ASM("primask");\r
554   return(__regPriMask);\r
555 }\r
556 \r
557 /**\r
558  * @brief  Set the Priority Mask value\r
559  *\r
560  * @param  uint32_t PriMask\r
561  * @return none\r
562  *\r
563  * Set the priority mask bit in the priority mask register\r
564  */\r
565 static __INLINE void __set_PRIMASK(uint32_t priMask)\r
566 {\r
567   register uint32_t __regPriMask         __ASM("primask");\r
568   __regPriMask = (priMask);\r
569 }\r
570 \r
571 /**\r
572  * @brief  Return the Fault Mask value\r
573  *\r
574  * @param  none\r
575  * @return uint32_t FaultMask\r
576  *\r
577  * Return the content of the fault mask register\r
578  */\r
579 static __INLINE uint32_t __get_FAULTMASK(void)\r
580 {\r
581   register uint32_t __regFaultMask       __ASM("faultmask");\r
582   return(__regFaultMask);\r
583 }\r
584 \r
585 /**\r
586  * @brief  Set the Fault Mask value\r
587  *\r
588  * @param  uint32_t faultMask value\r
589  * @return none\r
590  *\r
591  * Set the fault mask register\r
592  */\r
593 static __INLINE void __set_FAULTMASK(uint32_t faultMask)\r
594 {\r
595   register uint32_t __regFaultMask       __ASM("faultmask");\r
596   __regFaultMask = (faultMask & 1);\r
597 }\r
598 \r
599 /**\r
600  * @brief  Return the Control Register value\r
601  * \r
602  * @param  none\r
603  * @return uint32_t Control value\r
604  *\r
605  * Return the content of the control register\r
606  */\r
607 static __INLINE uint32_t __get_CONTROL(void)\r
608 {\r
609   register uint32_t __regControl         __ASM("control");\r
610   return(__regControl);\r
611 }\r
612 \r
613 /**\r
614  * @brief  Set the Control Register value\r
615  *\r
616  * @param  uint32_t Control value\r
617  * @return none\r
618  *\r
619  * Set the control register\r
620  */\r
621 static __INLINE void __set_CONTROL(uint32_t control)\r
622 {\r
623   register uint32_t __regControl         __ASM("control");\r
624   __regControl = control;\r
625 }\r
626 \r
627 #endif /* __ARMCC_VERSION  */ \r
628 \r
629 \r
630 \r
631 #elif (defined (__ICCARM__)) /*------------------ ICC Compiler -------------------*/\r
632 /* IAR iccarm specific functions */\r
633 \r
634 #define __enable_irq                              __enable_interrupt        /*!< global Interrupt enable */\r
635 #define __disable_irq                             __disable_interrupt       /*!< global Interrupt disable */\r
636 \r
637 static __INLINE void __enable_fault_irq()         { __ASM ("cpsie f"); }\r
638 static __INLINE void __disable_fault_irq()        { __ASM ("cpsid f"); }\r
639 \r
640 #define __NOP                                     __no_operation()          /*!< no operation intrinsic in IAR Compiler */ \r
641 static __INLINE  void __WFI()                     { __ASM ("wfi"); }\r
642 static __INLINE  void __WFE()                     { __ASM ("wfe"); }\r
643 static __INLINE  void __SEV()                     { __ASM ("sev"); }\r
644 static __INLINE  void __CLREX()                   { __ASM ("clrex"); }\r
645 \r
646 /* intrinsic void __ISB(void)                                     */\r
647 /* intrinsic void __DSB(void)                                     */\r
648 /* intrinsic void __DMB(void)                                     */\r
649 /* intrinsic void __set_PRIMASK();                                */\r
650 /* intrinsic void __get_PRIMASK();                                */\r
651 /* intrinsic void __set_FAULTMASK();                              */\r
652 /* intrinsic void __get_FAULTMASK();                              */\r
653 /* intrinsic uint32_t __REV(uint32_t value);                      */\r
654 /* intrinsic uint32_t __REVSH(uint32_t value);                    */\r
655 /* intrinsic unsigned long __STREX(unsigned long, unsigned long); */\r
656 /* intrinsic unsigned long __LDREX(unsigned long *);              */\r
657 \r
658 \r
659 /**\r
660  * @brief  Return the Process Stack Pointer\r
661  *\r
662  * @param  none\r
663  * @return uint32_t ProcessStackPointer\r
664  *\r
665  * Return the actual process stack pointer\r
666  */\r
667 extern uint32_t __get_PSP(void);\r
668 \r
669 /**\r
670  * @brief  Set the Process Stack Pointer\r
671  *\r
672  * @param  uint32_t Process Stack Pointer\r
673  * @return none\r
674  *\r
675  * Assign the value ProcessStackPointer to the MSP \r
676  * (process stack pointer) Cortex processor register\r
677  */\r
678 extern void __set_PSP(uint32_t topOfProcStack);\r
679 \r
680 /**\r
681  * @brief  Return the Main Stack Pointer\r
682  *\r
683  * @param  none\r
684  * @return uint32_t Main Stack Pointer\r
685  *\r
686  * Return the current value of the MSP (main stack pointer)\r
687  * Cortex processor register\r
688  */\r
689 extern uint32_t __get_MSP(void);\r
690 \r
691 /**\r
692  * @brief  Set the Main Stack Pointer\r
693  *\r
694  * @param  uint32_t Main Stack Pointer\r
695  * @return none\r
696  *\r
697  * Assign the value mainStackPointer to the MSP \r
698  * (main stack pointer) Cortex processor register\r
699  */\r
700 extern void __set_MSP(uint32_t topOfMainStack);\r
701 \r
702 /**\r
703  * @brief  Reverse byte order in unsigned short value\r
704  *\r
705  * @param  uint16_t value to reverse\r
706  * @return uint32_t reversed value\r
707  *\r
708  * Reverse byte order in unsigned short value\r
709  */\r
710 extern uint32_t __REV16(uint16_t value);\r
711 \r
712 /**\r
713  * @brief  Reverse bit order of value\r
714  *\r
715  * @param  uint32_t value to reverse\r
716  * @return uint32_t reversed value\r
717  *\r
718  * Reverse bit order of value\r
719  */\r
720 extern uint32_t __RBIT(uint32_t value);\r
721 \r
722 /**\r
723  * @brief  LDR Exclusive\r
724  *\r
725  * @param  uint8_t* address\r
726  * @return uint8_t value of (*address)\r
727  *\r
728  * Exclusive LDR command\r
729  */\r
730 extern uint8_t __LDREXB(uint8_t *addr);\r
731 \r
732 /**\r
733  * @brief  LDR Exclusive\r
734  *\r
735  * @param  uint16_t* address\r
736  * @return uint16_t value of (*address)\r
737  *\r
738  * Exclusive LDR command\r
739  */\r
740 extern uint16_t __LDREXH(uint16_t *addr);\r
741 \r
742 /**\r
743  * @brief  LDR Exclusive\r
744  *\r
745  * @param  uint32_t* address\r
746  * @return uint32_t value of (*address)\r
747  *\r
748  * Exclusive LDR command\r
749  */\r
750 extern uint32_t __LDREXW(uint32_t *addr);\r
751 \r
752 /**\r
753  * @brief  STR Exclusive\r
754  *\r
755  * @param  uint8_t *address\r
756  * @param  uint8_t value to store\r
757  * @return uint32_t successful / failed\r
758  *\r
759  * Exclusive STR command\r
760  */\r
761 extern uint32_t __STREXB(uint8_t value, uint8_t *addr);\r
762 \r
763 /**\r
764  * @brief  STR Exclusive\r
765  *\r
766  * @param  uint16_t *address\r
767  * @param  uint16_t value to store\r
768  * @return uint32_t successful / failed\r
769  *\r
770  * Exclusive STR command\r
771  */\r
772 extern uint32_t __STREXH(uint16_t value, uint16_t *addr);\r
773 \r
774 /**\r
775  * @brief  STR Exclusive\r
776  *\r
777  * @param  uint32_t *address\r
778  * @param  uint32_t value to store\r
779  * @return uint32_t successful / failed\r
780  *\r
781  * Exclusive STR command\r
782  */\r
783 extern uint32_t __STREXW(uint32_t value, uint32_t *addr);\r
784 \r
785 \r
786 \r
787 #elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/\r
788 /* GNU gcc specific functions */\r
789 \r
790 static __INLINE void __enable_irq()               { __ASM volatile ("cpsie i"); }\r
791 static __INLINE void __disable_irq()              { __ASM volatile ("cpsid i"); }\r
792 \r
793 static __INLINE void __enable_fault_irq()         { __ASM volatile ("cpsie f"); }\r
794 static __INLINE void __disable_fault_irq()        { __ASM volatile ("cpsid f"); }\r
795 \r
796 static __INLINE void __NOP()                      { __ASM volatile ("nop"); }\r
797 static __INLINE void __WFI()                      { __ASM volatile ("wfi"); }\r
798 static __INLINE void __WFE()                      { __ASM volatile ("wfe"); }\r
799 static __INLINE void __SEV()                      { __ASM volatile ("sev"); }\r
800 static __INLINE void __ISB()                      { __ASM volatile ("isb"); }\r
801 static __INLINE void __DSB()                      { __ASM volatile ("dsb"); }\r
802 static __INLINE void __DMB()                      { __ASM volatile ("dmb"); }\r
803 static __INLINE void __CLREX()                    { __ASM volatile ("clrex"); }\r
804 \r
805 \r
806 /**\r
807  * @brief  Return the Process Stack Pointer\r
808  *\r
809  * @param  none\r
810  * @return uint32_t ProcessStackPointer\r
811  *\r
812  * Return the actual process stack pointer\r
813  */\r
814 extern uint32_t __get_PSP(void);\r
815 \r
816 /**\r
817  * @brief  Set the Process Stack Pointer\r
818  *\r
819  * @param  uint32_t Process Stack Pointer\r
820  * @return none\r
821  *\r
822  * Assign the value ProcessStackPointer to the MSP \r
823  * (process stack pointer) Cortex processor register\r
824  */\r
825 extern void __set_PSP(uint32_t topOfProcStack);\r
826 \r
827 /**\r
828  * @brief  Return the Main Stack Pointer\r
829  *\r
830  * @param  none\r
831  * @return uint32_t Main Stack Pointer\r
832  *\r
833  * Return the current value of the MSP (main stack pointer)\r
834  * Cortex processor register\r
835  */\r
836 extern uint32_t __get_MSP(void);\r
837 \r
838 /**\r
839  * @brief  Set the Main Stack Pointer\r
840  *\r
841  * @param  uint32_t Main Stack Pointer\r
842  * @return none\r
843  *\r
844  * Assign the value mainStackPointer to the MSP \r
845  * (main stack pointer) Cortex processor register\r
846  */\r
847 extern void __set_MSP(uint32_t topOfMainStack);\r
848 \r
849 /**\r
850  * @brief  Return the Base Priority value\r
851  *\r
852  * @param  none\r
853  * @return uint32_t BasePriority\r
854  *\r
855  * Return the content of the base priority register\r
856  */\r
857 extern uint32_t __get_BASEPRI(void);\r
858 \r
859 /**\r
860  * @brief  Set the Base Priority value\r
861  *\r
862  * @param  uint32_t BasePriority\r
863  * @return none\r
864  *\r
865  * Set the base priority register\r
866  */\r
867 extern void __set_BASEPRI(uint32_t basePri);\r
868 \r
869 /**\r
870  * @brief  Return the Priority Mask value\r
871  *\r
872  * @param  none\r
873  * @return uint32_t PriMask\r
874  *\r
875  * Return the state of the priority mask bit from the priority mask\r
876  * register\r
877  */\r
878 extern uint32_t  __get_PRIMASK(void);\r
879 \r
880 /**\r
881  * @brief  Set the Priority Mask value\r
882  *\r
883  * @param  uint32_t PriMask\r
884  * @return none\r
885  *\r
886  * Set the priority mask bit in the priority mask register\r
887  */\r
888 extern void __set_PRIMASK(uint32_t priMask);\r
889 \r
890 /**\r
891  * @brief  Return the Fault Mask value\r
892  *\r
893  * @param  none\r
894  * @return uint32_t FaultMask\r
895  *\r
896  * Return the content of the fault mask register\r
897  */\r
898 extern uint32_t __get_FAULTMASK(void);\r
899 \r
900 /**\r
901  * @brief  Set the Fault Mask value\r
902  *\r
903  * @param  uint32_t faultMask value\r
904  * @return none\r
905  *\r
906  * Set the fault mask register\r
907  */\r
908 extern void __set_FAULTMASK(uint32_t faultMask);\r
909 \r
910 /**\r
911  * @brief  Return the Control Register value\r
912\r
913 *  @param  none\r
914 *  @return uint32_t Control value\r
915  *\r
916  * Return the content of the control register\r
917  */\r
918 extern uint32_t __get_CONTROL(void);\r
919 \r
920 /**\r
921  * @brief  Set the Control Register value\r
922  *\r
923  * @param  uint32_t Control value\r
924  * @return none\r
925  *\r
926  * Set the control register\r
927  */\r
928 extern void __set_CONTROL(uint32_t control);\r
929 \r
930 /**\r
931  * @brief  Reverse byte order in integer value\r
932  *\r
933  * @param  uint32_t value to reverse\r
934  * @return uint32_t reversed value\r
935  *\r
936  * Reverse byte order in integer value\r
937  */\r
938 extern uint32_t __REV(uint32_t value);\r
939 \r
940 /**\r
941  * @brief  Reverse byte order in unsigned short value\r
942  *\r
943  * @param  uint16_t value to reverse\r
944  * @return uint32_t reversed value\r
945  *\r
946  * Reverse byte order in unsigned short value\r
947  */\r
948 extern uint32_t __REV16(uint16_t value);\r
949 \r
950 /*\r
951  * Reverse byte order in signed short value with sign extension to integer\r
952  *\r
953  * @param  int16_t value to reverse\r
954  * @return int32_t reversed value\r
955  *\r
956  * @brief  Reverse byte order in signed short value with sign extension to integer\r
957  */\r
958 extern int32_t __REVSH(int16_t value);\r
959 \r
960 /**\r
961  * @brief  Reverse bit order of value\r
962  *\r
963  * @param  uint32_t value to reverse\r
964  * @return uint32_t reversed value\r
965  *\r
966  * Reverse bit order of value\r
967  */\r
968 extern uint32_t __RBIT(uint32_t value);\r
969 \r
970 /**\r
971  * @brief  LDR Exclusive\r
972  *\r
973  * @param  uint8_t* address\r
974  * @return uint8_t value of (*address)\r
975  *\r
976  * Exclusive LDR command\r
977  */\r
978 extern uint8_t __LDREXB(uint8_t *addr);\r
979 \r
980 /**\r
981  * @brief  LDR Exclusive\r
982  *\r
983  * @param  uint16_t* address\r
984  * @return uint16_t value of (*address)\r
985  *\r
986  * Exclusive LDR command\r
987  */\r
988 extern uint16_t __LDREXH(uint16_t *addr);\r
989 \r
990 /**\r
991  * @brief  LDR Exclusive\r
992  *\r
993  * @param  uint32_t* address\r
994  * @return uint32_t value of (*address)\r
995  *\r
996  * Exclusive LDR command\r
997  */\r
998 extern uint32_t __LDREXW(uint32_t *addr);\r
999 \r
1000 /**\r
1001  * @brief  STR Exclusive\r
1002  *\r
1003  * @param  uint8_t *address\r
1004  * @param  uint8_t value to store\r
1005  * @return uint32_t successful / failed\r
1006  *\r
1007  * Exclusive STR command\r
1008  */\r
1009 extern uint32_t __STREXB(uint8_t value, uint8_t *addr);\r
1010 \r
1011 /**\r
1012  * @brief  STR Exclusive\r
1013  *\r
1014  * @param  uint16_t *address\r
1015  * @param  uint16_t value to store\r
1016  * @return uint32_t successful / failed\r
1017  *\r
1018  * Exclusive STR command\r
1019  */\r
1020 extern uint32_t __STREXH(uint16_t value, uint16_t *addr);\r
1021 \r
1022 /**\r
1023  * @brief  STR Exclusive\r
1024  *\r
1025  * @param  uint32_t *address\r
1026  * @param  uint32_t value to store\r
1027  * @return uint32_t successful / failed\r
1028  *\r
1029  * Exclusive STR command\r
1030  */\r
1031 extern uint32_t __STREXW(uint32_t value, uint32_t *addr);\r
1032 \r
1033 \r
1034 #elif (defined (__TASKING__)) /*------------------ TASKING Compiler ---------------------*/\r
1035 /* TASKING carm specific functions */\r
1036 \r
1037 /*\r
1038  * The CMSIS functions have been implemented as intrinsics in the compiler.\r
1039  * Please use "carm -?i" to get an up to date list of all instrinsics,\r
1040  * Including the CMSIS ones.\r
1041  */\r
1042 \r
1043 #endif\r
1044 \r
1045 \r
1046 \r
1047 /* ##########################   NVIC functions  #################################### */\r
1048 \r
1049 \r
1050 /**\r
1051  * @brief  Set the Priority Grouping in NVIC Interrupt Controller\r
1052  *\r
1053  * @param  uint32_t priority_grouping is priority grouping field\r
1054  * @return none \r
1055  *\r
1056  * Set the priority grouping field using the required unlock sequence.\r
1057  * The parameter priority_grouping is assigned to the field \r
1058  * SCB->AIRCR [10:8] PRIGROUP field. Only values from 0..7 are used.\r
1059  * In case of a conflict between priority grouping and available\r
1060  * priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set.\r
1061  */\r
1062 static __INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)\r
1063 {\r
1064   uint32_t reg_value;\r
1065   uint32_t PriorityGroupTmp = (PriorityGroup & 0x07);                         /* only values 0..7 are used          */\r
1066   \r
1067   reg_value  = SCB->AIRCR;                                                    /* read old register configuration    */\r
1068   reg_value &= ~((0xFFFFU << 16) | (0x0F << 8));                              /* clear bits to change               */\r
1069   reg_value  = ((reg_value | NVIC_AIRCR_VECTKEY | (PriorityGroupTmp << 8)));  /* Insert write key and priorty group */\r
1070   SCB->AIRCR = reg_value;\r
1071 }\r
1072 \r
1073 /**\r
1074  * @brief  Get the Priority Grouping from NVIC Interrupt Controller\r
1075  *\r
1076  * @param  none\r
1077  * @return uint32_t   priority grouping field \r
1078  *\r
1079  * Get the priority grouping from NVIC Interrupt Controller.\r
1080  * priority grouping is SCB->AIRCR [10:8] PRIGROUP field.\r
1081  */\r
1082 static __INLINE uint32_t NVIC_GetPriorityGrouping(void)\r
1083 {\r
1084   return ((SCB->AIRCR >> 8) & 0x07);                                          /* read priority grouping field */\r
1085 }\r
1086 \r
1087 /**\r
1088  * @brief  Enable Interrupt in NVIC Interrupt Controller\r
1089  *\r
1090  * @param  IRQn_Type IRQn specifies the interrupt number\r
1091  * @return none \r
1092  *\r
1093  * Enable a device specific interupt in the NVIC interrupt controller.\r
1094  * The interrupt number cannot be a negative value.\r
1095  */\r
1096 static __INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)\r
1097 {\r
1098   NVIC->ISER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* enable interrupt */\r
1099 }\r
1100 \r
1101 /**\r
1102  * @brief  Disable the interrupt line for external interrupt specified\r
1103  * \r
1104  * @param  IRQn_Type IRQn is the positive number of the external interrupt\r
1105  * @return none\r
1106  * \r
1107  * Disable a device specific interupt in the NVIC interrupt controller.\r
1108  * The interrupt number cannot be a negative value.\r
1109  */\r
1110 static __INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)\r
1111 {\r
1112   NVIC->ICER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* disable interrupt */\r
1113 }\r
1114 \r
1115 /**\r
1116  * @brief  Read the interrupt pending bit for a device specific interrupt source\r
1117  * \r
1118  * @param  IRQn_Type IRQn is the number of the device specifc interrupt\r
1119  * @return uint32_t 1 if pending interrupt else 0\r
1120  *\r
1121  * Read the pending register in NVIC and return 1 if its status is pending, \r
1122  * otherwise it returns 0\r
1123  */\r
1124 static __INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)\r
1125 {\r
1126   return((uint32_t) ((NVIC->ISPR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if pending else 0 */\r
1127 }\r
1128 \r
1129 /**\r
1130  * @brief  Set the pending bit for an external interrupt\r
1131  * \r
1132  * @param  IRQn_Type IRQn is the Number of the interrupt\r
1133  * @return none\r
1134  *\r
1135  * Set the pending bit for the specified interrupt.\r
1136  * The interrupt number cannot be a negative value.\r
1137  */\r
1138 static __INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)\r
1139 {\r
1140   NVIC->ISPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* set interrupt pending */\r
1141 }\r
1142 \r
1143 /**\r
1144  * @brief  Clear the pending bit for an external interrupt\r
1145  *\r
1146  * @param  IRQn_Type IRQn is the Number of the interrupt\r
1147  * @return none\r
1148  *\r
1149  * Clear the pending bit for the specified interrupt. \r
1150  * The interrupt number cannot be a negative value.\r
1151  */\r
1152 static __INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)\r
1153 {\r
1154   NVIC->ICPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */\r
1155 }\r
1156 \r
1157 /**\r
1158  * @brief  Read the active bit for an external interrupt\r
1159  *\r
1160  * @param  IRQn_Type  IRQn is the Number of the interrupt\r
1161  * @return uint32_t   1 if active else 0\r
1162  *\r
1163  * Read the active register in NVIC and returns 1 if its status is active, \r
1164  * otherwise it returns 0.\r
1165  */\r
1166 static __INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn)\r
1167 {\r
1168   return((uint32_t)((NVIC->IABR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if active else 0 */\r
1169 }\r
1170 \r
1171 /**\r
1172  * @brief  Set the priority for an interrupt\r
1173  *\r
1174  * @param  IRQn_Type IRQn is the Number of the interrupt\r
1175  * @param  priority is the priority for the interrupt\r
1176  * @return none\r
1177  *\r
1178  * Set the priority for the specified interrupt. The interrupt \r
1179  * number can be positive to specify an external (device specific) \r
1180  * interrupt, or negative to specify an internal (core) interrupt. \n\r
1181  *\r
1182  * Note: The priority cannot be set for every core interrupt.\r
1183  */\r
1184 static __INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)\r
1185 {\r
1186   if(IRQn < 0) {\r
1187     SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for Cortex-M3 System Interrupts */\r
1188   else {\r
1189     NVIC->IP[(uint32_t)(IRQn)] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff);    }        /* set Priority for device specific Interrupts      */\r
1190 }\r
1191 \r
1192 /**\r
1193  * @brief  Read the priority for an interrupt\r
1194  *\r
1195  * @param  IRQn_Type IRQn is the Number of the interrupt\r
1196  * @return uint32_t  priority is the priority for the interrupt\r
1197  *\r
1198  * Read the priority for the specified interrupt. The interrupt \r
1199  * number can be positive to specify an external (device specific) \r
1200  * interrupt, or negative to specify an internal (core) interrupt.\r
1201  *\r
1202  * The returned priority value is automatically aligned to the implemented\r
1203  * priority bits of the microcontroller.\r
1204  *\r
1205  * Note: The priority cannot be set for every core interrupt.\r
1206  */\r
1207 static __INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)\r
1208 {\r
1209 \r
1210   if(IRQn < 0) {\r
1211     return((uint32_t)(SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] >> (8 - __NVIC_PRIO_BITS)));  } /* get priority for Cortex-M3 system interrupts */\r
1212   else {\r
1213     return((uint32_t)(NVIC->IP[(uint32_t)(IRQn)]           >> (8 - __NVIC_PRIO_BITS)));  } /* get priority for device specific interrupts  */\r
1214 }\r
1215 \r
1216 \r
1217 /**\r
1218  * @brief  Encode the priority for an interrupt\r
1219  *\r
1220  * @param  uint32_t PriorityGroup   is the used priority group\r
1221  * @param  uint32_t PreemptPriority is the preemptive priority value (starting from 0)\r
1222  * @param  uint32_t SubPriority     is the sub priority value (starting from 0)\r
1223  * @return uint32_t                    the priority for the interrupt\r
1224  *\r
1225  * Encode the priority for an interrupt with the given priority group,\r
1226  * preemptive priority value and sub priority value.\r
1227  * In case of a conflict between priority grouping and available\r
1228  * priority bits (__NVIC_PRIO_BITS) the samllest possible priority group is set.\r
1229  *\r
1230  * The returned priority value can be used for NVIC_SetPriority(...) function\r
1231  */\r
1232 static __INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)\r
1233 {\r
1234   uint32_t PriorityGroupTmp = (PriorityGroup & 0x07);                         /* only values 0..7 are used          */\r
1235   uint32_t PreemptPriorityBits;\r
1236   uint32_t SubPriorityBits;\r
1237 \r
1238   PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp;\r
1239   SubPriorityBits     = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS;\r
1240  \r
1241   return (\r
1242            ((PreemptPriority & ((1 << (PreemptPriorityBits)) - 1)) << SubPriorityBits) |\r
1243            ((SubPriority     & ((1 << (SubPriorityBits    )) - 1)))\r
1244          );\r
1245 }\r
1246 \r
1247 \r
1248 /**\r
1249  * @brief  Decode the priority of an interrupt\r
1250  *\r
1251  * @param  uint32_t   Priority       the priority for the interrupt\r
1252  * @param  uint32_t   PrioGroup   is the used priority group\r
1253  * @param  uint32_t* pPreemptPrio is the preemptive priority value (starting from 0)\r
1254  * @param  uint32_t* pSubPrio     is the sub priority value (starting from 0)\r
1255  * @return none\r
1256  *\r
1257  * Decode an interrupt priority value with the given priority group to \r
1258  * preemptive priority value and sub priority value.\r
1259  * In case of a conflict between priority grouping and available\r
1260  * priority bits (__NVIC_PRIO_BITS) the samllest possible priority group is set.\r
1261  *\r
1262  * The priority value can be retrieved with NVIC_GetPriority(...) function\r
1263  */\r
1264 static __INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority)\r
1265 {\r
1266   uint32_t PriorityGroupTmp = (PriorityGroup & 0x07);                         /* only values 0..7 are used          */\r
1267   uint32_t PreemptPriorityBits;\r
1268   uint32_t SubPriorityBits;\r
1269 \r
1270   PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp;\r
1271   SubPriorityBits     = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS;\r
1272   \r
1273   *pPreemptPriority = (Priority >> SubPriorityBits) & ((1 << (PreemptPriorityBits)) - 1);\r
1274   *pSubPriority     = (Priority                   ) & ((1 << (SubPriorityBits    )) - 1);\r
1275 }\r
1276 \r
1277 \r
1278 \r
1279 /* ##################################    SysTick function  ############################################ */\r
1280 \r
1281 #if (!defined (__Vendor_SysTickConfig)) || (__Vendor_SysTickConfig == 0)\r
1282 \r
1283 /* SysTick constants */\r
1284 #define SYSTICK_ENABLE              0                                          /* Config-Bit to start or stop the SysTick Timer                         */\r
1285 #define SYSTICK_TICKINT             1                                          /* Config-Bit to enable or disable the SysTick interrupt                 */\r
1286 #define SYSTICK_CLKSOURCE           2                                          /* Clocksource has the offset 2 in SysTick Control and Status Register   */\r
1287 #define SYSTICK_MAXCOUNT       ((1<<24) -1)                                    /* SysTick MaxCount                                                      */\r
1288 \r
1289 /**\r
1290  * @brief  Initialize and start the SysTick counter and its interrupt.\r
1291  *\r
1292  * @param  uint32_t ticks is the number of ticks between two interrupts\r
1293  * @return  none\r
1294  *\r
1295  * Initialise the system tick timer and its interrupt and start the\r
1296  * system tick timer / counter in free running mode to generate \r
1297  * periodical interrupts.\r
1298  */\r
1299 static __INLINE uint32_t SysTick_Config(uint32_t ticks)\r
1300\r
1301   if (ticks > SYSTICK_MAXCOUNT)  return (1);                                             /* Reload value impossible */\r
1302 \r
1303   SysTick->LOAD  =  (ticks & SYSTICK_MAXCOUNT) - 1;                                      /* set reload register */\r
1304   NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1);                            /* set Priority for Cortex-M0 System Interrupts */\r
1305   SysTick->VAL   =  (0x00);                                                              /* Load the SysTick Counter Value */\r
1306   SysTick->CTRL = (1 << SYSTICK_CLKSOURCE) | (1<<SYSTICK_ENABLE) | (1<<SYSTICK_TICKINT); /* Enable SysTick IRQ and SysTick Timer */\r
1307   return (0);                                                                            /* Function successful */\r
1308 }\r
1309 \r
1310 #endif\r
1311 \r
1312 \r
1313 \r
1314 \r
1315 \r
1316 /* ##################################    Reset function  ############################################ */\r
1317 \r
1318 /**\r
1319  * @brief  Initiate a system reset request.\r
1320  *\r
1321  * @param   none\r
1322  * @return  none\r
1323  *\r
1324  * Initialize a system reset request to reset the MCU\r
1325  */\r
1326 static __INLINE void NVIC_SystemReset(void)\r
1327 {\r
1328   SCB->AIRCR  = (NVIC_AIRCR_VECTKEY | (SCB->AIRCR & (0x700)) | (1<<NVIC_SYSRESETREQ)); /* Keep priority group unchanged */\r
1329   __DSB();                                                                             /* Ensure completion of memory access */              \r
1330   while(1);                                                                            /* wait until reset */\r
1331 }\r
1332 \r
1333 \r
1334 /* ##################################    Debug Output  function  ############################################ */\r
1335 \r
1336 \r
1337 /**\r
1338  * @brief  Outputs a character via the ITM channel 0\r
1339  *\r
1340  * @param   uint32_t character to output\r
1341  * @return  uint32_t input character\r
1342  *\r
1343  * The function outputs a character via the ITM channel 0. \r
1344  * The function returns when no debugger is connected that has booked the output.  \r
1345  * It is blocking when a debugger is connected, but the previous character send is not transmitted. \r
1346  */\r
1347 static __INLINE uint32_t ITM_SendChar (uint32_t ch)\r
1348 {\r
1349   if (ch == '\n') ITM_SendChar('\r');\r
1350   \r
1351   if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA)  &&\r
1352       (ITM->TCR & ITM_TCR_ITMENA)                  &&\r
1353       (ITM->TER & (1UL << 0))  ) \r
1354   {\r
1355     while (ITM->PORT[0].u32 == 0);\r
1356     ITM->PORT[0].u8 = (uint8_t) ch;\r
1357   }  \r
1358   return (ch);\r
1359 }\r
1360 \r
1361 #ifdef __cplusplus\r
1362 }\r
1363 #endif\r
1364 \r
1365 #endif /* __CM3_CORE_H__ */\r
1366 \r
1367 /*lint -restore */\r