core_cm3.h
Go to the documentation of this file.
1 /**************************************************************************/
24 #ifndef __CM3_CORE_H__
25 #define __CM3_CORE_H__
26 
27 #include "LPC17xx.h"
63 /*lint -save */
64 /*lint -e10 */
65 /*lint -e530 */
66 /*lint -e550 */
67 /*lint -e754 */
68 /*lint -e750 */
69 /*lint -e528 */
70 /*lint -e751 */
71 
72 
81 #ifdef __cplusplus
82  extern "C" {
83 #endif
84 
85 #define __CM3_CMSIS_VERSION_MAIN (0x01)
86 #define __CM3_CMSIS_VERSION_SUB (0x30)
87 #define __CM3_CMSIS_VERSION ((__CM3_CMSIS_VERSION_MAIN << 16) | __CM3_CMSIS_VERSION_SUB)
89 #define __CORTEX_M (0x03)
91 #include <stdint.h> /* Include standard types */
92 
93 #if defined (__ICCARM__)
94  #include <intrinsics.h> /* IAR Intrinsics */
95 #endif
96 
97 
98 #ifndef __NVIC_PRIO_BITS
99  #define __NVIC_PRIO_BITS 4
100 #endif
101 
102 
103 
104 
105 /*******************************************************************************
106  * Register Abstraction
107  ******************************************************************************/
117 typedef struct
118 {
119  __IO uint32_t ISER[8];
120  uint32_t RESERVED0[24];
121  __IO uint32_t ICER[8];
122  uint32_t RSERVED1[24];
123  __IO uint32_t ISPR[8];
124  uint32_t RESERVED2[24];
125  __IO uint32_t ICPR[8];
126  uint32_t RESERVED3[24];
127  __IO uint32_t IABR[8];
128  uint32_t RESERVED4[56];
129  __IO uint8_t IP[240];
130  uint32_t RESERVED5[644];
131  __O uint32_t STIR;
132 } NVIC_Type; /* end of group CMSIS_CM3_NVIC */
134 
135 
140 typedef struct
141 {
142  __I uint32_t CPUID;
143  __IO uint32_t ICSR;
144  __IO uint32_t VTOR;
145  __IO uint32_t AIRCR;
146  __IO uint32_t SCR;
147  __IO uint32_t CCR;
148  __IO uint8_t SHP[12];
149  __IO uint32_t SHCSR;
150  __IO uint32_t CFSR;
151  __IO uint32_t HFSR;
152  __IO uint32_t DFSR;
153  __IO uint32_t MMFAR;
154  __IO uint32_t BFAR;
155  __IO uint32_t AFSR;
156  __I uint32_t PFR[2];
157  __I uint32_t DFR;
158  __I uint32_t ADR;
159  __I uint32_t MMFR[4];
160  __I uint32_t ISAR[5];
161 } SCB_Type;
162 
163 /* SCB CPUID Register Definitions */
164 #define SCB_CPUID_IMPLEMENTER_Pos 24
165 #define SCB_CPUID_IMPLEMENTER_Msk (0xFFul << SCB_CPUID_IMPLEMENTER_Pos)
167 #define SCB_CPUID_VARIANT_Pos 20
168 #define SCB_CPUID_VARIANT_Msk (0xFul << SCB_CPUID_VARIANT_Pos)
170 #define SCB_CPUID_PARTNO_Pos 4
171 #define SCB_CPUID_PARTNO_Msk (0xFFFul << SCB_CPUID_PARTNO_Pos)
173 #define SCB_CPUID_REVISION_Pos 0
174 #define SCB_CPUID_REVISION_Msk (0xFul << SCB_CPUID_REVISION_Pos)
176 /* SCB Interrupt Control State Register Definitions */
177 #define SCB_ICSR_NMIPENDSET_Pos 31
178 #define SCB_ICSR_NMIPENDSET_Msk (1ul << SCB_ICSR_NMIPENDSET_Pos)
180 #define SCB_ICSR_PENDSVSET_Pos 28
181 #define SCB_ICSR_PENDSVSET_Msk (1ul << SCB_ICSR_PENDSVSET_Pos)
183 #define SCB_ICSR_PENDSVCLR_Pos 27
184 #define SCB_ICSR_PENDSVCLR_Msk (1ul << SCB_ICSR_PENDSVCLR_Pos)
186 #define SCB_ICSR_PENDSTSET_Pos 26
187 #define SCB_ICSR_PENDSTSET_Msk (1ul << SCB_ICSR_PENDSTSET_Pos)
189 #define SCB_ICSR_PENDSTCLR_Pos 25
190 #define SCB_ICSR_PENDSTCLR_Msk (1ul << SCB_ICSR_PENDSTCLR_Pos)
192 #define SCB_ICSR_ISRPREEMPT_Pos 23
193 #define SCB_ICSR_ISRPREEMPT_Msk (1ul << SCB_ICSR_ISRPREEMPT_Pos)
195 #define SCB_ICSR_ISRPENDING_Pos 22
196 #define SCB_ICSR_ISRPENDING_Msk (1ul << SCB_ICSR_ISRPENDING_Pos)
198 #define SCB_ICSR_VECTPENDING_Pos 12
199 #define SCB_ICSR_VECTPENDING_Msk (0x1FFul << SCB_ICSR_VECTPENDING_Pos)
201 #define SCB_ICSR_RETTOBASE_Pos 11
202 #define SCB_ICSR_RETTOBASE_Msk (1ul << SCB_ICSR_RETTOBASE_Pos)
204 #define SCB_ICSR_VECTACTIVE_Pos 0
205 #define SCB_ICSR_VECTACTIVE_Msk (0x1FFul << SCB_ICSR_VECTACTIVE_Pos)
207 /* SCB Interrupt Control State Register Definitions */
208 #define SCB_VTOR_TBLBASE_Pos 29
209 #define SCB_VTOR_TBLBASE_Msk (0x1FFul << SCB_VTOR_TBLBASE_Pos)
211 #define SCB_VTOR_TBLOFF_Pos 7
212 #define SCB_VTOR_TBLOFF_Msk (0x3FFFFFul << SCB_VTOR_TBLOFF_Pos)
214 /* SCB Application Interrupt and Reset Control Register Definitions */
215 #define SCB_AIRCR_VECTKEY_Pos 16
216 #define SCB_AIRCR_VECTKEY_Msk (0xFFFFul << SCB_AIRCR_VECTKEY_Pos)
218 #define SCB_AIRCR_VECTKEYSTAT_Pos 16
219 #define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFul << SCB_AIRCR_VECTKEYSTAT_Pos)
221 #define SCB_AIRCR_ENDIANESS_Pos 15
222 #define SCB_AIRCR_ENDIANESS_Msk (1ul << SCB_AIRCR_ENDIANESS_Pos)
224 #define SCB_AIRCR_PRIGROUP_Pos 8
225 #define SCB_AIRCR_PRIGROUP_Msk (7ul << SCB_AIRCR_PRIGROUP_Pos)
227 #define SCB_AIRCR_SYSRESETREQ_Pos 2
228 #define SCB_AIRCR_SYSRESETREQ_Msk (1ul << SCB_AIRCR_SYSRESETREQ_Pos)
230 #define SCB_AIRCR_VECTCLRACTIVE_Pos 1
231 #define SCB_AIRCR_VECTCLRACTIVE_Msk (1ul << SCB_AIRCR_VECTCLRACTIVE_Pos)
233 #define SCB_AIRCR_VECTRESET_Pos 0
234 #define SCB_AIRCR_VECTRESET_Msk (1ul << SCB_AIRCR_VECTRESET_Pos)
236 /* SCB System Control Register Definitions */
237 #define SCB_SCR_SEVONPEND_Pos 4
238 #define SCB_SCR_SEVONPEND_Msk (1ul << SCB_SCR_SEVONPEND_Pos)
240 #define SCB_SCR_SLEEPDEEP_Pos 2
241 #define SCB_SCR_SLEEPDEEP_Msk (1ul << SCB_SCR_SLEEPDEEP_Pos)
243 #define SCB_SCR_SLEEPONEXIT_Pos 1
244 #define SCB_SCR_SLEEPONEXIT_Msk (1ul << SCB_SCR_SLEEPONEXIT_Pos)
246 /* SCB Configuration Control Register Definitions */
247 #define SCB_CCR_STKALIGN_Pos 9
248 #define SCB_CCR_STKALIGN_Msk (1ul << SCB_CCR_STKALIGN_Pos)
250 #define SCB_CCR_BFHFNMIGN_Pos 8
251 #define SCB_CCR_BFHFNMIGN_Msk (1ul << SCB_CCR_BFHFNMIGN_Pos)
253 #define SCB_CCR_DIV_0_TRP_Pos 4
254 #define SCB_CCR_DIV_0_TRP_Msk (1ul << SCB_CCR_DIV_0_TRP_Pos)
256 #define SCB_CCR_UNALIGN_TRP_Pos 3
257 #define SCB_CCR_UNALIGN_TRP_Msk (1ul << SCB_CCR_UNALIGN_TRP_Pos)
259 #define SCB_CCR_USERSETMPEND_Pos 1
260 #define SCB_CCR_USERSETMPEND_Msk (1ul << SCB_CCR_USERSETMPEND_Pos)
262 #define SCB_CCR_NONBASETHRDENA_Pos 0
263 #define SCB_CCR_NONBASETHRDENA_Msk (1ul << SCB_CCR_NONBASETHRDENA_Pos)
265 /* SCB System Handler Control and State Register Definitions */
266 #define SCB_SHCSR_USGFAULTENA_Pos 18
267 #define SCB_SHCSR_USGFAULTENA_Msk (1ul << SCB_SHCSR_USGFAULTENA_Pos)
269 #define SCB_SHCSR_BUSFAULTENA_Pos 17
270 #define SCB_SHCSR_BUSFAULTENA_Msk (1ul << SCB_SHCSR_BUSFAULTENA_Pos)
272 #define SCB_SHCSR_MEMFAULTENA_Pos 16
273 #define SCB_SHCSR_MEMFAULTENA_Msk (1ul << SCB_SHCSR_MEMFAULTENA_Pos)
275 #define SCB_SHCSR_SVCALLPENDED_Pos 15
276 #define SCB_SHCSR_SVCALLPENDED_Msk (1ul << SCB_SHCSR_SVCALLPENDED_Pos)
278 #define SCB_SHCSR_BUSFAULTPENDED_Pos 14
279 #define SCB_SHCSR_BUSFAULTPENDED_Msk (1ul << SCB_SHCSR_BUSFAULTPENDED_Pos)
281 #define SCB_SHCSR_MEMFAULTPENDED_Pos 13
282 #define SCB_SHCSR_MEMFAULTPENDED_Msk (1ul << SCB_SHCSR_MEMFAULTPENDED_Pos)
284 #define SCB_SHCSR_USGFAULTPENDED_Pos 12
285 #define SCB_SHCSR_USGFAULTPENDED_Msk (1ul << SCB_SHCSR_USGFAULTPENDED_Pos)
287 #define SCB_SHCSR_SYSTICKACT_Pos 11
288 #define SCB_SHCSR_SYSTICKACT_Msk (1ul << SCB_SHCSR_SYSTICKACT_Pos)
290 #define SCB_SHCSR_PENDSVACT_Pos 10
291 #define SCB_SHCSR_PENDSVACT_Msk (1ul << SCB_SHCSR_PENDSVACT_Pos)
293 #define SCB_SHCSR_MONITORACT_Pos 8
294 #define SCB_SHCSR_MONITORACT_Msk (1ul << SCB_SHCSR_MONITORACT_Pos)
296 #define SCB_SHCSR_SVCALLACT_Pos 7
297 #define SCB_SHCSR_SVCALLACT_Msk (1ul << SCB_SHCSR_SVCALLACT_Pos)
299 #define SCB_SHCSR_USGFAULTACT_Pos 3
300 #define SCB_SHCSR_USGFAULTACT_Msk (1ul << SCB_SHCSR_USGFAULTACT_Pos)
302 #define SCB_SHCSR_BUSFAULTACT_Pos 1
303 #define SCB_SHCSR_BUSFAULTACT_Msk (1ul << SCB_SHCSR_BUSFAULTACT_Pos)
305 #define SCB_SHCSR_MEMFAULTACT_Pos 0
306 #define SCB_SHCSR_MEMFAULTACT_Msk (1ul << SCB_SHCSR_MEMFAULTACT_Pos)
308 /* SCB Configurable Fault Status Registers Definitions */
309 #define SCB_CFSR_USGFAULTSR_Pos 16
310 #define SCB_CFSR_USGFAULTSR_Msk (0xFFFFul << SCB_CFSR_USGFAULTSR_Pos)
312 #define SCB_CFSR_BUSFAULTSR_Pos 8
313 #define SCB_CFSR_BUSFAULTSR_Msk (0xFFul << SCB_CFSR_BUSFAULTSR_Pos)
315 #define SCB_CFSR_MEMFAULTSR_Pos 0
316 #define SCB_CFSR_MEMFAULTSR_Msk (0xFFul << SCB_CFSR_MEMFAULTSR_Pos)
318 /* SCB Hard Fault Status Registers Definitions */
319 #define SCB_HFSR_DEBUGEVT_Pos 31
320 #define SCB_HFSR_DEBUGEVT_Msk (1ul << SCB_HFSR_DEBUGEVT_Pos)
322 #define SCB_HFSR_FORCED_Pos 30
323 #define SCB_HFSR_FORCED_Msk (1ul << SCB_HFSR_FORCED_Pos)
325 #define SCB_HFSR_VECTTBL_Pos 1
326 #define SCB_HFSR_VECTTBL_Msk (1ul << SCB_HFSR_VECTTBL_Pos)
328 /* SCB Debug Fault Status Register Definitions */
329 #define SCB_DFSR_EXTERNAL_Pos 4
330 #define SCB_DFSR_EXTERNAL_Msk (1ul << SCB_DFSR_EXTERNAL_Pos)
332 #define SCB_DFSR_VCATCH_Pos 3
333 #define SCB_DFSR_VCATCH_Msk (1ul << SCB_DFSR_VCATCH_Pos)
335 #define SCB_DFSR_DWTTRAP_Pos 2
336 #define SCB_DFSR_DWTTRAP_Msk (1ul << SCB_DFSR_DWTTRAP_Pos)
338 #define SCB_DFSR_BKPT_Pos 1
339 #define SCB_DFSR_BKPT_Msk (1ul << SCB_DFSR_BKPT_Pos)
341 #define SCB_DFSR_HALTED_Pos 0
342 #define SCB_DFSR_HALTED_Msk (1ul << SCB_DFSR_HALTED_Pos)
343  /* end of group CMSIS_CM3_SCB */
344 
345 
350 typedef struct
351 {
352  __IO uint32_t CTRL;
353  __IO uint32_t LOAD;
354  __IO uint32_t VAL;
355  __I uint32_t CALIB;
356 } SysTick_Type;
357 
358 /* SysTick Control / Status Register Definitions */
359 #define SysTick_CTRL_COUNTFLAG_Pos 16
360 #define SysTick_CTRL_COUNTFLAG_Msk (1ul << SysTick_CTRL_COUNTFLAG_Pos)
362 #define SysTick_CTRL_CLKSOURCE_Pos 2
363 #define SysTick_CTRL_CLKSOURCE_Msk (1ul << SysTick_CTRL_CLKSOURCE_Pos)
365 #define SysTick_CTRL_TICKINT_Pos 1
366 #define SysTick_CTRL_TICKINT_Msk (1ul << SysTick_CTRL_TICKINT_Pos)
368 #define SysTick_CTRL_ENABLE_Pos 0
369 #define SysTick_CTRL_ENABLE_Msk (1ul << SysTick_CTRL_ENABLE_Pos)
371 /* SysTick Reload Register Definitions */
372 #define SysTick_LOAD_RELOAD_Pos 0
373 #define SysTick_LOAD_RELOAD_Msk (0xFFFFFFul << SysTick_LOAD_RELOAD_Pos)
375 /* SysTick Current Register Definitions */
376 #define SysTick_VAL_CURRENT_Pos 0
377 #define SysTick_VAL_CURRENT_Msk (0xFFFFFFul << SysTick_VAL_CURRENT_Pos)
379 /* SysTick Calibration Register Definitions */
380 #define SysTick_CALIB_NOREF_Pos 31
381 #define SysTick_CALIB_NOREF_Msk (1ul << SysTick_CALIB_NOREF_Pos)
383 #define SysTick_CALIB_SKEW_Pos 30
384 #define SysTick_CALIB_SKEW_Msk (1ul << SysTick_CALIB_SKEW_Pos)
386 #define SysTick_CALIB_TENMS_Pos 0
387 #define SysTick_CALIB_TENMS_Msk (0xFFFFFFul << SysTick_VAL_CURRENT_Pos)
388  /* end of group CMSIS_CM3_SysTick */
389 
390 
395 typedef struct
396 {
397  __O union
398  {
399  __O uint8_t u8;
400  __O uint16_t u16;
401  __O uint32_t u32;
402  } PORT [32];
403  uint32_t RESERVED0[864];
404  __IO uint32_t TER;
405  uint32_t RESERVED1[15];
406  __IO uint32_t TPR;
407  uint32_t RESERVED2[15];
408  __IO uint32_t TCR;
409  uint32_t RESERVED3[29];
410  __IO uint32_t IWR;
411  __IO uint32_t IRR;
412  __IO uint32_t IMCR;
413  uint32_t RESERVED4[43];
414  __IO uint32_t LAR;
415  __IO uint32_t LSR;
416  uint32_t RESERVED5[6];
417  __I uint32_t PID4;
418  __I uint32_t PID5;
419  __I uint32_t PID6;
420  __I uint32_t PID7;
421  __I uint32_t PID0;
422  __I uint32_t PID1;
423  __I uint32_t PID2;
424  __I uint32_t PID3;
425  __I uint32_t CID0;
426  __I uint32_t CID1;
427  __I uint32_t CID2;
428  __I uint32_t CID3;
429 } ITM_Type;
430 
431 /* ITM Trace Privilege Register Definitions */
432 #define ITM_TPR_PRIVMASK_Pos 0
433 #define ITM_TPR_PRIVMASK_Msk (0xFul << ITM_TPR_PRIVMASK_Pos)
435 /* ITM Trace Control Register Definitions */
436 #define ITM_TCR_BUSY_Pos 23
437 #define ITM_TCR_BUSY_Msk (1ul << ITM_TCR_BUSY_Pos)
439 #define ITM_TCR_ATBID_Pos 16
440 #define ITM_TCR_ATBID_Msk (0x7Ful << ITM_TCR_ATBID_Pos)
442 #define ITM_TCR_TSPrescale_Pos 8
443 #define ITM_TCR_TSPrescale_Msk (3ul << ITM_TCR_TSPrescale_Pos)
445 #define ITM_TCR_SWOENA_Pos 4
446 #define ITM_TCR_SWOENA_Msk (1ul << ITM_TCR_SWOENA_Pos)
448 #define ITM_TCR_DWTENA_Pos 3
449 #define ITM_TCR_DWTENA_Msk (1ul << ITM_TCR_DWTENA_Pos)
451 #define ITM_TCR_SYNCENA_Pos 2
452 #define ITM_TCR_SYNCENA_Msk (1ul << ITM_TCR_SYNCENA_Pos)
454 #define ITM_TCR_TSENA_Pos 1
455 #define ITM_TCR_TSENA_Msk (1ul << ITM_TCR_TSENA_Pos)
457 #define ITM_TCR_ITMENA_Pos 0
458 #define ITM_TCR_ITMENA_Msk (1ul << ITM_TCR_ITMENA_Pos)
460 /* ITM Integration Write Register Definitions */
461 #define ITM_IWR_ATVALIDM_Pos 0
462 #define ITM_IWR_ATVALIDM_Msk (1ul << ITM_IWR_ATVALIDM_Pos)
464 /* ITM Integration Read Register Definitions */
465 #define ITM_IRR_ATREADYM_Pos 0
466 #define ITM_IRR_ATREADYM_Msk (1ul << ITM_IRR_ATREADYM_Pos)
468 /* ITM Integration Mode Control Register Definitions */
469 #define ITM_IMCR_INTEGRATION_Pos 0
470 #define ITM_IMCR_INTEGRATION_Msk (1ul << ITM_IMCR_INTEGRATION_Pos)
472 /* ITM Lock Status Register Definitions */
473 #define ITM_LSR_ByteAcc_Pos 2
474 #define ITM_LSR_ByteAcc_Msk (1ul << ITM_LSR_ByteAcc_Pos)
476 #define ITM_LSR_Access_Pos 1
477 #define ITM_LSR_Access_Msk (1ul << ITM_LSR_Access_Pos)
479 #define ITM_LSR_Present_Pos 0
480 #define ITM_LSR_Present_Msk (1ul << ITM_LSR_Present_Pos)
481  /* end of group CMSIS_CM3_ITM */
482 
483 
488 typedef struct
489 {
490  uint32_t RESERVED0;
491  __I uint32_t ICTR;
492 #if ((defined __CM3_REV) && (__CM3_REV >= 0x200))
493  __IO uint32_t ACTLR;
494 #else
495  uint32_t RESERVED1;
496 #endif
498 
499 /* Interrupt Controller Type Register Definitions */
500 #define InterruptType_ICTR_INTLINESNUM_Pos 0
501 #define InterruptType_ICTR_INTLINESNUM_Msk (0x1Ful << InterruptType_ICTR_INTLINESNUM_Pos)
503 /* Auxiliary Control Register Definitions */
504 #define InterruptType_ACTLR_DISFOLD_Pos 2
505 #define InterruptType_ACTLR_DISFOLD_Msk (1ul << InterruptType_ACTLR_DISFOLD_Pos)
507 #define InterruptType_ACTLR_DISDEFWBUF_Pos 1
508 #define InterruptType_ACTLR_DISDEFWBUF_Msk (1ul << InterruptType_ACTLR_DISDEFWBUF_Pos)
510 #define InterruptType_ACTLR_DISMCYCINT_Pos 0
511 #define InterruptType_ACTLR_DISMCYCINT_Msk (1ul << InterruptType_ACTLR_DISMCYCINT_Pos)
512  /* end of group CMSIS_CM3_InterruptType */
513 
514 
515 #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1)
516 
520 typedef struct
521 {
522  __I uint32_t TYPE;
523  __IO uint32_t CTRL;
524  __IO uint32_t RNR;
525  __IO uint32_t RBAR;
526  __IO uint32_t RASR;
527  __IO uint32_t RBAR_A1;
528  __IO uint32_t RASR_A1;
529  __IO uint32_t RBAR_A2;
530  __IO uint32_t RASR_A2;
531  __IO uint32_t RBAR_A3;
532  __IO uint32_t RASR_A3;
533 } MPU_Type;
534 
535 /* MPU Type Register */
536 #define MPU_TYPE_IREGION_Pos 16
537 #define MPU_TYPE_IREGION_Msk (0xFFul << MPU_TYPE_IREGION_Pos)
539 #define MPU_TYPE_DREGION_Pos 8
540 #define MPU_TYPE_DREGION_Msk (0xFFul << MPU_TYPE_DREGION_Pos)
542 #define MPU_TYPE_SEPARATE_Pos 0
543 #define MPU_TYPE_SEPARATE_Msk (1ul << MPU_TYPE_SEPARATE_Pos)
545 /* MPU Control Register */
546 #define MPU_CTRL_PRIVDEFENA_Pos 2
547 #define MPU_CTRL_PRIVDEFENA_Msk (1ul << MPU_CTRL_PRIVDEFENA_Pos)
549 #define MPU_CTRL_HFNMIENA_Pos 1
550 #define MPU_CTRL_HFNMIENA_Msk (1ul << MPU_CTRL_HFNMIENA_Pos)
552 #define MPU_CTRL_ENABLE_Pos 0
553 #define MPU_CTRL_ENABLE_Msk (1ul << MPU_CTRL_ENABLE_Pos)
555 /* MPU Region Number Register */
556 #define MPU_RNR_REGION_Pos 0
557 #define MPU_RNR_REGION_Msk (0xFFul << MPU_RNR_REGION_Pos)
559 /* MPU Region Base Address Register */
560 #define MPU_RBAR_ADDR_Pos 5
561 #define MPU_RBAR_ADDR_Msk (0x7FFFFFFul << MPU_RBAR_ADDR_Pos)
563 #define MPU_RBAR_VALID_Pos 4
564 #define MPU_RBAR_VALID_Msk (1ul << MPU_RBAR_VALID_Pos)
566 #define MPU_RBAR_REGION_Pos 0
567 #define MPU_RBAR_REGION_Msk (0xFul << MPU_RBAR_REGION_Pos)
569 /* MPU Region Attribute and Size Register */
570 #define MPU_RASR_XN_Pos 28
571 #define MPU_RASR_XN_Msk (1ul << MPU_RASR_XN_Pos)
573 #define MPU_RASR_AP_Pos 24
574 #define MPU_RASR_AP_Msk (7ul << MPU_RASR_AP_Pos)
576 #define MPU_RASR_TEX_Pos 19
577 #define MPU_RASR_TEX_Msk (7ul << MPU_RASR_TEX_Pos)
579 #define MPU_RASR_S_Pos 18
580 #define MPU_RASR_S_Msk (1ul << MPU_RASR_S_Pos)
582 #define MPU_RASR_C_Pos 17
583 #define MPU_RASR_C_Msk (1ul << MPU_RASR_C_Pos)
585 #define MPU_RASR_B_Pos 16
586 #define MPU_RASR_B_Msk (1ul << MPU_RASR_B_Pos)
588 #define MPU_RASR_SRD_Pos 8
589 #define MPU_RASR_SRD_Msk (0xFFul << MPU_RASR_SRD_Pos)
591 #define MPU_RASR_SIZE_Pos 1
592 #define MPU_RASR_SIZE_Msk (0x1Ful << MPU_RASR_SIZE_Pos)
594 #define MPU_RASR_ENA_Pos 0
595 #define MPU_RASR_ENA_Msk (0x1Ful << MPU_RASR_ENA_Pos)
597  /* end of group CMSIS_CM3_MPU */
598 #endif
599 
600 
605 typedef struct
606 {
607  __IO uint32_t DHCSR;
608  __O uint32_t DCRSR;
609  __IO uint32_t DCRDR;
610  __IO uint32_t DEMCR;
612 
613 /* Debug Halting Control and Status Register */
614 #define CoreDebug_DHCSR_DBGKEY_Pos 16
615 #define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFul << CoreDebug_DHCSR_DBGKEY_Pos)
617 #define CoreDebug_DHCSR_S_RESET_ST_Pos 25
618 #define CoreDebug_DHCSR_S_RESET_ST_Msk (1ul << CoreDebug_DHCSR_S_RESET_ST_Pos)
620 #define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24
621 #define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1ul << CoreDebug_DHCSR_S_RETIRE_ST_Pos)
623 #define CoreDebug_DHCSR_S_LOCKUP_Pos 19
624 #define CoreDebug_DHCSR_S_LOCKUP_Msk (1ul << CoreDebug_DHCSR_S_LOCKUP_Pos)
626 #define CoreDebug_DHCSR_S_SLEEP_Pos 18
627 #define CoreDebug_DHCSR_S_SLEEP_Msk (1ul << CoreDebug_DHCSR_S_SLEEP_Pos)
629 #define CoreDebug_DHCSR_S_HALT_Pos 17
630 #define CoreDebug_DHCSR_S_HALT_Msk (1ul << CoreDebug_DHCSR_S_HALT_Pos)
632 #define CoreDebug_DHCSR_S_REGRDY_Pos 16
633 #define CoreDebug_DHCSR_S_REGRDY_Msk (1ul << CoreDebug_DHCSR_S_REGRDY_Pos)
635 #define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5
636 #define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1ul << CoreDebug_DHCSR_C_SNAPSTALL_Pos)
638 #define CoreDebug_DHCSR_C_MASKINTS_Pos 3
639 #define CoreDebug_DHCSR_C_MASKINTS_Msk (1ul << CoreDebug_DHCSR_C_MASKINTS_Pos)
641 #define CoreDebug_DHCSR_C_STEP_Pos 2
642 #define CoreDebug_DHCSR_C_STEP_Msk (1ul << CoreDebug_DHCSR_C_STEP_Pos)
644 #define CoreDebug_DHCSR_C_HALT_Pos 1
645 #define CoreDebug_DHCSR_C_HALT_Msk (1ul << CoreDebug_DHCSR_C_HALT_Pos)
647 #define CoreDebug_DHCSR_C_DEBUGEN_Pos 0
648 #define CoreDebug_DHCSR_C_DEBUGEN_Msk (1ul << CoreDebug_DHCSR_C_DEBUGEN_Pos)
650 /* Debug Core Register Selector Register */
651 #define CoreDebug_DCRSR_REGWnR_Pos 16
652 #define CoreDebug_DCRSR_REGWnR_Msk (1ul << CoreDebug_DCRSR_REGWnR_Pos)
654 #define CoreDebug_DCRSR_REGSEL_Pos 0
655 #define CoreDebug_DCRSR_REGSEL_Msk (0x1Ful << CoreDebug_DCRSR_REGSEL_Pos)
657 /* Debug Exception and Monitor Control Register */
658 #define CoreDebug_DEMCR_TRCENA_Pos 24
659 #define CoreDebug_DEMCR_TRCENA_Msk (1ul << CoreDebug_DEMCR_TRCENA_Pos)
661 #define CoreDebug_DEMCR_MON_REQ_Pos 19
662 #define CoreDebug_DEMCR_MON_REQ_Msk (1ul << CoreDebug_DEMCR_MON_REQ_Pos)
664 #define CoreDebug_DEMCR_MON_STEP_Pos 18
665 #define CoreDebug_DEMCR_MON_STEP_Msk (1ul << CoreDebug_DEMCR_MON_STEP_Pos)
667 #define CoreDebug_DEMCR_MON_PEND_Pos 17
668 #define CoreDebug_DEMCR_MON_PEND_Msk (1ul << CoreDebug_DEMCR_MON_PEND_Pos)
670 #define CoreDebug_DEMCR_MON_EN_Pos 16
671 #define CoreDebug_DEMCR_MON_EN_Msk (1ul << CoreDebug_DEMCR_MON_EN_Pos)
673 #define CoreDebug_DEMCR_VC_HARDERR_Pos 10
674 #define CoreDebug_DEMCR_VC_HARDERR_Msk (1ul << CoreDebug_DEMCR_VC_HARDERR_Pos)
676 #define CoreDebug_DEMCR_VC_INTERR_Pos 9
677 #define CoreDebug_DEMCR_VC_INTERR_Msk (1ul << CoreDebug_DEMCR_VC_INTERR_Pos)
679 #define CoreDebug_DEMCR_VC_BUSERR_Pos 8
680 #define CoreDebug_DEMCR_VC_BUSERR_Msk (1ul << CoreDebug_DEMCR_VC_BUSERR_Pos)
682 #define CoreDebug_DEMCR_VC_STATERR_Pos 7
683 #define CoreDebug_DEMCR_VC_STATERR_Msk (1ul << CoreDebug_DEMCR_VC_STATERR_Pos)
685 #define CoreDebug_DEMCR_VC_CHKERR_Pos 6
686 #define CoreDebug_DEMCR_VC_CHKERR_Msk (1ul << CoreDebug_DEMCR_VC_CHKERR_Pos)
688 #define CoreDebug_DEMCR_VC_NOCPERR_Pos 5
689 #define CoreDebug_DEMCR_VC_NOCPERR_Msk (1ul << CoreDebug_DEMCR_VC_NOCPERR_Pos)
691 #define CoreDebug_DEMCR_VC_MMERR_Pos 4
692 #define CoreDebug_DEMCR_VC_MMERR_Msk (1ul << CoreDebug_DEMCR_VC_MMERR_Pos)
694 #define CoreDebug_DEMCR_VC_CORERESET_Pos 0
695 #define CoreDebug_DEMCR_VC_CORERESET_Msk (1ul << CoreDebug_DEMCR_VC_CORERESET_Pos)
696  /* end of group CMSIS_CM3_CoreDebug */
697 
698 
699 /* Memory mapping of Cortex-M3 Hardware */
700 #define SCS_BASE (0xE000E000)
701 #define ITM_BASE (0xE0000000)
702 #define CoreDebug_BASE (0xE000EDF0)
703 #define SysTick_BASE (SCS_BASE + 0x0010)
704 #define NVIC_BASE (SCS_BASE + 0x0100)
705 #define SCB_BASE (SCS_BASE + 0x0D00)
707 #define InterruptType ((InterruptType_Type *) SCS_BASE)
708 #define SCB ((SCB_Type *) SCB_BASE)
709 #define SysTick ((SysTick_Type *) SysTick_BASE)
710 #define NVIC ((NVIC_Type *) NVIC_BASE)
711 #define ITM ((ITM_Type *) ITM_BASE)
712 #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE)
714 #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1)
715  #define MPU_BASE (SCS_BASE + 0x0D90)
716  #define MPU ((MPU_Type*) MPU_BASE)
717 #endif
718  /* end of group CMSIS_CM3_core_register */
720 
721 
722 /*******************************************************************************
723  * Hardware Abstraction Layer
724  ******************************************************************************/
725 
726 #if defined ( __CC_ARM )
727  #define __ASM __asm
728  #define __INLINE __inline
730 #elif defined ( __ICCARM__ )
731  #define __ASM __asm
732  #define __INLINE inline
734 #elif defined ( __GNUC__ )
735  #define __ASM __asm
736  #define __INLINE inline
738 #elif defined ( __TASKING__ )
739  #define __ASM __asm
740  #define __INLINE inline
742 #endif
743 
744 
745 /* ################### Compiler specific Intrinsics ########################### */
746 
747 #if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
748 /* ARM armcc specific functions */
749 
750 #define __enable_fault_irq __enable_fiq
751 #define __disable_fault_irq __disable_fiq
752 
753 #define __NOP __nop
754 #define __WFI __wfi
755 #define __WFE __wfe
756 #define __SEV __sev
757 #define __ISB() __isb(0)
758 #define __DSB() __dsb(0)
759 #define __DMB() __dmb(0)
760 #define __REV __rev
761 #define __RBIT __rbit
762 #define __LDREXB(ptr) ((unsigned char ) __ldrex(ptr))
763 #define __LDREXH(ptr) ((unsigned short) __ldrex(ptr))
764 #define __LDREXW(ptr) ((unsigned int ) __ldrex(ptr))
765 #define __STREXB(value, ptr) __strex(value, ptr)
766 #define __STREXH(value, ptr) __strex(value, ptr)
767 #define __STREXW(value, ptr) __strex(value, ptr)
768 
769 
770 /* intrinsic unsigned long long __ldrexd(volatile void *ptr) */
771 /* intrinsic int __strexd(unsigned long long val, volatile void *ptr) */
772 /* intrinsic void __enable_irq(); */
773 /* intrinsic void __disable_irq(); */
774 
775 
783 extern uint32_t __get_PSP(void);
784 
793 extern void __set_PSP(uint32_t topOfProcStack);
794 
803 extern uint32_t __get_MSP(void);
804 
813 extern void __set_MSP(uint32_t topOfMainStack);
814 
823 extern uint32_t __REV16(uint16_t value);
824 
833 extern int32_t __REVSH(int16_t value);
834 
835 
836 #if (__ARMCC_VERSION < 400000)
837 
843 extern void __CLREX(void);
844 
852 extern uint32_t __get_BASEPRI(void);
853 
861 extern void __set_BASEPRI(uint32_t basePri);
862 
870 extern uint32_t __get_PRIMASK(void);
871 
879 extern void __set_PRIMASK(uint32_t priMask);
880 
888 extern uint32_t __get_FAULTMASK(void);
889 
897 extern void __set_FAULTMASK(uint32_t faultMask);
898 
906 extern uint32_t __get_CONTROL(void);
907 
915 extern void __set_CONTROL(uint32_t control);
916 
917 #else /* (__ARMCC_VERSION >= 400000) */
918 
924 #define __CLREX __clrex
925 
933 static __INLINE uint32_t __get_BASEPRI(void)
934 {
935  register uint32_t __regBasePri __ASM("basepri");
936  return(__regBasePri);
937 }
938 
946 static __INLINE void __set_BASEPRI(uint32_t basePri)
947 {
948  register uint32_t __regBasePri __ASM("basepri");
949  __regBasePri = (basePri & 0xff);
950 }
951 
959 static __INLINE uint32_t __get_PRIMASK(void)
960 {
961  register uint32_t __regPriMask __ASM("primask");
962  return(__regPriMask);
963 }
964 
972 static __INLINE void __set_PRIMASK(uint32_t priMask)
973 {
974  register uint32_t __regPriMask __ASM("primask");
975  __regPriMask = (priMask);
976 }
977 
985 static __INLINE uint32_t __get_FAULTMASK(void)
986 {
987  register uint32_t __regFaultMask __ASM("faultmask");
988  return(__regFaultMask);
989 }
990 
998 static __INLINE void __set_FAULTMASK(uint32_t faultMask)
999 {
1000  register uint32_t __regFaultMask __ASM("faultmask");
1001  __regFaultMask = (faultMask & 1);
1002 }
1003 
1011 static __INLINE uint32_t __get_CONTROL(void)
1012 {
1013  register uint32_t __regControl __ASM("control");
1014  return(__regControl);
1015 }
1016 
1024 static __INLINE void __set_CONTROL(uint32_t control)
1025 {
1026  register uint32_t __regControl __ASM("control");
1027  __regControl = control;
1028 }
1029 
1030 #endif /* __ARMCC_VERSION */
1031 
1032 
1033 
1034 #elif (defined (__ICCARM__)) /*------------------ ICC Compiler -------------------*/
1035 /* IAR iccarm specific functions */
1036 
1037 #define __enable_irq __enable_interrupt
1038 #define __disable_irq __disable_interrupt
1040 static __INLINE void __enable_fault_irq() { __ASM ("cpsie f"); }
1041 static __INLINE void __disable_fault_irq() { __ASM ("cpsid f"); }
1042 
1043 #define __NOP __no_operation
1044 static __INLINE void __WFI() { __ASM ("wfi"); }
1045 static __INLINE void __WFE() { __ASM ("wfe"); }
1046 static __INLINE void __SEV() { __ASM ("sev"); }
1047 static __INLINE void __CLREX() { __ASM ("clrex"); }
1048 
1049 /* intrinsic void __ISB(void) */
1050 /* intrinsic void __DSB(void) */
1051 /* intrinsic void __DMB(void) */
1052 /* intrinsic void __set_PRIMASK(); */
1053 /* intrinsic void __get_PRIMASK(); */
1054 /* intrinsic void __set_FAULTMASK(); */
1055 /* intrinsic void __get_FAULTMASK(); */
1056 /* intrinsic uint32_t __REV(uint32_t value); */
1057 /* intrinsic uint32_t __REVSH(uint32_t value); */
1058 /* intrinsic unsigned long __STREX(unsigned long, unsigned long); */
1059 /* intrinsic unsigned long __LDREX(unsigned long *); */
1060 
1061 
1069 extern uint32_t __get_PSP(void);
1070 
1079 extern void __set_PSP(uint32_t topOfProcStack);
1080 
1089 extern uint32_t __get_MSP(void);
1090 
1099 extern void __set_MSP(uint32_t topOfMainStack);
1100 
1109 extern uint32_t __REV16(uint16_t value);
1110 
1119 extern uint32_t __RBIT(uint32_t value);
1120 
1129 extern uint8_t __LDREXB(uint8_t *addr);
1130 
1139 extern uint16_t __LDREXH(uint16_t *addr);
1140 
1149 extern uint32_t __LDREXW(uint32_t *addr);
1150 
1160 extern uint32_t __STREXB(uint8_t value, uint8_t *addr);
1161 
1171 extern uint32_t __STREXH(uint16_t value, uint16_t *addr);
1172 
1182 extern uint32_t __STREXW(uint32_t value, uint32_t *addr);
1183 
1184 
1185 
1186 #elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/
1187 /* GNU gcc specific functions */
1188 
1189 static __INLINE void __enable_irq() { __ASM volatile ("cpsie i"); }
1190 static __INLINE void __disable_irq() { __ASM volatile ("cpsid i"); }
1191 
1192 static __INLINE void __enable_fault_irq() { __ASM volatile ("cpsie f"); }
1193 static __INLINE void __disable_fault_irq() { __ASM volatile ("cpsid f"); }
1194 
1195 static __INLINE void __NOP() { __ASM volatile ("nop"); }
1196 static __INLINE void __WFI() { __ASM volatile ("wfi"); }
1197 static __INLINE void __WFE() { __ASM volatile ("wfe"); }
1198 static __INLINE void __SEV() { __ASM volatile ("sev"); }
1199 static __INLINE void __ISB() { __ASM volatile ("isb"); }
1200 static __INLINE void __DSB() { __ASM volatile ("dsb"); }
1201 static __INLINE void __DMB() { __ASM volatile ("dmb"); }
1202 static __INLINE void __CLREX() { __ASM volatile ("clrex"); }
1203 
1204 
1212 extern uint32_t __get_PSP(void);
1213 
1222 extern void __set_PSP(uint32_t topOfProcStack);
1223 
1232 extern uint32_t __get_MSP(void);
1233 
1242 extern void __set_MSP(uint32_t topOfMainStack);
1243 
1251 extern uint32_t __get_BASEPRI(void);
1252 
1260 extern void __set_BASEPRI(uint32_t basePri);
1261 
1269 extern uint32_t __get_PRIMASK(void);
1270 
1278 extern void __set_PRIMASK(uint32_t priMask);
1279 
1287 extern uint32_t __get_FAULTMASK(void);
1288 
1296 extern void __set_FAULTMASK(uint32_t faultMask);
1297 
1305 extern uint32_t __get_CONTROL(void);
1306 
1314 extern void __set_CONTROL(uint32_t control);
1315 
1324 extern uint32_t __REV(uint32_t value);
1325 
1334 extern uint32_t __REV16(uint16_t value);
1335 
1344 extern int32_t __REVSH(int16_t value);
1345 
1354 extern uint32_t __RBIT(uint32_t value);
1355 
1364 extern uint8_t __LDREXB(uint8_t *addr);
1365 
1374 extern uint16_t __LDREXH(uint16_t *addr);
1375 
1384 extern uint32_t __LDREXW(uint32_t *addr);
1385 
1395 extern uint32_t __STREXB(uint8_t value, uint8_t *addr);
1396 
1406 extern uint32_t __STREXH(uint16_t value, uint16_t *addr);
1407 
1417 extern uint32_t __STREXW(uint32_t value, uint32_t *addr);
1418 
1419 
1420 #elif (defined (__TASKING__)) /*------------------ TASKING Compiler ---------------------*/
1421 /* TASKING carm specific functions */
1422 
1423 /*
1424  * The CMSIS functions have been implemented as intrinsics in the compiler.
1425  * Please use "carm -?i" to get an up to date list of all instrinsics,
1426  * Including the CMSIS ones.
1427  */
1428 
1429 #endif
1430 
1431 
1439 
1440 /* ########################## NVIC functions #################################### */
1441 
1453 static __INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
1454 {
1455  uint32_t reg_value;
1456  uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */
1457 
1458  reg_value = SCB->AIRCR; /* read old register configuration */
1459  reg_value &= ~(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk); /* clear bits to change */
1460  reg_value = (reg_value |
1461  (0x5FA << SCB_AIRCR_VECTKEY_Pos) |
1462  (PriorityGroupTmp << 8)); /* Insert write key and priorty group */
1463  SCB->AIRCR = reg_value;
1464 }
1465 
1474 static __INLINE uint32_t NVIC_GetPriorityGrouping(void)
1475 {
1476  return ((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos); /* read priority grouping field */
1477 }
1478 
1487 static __INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
1488 {
1489  NVIC->ISER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* enable interrupt */
1490 }
1491 
1500 static __INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
1501 {
1502  NVIC->ICER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* disable interrupt */
1503 }
1504 
1514 static __INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
1515 {
1516  return((uint32_t) ((NVIC->ISPR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if pending else 0 */
1517 }
1518 
1527 static __INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
1528 {
1529  NVIC->ISPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* set interrupt pending */
1530 }
1531 
1540 static __INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
1541 {
1542  NVIC->ICPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */
1543 }
1544 
1554 static __INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn)
1555 {
1556  return((uint32_t)((NVIC->IABR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if active else 0 */
1557 }
1558 
1571 static __INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
1572 {
1573  if(IRQn < 0) {
1574  SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for Cortex-M3 System Interrupts */
1575  else {
1576  NVIC->IP[(uint32_t)(IRQn)] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for device specific Interrupts */
1577 }
1578 
1594 static __INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
1595 {
1596 
1597  if(IRQn < 0) {
1598  return((uint32_t)(SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M3 system interrupts */
1599  else {
1600  return((uint32_t)(NVIC->IP[(uint32_t)(IRQn)] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */
1601 }
1602 
1603 
1619 static __INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)
1620 {
1621  uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */
1622  uint32_t PreemptPriorityBits;
1623  uint32_t SubPriorityBits;
1624 
1625  PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp;
1626  SubPriorityBits = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS;
1627 
1628  return (
1629  ((PreemptPriority & ((1 << (PreemptPriorityBits)) - 1)) << SubPriorityBits) |
1630  ((SubPriority & ((1 << (SubPriorityBits )) - 1)))
1631  );
1632 }
1633 
1634 
1650 static __INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority)
1651 {
1652  uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */
1653  uint32_t PreemptPriorityBits;
1654  uint32_t SubPriorityBits;
1655 
1656  PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp;
1657  SubPriorityBits = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS;
1658 
1659  *pPreemptPriority = (Priority >> SubPriorityBits) & ((1 << (PreemptPriorityBits)) - 1);
1660  *pSubPriority = (Priority ) & ((1 << (SubPriorityBits )) - 1);
1661 }
1662 
1663 
1664 
1665 /* ################################## SysTick function ############################################ */
1666 
1667 #if (!defined (__Vendor_SysTickConfig)) || (__Vendor_SysTickConfig == 0)
1668 
1679 static __INLINE uint32_t SysTick_Config(uint32_t ticks)
1680 {
1681  if (ticks > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */
1682 
1683  SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1; /* set reload register */
1684  NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Cortex-M0 System Interrupts */
1685  SysTick->VAL = 0; /* Load the SysTick Counter Value */
1688  SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
1689  return (0); /* Function successful */
1690 }
1691 
1692 #endif
1693 
1694 
1695 
1696 
1697 /* ################################## Reset function ############################################ */
1698 
1704 static __INLINE void NVIC_SystemReset(void)
1705 {
1706  SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) |
1707  (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) |
1708  SCB_AIRCR_SYSRESETREQ_Msk); /* Keep priority group unchanged */
1709  __DSB(); /* Ensure completion of memory access */
1710  while(1); /* wait until reset */
1711 }
1712  /* end of group CMSIS_CM3_Core_FunctionInterface */
1714 
1715 
1716 
1717 /* ##################################### Debug In/Output function ########################################### */
1718 
1726 
1727 extern volatile int ITM_RxBuffer;
1728 #define ITM_RXBUFFER_EMPTY 0x5AA55AA5
1741 static __INLINE uint32_t ITM_SendChar (uint32_t ch)
1742 {
1743  if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk) && /* Trace enabled */
1744  (ITM->TCR & ITM_TCR_ITMENA_Msk) && /* ITM enabled */
1745  (ITM->TER & (1ul << 0) ) ) /* ITM Port #0 enabled */
1746  {
1747  while (ITM->PORT[0].u32 == 0);
1748  ITM->PORT[0].u8 = (uint8_t) ch;
1749  }
1750  return (ch);
1751 }
1752 
1753 
1763 static __INLINE int ITM_ReceiveChar (void) {
1764  int ch = -1; /* no character available */
1765 
1766  if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) {
1767  ch = ITM_RxBuffer;
1768  ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */
1769  }
1770 
1771  return (ch);
1772 }
1773 
1774 
1783 static __INLINE int ITM_CheckChar (void) {
1784 
1785  if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY) {
1786  return (0); /* no character available */
1787  } else {
1788  return (1); /* character available */
1789  }
1790 }
1791  /* end of group CMSIS_CM3_core_DebugInterface */
1793 
1794 
1795 #ifdef __cplusplus
1796 }
1797 #endif
1798  /* end of group CMSIS_CM3_core_definitions */
1800 
1801 #endif /* __CM3_CORE_H__ */
1802 
1803 /*lint -restore */
__IO uint32_t CTRL
Definition: core_cm3.h:523
#define __I
Definition: LPC17xx.h:39
#define SCB_AIRCR_VECTKEY_Pos
Definition: core_cm3.h:215
__O uint32_t STIR
Definition: core_cm3.h:131
__IO uint32_t RBAR_A1
Definition: core_cm3.h:527
#define ITM
Definition: core_cm3.h:711
__IO uint32_t DCRDR
Definition: core_cm3.h:609
__IO uint32_t MMFAR
Definition: core_cm3.h:153
__IO uint32_t DHCSR
Definition: core_cm3.h:607
#define CoreDebug_DEMCR_TRCENA_Msk
Definition: core_cm3.h:659
__IO uint32_t TPR
Definition: core_cm3.h:406
#define SysTick_CTRL_CLKSOURCE_Msk
Definition: core_cm3.h:363
__I uint32_t PID5
Definition: core_cm3.h:418
__IO uint32_t RASR_A2
Definition: core_cm3.h:530
__I uint32_t PID2
Definition: core_cm3.h:423
__IO uint32_t SHCSR
Definition: core_cm3.h:149
__O uint32_t DCRSR
Definition: core_cm3.h:608
__I uint32_t PID3
Definition: core_cm3.h:424
#define CoreDebug
Definition: core_cm3.h:712
__IO uint32_t LSR
Definition: core_cm3.h:415
IRQn
Definition: LPC17xx.h:53
Definition: core_cm3.h:117
__IO uint32_t CFSR
Definition: core_cm3.h:150
#define SysTick_LOAD_RELOAD_Msk
Definition: core_cm3.h:373
Definition: core_cm3.h:140
uint32_t RESERVED0
Definition: core_cm3.h:490
__IO uint32_t VAL
Definition: core_cm3.h:354
__I uint32_t PID7
Definition: core_cm3.h:420
#define SCB_AIRCR_VECTKEY_Msk
Definition: core_cm3.h:216
__IO uint32_t RASR_A3
Definition: core_cm3.h:532
__IO uint32_t VTOR
Definition: core_cm3.h:144
__IO uint32_t TER
Definition: core_cm3.h:404
__I uint32_t CALIB
Definition: core_cm3.h:355
__IO uint32_t LAR
Definition: core_cm3.h:414
volatile int ITM_RxBuffer
#define ITM_RXBUFFER_EMPTY
Definition: core_cm3.h:1728
__IO uint32_t RBAR_A2
Definition: core_cm3.h:529
__IO uint32_t IRR
Definition: core_cm3.h:411
__IO uint32_t ICSR
Definition: core_cm3.h:143
__IO uint32_t AIRCR
Definition: core_cm3.h:145
__IO uint32_t RASR
Definition: core_cm3.h:526
__IO uint32_t DFSR
Definition: core_cm3.h:152
__IO uint32_t AFSR
Definition: core_cm3.h:155
__IO uint32_t HFSR
Definition: core_cm3.h:151
__I uint32_t PID6
Definition: core_cm3.h:419
Definition: core_cm3.h:350
Definition: core_cm3.h:605
#define SysTick_CTRL_TICKINT_Msk
Definition: core_cm3.h:366
__I uint32_t PID0
Definition: core_cm3.h:421
__O uint8_t u8
Definition: core_cm3.h:399
__IO uint32_t DEMCR
Definition: core_cm3.h:610
__I uint32_t DFR
Definition: core_cm3.h:157
Definition: core_cm3.h:488
Definition: LPC17xx.h:63
CMSIS Cortex-M3 Core Peripheral Access Layer Header File for NXP LPC17xx Device Series.
#define __IO
Definition: LPC17xx.h:42
__I uint32_t CPUID
Definition: core_cm3.h:142
__IO uint32_t CTRL
Definition: core_cm3.h:352
#define SCB_AIRCR_PRIGROUP_Msk
Definition: core_cm3.h:225
__IO uint32_t SCR
Definition: core_cm3.h:146
#define ITM_TCR_ITMENA_Msk
Definition: core_cm3.h:458
__IO uint32_t TCR
Definition: core_cm3.h:408
#define __NVIC_PRIO_BITS
Definition: LPC17xx.h:112
__IO uint32_t IMCR
Definition: core_cm3.h:412
__IO uint32_t IWR
Definition: core_cm3.h:410
#define SCB
Definition: core_cm3.h:708
__I uint32_t ICTR
Definition: core_cm3.h:491
__IO uint32_t RBAR_A3
Definition: core_cm3.h:531
#define SysTick
Definition: core_cm3.h:709
__IO uint32_t LOAD
Definition: core_cm3.h:353
__IO uint32_t RNR
Definition: core_cm3.h:524
__I uint32_t TYPE
Definition: core_cm3.h:522
__IO uint32_t CCR
Definition: core_cm3.h:147
enum IRQn IRQn_Type
__I uint32_t CID0
Definition: core_cm3.h:425
__I uint32_t CID3
Definition: core_cm3.h:428
__I uint32_t CID2
Definition: core_cm3.h:427
Definition: core_cm3.h:520
#define __O
Definition: LPC17xx.h:41
__IO uint32_t RBAR
Definition: core_cm3.h:525
#define SCB_AIRCR_PRIGROUP_Pos
Definition: core_cm3.h:224
__I uint32_t CID1
Definition: core_cm3.h:426
uint32_t RESERVED1
Definition: core_cm3.h:495
__O uint32_t u32
Definition: core_cm3.h:401
__O uint16_t u16
Definition: core_cm3.h:400
__I uint32_t PID1
Definition: core_cm3.h:422
__I uint32_t PID4
Definition: core_cm3.h:417
#define SCB_AIRCR_SYSRESETREQ_Msk
Definition: core_cm3.h:228
Definition: core_cm3.h:395
__I uint32_t ADR
Definition: core_cm3.h:158
__IO uint32_t RASR_A1
Definition: core_cm3.h:528
__IO uint32_t BFAR
Definition: core_cm3.h:154
#define SysTick_CTRL_ENABLE_Msk
Definition: core_cm3.h:369
#define NVIC
Definition: core_cm3.h:710