uc-sdk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
core_cm3.h
Go to the documentation of this file.
1 /**************************************************************************/
24 #ifndef __CM3_CORE_H__
25 #define __CM3_CORE_H__
26 
66 /*lint -save */
67 /*lint -e10 */
68 /*lint -e530 */
69 /*lint -e550 */
70 /*lint -e754 */
71 /*lint -e750 */
72 /*lint -e528 */
73 /*lint -e751 */
74 
75 
84 #ifdef __cplusplus
85  extern "C" {
86 #endif
87 
88 #define __CM3_CMSIS_VERSION_MAIN (0x01)
89 #define __CM3_CMSIS_VERSION_SUB (0x30)
90 #define __CM3_CMSIS_VERSION ((__CM3_CMSIS_VERSION_MAIN << 16) | __CM3_CMSIS_VERSION_SUB)
92 #define __CORTEX_M (0x03)
94 #include <stdint.h> /* Include standard types */
95 
96 #if defined (__ICCARM__)
97  #include <intrinsics.h> /* IAR Intrinsics */
98 #endif
99 
100 
101 #ifndef __NVIC_PRIO_BITS
102  #define __NVIC_PRIO_BITS 4
103 #endif
104 
105 
106 
107 
114 #ifdef __cplusplus
115  #define __I volatile
116 #else
117  #define __I volatile const
118 #endif
119 #define __O volatile
120 #define __IO volatile
124 /*******************************************************************************
125  * Register Abstraction
126  ******************************************************************************/
127 
137 typedef struct
138 {
139  __IO uint32_t ISER[8];
140  uint32_t RESERVED0[24];
141  __IO uint32_t ICER[8];
142  uint32_t RSERVED1[24];
143  __IO uint32_t ISPR[8];
144  uint32_t RESERVED2[24];
145  __IO uint32_t ICPR[8];
146  uint32_t RESERVED3[24];
147  __IO uint32_t IABR[8];
148  uint32_t RESERVED4[56];
149  __IO uint8_t IP[240];
150  uint32_t RESERVED5[644];
151  __O uint32_t STIR;
152 } NVIC_Type; /* end of group CMSIS_CM3_NVIC */
154 
155 
161 typedef struct
162 {
163  __I uint32_t CPUID;
164  __IO uint32_t ICSR;
165  __IO uint32_t VTOR;
166  __IO uint32_t AIRCR;
167  __IO uint32_t SCR;
168  __IO uint32_t CCR;
169  __IO uint8_t SHP[12];
170  __IO uint32_t SHCSR;
171  __IO uint32_t CFSR;
172  __IO uint32_t HFSR;
173  __IO uint32_t DFSR;
174  __IO uint32_t MMFAR;
175  __IO uint32_t BFAR;
176  __IO uint32_t AFSR;
177  __I uint32_t PFR[2];
178  __I uint32_t DFR;
179  __I uint32_t ADR;
180  __I uint32_t MMFR[4];
181  __I uint32_t ISAR[5];
182 } SCB_Type;
183 
184 /* SCB CPUID Register Definitions */
185 #define SCB_CPUID_IMPLEMENTER_Pos 24
186 #define SCB_CPUID_IMPLEMENTER_Msk (0xFFul << SCB_CPUID_IMPLEMENTER_Pos)
188 #define SCB_CPUID_VARIANT_Pos 20
189 #define SCB_CPUID_VARIANT_Msk (0xFul << SCB_CPUID_VARIANT_Pos)
191 #define SCB_CPUID_PARTNO_Pos 4
192 #define SCB_CPUID_PARTNO_Msk (0xFFFul << SCB_CPUID_PARTNO_Pos)
194 #define SCB_CPUID_REVISION_Pos 0
195 #define SCB_CPUID_REVISION_Msk (0xFul << SCB_CPUID_REVISION_Pos)
197 /* SCB Interrupt Control State Register Definitions */
198 #define SCB_ICSR_NMIPENDSET_Pos 31
199 #define SCB_ICSR_NMIPENDSET_Msk (1ul << SCB_ICSR_NMIPENDSET_Pos)
201 #define SCB_ICSR_PENDSVSET_Pos 28
202 #define SCB_ICSR_PENDSVSET_Msk (1ul << SCB_ICSR_PENDSVSET_Pos)
204 #define SCB_ICSR_PENDSVCLR_Pos 27
205 #define SCB_ICSR_PENDSVCLR_Msk (1ul << SCB_ICSR_PENDSVCLR_Pos)
207 #define SCB_ICSR_PENDSTSET_Pos 26
208 #define SCB_ICSR_PENDSTSET_Msk (1ul << SCB_ICSR_PENDSTSET_Pos)
210 #define SCB_ICSR_PENDSTCLR_Pos 25
211 #define SCB_ICSR_PENDSTCLR_Msk (1ul << SCB_ICSR_PENDSTCLR_Pos)
213 #define SCB_ICSR_ISRPREEMPT_Pos 23
214 #define SCB_ICSR_ISRPREEMPT_Msk (1ul << SCB_ICSR_ISRPREEMPT_Pos)
216 #define SCB_ICSR_ISRPENDING_Pos 22
217 #define SCB_ICSR_ISRPENDING_Msk (1ul << SCB_ICSR_ISRPENDING_Pos)
219 #define SCB_ICSR_VECTPENDING_Pos 12
220 #define SCB_ICSR_VECTPENDING_Msk (0x1FFul << SCB_ICSR_VECTPENDING_Pos)
222 #define SCB_ICSR_RETTOBASE_Pos 11
223 #define SCB_ICSR_RETTOBASE_Msk (1ul << SCB_ICSR_RETTOBASE_Pos)
225 #define SCB_ICSR_VECTACTIVE_Pos 0
226 #define SCB_ICSR_VECTACTIVE_Msk (0x1FFul << SCB_ICSR_VECTACTIVE_Pos)
228 /* SCB Interrupt Control State Register Definitions */
229 #define SCB_VTOR_TBLBASE_Pos 29
230 #define SCB_VTOR_TBLBASE_Msk (0x1FFul << SCB_VTOR_TBLBASE_Pos)
232 #define SCB_VTOR_TBLOFF_Pos 7
233 #define SCB_VTOR_TBLOFF_Msk (0x3FFFFFul << SCB_VTOR_TBLOFF_Pos)
235 /* SCB Application Interrupt and Reset Control Register Definitions */
236 #define SCB_AIRCR_VECTKEY_Pos 16
237 #define SCB_AIRCR_VECTKEY_Msk (0xFFFFul << SCB_AIRCR_VECTKEY_Pos)
239 #define SCB_AIRCR_VECTKEYSTAT_Pos 16
240 #define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFul << SCB_AIRCR_VECTKEYSTAT_Pos)
242 #define SCB_AIRCR_ENDIANESS_Pos 15
243 #define SCB_AIRCR_ENDIANESS_Msk (1ul << SCB_AIRCR_ENDIANESS_Pos)
245 #define SCB_AIRCR_PRIGROUP_Pos 8
246 #define SCB_AIRCR_PRIGROUP_Msk (7ul << SCB_AIRCR_PRIGROUP_Pos)
248 #define SCB_AIRCR_SYSRESETREQ_Pos 2
249 #define SCB_AIRCR_SYSRESETREQ_Msk (1ul << SCB_AIRCR_SYSRESETREQ_Pos)
251 #define SCB_AIRCR_VECTCLRACTIVE_Pos 1
252 #define SCB_AIRCR_VECTCLRACTIVE_Msk (1ul << SCB_AIRCR_VECTCLRACTIVE_Pos)
254 #define SCB_AIRCR_VECTRESET_Pos 0
255 #define SCB_AIRCR_VECTRESET_Msk (1ul << SCB_AIRCR_VECTRESET_Pos)
257 /* SCB System Control Register Definitions */
258 #define SCB_SCR_SEVONPEND_Pos 4
259 #define SCB_SCR_SEVONPEND_Msk (1ul << SCB_SCR_SEVONPEND_Pos)
261 #define SCB_SCR_SLEEPDEEP_Pos 2
262 #define SCB_SCR_SLEEPDEEP_Msk (1ul << SCB_SCR_SLEEPDEEP_Pos)
264 #define SCB_SCR_SLEEPONEXIT_Pos 1
265 #define SCB_SCR_SLEEPONEXIT_Msk (1ul << SCB_SCR_SLEEPONEXIT_Pos)
267 /* SCB Configuration Control Register Definitions */
268 #define SCB_CCR_STKALIGN_Pos 9
269 #define SCB_CCR_STKALIGN_Msk (1ul << SCB_CCR_STKALIGN_Pos)
271 #define SCB_CCR_BFHFNMIGN_Pos 8
272 #define SCB_CCR_BFHFNMIGN_Msk (1ul << SCB_CCR_BFHFNMIGN_Pos)
274 #define SCB_CCR_DIV_0_TRP_Pos 4
275 #define SCB_CCR_DIV_0_TRP_Msk (1ul << SCB_CCR_DIV_0_TRP_Pos)
277 #define SCB_CCR_UNALIGN_TRP_Pos 3
278 #define SCB_CCR_UNALIGN_TRP_Msk (1ul << SCB_CCR_UNALIGN_TRP_Pos)
280 #define SCB_CCR_USERSETMPEND_Pos 1
281 #define SCB_CCR_USERSETMPEND_Msk (1ul << SCB_CCR_USERSETMPEND_Pos)
283 #define SCB_CCR_NONBASETHRDENA_Pos 0
284 #define SCB_CCR_NONBASETHRDENA_Msk (1ul << SCB_CCR_NONBASETHRDENA_Pos)
286 /* SCB System Handler Control and State Register Definitions */
287 #define SCB_SHCSR_USGFAULTENA_Pos 18
288 #define SCB_SHCSR_USGFAULTENA_Msk (1ul << SCB_SHCSR_USGFAULTENA_Pos)
290 #define SCB_SHCSR_BUSFAULTENA_Pos 17
291 #define SCB_SHCSR_BUSFAULTENA_Msk (1ul << SCB_SHCSR_BUSFAULTENA_Pos)
293 #define SCB_SHCSR_MEMFAULTENA_Pos 16
294 #define SCB_SHCSR_MEMFAULTENA_Msk (1ul << SCB_SHCSR_MEMFAULTENA_Pos)
296 #define SCB_SHCSR_SVCALLPENDED_Pos 15
297 #define SCB_SHCSR_SVCALLPENDED_Msk (1ul << SCB_SHCSR_SVCALLPENDED_Pos)
299 #define SCB_SHCSR_BUSFAULTPENDED_Pos 14
300 #define SCB_SHCSR_BUSFAULTPENDED_Msk (1ul << SCB_SHCSR_BUSFAULTPENDED_Pos)
302 #define SCB_SHCSR_MEMFAULTPENDED_Pos 13
303 #define SCB_SHCSR_MEMFAULTPENDED_Msk (1ul << SCB_SHCSR_MEMFAULTPENDED_Pos)
305 #define SCB_SHCSR_USGFAULTPENDED_Pos 12
306 #define SCB_SHCSR_USGFAULTPENDED_Msk (1ul << SCB_SHCSR_USGFAULTPENDED_Pos)
308 #define SCB_SHCSR_SYSTICKACT_Pos 11
309 #define SCB_SHCSR_SYSTICKACT_Msk (1ul << SCB_SHCSR_SYSTICKACT_Pos)
311 #define SCB_SHCSR_PENDSVACT_Pos 10
312 #define SCB_SHCSR_PENDSVACT_Msk (1ul << SCB_SHCSR_PENDSVACT_Pos)
314 #define SCB_SHCSR_MONITORACT_Pos 8
315 #define SCB_SHCSR_MONITORACT_Msk (1ul << SCB_SHCSR_MONITORACT_Pos)
317 #define SCB_SHCSR_SVCALLACT_Pos 7
318 #define SCB_SHCSR_SVCALLACT_Msk (1ul << SCB_SHCSR_SVCALLACT_Pos)
320 #define SCB_SHCSR_USGFAULTACT_Pos 3
321 #define SCB_SHCSR_USGFAULTACT_Msk (1ul << SCB_SHCSR_USGFAULTACT_Pos)
323 #define SCB_SHCSR_BUSFAULTACT_Pos 1
324 #define SCB_SHCSR_BUSFAULTACT_Msk (1ul << SCB_SHCSR_BUSFAULTACT_Pos)
326 #define SCB_SHCSR_MEMFAULTACT_Pos 0
327 #define SCB_SHCSR_MEMFAULTACT_Msk (1ul << SCB_SHCSR_MEMFAULTACT_Pos)
329 /* SCB Configurable Fault Status Registers Definitions */
330 #define SCB_CFSR_USGFAULTSR_Pos 16
331 #define SCB_CFSR_USGFAULTSR_Msk (0xFFFFul << SCB_CFSR_USGFAULTSR_Pos)
333 #define SCB_CFSR_BUSFAULTSR_Pos 8
334 #define SCB_CFSR_BUSFAULTSR_Msk (0xFFul << SCB_CFSR_BUSFAULTSR_Pos)
336 #define SCB_CFSR_MEMFAULTSR_Pos 0
337 #define SCB_CFSR_MEMFAULTSR_Msk (0xFFul << SCB_CFSR_MEMFAULTSR_Pos)
339 /* SCB Hard Fault Status Registers Definitions */
340 #define SCB_HFSR_DEBUGEVT_Pos 31
341 #define SCB_HFSR_DEBUGEVT_Msk (1ul << SCB_HFSR_DEBUGEVT_Pos)
343 #define SCB_HFSR_FORCED_Pos 30
344 #define SCB_HFSR_FORCED_Msk (1ul << SCB_HFSR_FORCED_Pos)
346 #define SCB_HFSR_VECTTBL_Pos 1
347 #define SCB_HFSR_VECTTBL_Msk (1ul << SCB_HFSR_VECTTBL_Pos)
349 /* SCB Debug Fault Status Register Definitions */
350 #define SCB_DFSR_EXTERNAL_Pos 4
351 #define SCB_DFSR_EXTERNAL_Msk (1ul << SCB_DFSR_EXTERNAL_Pos)
353 #define SCB_DFSR_VCATCH_Pos 3
354 #define SCB_DFSR_VCATCH_Msk (1ul << SCB_DFSR_VCATCH_Pos)
356 #define SCB_DFSR_DWTTRAP_Pos 2
357 #define SCB_DFSR_DWTTRAP_Msk (1ul << SCB_DFSR_DWTTRAP_Pos)
359 #define SCB_DFSR_BKPT_Pos 1
360 #define SCB_DFSR_BKPT_Msk (1ul << SCB_DFSR_BKPT_Pos)
362 #define SCB_DFSR_HALTED_Pos 0
363 #define SCB_DFSR_HALTED_Msk (1ul << SCB_DFSR_HALTED_Pos)
364  /* end of group CMSIS_CM3_SCB */
365 
366 
372 typedef struct
373 {
374  __IO uint32_t CTRL;
375  __IO uint32_t RELOAD;
376  __IO uint32_t CURR;
377  __IO uint32_t CALIB;
378 } SysTick_Type;
379 
380 /* SysTick Control / Status Register Definitions */
381 #define SysTick_CTRL_COUNTFLAG_Pos 16
382 #define SysTick_CTRL_COUNTFLAG_Msk (1ul << SysTick_CTRL_COUNTFLAG_Pos)
384 #define SysTick_CTRL_CLKSOURCE_Pos 2
385 #define SysTick_CTRL_CLKSOURCE_Msk (1ul << SysTick_CTRL_CLKSOURCE_Pos)
387 #define SysTick_CTRL_TICKINT_Pos 1
388 #define SysTick_CTRL_TICKINT_Msk (1ul << SysTick_CTRL_TICKINT_Pos)
390 #define SysTick_CTRL_ENABLE_Pos 0
391 #define SysTick_CTRL_ENABLE_Msk (1ul << SysTick_CTRL_ENABLE_Pos)
393 /* SysTick Reload Register Definitions */
394 #define SysTick_LOAD_RELOAD_Pos 0
395 #define SysTick_LOAD_RELOAD_Msk (0xFFFFFFul << SysTick_LOAD_RELOAD_Pos)
397 /* SysTick Current Register Definitions */
398 #define SysTick_VAL_CURRENT_Pos 0
399 #define SysTick_VAL_CURRENT_Msk (0xFFFFFFul << SysTick_VAL_CURRENT_Pos)
401 /* SysTick Calibration Register Definitions */
402 #define SysTick_CALIB_NOREF_Pos 31
403 #define SysTick_CALIB_NOREF_Msk (1ul << SysTick_CALIB_NOREF_Pos)
405 #define SysTick_CALIB_SKEW_Pos 30
406 #define SysTick_CALIB_SKEW_Msk (1ul << SysTick_CALIB_SKEW_Pos)
408 #define SysTick_CALIB_TENMS_Pos 0
409 #define SysTick_CALIB_TENMS_Msk (0xFFFFFFul << SysTick_VAL_CURRENT_Pos)
410  /* end of group CMSIS_CM3_SysTick */
411 
412 
418 typedef struct
419 {
420  __O union
421  {
422  __O uint8_t u8;
423  __O uint16_t u16;
424  __O uint32_t u32;
425  } PORT [32];
426  uint32_t RESERVED0[864];
427  __IO uint32_t TER;
428  uint32_t RESERVED1[15];
429  __IO uint32_t TPR;
430  uint32_t RESERVED2[15];
431  __IO uint32_t TCR;
432  uint32_t RESERVED3[29];
433  __IO uint32_t IWR;
434  __IO uint32_t IRR;
435  __IO uint32_t IMCR;
436  uint32_t RESERVED4[43];
437  __IO uint32_t LAR;
438  __IO uint32_t LSR;
439  uint32_t RESERVED5[6];
440  __I uint32_t PID4;
441  __I uint32_t PID5;
442  __I uint32_t PID6;
443  __I uint32_t PID7;
444  __I uint32_t PID0;
445  __I uint32_t PID1;
446  __I uint32_t PID2;
447  __I uint32_t PID3;
448  __I uint32_t CID0;
449  __I uint32_t CID1;
450  __I uint32_t CID2;
451  __I uint32_t CID3;
452 } ITM_Type;
453 
454 /* ITM Trace Privilege Register Definitions */
455 #define ITM_TPR_PRIVMASK_Pos 0
456 #define ITM_TPR_PRIVMASK_Msk (0xFul << ITM_TPR_PRIVMASK_Pos)
458 /* ITM Trace Control Register Definitions */
459 #define ITM_TCR_BUSY_Pos 23
460 #define ITM_TCR_BUSY_Msk (1ul << ITM_TCR_BUSY_Pos)
462 #define ITM_TCR_ATBID_Pos 16
463 #define ITM_TCR_ATBID_Msk (0x7Ful << ITM_TCR_ATBID_Pos)
465 #define ITM_TCR_TSPrescale_Pos 8
466 #define ITM_TCR_TSPrescale_Msk (3ul << ITM_TCR_TSPrescale_Pos)
468 #define ITM_TCR_SWOENA_Pos 4
469 #define ITM_TCR_SWOENA_Msk (1ul << ITM_TCR_SWOENA_Pos)
471 #define ITM_TCR_DWTENA_Pos 3
472 #define ITM_TCR_DWTENA_Msk (1ul << ITM_TCR_DWTENA_Pos)
474 #define ITM_TCR_SYNCENA_Pos 2
475 #define ITM_TCR_SYNCENA_Msk (1ul << ITM_TCR_SYNCENA_Pos)
477 #define ITM_TCR_TSENA_Pos 1
478 #define ITM_TCR_TSENA_Msk (1ul << ITM_TCR_TSENA_Pos)
480 #define ITM_TCR_ITMENA_Pos 0
481 #define ITM_TCR_ITMENA_Msk (1ul << ITM_TCR_ITMENA_Pos)
483 /* ITM Integration Write Register Definitions */
484 #define ITM_IWR_ATVALIDM_Pos 0
485 #define ITM_IWR_ATVALIDM_Msk (1ul << ITM_IWR_ATVALIDM_Pos)
487 /* ITM Integration Read Register Definitions */
488 #define ITM_IRR_ATREADYM_Pos 0
489 #define ITM_IRR_ATREADYM_Msk (1ul << ITM_IRR_ATREADYM_Pos)
491 /* ITM Integration Mode Control Register Definitions */
492 #define ITM_IMCR_INTEGRATION_Pos 0
493 #define ITM_IMCR_INTEGRATION_Msk (1ul << ITM_IMCR_INTEGRATION_Pos)
495 /* ITM Lock Status Register Definitions */
496 #define ITM_LSR_ByteAcc_Pos 2
497 #define ITM_LSR_ByteAcc_Msk (1ul << ITM_LSR_ByteAcc_Pos)
499 #define ITM_LSR_Access_Pos 1
500 #define ITM_LSR_Access_Msk (1ul << ITM_LSR_Access_Pos)
502 #define ITM_LSR_Present_Pos 0
503 #define ITM_LSR_Present_Msk (1ul << ITM_LSR_Present_Pos)
504  /* end of group CMSIS_CM3_ITM */
505 
506 
512 typedef struct
513 {
514  uint32_t RESERVED0;
515  __I uint32_t ICTR;
516 #if ((defined __CM3_REV) && (__CM3_REV >= 0x200))
517  __IO uint32_t ACTLR;
518 #else
519  uint32_t RESERVED1;
520 #endif
522 
523 /* Interrupt Controller Type Register Definitions */
524 #define InterruptType_ICTR_INTLINESNUM_Pos 0
525 #define InterruptType_ICTR_INTLINESNUM_Msk (0x1Ful << InterruptType_ICTR_INTLINESNUM_Pos)
527 /* Auxiliary Control Register Definitions */
528 #define InterruptType_ACTLR_DISFOLD_Pos 2
529 #define InterruptType_ACTLR_DISFOLD_Msk (1ul << InterruptType_ACTLR_DISFOLD_Pos)
531 #define InterruptType_ACTLR_DISDEFWBUF_Pos 1
532 #define InterruptType_ACTLR_DISDEFWBUF_Msk (1ul << InterruptType_ACTLR_DISDEFWBUF_Pos)
534 #define InterruptType_ACTLR_DISMCYCINT_Pos 0
535 #define InterruptType_ACTLR_DISMCYCINT_Msk (1ul << InterruptType_ACTLR_DISMCYCINT_Pos)
536  /* end of group CMSIS_CM3_InterruptType */
537 
538 
539 #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1)
540 
545 typedef struct
546 {
547  __I uint32_t TYPE;
548  __IO uint32_t CTRL;
549  __IO uint32_t RNR;
550  __IO uint32_t RBAR;
551  __IO uint32_t RASR;
552  __IO uint32_t RBAR_A1;
553  __IO uint32_t RASR_A1;
554  __IO uint32_t RBAR_A2;
555  __IO uint32_t RASR_A2;
556  __IO uint32_t RBAR_A3;
557  __IO uint32_t RASR_A3;
558 } MPU_Type;
559 
560 /* MPU Type Register */
561 #define MPU_TYPE_IREGION_Pos 16
562 #define MPU_TYPE_IREGION_Msk (0xFFul << MPU_TYPE_IREGION_Pos)
564 #define MPU_TYPE_DREGION_Pos 8
565 #define MPU_TYPE_DREGION_Msk (0xFFul << MPU_TYPE_DREGION_Pos)
567 #define MPU_TYPE_SEPARATE_Pos 0
568 #define MPU_TYPE_SEPARATE_Msk (1ul << MPU_TYPE_SEPARATE_Pos)
570 /* MPU Control Register */
571 #define MPU_CTRL_PRIVDEFENA_Pos 2
572 #define MPU_CTRL_PRIVDEFENA_Msk (1ul << MPU_CTRL_PRIVDEFENA_Pos)
574 #define MPU_CTRL_HFNMIENA_Pos 1
575 #define MPU_CTRL_HFNMIENA_Msk (1ul << MPU_CTRL_HFNMIENA_Pos)
577 #define MPU_CTRL_ENABLE_Pos 0
578 #define MPU_CTRL_ENABLE_Msk (1ul << MPU_CTRL_ENABLE_Pos)
580 /* MPU Region Number Register */
581 #define MPU_RNR_REGION_Pos 0
582 #define MPU_RNR_REGION_Msk (0xFFul << MPU_RNR_REGION_Pos)
584 /* MPU Region Base Address Register */
585 #define MPU_RBAR_ADDR_Pos 5
586 #define MPU_RBAR_ADDR_Msk (0x7FFFFFFul << MPU_RBAR_ADDR_Pos)
588 #define MPU_RBAR_VALID_Pos 4
589 #define MPU_RBAR_VALID_Msk (1ul << MPU_RBAR_VALID_Pos)
591 #define MPU_RBAR_REGION_Pos 0
592 #define MPU_RBAR_REGION_Msk (0xFul << MPU_RBAR_REGION_Pos)
594 /* MPU Region Attribute and Size Register */
595 #define MPU_RASR_XN_Pos 28
596 #define MPU_RASR_XN_Msk (1ul << MPU_RASR_XN_Pos)
598 #define MPU_RASR_AP_Pos 24
599 #define MPU_RASR_AP_Msk (7ul << MPU_RASR_AP_Pos)
601 #define MPU_RASR_TEX_Pos 19
602 #define MPU_RASR_TEX_Msk (7ul << MPU_RASR_TEX_Pos)
604 #define MPU_RASR_S_Pos 18
605 #define MPU_RASR_S_Msk (1ul << MPU_RASR_S_Pos)
607 #define MPU_RASR_C_Pos 17
608 #define MPU_RASR_C_Msk (1ul << MPU_RASR_C_Pos)
610 #define MPU_RASR_B_Pos 16
611 #define MPU_RASR_B_Msk (1ul << MPU_RASR_B_Pos)
613 #define MPU_RASR_SRD_Pos 8
614 #define MPU_RASR_SRD_Msk (0xFFul << MPU_RASR_SRD_Pos)
616 #define MPU_RASR_SIZE_Pos 1
617 #define MPU_RASR_SIZE_Msk (0x1Ful << MPU_RASR_SIZE_Pos)
619 #define MPU_RASR_ENA_Pos 0
620 #define MPU_RASR_ENA_Msk (0x1Ful << MPU_RASR_ENA_Pos)
622  /* end of group CMSIS_CM3_MPU */
623 #endif
624 
625 
631 typedef struct
632 {
633  __IO uint32_t DHCSR;
634  __O uint32_t DCRSR;
635  __IO uint32_t DCRDR;
636  __IO uint32_t DEMCR;
638 
639 /* Debug Halting Control and Status Register */
640 #define CoreDebug_DHCSR_DBGKEY_Pos 16
641 #define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFul << CoreDebug_DHCSR_DBGKEY_Pos)
643 #define CoreDebug_DHCSR_S_RESET_ST_Pos 25
644 #define CoreDebug_DHCSR_S_RESET_ST_Msk (1ul << CoreDebug_DHCSR_S_RESET_ST_Pos)
646 #define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24
647 #define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1ul << CoreDebug_DHCSR_S_RETIRE_ST_Pos)
649 #define CoreDebug_DHCSR_S_LOCKUP_Pos 19
650 #define CoreDebug_DHCSR_S_LOCKUP_Msk (1ul << CoreDebug_DHCSR_S_LOCKUP_Pos)
652 #define CoreDebug_DHCSR_S_SLEEP_Pos 18
653 #define CoreDebug_DHCSR_S_SLEEP_Msk (1ul << CoreDebug_DHCSR_S_SLEEP_Pos)
655 #define CoreDebug_DHCSR_S_HALT_Pos 17
656 #define CoreDebug_DHCSR_S_HALT_Msk (1ul << CoreDebug_DHCSR_S_HALT_Pos)
658 #define CoreDebug_DHCSR_S_REGRDY_Pos 16
659 #define CoreDebug_DHCSR_S_REGRDY_Msk (1ul << CoreDebug_DHCSR_S_REGRDY_Pos)
661 #define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5
662 #define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1ul << CoreDebug_DHCSR_C_SNAPSTALL_Pos)
664 #define CoreDebug_DHCSR_C_MASKINTS_Pos 3
665 #define CoreDebug_DHCSR_C_MASKINTS_Msk (1ul << CoreDebug_DHCSR_C_MASKINTS_Pos)
667 #define CoreDebug_DHCSR_C_STEP_Pos 2
668 #define CoreDebug_DHCSR_C_STEP_Msk (1ul << CoreDebug_DHCSR_C_STEP_Pos)
670 #define CoreDebug_DHCSR_C_HALT_Pos 1
671 #define CoreDebug_DHCSR_C_HALT_Msk (1ul << CoreDebug_DHCSR_C_HALT_Pos)
673 #define CoreDebug_DHCSR_C_DEBUGEN_Pos 0
674 #define CoreDebug_DHCSR_C_DEBUGEN_Msk (1ul << CoreDebug_DHCSR_C_DEBUGEN_Pos)
676 /* Debug Core Register Selector Register */
677 #define CoreDebug_DCRSR_REGWnR_Pos 16
678 #define CoreDebug_DCRSR_REGWnR_Msk (1ul << CoreDebug_DCRSR_REGWnR_Pos)
680 #define CoreDebug_DCRSR_REGSEL_Pos 0
681 #define CoreDebug_DCRSR_REGSEL_Msk (0x1Ful << CoreDebug_DCRSR_REGSEL_Pos)
683 /* Debug Exception and Monitor Control Register */
684 #define CoreDebug_DEMCR_TRCENA_Pos 24
685 #define CoreDebug_DEMCR_TRCENA_Msk (1ul << CoreDebug_DEMCR_TRCENA_Pos)
687 #define CoreDebug_DEMCR_MON_REQ_Pos 19
688 #define CoreDebug_DEMCR_MON_REQ_Msk (1ul << CoreDebug_DEMCR_MON_REQ_Pos)
690 #define CoreDebug_DEMCR_MON_STEP_Pos 18
691 #define CoreDebug_DEMCR_MON_STEP_Msk (1ul << CoreDebug_DEMCR_MON_STEP_Pos)
693 #define CoreDebug_DEMCR_MON_PEND_Pos 17
694 #define CoreDebug_DEMCR_MON_PEND_Msk (1ul << CoreDebug_DEMCR_MON_PEND_Pos)
696 #define CoreDebug_DEMCR_MON_EN_Pos 16
697 #define CoreDebug_DEMCR_MON_EN_Msk (1ul << CoreDebug_DEMCR_MON_EN_Pos)
699 #define CoreDebug_DEMCR_VC_HARDERR_Pos 10
700 #define CoreDebug_DEMCR_VC_HARDERR_Msk (1ul << CoreDebug_DEMCR_VC_HARDERR_Pos)
702 #define CoreDebug_DEMCR_VC_INTERR_Pos 9
703 #define CoreDebug_DEMCR_VC_INTERR_Msk (1ul << CoreDebug_DEMCR_VC_INTERR_Pos)
705 #define CoreDebug_DEMCR_VC_BUSERR_Pos 8
706 #define CoreDebug_DEMCR_VC_BUSERR_Msk (1ul << CoreDebug_DEMCR_VC_BUSERR_Pos)
708 #define CoreDebug_DEMCR_VC_STATERR_Pos 7
709 #define CoreDebug_DEMCR_VC_STATERR_Msk (1ul << CoreDebug_DEMCR_VC_STATERR_Pos)
711 #define CoreDebug_DEMCR_VC_CHKERR_Pos 6
712 #define CoreDebug_DEMCR_VC_CHKERR_Msk (1ul << CoreDebug_DEMCR_VC_CHKERR_Pos)
714 #define CoreDebug_DEMCR_VC_NOCPERR_Pos 5
715 #define CoreDebug_DEMCR_VC_NOCPERR_Msk (1ul << CoreDebug_DEMCR_VC_NOCPERR_Pos)
717 #define CoreDebug_DEMCR_VC_MMERR_Pos 4
718 #define CoreDebug_DEMCR_VC_MMERR_Msk (1ul << CoreDebug_DEMCR_VC_MMERR_Pos)
720 #define CoreDebug_DEMCR_VC_CORERESET_Pos 0
721 #define CoreDebug_DEMCR_VC_CORERESET_Msk (1ul << CoreDebug_DEMCR_VC_CORERESET_Pos)
722  /* end of group CMSIS_CM3_CoreDebug */
723 
724 
725 /* Memory mapping of Cortex-M3 Hardware */
726 #define SCS_BASE (0xE000E000)
727 #define ITM_BASE (0xE0000000)
728 #define CoreDebug_BASE (0xE000EDF0)
729 #define SysTick_BASE (SCS_BASE + 0x0010)
730 #define NVIC_BASE (SCS_BASE + 0x0100)
731 #define SCB_BASE (SCS_BASE + 0x0D00)
733 #define InterruptType ((InterruptType_Type *) SCS_BASE)
734 #define SCB ((SCB_Type *) SCB_BASE)
735 #define SysTick ((SysTick_Type *) SysTick_BASE)
736 #define NVIC ((NVIC_Type *) NVIC_BASE)
737 #define ITM ((ITM_Type *) ITM_BASE)
738 #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE)
740 #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1)
741  #define MPU_BASE (SCS_BASE + 0x0D90)
742  #define MPU ((MPU_Type*) MPU_BASE)
743 #endif
744  /* end of group CMSIS_CM3_core_register */
746 
747 
748 /*******************************************************************************
749  * Hardware Abstraction Layer
750  ******************************************************************************/
751 
752 #if defined ( __CC_ARM )
753  #define __ASM __asm
754  #define __INLINE __inline
756 #elif defined ( __ICCARM__ )
757  #define __ASM __asm
758  #define __INLINE inline
760 #elif defined ( __GNUC__ )
761  #define __ASM __asm
762  #define __INLINE inline
764 #elif defined ( __TASKING__ )
765  #define __ASM __asm
766  #define __INLINE inline
768 #endif
769 
770 
771 /* ################### Compiler specific Intrinsics ########################### */
772 
773 #if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
774 /* ARM armcc specific functions */
775 
776 #define __enable_fault_irq __enable_fiq
777 #define __disable_fault_irq __disable_fiq
778 
779 #define __NOP __nop
780 #define __WFI __wfi
781 #define __WFE __wfe
782 #define __SEV __sev
783 #define __ISB() __isb(0)
784 #define __DSB() __dsb(0)
785 #define __DMB() __dmb(0)
786 #define __REV __rev
787 #define __RBIT __rbit
788 #define __LDREXB(ptr) ((unsigned char ) __ldrex(ptr))
789 #define __LDREXH(ptr) ((unsigned short) __ldrex(ptr))
790 #define __LDREXW(ptr) ((unsigned int ) __ldrex(ptr))
791 #define __STREXB(value, ptr) __strex(value, ptr)
792 #define __STREXH(value, ptr) __strex(value, ptr)
793 #define __STREXW(value, ptr) __strex(value, ptr)
794 
795 
796 /* intrinsic unsigned long long __ldrexd(volatile void *ptr) */
797 /* intrinsic int __strexd(unsigned long long val, volatile void *ptr) */
798 /* intrinsic void __enable_irq(); */
799 /* intrinsic void __disable_irq(); */
800 
801 
809 extern uint32_t __get_PSP(void);
810 
819 extern void __set_PSP(uint32_t topOfProcStack);
820 
829 extern uint32_t __get_MSP(void);
830 
839 extern void __set_MSP(uint32_t topOfMainStack);
840 
849 extern uint32_t __REV16(uint16_t value);
850 
859 extern int32_t __REVSH(int16_t value);
860 
861 
862 #if (__ARMCC_VERSION < 400000)
863 
869 extern void __CLREX(void);
870 
878 extern uint32_t __get_BASEPRI(void);
879 
887 extern void __set_BASEPRI(uint32_t basePri);
888 
896 extern uint32_t __get_PRIMASK(void);
897 
905 extern void __set_PRIMASK(uint32_t priMask);
906 
914 extern uint32_t __get_FAULTMASK(void);
915 
923 extern void __set_FAULTMASK(uint32_t faultMask);
924 
932 extern uint32_t __get_CONTROL(void);
933 
941 extern void __set_CONTROL(uint32_t control);
942 
943 #else /* (__ARMCC_VERSION >= 400000) */
944 
950 #define __CLREX __clrex
951 
959 static __INLINE uint32_t __get_BASEPRI(void)
960 {
961  register uint32_t __regBasePri __ASM("basepri");
962  return(__regBasePri);
963 }
964 
972 static __INLINE void __set_BASEPRI(uint32_t basePri)
973 {
974  register uint32_t __regBasePri __ASM("basepri");
975  __regBasePri = (basePri & 0xff);
976 }
977 
985 static __INLINE uint32_t __get_PRIMASK(void)
986 {
987  register uint32_t __regPriMask __ASM("primask");
988  return(__regPriMask);
989 }
990 
998 static __INLINE void __set_PRIMASK(uint32_t priMask)
999 {
1000  register uint32_t __regPriMask __ASM("primask");
1001  __regPriMask = (priMask);
1002 }
1003 
1011 static __INLINE uint32_t __get_FAULTMASK(void)
1012 {
1013  register uint32_t __regFaultMask __ASM("faultmask");
1014  return(__regFaultMask);
1015 }
1016 
1024 static __INLINE void __set_FAULTMASK(uint32_t faultMask)
1025 {
1026  register uint32_t __regFaultMask __ASM("faultmask");
1027  __regFaultMask = (faultMask & 1);
1028 }
1029 
1037 static __INLINE uint32_t __get_CONTROL(void)
1038 {
1039  register uint32_t __regControl __ASM("control");
1040  return(__regControl);
1041 }
1042 
1050 static __INLINE void __set_CONTROL(uint32_t control)
1051 {
1052  register uint32_t __regControl __ASM("control");
1053  __regControl = control;
1054 }
1055 
1056 #endif /* __ARMCC_VERSION */
1057 
1058 
1059 
1060 #elif (defined (__ICCARM__)) /*------------------ ICC Compiler -------------------*/
1061 /* IAR iccarm specific functions */
1062 
1063 #define __enable_irq __enable_interrupt
1064 #define __disable_irq __disable_interrupt
1066 static __INLINE void __enable_fault_irq() { __ASM ("cpsie f"); }
1067 static __INLINE void __disable_fault_irq() { __ASM ("cpsid f"); }
1068 
1069 #define __NOP __no_operation
1070 static __INLINE void __WFI() { __ASM ("wfi"); }
1071 static __INLINE void __WFE() { __ASM ("wfe"); }
1072 static __INLINE void __SEV() { __ASM ("sev"); }
1073 static __INLINE void __CLREX() { __ASM ("clrex"); }
1074 
1075 /* intrinsic void __ISB(void) */
1076 /* intrinsic void __DSB(void) */
1077 /* intrinsic void __DMB(void) */
1078 /* intrinsic void __set_PRIMASK(); */
1079 /* intrinsic void __get_PRIMASK(); */
1080 /* intrinsic void __set_FAULTMASK(); */
1081 /* intrinsic void __get_FAULTMASK(); */
1082 /* intrinsic uint32_t __REV(uint32_t value); */
1083 /* intrinsic uint32_t __REVSH(uint32_t value); */
1084 /* intrinsic unsigned long __STREX(unsigned long, unsigned long); */
1085 /* intrinsic unsigned long __LDREX(unsigned long *); */
1086 
1087 
1095 extern uint32_t __get_PSP(void);
1096 
1105 extern void __set_PSP(uint32_t topOfProcStack);
1106 
1115 extern uint32_t __get_MSP(void);
1116 
1125 extern void __set_MSP(uint32_t topOfMainStack);
1126 
1135 extern uint32_t __REV16(uint16_t value);
1136 
1145 extern uint32_t __RBIT(uint32_t value);
1146 
1155 extern uint8_t __LDREXB(uint8_t *addr);
1156 
1165 extern uint16_t __LDREXH(uint16_t *addr);
1166 
1175 extern uint32_t __LDREXW(uint32_t *addr);
1176 
1186 extern uint32_t __STREXB(uint8_t value, uint8_t *addr);
1187 
1197 extern uint32_t __STREXH(uint16_t value, uint16_t *addr);
1198 
1208 extern uint32_t __STREXW(uint32_t value, uint32_t *addr);
1209 
1210 
1211 
1212 #elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/
1213 /* GNU gcc specific functions */
1214 
1215 static __INLINE void __enable_irq() { __ASM volatile ("cpsie i"); }
1216 static __INLINE void __disable_irq() { __ASM volatile ("cpsid i"); }
1217 
1218 static __INLINE void __enable_fault_irq() { __ASM volatile ("cpsie f"); }
1219 static __INLINE void __disable_fault_irq() { __ASM volatile ("cpsid f"); }
1220 
1221 static __INLINE void __NOP() { __ASM volatile ("nop"); }
1222 static __INLINE void __WFI() { __ASM volatile ("wfi"); }
1223 static __INLINE void __WFE() { __ASM volatile ("wfe"); }
1224 static __INLINE void __SEV() { __ASM volatile ("sev"); }
1225 static __INLINE void __ISB() { __ASM volatile ("isb"); }
1226 static __INLINE void __DSB() { __ASM volatile ("dsb"); }
1227 static __INLINE void __DMB() { __ASM volatile ("dmb"); }
1228 static __INLINE void __CLREX() { __ASM volatile ("clrex"); }
1229 
1230 
1238 extern uint32_t __get_PSP(void);
1239 
1248 extern void __set_PSP(uint32_t topOfProcStack);
1249 
1258 extern uint32_t __get_MSP(void);
1259 
1268 extern void __set_MSP(uint32_t topOfMainStack);
1269 
1277 extern uint32_t __get_BASEPRI(void);
1278 
1286 extern void __set_BASEPRI(uint32_t basePri);
1287 
1295 extern uint32_t __get_PRIMASK(void);
1296 
1304 extern void __set_PRIMASK(uint32_t priMask);
1305 
1313 extern uint32_t __get_FAULTMASK(void);
1314 
1322 extern void __set_FAULTMASK(uint32_t faultMask);
1323 
1331 extern uint32_t __get_CONTROL(void);
1332 
1340 extern void __set_CONTROL(uint32_t control);
1341 
1350 extern uint32_t __REV(uint32_t value);
1351 
1360 extern uint32_t __REV16(uint16_t value);
1361 
1370 extern int32_t __REVSH(int16_t value);
1371 
1380 extern uint32_t __RBIT(uint32_t value);
1381 
1390 extern uint8_t __LDREXB(uint8_t *addr);
1391 
1400 extern uint16_t __LDREXH(uint16_t *addr);
1401 
1410 extern uint32_t __LDREXW(uint32_t *addr);
1411 
1421 extern uint32_t __STREXB(uint8_t value, uint8_t *addr);
1422 
1432 extern uint32_t __STREXH(uint16_t value, uint16_t *addr);
1433 
1443 extern uint32_t __STREXW(uint32_t value, uint32_t *addr);
1444 
1445 
1446 #elif (defined (__TASKING__)) /*------------------ TASKING Compiler ---------------------*/
1447 /* TASKING carm specific functions */
1448 
1449 /*
1450  * The CMSIS functions have been implemented as intrinsics in the compiler.
1451  * Please use "carm -?i" to get an up to date list of all instrinsics,
1452  * Including the CMSIS ones.
1453  */
1454 
1455 #endif
1456 
1457 
1465 
1466 
1467 /* ########################## NVIC functions #################################### */
1468 
1480 static __INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
1481 {
1482  uint32_t reg_value;
1483  uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */
1484 
1485  reg_value = SCB->AIRCR; /* read old register configuration */
1486  reg_value &= ~(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk); /* clear bits to change */
1487  reg_value = (reg_value |
1488  (0x5FA << SCB_AIRCR_VECTKEY_Pos) |
1489  (PriorityGroupTmp << 8)); /* Insert write key and priorty group */
1490  SCB->AIRCR = reg_value;
1491 }
1492 
1501 static __INLINE uint32_t NVIC_GetPriorityGrouping(void)
1502 {
1503  return ((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos); /* read priority grouping field */
1504 }
1505 
1514 static __INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
1515 {
1516  NVIC->ISER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* enable interrupt */
1517 }
1518 
1527 static __INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
1528 {
1529  NVIC->ICER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* disable interrupt */
1530 }
1531 
1541 static __INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
1542 {
1543  return((uint32_t) ((NVIC->ISPR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if pending else 0 */
1544 }
1545 
1554 static __INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
1555 {
1556  NVIC->ISPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* set interrupt pending */
1557 }
1558 
1567 static __INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
1568 {
1569  NVIC->ICPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */
1570 }
1571 
1581 static __INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn)
1582 {
1583  return((uint32_t)((NVIC->IABR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if active else 0 */
1584 }
1585 
1598 static __INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
1599 {
1600  if(IRQn < 0) {
1601  SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for Cortex-M3 System Interrupts */
1602  else {
1603  NVIC->IP[(uint32_t)(IRQn)] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for device specific Interrupts */
1604 }
1605 
1621 static __INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
1622 {
1623 
1624  if(IRQn < 0) {
1625  return((uint32_t)(SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M3 system interrupts */
1626  else {
1627  return((uint32_t)(NVIC->IP[(uint32_t)(IRQn)] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */
1628 }
1629 
1630 
1646 static __INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)
1647 {
1648  uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */
1649  uint32_t PreemptPriorityBits;
1650  uint32_t SubPriorityBits;
1651 
1652  PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp;
1653  SubPriorityBits = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS;
1654 
1655  return (
1656  ((PreemptPriority & ((1 << (PreemptPriorityBits)) - 1)) << SubPriorityBits) |
1657  ((SubPriority & ((1 << (SubPriorityBits )) - 1)))
1658  );
1659 }
1660 
1661 
1677 static __INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority)
1678 {
1679  uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */
1680  uint32_t PreemptPriorityBits;
1681  uint32_t SubPriorityBits;
1682 
1683  PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp;
1684  SubPriorityBits = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS;
1685 
1686  *pPreemptPriority = (Priority >> SubPriorityBits) & ((1 << (PreemptPriorityBits)) - 1);
1687  *pSubPriority = (Priority ) & ((1 << (SubPriorityBits )) - 1);
1688 }
1689 
1690 
1691 
1692 /* ################################## SysTick function ############################################ */
1693 
1694 #if (!defined (__Vendor_SysTickConfig)) || (__Vendor_SysTickConfig == 0)
1695 
1706 static __INLINE uint32_t SysTick_Config(uint32_t ticks)
1707 {
1708  if (ticks > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */
1709 
1710  SysTick->RELOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1; /* set reload register */
1711  NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Cortex-M0 System Interrupts */
1712  SysTick->CURR = 0; /* Load the SysTick Counter Value */
1715  SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
1716  return (0); /* Function successful */
1717 }
1718 
1719 #endif
1720 
1721 
1722 
1723 
1724 /* ################################## Reset function ############################################ */
1725 
1731 static __INLINE void NVIC_SystemReset(void)
1732 {
1733  SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) |
1734  (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) |
1735  SCB_AIRCR_SYSRESETREQ_Msk); /* Keep priority group unchanged */
1736  __DSB(); /* Ensure completion of memory access */
1737  while(1); /* wait until reset */
1738 }
1739  /* end of group CMSIS_CM3_Core_FunctionInterface */
1741 
1742 
1743 
1744 /* ##################################### Debug In/Output function ########################################### */
1745 
1753 
1754 extern volatile int ITM_RxBuffer;
1755 #define ITM_RXBUFFER_EMPTY 0x5AA55AA5
1768 static __INLINE uint32_t ITM_SendChar (uint32_t ch)
1769 {
1770  if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk) && /* Trace enabled */
1771  (ITM->TCR & ITM_TCR_ITMENA_Msk) && /* ITM enabled */
1772  (ITM->TER & (1ul << 0) ) ) /* ITM Port #0 enabled */
1773  {
1774  while (ITM->PORT[0].u32 == 0);
1775  ITM->PORT[0].u8 = (uint8_t) ch;
1776  }
1777  return (ch);
1778 }
1779 
1780 
1790 static __INLINE int ITM_ReceiveChar (void) {
1791  int ch = -1; /* no character available */
1792 
1793  if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) {
1794  ch = ITM_RxBuffer;
1795  ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */
1796  }
1797 
1798  return (ch);
1799 }
1800 
1801 
1810 static __INLINE int ITM_CheckChar (void) {
1811 
1812  if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY) {
1813  return (0); /* no character available */
1814  } else {
1815  return (1); /* character available */
1816  }
1817 }
1818  /* end of group CMSIS_CM3_core_DebugInterface */
1820 
1821 
1822 #ifdef __cplusplus
1823 }
1824 #endif
1825  /* end of group CMSIS_CM3_core_definitions */
1827 
1828 #endif /* __CM3_CORE_H__ */
1829 
1834 /*lint -restore */