Robobo
core_cm3.h
Go to the documentation of this file.
1 /**************************************************************************/
23 #if defined ( __ICCARM__ )
24  #pragma system_include /* treat file as system include file for MISRA check */
25 #endif
26 
27 #ifdef __cplusplus
28  extern "C" {
29 #endif
30 
31 #ifndef __CORE_CM3_H_GENERIC
32 #define __CORE_CM3_H_GENERIC
33 
34 
63 /*******************************************************************************
64  * CMSIS definitions
65  ******************************************************************************/
74 /* CMSIS CM3 definitions */
75 #define __CM3_CMSIS_VERSION_MAIN (0x02)
76 #define __CM3_CMSIS_VERSION_SUB (0x10)
77 #define __CM3_CMSIS_VERSION ((__CM3_CMSIS_VERSION_MAIN << 16) | __CM3_CMSIS_VERSION_SUB)
79 #define __CORTEX_M (0x03)
82 #if defined ( __CC_ARM )
83  #define __ASM __asm
84  #define __INLINE __inline
86 #elif defined ( __ICCARM__ )
87  #define __ASM __asm
88  #define __INLINE inline
90 #elif defined ( __GNUC__ )
91  #define __ASM __asm
92  #define __INLINE inline
94 #elif defined ( __TASKING__ )
95  #define __ASM __asm
96  #define __INLINE inline
98 #endif
99 
100 
101 #define __FPU_USED 0
103 #if defined ( __CC_ARM )
104  #if defined __TARGET_FPU_VFP
105  #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
106  #endif
107 #elif defined ( __ICCARM__ )
108  #if defined __ARMVFP__
109  #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
110  #endif
111 
112 #elif defined ( __GNUC__ )
113  #if defined (__VFP_FP__) && !defined(__SOFTFP__)
114  #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
115  #endif
116 
117 #elif defined ( __TASKING__ )
118  /* add preprocessor checks */
119 #endif
120 
121 #include <stdint.h>
122 #include "core_cmInstr.h"
123 #include "core_cmFunc.h"
125 #endif /* __CORE_CM3_H_GENERIC */
126 
127 #ifndef __CMSIS_GENERIC
128 
129 #ifndef __CORE_CM3_H_DEPENDANT
130 #define __CORE_CM3_H_DEPENDANT
131 
132 /* check device defines and use defaults */
133 #if defined __CHECK_DEVICE_DEFINES
134  #ifndef __CM3_REV
135  #define __CM3_REV 0x0200
136  #warning "__CM3_REV not defined in device header file; using default!"
137  #endif
138 
139  #ifndef __MPU_PRESENT
140  #define __MPU_PRESENT 0
141  #warning "__MPU_PRESENT not defined in device header file; using default!"
142  #endif
143 
144  #ifndef __NVIC_PRIO_BITS
145  #define __NVIC_PRIO_BITS 4
146  #warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
147  #endif
148 
149  #ifndef __Vendor_SysTickConfig
150  #define __Vendor_SysTickConfig 0
151  #warning "__Vendor_SysTickConfig not defined in device header file; using default!"
152  #endif
153 #endif
154 
155 /* IO definitions (access restrictions to peripheral registers) */
156 #ifdef __cplusplus
157  #define __I volatile
158 #else
159  #define __I volatile const
160 #endif
161 #define __O volatile
162 #define __IO volatile
164 
168 /*******************************************************************************
169  * Register Abstraction
170  ******************************************************************************/
171 
189 typedef union
190 {
191  struct
192  {
193 #if (__CORTEX_M != 0x04)
194  uint32_t _reserved0:27;
195 #else
196  uint32_t _reserved0:16;
197  uint32_t GE:4;
198  uint32_t _reserved1:7;
199 #endif
200  uint32_t Q:1;
201  uint32_t V:1;
202  uint32_t C:1;
203  uint32_t Z:1;
204  uint32_t N:1;
205  } b;
206  uint32_t w;
207 } APSR_Type;
208 
209 
212 typedef union
213 {
214  struct
215  {
216  uint32_t ISR:9;
217  uint32_t _reserved0:23;
218  } b;
219  uint32_t w;
220 } IPSR_Type;
221 
222 
225 typedef union
226 {
227  struct
228  {
229  uint32_t ISR:9;
230 #if (__CORTEX_M != 0x04)
231  uint32_t _reserved0:15;
232 #else
233  uint32_t _reserved0:7;
234  uint32_t GE:4;
235  uint32_t _reserved1:4;
236 #endif
237  uint32_t T:1;
238  uint32_t IT:2;
239  uint32_t Q:1;
240  uint32_t V:1;
241  uint32_t C:1;
242  uint32_t Z:1;
243  uint32_t N:1;
244  } b;
245  uint32_t w;
246 } xPSR_Type;
247 
248 
251 typedef union
252 {
253  struct
254  {
255  uint32_t nPRIV:1;
256  uint32_t SPSEL:1;
257  uint32_t FPCA:1;
258  uint32_t _reserved0:29;
259  } b;
260  uint32_t w;
261 } CONTROL_Type;
262 
274 typedef struct
275 {
276  __IO uint32_t ISER[8];
277  uint32_t RESERVED0[24];
278  __IO uint32_t ICER[8];
279  uint32_t RSERVED1[24];
280  __IO uint32_t ISPR[8];
281  uint32_t RESERVED2[24];
282  __IO uint32_t ICPR[8];
283  uint32_t RESERVED3[24];
284  __IO uint32_t IABR[8];
285  uint32_t RESERVED4[56];
286  __IO uint8_t IP[240];
287  uint32_t RESERVED5[644];
288  __O uint32_t STIR;
289 } NVIC_Type;
290 
291 /* Software Triggered Interrupt Register Definitions */
292 #define NVIC_STIR_INTID_Pos 0
293 #define NVIC_STIR_INTID_Msk (0x1FFUL << NVIC_STIR_INTID_Pos)
295 
306 typedef struct
307 {
308  __I uint32_t CPUID;
309  __IO uint32_t ICSR;
310  __IO uint32_t VTOR;
311  __IO uint32_t AIRCR;
312  __IO uint32_t SCR;
313  __IO uint32_t CCR;
314  __IO uint8_t SHP[12];
315  __IO uint32_t SHCSR;
316  __IO uint32_t CFSR;
317  __IO uint32_t HFSR;
318  __IO uint32_t DFSR;
319  __IO uint32_t MMFAR;
320  __IO uint32_t BFAR;
321  __IO uint32_t AFSR;
322  __I uint32_t PFR[2];
323  __I uint32_t DFR;
324  __I uint32_t ADR;
325  __I uint32_t MMFR[4];
326  __I uint32_t ISAR[5];
327  uint32_t RESERVED0[5];
328  __IO uint32_t CPACR;
329 } SCB_Type;
330 
331 /* SCB CPUID Register Definitions */
332 #define SCB_CPUID_IMPLEMENTER_Pos 24
333 #define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos)
335 #define SCB_CPUID_VARIANT_Pos 20
336 #define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos)
338 #define SCB_CPUID_ARCHITECTURE_Pos 16
339 #define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos)
341 #define SCB_CPUID_PARTNO_Pos 4
342 #define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos)
344 #define SCB_CPUID_REVISION_Pos 0
345 #define SCB_CPUID_REVISION_Msk (0xFUL << SCB_CPUID_REVISION_Pos)
347 /* SCB Interrupt Control State Register Definitions */
348 #define SCB_ICSR_NMIPENDSET_Pos 31
349 #define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos)
351 #define SCB_ICSR_PENDSVSET_Pos 28
352 #define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos)
354 #define SCB_ICSR_PENDSVCLR_Pos 27
355 #define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos)
357 #define SCB_ICSR_PENDSTSET_Pos 26
358 #define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos)
360 #define SCB_ICSR_PENDSTCLR_Pos 25
361 #define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos)
363 #define SCB_ICSR_ISRPREEMPT_Pos 23
364 #define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos)
366 #define SCB_ICSR_ISRPENDING_Pos 22
367 #define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos)
369 #define SCB_ICSR_VECTPENDING_Pos 12
370 #define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos)
372 #define SCB_ICSR_RETTOBASE_Pos 11
373 #define SCB_ICSR_RETTOBASE_Msk (1UL << SCB_ICSR_RETTOBASE_Pos)
375 #define SCB_ICSR_VECTACTIVE_Pos 0
376 #define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL << SCB_ICSR_VECTACTIVE_Pos)
378 /* SCB Vector Table Offset Register Definitions */
379 #if (__CM3_REV < 0x0201) /* core r2p1 */
380 #define SCB_VTOR_TBLBASE_Pos 29
381 #define SCB_VTOR_TBLBASE_Msk (1UL << SCB_VTOR_TBLBASE_Pos)
383 #define SCB_VTOR_TBLOFF_Pos 7
384 #define SCB_VTOR_TBLOFF_Msk (0x3FFFFFUL << SCB_VTOR_TBLOFF_Pos)
385 #else
386 #define SCB_VTOR_TBLOFF_Pos 7
387 #define SCB_VTOR_TBLOFF_Msk (0x1FFFFFFUL << SCB_VTOR_TBLOFF_Pos)
388 #endif
389 
390 /* SCB Application Interrupt and Reset Control Register Definitions */
391 #define SCB_AIRCR_VECTKEY_Pos 16
392 #define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos)
394 #define SCB_AIRCR_VECTKEYSTAT_Pos 16
395 #define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos)
397 #define SCB_AIRCR_ENDIANESS_Pos 15
398 #define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos)
400 #define SCB_AIRCR_PRIGROUP_Pos 8
401 #define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos)
403 #define SCB_AIRCR_SYSRESETREQ_Pos 2
404 #define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos)
406 #define SCB_AIRCR_VECTCLRACTIVE_Pos 1
407 #define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos)
409 #define SCB_AIRCR_VECTRESET_Pos 0
410 #define SCB_AIRCR_VECTRESET_Msk (1UL << SCB_AIRCR_VECTRESET_Pos)
412 /* SCB System Control Register Definitions */
413 #define SCB_SCR_SEVONPEND_Pos 4
414 #define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos)
416 #define SCB_SCR_SLEEPDEEP_Pos 2
417 #define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos)
419 #define SCB_SCR_SLEEPONEXIT_Pos 1
420 #define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos)
422 /* SCB Configuration Control Register Definitions */
423 #define SCB_CCR_STKALIGN_Pos 9
424 #define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos)
426 #define SCB_CCR_BFHFNMIGN_Pos 8
427 #define SCB_CCR_BFHFNMIGN_Msk (1UL << SCB_CCR_BFHFNMIGN_Pos)
429 #define SCB_CCR_DIV_0_TRP_Pos 4
430 #define SCB_CCR_DIV_0_TRP_Msk (1UL << SCB_CCR_DIV_0_TRP_Pos)
432 #define SCB_CCR_UNALIGN_TRP_Pos 3
433 #define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos)
435 #define SCB_CCR_USERSETMPEND_Pos 1
436 #define SCB_CCR_USERSETMPEND_Msk (1UL << SCB_CCR_USERSETMPEND_Pos)
438 #define SCB_CCR_NONBASETHRDENA_Pos 0
439 #define SCB_CCR_NONBASETHRDENA_Msk (1UL << SCB_CCR_NONBASETHRDENA_Pos)
441 /* SCB System Handler Control and State Register Definitions */
442 #define SCB_SHCSR_USGFAULTENA_Pos 18
443 #define SCB_SHCSR_USGFAULTENA_Msk (1UL << SCB_SHCSR_USGFAULTENA_Pos)
445 #define SCB_SHCSR_BUSFAULTENA_Pos 17
446 #define SCB_SHCSR_BUSFAULTENA_Msk (1UL << SCB_SHCSR_BUSFAULTENA_Pos)
448 #define SCB_SHCSR_MEMFAULTENA_Pos 16
449 #define SCB_SHCSR_MEMFAULTENA_Msk (1UL << SCB_SHCSR_MEMFAULTENA_Pos)
451 #define SCB_SHCSR_SVCALLPENDED_Pos 15
452 #define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos)
454 #define SCB_SHCSR_BUSFAULTPENDED_Pos 14
455 #define SCB_SHCSR_BUSFAULTPENDED_Msk (1UL << SCB_SHCSR_BUSFAULTPENDED_Pos)
457 #define SCB_SHCSR_MEMFAULTPENDED_Pos 13
458 #define SCB_SHCSR_MEMFAULTPENDED_Msk (1UL << SCB_SHCSR_MEMFAULTPENDED_Pos)
460 #define SCB_SHCSR_USGFAULTPENDED_Pos 12
461 #define SCB_SHCSR_USGFAULTPENDED_Msk (1UL << SCB_SHCSR_USGFAULTPENDED_Pos)
463 #define SCB_SHCSR_SYSTICKACT_Pos 11
464 #define SCB_SHCSR_SYSTICKACT_Msk (1UL << SCB_SHCSR_SYSTICKACT_Pos)
466 #define SCB_SHCSR_PENDSVACT_Pos 10
467 #define SCB_SHCSR_PENDSVACT_Msk (1UL << SCB_SHCSR_PENDSVACT_Pos)
469 #define SCB_SHCSR_MONITORACT_Pos 8
470 #define SCB_SHCSR_MONITORACT_Msk (1UL << SCB_SHCSR_MONITORACT_Pos)
472 #define SCB_SHCSR_SVCALLACT_Pos 7
473 #define SCB_SHCSR_SVCALLACT_Msk (1UL << SCB_SHCSR_SVCALLACT_Pos)
475 #define SCB_SHCSR_USGFAULTACT_Pos 3
476 #define SCB_SHCSR_USGFAULTACT_Msk (1UL << SCB_SHCSR_USGFAULTACT_Pos)
478 #define SCB_SHCSR_BUSFAULTACT_Pos 1
479 #define SCB_SHCSR_BUSFAULTACT_Msk (1UL << SCB_SHCSR_BUSFAULTACT_Pos)
481 #define SCB_SHCSR_MEMFAULTACT_Pos 0
482 #define SCB_SHCSR_MEMFAULTACT_Msk (1UL << SCB_SHCSR_MEMFAULTACT_Pos)
484 /* SCB Configurable Fault Status Registers Definitions */
485 #define SCB_CFSR_USGFAULTSR_Pos 16
486 #define SCB_CFSR_USGFAULTSR_Msk (0xFFFFUL << SCB_CFSR_USGFAULTSR_Pos)
488 #define SCB_CFSR_BUSFAULTSR_Pos 8
489 #define SCB_CFSR_BUSFAULTSR_Msk (0xFFUL << SCB_CFSR_BUSFAULTSR_Pos)
491 #define SCB_CFSR_MEMFAULTSR_Pos 0
492 #define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL << SCB_CFSR_MEMFAULTSR_Pos)
494 /* SCB Hard Fault Status Registers Definitions */
495 #define SCB_HFSR_DEBUGEVT_Pos 31
496 #define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos)
498 #define SCB_HFSR_FORCED_Pos 30
499 #define SCB_HFSR_FORCED_Msk (1UL << SCB_HFSR_FORCED_Pos)
501 #define SCB_HFSR_VECTTBL_Pos 1
502 #define SCB_HFSR_VECTTBL_Msk (1UL << SCB_HFSR_VECTTBL_Pos)
504 /* SCB Debug Fault Status Register Definitions */
505 #define SCB_DFSR_EXTERNAL_Pos 4
506 #define SCB_DFSR_EXTERNAL_Msk (1UL << SCB_DFSR_EXTERNAL_Pos)
508 #define SCB_DFSR_VCATCH_Pos 3
509 #define SCB_DFSR_VCATCH_Msk (1UL << SCB_DFSR_VCATCH_Pos)
511 #define SCB_DFSR_DWTTRAP_Pos 2
512 #define SCB_DFSR_DWTTRAP_Msk (1UL << SCB_DFSR_DWTTRAP_Pos)
514 #define SCB_DFSR_BKPT_Pos 1
515 #define SCB_DFSR_BKPT_Msk (1UL << SCB_DFSR_BKPT_Pos)
517 #define SCB_DFSR_HALTED_Pos 0
518 #define SCB_DFSR_HALTED_Msk (1UL << SCB_DFSR_HALTED_Pos)
520 
531 typedef struct
532 {
533  uint32_t RESERVED0[1];
534  __I uint32_t ICTR;
535 #if ((defined __CM3_REV) && (__CM3_REV >= 0x200))
536  __IO uint32_t ACTLR;
537 #else
538  uint32_t RESERVED1[1];
539 #endif
540 } SCnSCB_Type;
541 
542 /* Interrupt Controller Type Register Definitions */
543 #define SCnSCB_ICTR_INTLINESNUM_Pos 0
544 #define SCnSCB_ICTR_INTLINESNUM_Msk (0xFUL << SCnSCB_ICTR_INTLINESNUM_Pos)
546 /* Auxiliary Control Register Definitions */
547 
548 #define SCnSCB_ACTLR_DISFOLD_Pos 2
549 #define SCnSCB_ACTLR_DISFOLD_Msk (1UL << SCnSCB_ACTLR_DISFOLD_Pos)
551 #define SCnSCB_ACTLR_DISDEFWBUF_Pos 1
552 #define SCnSCB_ACTLR_DISDEFWBUF_Msk (1UL << SCnSCB_ACTLR_DISDEFWBUF_Pos)
554 #define SCnSCB_ACTLR_DISMCYCINT_Pos 0
555 #define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL << SCnSCB_ACTLR_DISMCYCINT_Pos)
557 
568 typedef struct
569 {
570  __IO uint32_t CTRL;
571  __IO uint32_t LOAD;
572  __IO uint32_t VAL;
573  __I uint32_t CALIB;
574 } SysTick_Type;
575 
576 /* SysTick Control / Status Register Definitions */
577 #define SysTick_CTRL_COUNTFLAG_Pos 16
578 #define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos)
580 #define SysTick_CTRL_CLKSOURCE_Pos 2
581 #define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos)
583 #define SysTick_CTRL_TICKINT_Pos 1
584 #define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos)
586 #define SysTick_CTRL_ENABLE_Pos 0
587 #define SysTick_CTRL_ENABLE_Msk (1UL << SysTick_CTRL_ENABLE_Pos)
589 /* SysTick Reload Register Definitions */
590 #define SysTick_LOAD_RELOAD_Pos 0
591 #define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL << SysTick_LOAD_RELOAD_Pos)
593 /* SysTick Current Register Definitions */
594 #define SysTick_VAL_CURRENT_Pos 0
595 #define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos)
597 /* SysTick Calibration Register Definitions */
598 #define SysTick_CALIB_NOREF_Pos 31
599 #define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos)
601 #define SysTick_CALIB_SKEW_Pos 30
602 #define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos)
604 #define SysTick_CALIB_TENMS_Pos 0
605 #define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos)
607 
618 typedef struct
619 {
620  __O union
621  {
622  __O uint8_t u8;
623  __O uint16_t u16;
624  __O uint32_t u32;
625  } PORT [32];
626  uint32_t RESERVED0[864];
627  __IO uint32_t TER;
628  uint32_t RESERVED1[15];
629  __IO uint32_t TPR;
630  uint32_t RESERVED2[15];
631  __IO uint32_t TCR;
632 } ITM_Type;
633 
634 /* ITM Trace Privilege Register Definitions */
635 #define ITM_TPR_PRIVMASK_Pos 0
636 #define ITM_TPR_PRIVMASK_Msk (0xFUL << ITM_TPR_PRIVMASK_Pos)
638 /* ITM Trace Control Register Definitions */
639 #define ITM_TCR_BUSY_Pos 23
640 #define ITM_TCR_BUSY_Msk (1UL << ITM_TCR_BUSY_Pos)
642 #define ITM_TCR_TraceBusID_Pos 16
643 #define ITM_TCR_TraceBusID_Msk (0x7FUL << ITM_TCR_TraceBusID_Pos)
645 #define ITM_TCR_GTSFREQ_Pos 10
646 #define ITM_TCR_GTSFREQ_Msk (3UL << ITM_TCR_GTSFREQ_Pos)
648 #define ITM_TCR_TSPrescale_Pos 8
649 #define ITM_TCR_TSPrescale_Msk (3UL << ITM_TCR_TSPrescale_Pos)
651 #define ITM_TCR_SWOENA_Pos 4
652 #define ITM_TCR_SWOENA_Msk (1UL << ITM_TCR_SWOENA_Pos)
654 #define ITM_TCR_TXENA_Pos 3
655 #define ITM_TCR_TXENA_Msk (1UL << ITM_TCR_TXENA_Pos)
657 #define ITM_TCR_SYNCENA_Pos 2
658 #define ITM_TCR_SYNCENA_Msk (1UL << ITM_TCR_SYNCENA_Pos)
660 #define ITM_TCR_TSENA_Pos 1
661 #define ITM_TCR_TSENA_Msk (1UL << ITM_TCR_TSENA_Pos)
663 #define ITM_TCR_ITMENA_Pos 0
664 #define ITM_TCR_ITMENA_Msk (1UL << ITM_TCR_ITMENA_Pos)
666  /* end of group CMSIS_ITM */
667 
668 
669 #if (__MPU_PRESENT == 1)
670 
678 typedef struct
679 {
680  __I uint32_t TYPE;
681  __IO uint32_t CTRL;
682  __IO uint32_t RNR;
683  __IO uint32_t RBAR;
684  __IO uint32_t RASR;
685  __IO uint32_t RBAR_A1;
686  __IO uint32_t RASR_A1;
687  __IO uint32_t RBAR_A2;
688  __IO uint32_t RASR_A2;
689  __IO uint32_t RBAR_A3;
690  __IO uint32_t RASR_A3;
691 } MPU_Type;
692 
693 /* MPU Type Register */
694 #define MPU_TYPE_IREGION_Pos 16
695 #define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos)
697 #define MPU_TYPE_DREGION_Pos 8
698 #define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos)
700 #define MPU_TYPE_SEPARATE_Pos 0
701 #define MPU_TYPE_SEPARATE_Msk (1UL << MPU_TYPE_SEPARATE_Pos)
703 /* MPU Control Register */
704 #define MPU_CTRL_PRIVDEFENA_Pos 2
705 #define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos)
707 #define MPU_CTRL_HFNMIENA_Pos 1
708 #define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos)
710 #define MPU_CTRL_ENABLE_Pos 0
711 #define MPU_CTRL_ENABLE_Msk (1UL << MPU_CTRL_ENABLE_Pos)
713 /* MPU Region Number Register */
714 #define MPU_RNR_REGION_Pos 0
715 #define MPU_RNR_REGION_Msk (0xFFUL << MPU_RNR_REGION_Pos)
717 /* MPU Region Base Address Register */
718 #define MPU_RBAR_ADDR_Pos 5
719 #define MPU_RBAR_ADDR_Msk (0x7FFFFFFUL << MPU_RBAR_ADDR_Pos)
721 #define MPU_RBAR_VALID_Pos 4
722 #define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos)
724 #define MPU_RBAR_REGION_Pos 0
725 #define MPU_RBAR_REGION_Msk (0xFUL << MPU_RBAR_REGION_Pos)
727 /* MPU Region Attribute and Size Register */
728 #define MPU_RASR_ATTRS_Pos 16
729 #define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos)
731 #define MPU_RASR_SRD_Pos 8
732 #define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos)
734 #define MPU_RASR_SIZE_Pos 1
735 #define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos)
737 #define MPU_RASR_ENABLE_Pos 0
738 #define MPU_RASR_ENABLE_Msk (1UL << MPU_RASR_ENABLE_Pos)
740 
741 #endif
742 
743 
752 typedef struct
753 {
754  __IO uint32_t DHCSR;
755  __O uint32_t DCRSR;
756  __IO uint32_t DCRDR;
757  __IO uint32_t DEMCR;
759 
760 /* Debug Halting Control and Status Register */
761 #define CoreDebug_DHCSR_DBGKEY_Pos 16
762 #define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos)
764 #define CoreDebug_DHCSR_S_RESET_ST_Pos 25
765 #define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos)
767 #define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24
768 #define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos)
770 #define CoreDebug_DHCSR_S_LOCKUP_Pos 19
771 #define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos)
773 #define CoreDebug_DHCSR_S_SLEEP_Pos 18
774 #define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos)
776 #define CoreDebug_DHCSR_S_HALT_Pos 17
777 #define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos)
779 #define CoreDebug_DHCSR_S_REGRDY_Pos 16
780 #define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos)
782 #define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5
783 #define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos)
785 #define CoreDebug_DHCSR_C_MASKINTS_Pos 3
786 #define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos)
788 #define CoreDebug_DHCSR_C_STEP_Pos 2
789 #define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos)
791 #define CoreDebug_DHCSR_C_HALT_Pos 1
792 #define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos)
794 #define CoreDebug_DHCSR_C_DEBUGEN_Pos 0
795 #define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL << CoreDebug_DHCSR_C_DEBUGEN_Pos)
797 /* Debug Core Register Selector Register */
798 #define CoreDebug_DCRSR_REGWnR_Pos 16
799 #define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos)
801 #define CoreDebug_DCRSR_REGSEL_Pos 0
802 #define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL << CoreDebug_DCRSR_REGSEL_Pos)
804 /* Debug Exception and Monitor Control Register */
805 #define CoreDebug_DEMCR_TRCENA_Pos 24
806 #define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos)
808 #define CoreDebug_DEMCR_MON_REQ_Pos 19
809 #define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos)
811 #define CoreDebug_DEMCR_MON_STEP_Pos 18
812 #define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos)
814 #define CoreDebug_DEMCR_MON_PEND_Pos 17
815 #define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos)
817 #define CoreDebug_DEMCR_MON_EN_Pos 16
818 #define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos)
820 #define CoreDebug_DEMCR_VC_HARDERR_Pos 10
821 #define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos)
823 #define CoreDebug_DEMCR_VC_INTERR_Pos 9
824 #define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos)
826 #define CoreDebug_DEMCR_VC_BUSERR_Pos 8
827 #define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos)
829 #define CoreDebug_DEMCR_VC_STATERR_Pos 7
830 #define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos)
832 #define CoreDebug_DEMCR_VC_CHKERR_Pos 6
833 #define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos)
835 #define CoreDebug_DEMCR_VC_NOCPERR_Pos 5
836 #define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos)
838 #define CoreDebug_DEMCR_VC_MMERR_Pos 4
839 #define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos)
841 #define CoreDebug_DEMCR_VC_CORERESET_Pos 0
842 #define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL << CoreDebug_DEMCR_VC_CORERESET_Pos)
844 
851 /* Memory mapping of Cortex-M3 Hardware */
852 #define SCS_BASE (0xE000E000UL)
853 #define ITM_BASE (0xE0000000UL)
854 #define CoreDebug_BASE (0xE000EDF0UL)
855 #define SysTick_BASE (SCS_BASE + 0x0010UL)
856 #define NVIC_BASE (SCS_BASE + 0x0100UL)
857 #define SCB_BASE (SCS_BASE + 0x0D00UL)
859 #define SCnSCB ((SCnSCB_Type *) SCS_BASE )
860 #define SCB ((SCB_Type *) SCB_BASE )
861 #define SysTick ((SysTick_Type *) SysTick_BASE )
862 #define NVIC ((NVIC_Type *) NVIC_BASE )
863 #define ITM ((ITM_Type *) ITM_BASE )
864 #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE)
866 #if (__MPU_PRESENT == 1)
867  #define MPU_BASE (SCS_BASE + 0x0D90UL)
868  #define MPU ((MPU_Type *) MPU_BASE )
869 #endif
870 
875 /*******************************************************************************
876  * Hardware Abstraction Layer
877  ******************************************************************************/
888 /* ########################## NVIC functions #################################### */
904 static __INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
905 {
906  uint32_t reg_value;
907  uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07); /* only values 0..7 are used */
908 
909  reg_value = SCB->AIRCR; /* read old register configuration */
910  reg_value &= ~(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk); /* clear bits to change */
911  reg_value = (reg_value |
912  ((uint32_t)0x5FA << SCB_AIRCR_VECTKEY_Pos) |
913  (PriorityGroupTmp << 8)); /* Insert write key and priorty group */
914  SCB->AIRCR = reg_value;
915 }
916 
917 
925 static __INLINE uint32_t NVIC_GetPriorityGrouping(void)
926 {
927  return ((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos); /* read priority grouping field */
928 }
929 
930 
938 static __INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
939 {
940  NVIC->ISER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* enable interrupt */
941 }
942 
943 
951 static __INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
952 {
953  NVIC->ICER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* disable interrupt */
954 }
955 
956 
966 static __INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
967 {
968  return((uint32_t) ((NVIC->ISPR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if pending else 0 */
969 }
970 
971 
979 static __INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
980 {
981  NVIC->ISPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* set interrupt pending */
982 }
983 
984 
992 static __INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
993 {
994  NVIC->ICPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */
995 }
996 
997 
1005 static __INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn)
1006 {
1007  return((uint32_t)((NVIC->IABR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if active else 0 */
1008 }
1009 
1010 
1022 static __INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
1023 {
1024  if(IRQn < 0) {
1025  SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for Cortex-M System Interrupts */
1026  else {
1027  NVIC->IP[(uint32_t)(IRQn)] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for device specific Interrupts */
1028 }
1029 
1030 
1043 static __INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
1044 {
1045 
1046  if(IRQn < 0) {
1047  return((uint32_t)(SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M system interrupts */
1048  else {
1049  return((uint32_t)(NVIC->IP[(uint32_t)(IRQn)] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */
1050 }
1051 
1052 
1067 static __INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)
1068 {
1069  uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */
1070  uint32_t PreemptPriorityBits;
1071  uint32_t SubPriorityBits;
1072 
1073  PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp;
1074  SubPriorityBits = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS;
1075 
1076  return (
1077  ((PreemptPriority & ((1 << (PreemptPriorityBits)) - 1)) << SubPriorityBits) |
1078  ((SubPriority & ((1 << (SubPriorityBits )) - 1)))
1079  );
1080 }
1081 
1082 
1097 static __INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority)
1098 {
1099  uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */
1100  uint32_t PreemptPriorityBits;
1101  uint32_t SubPriorityBits;
1102 
1103  PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp;
1104  SubPriorityBits = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS;
1105 
1106  *pPreemptPriority = (Priority >> SubPriorityBits) & ((1 << (PreemptPriorityBits)) - 1);
1107  *pSubPriority = (Priority ) & ((1 << (SubPriorityBits )) - 1);
1108 }
1109 
1110 
1115 static __INLINE void NVIC_SystemReset(void)
1116 {
1117  __DSB(); /* Ensure all outstanding memory accesses included
1118  buffered write are completed before reset */
1119  SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) |
1120  (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) |
1121  SCB_AIRCR_SYSRESETREQ_Msk); /* Keep priority group unchanged */
1122  __DSB(); /* Ensure completion of memory access */
1123  while(1); /* wait until reset */
1124 }
1125 
1130 /* ################################## SysTick function ############################################ */
1136 #if (__Vendor_SysTickConfig == 0)
1137 
1147 static __INLINE uint32_t SysTick_Config(uint32_t ticks)
1148 {
1149  if (ticks > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */
1150 
1151  SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1; /* set reload register */
1152  NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Cortex-M0 System Interrupts */
1153  SysTick->VAL = 0; /* Load the SysTick Counter Value */
1156  SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
1157  return (0); /* Function successful */
1158 }
1159 
1160 #endif
1161 
1166 /* ##################################### Debug In/Output function ########################################### */
1172 extern volatile int32_t ITM_RxBuffer;
1173 #define ITM_RXBUFFER_EMPTY 0x5AA55AA5
1185 static __INLINE uint32_t ITM_SendChar (uint32_t ch)
1186 {
1187  if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk) && /* Trace enabled */
1188  (ITM->TCR & ITM_TCR_ITMENA_Msk) && /* ITM enabled */
1189  (ITM->TER & (1UL << 0) ) ) /* ITM Port #0 enabled */
1190  {
1191  while (ITM->PORT[0].u32 == 0);
1192  ITM->PORT[0].u8 = (uint8_t) ch;
1193  }
1194  return (ch);
1195 }
1196 
1197 
1207 static __INLINE int32_t ITM_ReceiveChar (void) {
1208  int32_t ch = -1; /* no character available */
1209 
1210  if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) {
1211  ch = ITM_RxBuffer;
1212  ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */
1213  }
1214 
1215  return (ch);
1216 }
1217 
1218 
1227 static __INLINE int32_t ITM_CheckChar (void) {
1228 
1229  if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY) {
1230  return (0); /* no character available */
1231  } else {
1232  return (1); /* character available */
1233  }
1234 }
1235 
1238 #endif /* __CORE_CM3_H_DEPENDANT */
1239 
1240 #endif /* __CMSIS_GENERIC */
1241 
1242 #ifdef __cplusplus
1243 }
1244 #endif
__IO uint32_t DEMCR
Definition: core_cm3.h:757
__O uint32_t STIR
Definition: core_cm3.h:288
#define SCB_AIRCR_PRIGROUP_Msk
Definition: core_cm3.h:401
__IO uint32_t DCRDR
Definition: core_cm3.h:756
__I uint32_t DFR
Definition: core_cm3.h:323
__O uint8_t u8
Definition: core_cm3.h:622
Structure type to access the System Control and ID Register not in the SCB.
Definition: core_cm3.h:531
__IO uint32_t AFSR
Definition: core_cm3.h:321
__IO uint32_t DHCSR
Definition: core_cm3.h:754
#define ISR(func)
Define service routine.
Definition: interrupt_sam_nvic.h:65
__I uint32_t ADR
Definition: core_cm3.h:324
__O uint32_t DCRSR
Definition: core_cm3.h:755
#define SysTick_CTRL_TICKINT_Msk
Definition: core_cm3.h:584
__IO uint32_t HFSR
Definition: core_cm3.h:317
Union type to access the Application Program Status Register (APSR).
Definition: core_cm0.h:182
IRQn
Definition: ARMCM0.h:35
Definition: ARMCM0.h:46
Structure type to access the System Timer (SysTick).
Definition: core_cm0.h:397
Structure type to access the Instrumentation Trace Macrocell Register (ITM).
Definition: core_cm3.h:618
#define NVIC
Definition: core_cm3.h:862
__IO uint32_t DFSR
Definition: core_cm3.h:318
__O uint32_t u32
Definition: core_cm3.h:624
__IO uint32_t CFSR
Definition: core_cm3.h:316
Structure type to access the System Control Block (SCB).
Definition: core_cm0.h:292
#define SysTick
Definition: core_cm3.h:861
__IO uint32_t TCR
Definition: core_cm3.h:631
#define SCB
Definition: core_cm3.h:860
#define ITM_TCR_ITMENA_Msk
Definition: core_cm3.h:664
#define ITM_RXBUFFER_EMPTY
Definition: core_cm3.h:1173
__IO uint32_t BFAR
Definition: core_cm3.h:320
#define SCB_AIRCR_SYSRESETREQ_Msk
Definition: core_cm3.h:404
Union type to access the Control Registers (CONTROL).
Definition: core_cm0.h:244
volatile int32_t ITM_RxBuffer
#define SysTick_CTRL_ENABLE_Msk
Definition: core_cm3.h:587
#define SysTick_CTRL_CLKSOURCE_Msk
Definition: core_cm3.h:581
#define __IO
Definition: core_cm3.h:162
#define SCB_AIRCR_PRIGROUP_Pos
Definition: core_cm3.h:400
Union type to access the Interrupt Program Status Register (IPSR).
Definition: core_cm0.h:205
__I uint32_t ICTR
Definition: core_cm3.h:534
#define __O
Definition: core_cm3.h:161
#define __I
Definition: core_cm3.h:159
__IO uint32_t TPR
Definition: core_cm3.h:629
#define __NVIC_PRIO_BITS
Definition: ARMCM0.h:62
Structure type to access the Nested Vectored Interrupt Controller (NVIC).
Definition: core_cm0.h:267
Structure type to access the Core Debug Register (CoreDebug).
Definition: core_cm3.h:752
CMSIS Cortex-M Core Instruction Access Header File.
#define CoreDebug
Definition: core_cm3.h:864
__IO uint32_t MMFAR
Definition: core_cm3.h:319
#define SCB_AIRCR_VECTKEY_Pos
Definition: core_cm3.h:391
#define SysTick_LOAD_RELOAD_Msk
Definition: core_cm3.h:591
Union type to access the Special-Purpose Program Status Registers (xPSR).
Definition: core_cm0.h:218
#define SCB_AIRCR_VECTKEY_Msk
Definition: core_cm3.h:392
__IO uint32_t CPACR
Definition: core_cm3.h:328
#define CoreDebug_DEMCR_TRCENA_Msk
Definition: core_cm3.h:806
__O uint16_t u16
Definition: core_cm3.h:623
__IO uint32_t VTOR
Definition: core_cm3.h:310
__IO uint32_t TER
Definition: core_cm3.h:627
CMSIS Cortex-M Core Function Access Header File.
#define ITM
Definition: core_cm3.h:863