21#ifndef LIBOPENCM3_SCB_H
22#define LIBOPENCM3_SCB_H
43#define SCB_CPUID MMIO32(SCB_BASE + 0x00)
46#define SCB_ICSR MMIO32(SCB_BASE + 0x04)
49#define SCB_VTOR MMIO32(SCB_BASE + 0x08)
52#define SCB_AIRCR MMIO32(SCB_BASE + 0x0C)
55#define SCB_SCR MMIO32(SCB_BASE + 0x10)
58#define SCB_CCR MMIO32(SCB_BASE + 0x14)
65#if defined(__ARM_ARCH_6M__)
66#define SCB_SHPR32(ipr_id) MMIO32(SCS_BASE + 0xD18 + ((ipr_id) * 4))
68#define SCB_SHPR(ipr_id) MMIO8(SCS_BASE + 0xD18 + (ipr_id))
72#define SCB_SHCSR MMIO32(SCB_BASE + 0x24)
75#define SCB_DFSR MMIO32(SCB_BASE + 0x30)
78#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
80#define SCB_CFSR MMIO32(SCB_BASE + 0x28)
83#define SCB_HFSR MMIO32(SCB_BASE + 0x2C)
86#define SCB_MMFAR MMIO32(SCB_BASE + 0x34)
89#define SCB_BFAR MMIO32(SCB_BASE + 0x38)
92#define SCB_AFSR MMIO32(SCB_BASE + 0x3C)
95#define SCB_ID_PFR0 MMIO32(SCB_BASE + 0x40)
98#define SCB_ID_PFR1 MMIO32(SCB_BASE + 0x44)
101#define SCB_ID_DFR0 MMIO32(SCB_BASE + 0x48)
104#define SCB_ID_AFR0 MMIO32(SCB_BASE + 0x4C)
107#define SCB_ID_MMFR0 MMIO32(SCB_BASE + 0x50)
110#define SCB_ID_MMFR1 MMIO32(SCB_BASE + 0x54)
113#define SCB_ID_MMFR2 MMIO32(SCB_BASE + 0x58)
116#define SCB_ID_MMFR3 MMIO32(SCB_BASE + 0x5C)
119#define SCB_ID_ISAR0 MMIO32(SCB_BASE + 0x60)
122#define SCB_ID_ISAR1 MMIO32(SCB_BASE + 0x64)
125#define SCB_ID_ISAR2 MMIO32(SCB_BASE + 0x68)
128#define SCB_ID_ISAR3 MMIO32(SCB_BASE + 0x6C)
131#define SCB_ID_ISAR4 MMIO32(SCB_BASE + 0x70)
134#define SCB_CPACR MMIO32(SCB_BASE + 0x88)
137#define SCB_FPCCR MMIO32(SCB_BASE + 0x234)
140#define SCB_FPCAR MMIO32(SCB_BASE + 0x238)
143#define SCB_FPDSCR MMIO32(SCB_BASE + 0x23C)
146#define SCB_MVFR0 MMIO32(SCB_BASE + 0x240)
149#define SCB_MVFR1 MMIO32(SCB_BASE + 0x244)
153#if defined(__ARM_ARCH_7EM__)
155#define SCB_CLIDR MMIO32(SCB_BASE + 0x78)
158#define SCB_CTR MMIO32(SCB_BASE + 0x7C)
161#define SCB_CCSIDR MMIO32(SCB_BASE + 0x80)
164#define SCB_CCSELR MMIO32(SCB_BASE + 0x84)
167#define SCB_ICIALLU MMIO32(SCB_BASE + 0x250)
170#define SCB_ICIMVAU MMIO32(SCB_BASE + 0x258)
173#define SCB_DCIMVAC MMIO32(SCB_BASE + 0x25C)
176#define SCB_DCISW MMIO32(SCB_BASE + 0x260)
179#define SCB_DCCMVAU MMIO32(SCB_BASE + 0x264)
182#define SCB_DCCMVAC MMIO32(SCB_BASE + 0x268)
185#define SCB_DCCSW MMIO32(SCB_BASE + 0x26C)
188#define SCB_DCCIMVAC MMIO32(SCB_BASE + 0x270)
191#define SCB_DCCISW MMIO32(SCB_BASE + 0x274)
194#define SCB_BPIALL MMIO32(SCB_BASE + 0x278)
206#define SCB_CPUID_IMPLEMENTER_LSB 24
207#define SCB_CPUID_IMPLEMENTER (0xFF << SCB_CPUID_IMPLEMENTER_LSB)
209#define SCB_CPUID_VARIANT_LSB 20
210#define SCB_CPUID_VARIANT (0xF << SCB_CPUID_VARIANT_LSB)
215#define SCB_CPUID_CONSTANT_LSB 16
216#define SCB_CPUID_CONSTANT (0xF << SCB_CPUID_CONSTANT_LSB)
217#define SCB_CPUID_CONSTANT_ARMV6 (0xC << SCB_CPUID_CONSTANT_LSB)
218#define SCB_CPUID_CONSTANT_ARMV7 (0xF << SCB_CPUID_CONSTANT_LSB)
221#define SCB_CPUID_PARTNO_LSB 4
222#define SCB_CPUID_PARTNO (0xFFF << SCB_CPUID_PARTNO_LSB)
224#define SCB_CPUID_REVISION_LSB 0
225#define SCB_CPUID_REVISION (0xF << SCB_CPUID_REVISION_LSB)
233#define SCB_ICSR_NMIPENDSET (1 << 31)
236#define SCB_ICSR_PENDSVSET (1 << 28)
238#define SCB_ICSR_PENDSVCLR (1 << 27)
240#define SCB_ICSR_PENDSTSET (1 << 26)
242#define SCB_ICSR_PENDSTCLR (1 << 25)
245#define SCB_ICSR_ISRPREEMPT (1 << 23)
247#define SCB_ICSR_ISRPENDING (1 << 22)
249#define SCB_ICSR_VECTPENDING_LSB 12
250#define SCB_ICSR_VECTPENDING (0x1FF << SCB_ICSR_VECTPENDING_LSB)
252#define SCB_ICSR_RETOBASE (1 << 11)
255#define SCB_ICSR_VECTACTIVE_LSB 0
256#define SCB_ICSR_VECTACTIVE (0x1FF << SCB_ICSR_VECTACTIVE_LSB)
266#if defined(__ARM_ARCH_6M__)
268#define SCB_VTOR_TBLOFF_LSB 7
269#define SCB_VTOR_TBLOFF (0x1FFFFFF << SCB_VTOR_TBLOFF_LSB)
274#elif defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
280#define SCB_VTOR_TBLOFF_LSB 9
281#define SCB_VTOR_TBLOFF (0x7FFFFF << SCB_VTOR_TBLOFF_LSB)
292#define SCB_AIRCR_VECTKEYSTAT_LSB 16
293#define SCB_AIRCR_VECTKEYSTAT (0xFFFF << SCB_AIRCR_VECTKEYSTAT_LSB)
294#define SCB_AIRCR_VECTKEY (0x05FA << SCB_AIRCR_VECTKEYSTAT_LSB)
297#define SCB_AIRCR_ENDIANESS (1 << 15)
300#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
303#define SCB_AIRCR_PRIGROUP_GROUP16_NOSUB (0x3 << 8)
304#define SCB_AIRCR_PRIGROUP_GROUP8_SUB2 (0x4 << 8)
305#define SCB_AIRCR_PRIGROUP_GROUP4_SUB4 (0x5 << 8)
306#define SCB_AIRCR_PRIGROUP_GROUP2_SUB8 (0x6 << 8)
307#define SCB_AIRCR_PRIGROUP_NOGROUP_SUB16 (0x7 << 8)
308#define SCB_AIRCR_PRIGROUP_MASK (0x7 << 8)
309#define SCB_AIRCR_PRIGROUP_SHIFT 8
314#define SCB_AIRCR_SYSRESETREQ (1 << 2)
316#define SCB_AIRCR_VECTCLRACTIVE (1 << 1)
319#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
321#define SCB_AIRCR_VECTRESET (1 << 0)
331#define SCB_SCR_SEVONPEND (1 << 4)
334#define SCB_SCR_SLEEPDEEP (1 << 2)
336#define SCB_SCR_SLEEPONEXIT (1 << 1)
346#define SCB_CCR_STKALIGN (1 << 9)
349#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
351#define SCB_CCR_BFHFNMIGN (1 << 8)
354#define SCB_CCR_DIV_0_TRP (1 << 4)
358#define SCB_CCR_UNALIGN_TRP (1 << 3)
361#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
364#define SCB_CCR_USERSETMPEND (1 << 1)
366#define SCB_CCR_NONBASETHRDENA (1 << 0)
370#if defined(__ARM_ARCH_7EM__)
372#define SCB_CCR_BP (1 << 18)
374#define SCB_CCR_IC (1 << 17)
376#define SCB_CCR_DC (1 << 16)
383#define SCB_SHPR_PRI_4_MEMMANAGE 0
384#define SCB_SHPR_PRI_5_BUSFAULT 1
385#define SCB_SHPR_PRI_6_USAGEFAULT 2
386#define SCB_SHPR_PRI_7_RESERVED 3
388#define SCB_SHPR_PRI_8_RESERVED 4
389#define SCB_SHPR_PRI_9_RESERVED 5
390#define SCB_SHPR_PRI_10_RESERVED 6
391#define SCB_SHPR_PRI_11_SVCALL 7
393#define SCB_SHPR_PRI_12_RESERVED 8
394#define SCB_SHPR_PRI_13_RESERVED 9
395#define SCB_SHPR_PRI_14_PENDSV 10
396#define SCB_SHPR_PRI_15_SYSTICK 11
403#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
405#define SCB_SHCSR_USGFAULTENA (1 << 18)
407#define SCB_SHCSR_BUSFAULTENA (1 << 17)
409#define SCB_SHCSR_MEMFAULTENA (1 << 16)
413#define SCB_SHCSR_SVCALLPENDED (1 << 15)
416#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
418#define SCB_SHCSR_BUSFAULTPENDED (1 << 14)
420#define SCB_SHCSR_MEMFAULTPENDED (1 << 13)
422#define SCB_SHCSR_USGFAULTPENDED (1 << 12)
424#define SCB_SHCSR_SYSTICKACT (1 << 11)
426#define SCB_SHCSR_PENDSVACT (1 << 10)
429#define SCB_SHCSR_MONITORACT (1 << 8)
431#define SCB_SHCSR_SVCALLACT (1 << 7)
434#define SCB_SHCSR_USGFAULTACT (1 << 3)
437#define SCB_SHCSR_BUSFAULTACT (1 << 1)
439#define SCB_SHCSR_MEMFAULTACT (1 << 0)
445#define SCB_CFSR_DIVBYZERO (1 << 25)
447#define SCB_CFSR_UNALIGNED (1 << 24)
450#define SCB_CFSR_NOCP (1 << 19)
452#define SCB_CFSR_INVPC (1 << 18)
454#define SCB_CFSR_INVSTATE (1 << 17)
456#define SCB_CFSR_UNDEFINSTR (1 << 16)
458#define SCB_CFSR_BFARVALID (1 << 15)
461#define SCB_CFSR_STKERR (1 << 12)
463#define SCB_CFSR_UNSTKERR (1 << 11)
465#define SCB_CFSR_IMPRECISERR (1 << 10)
467#define SCB_CFSR_PRECISERR (1 << 9)
469#define SCB_CFSR_IBUSERR (1 << 8)
471#define SCB_CFSR_MMARVALID (1 << 7)
474#define SCB_CFSR_MSTKERR (1 << 4)
476#define SCB_CFSR_MUNSTKERR (1 << 3)
479#define SCB_CFSR_DACCVIOL (1 << 1)
481#define SCB_CFSR_IACCVIOL (1 << 0)
486#define SCB_HFSR_DEBUG_VT (1 << 31)
488#define SCB_HFSR_FORCED (1 << 30)
491#define SCB_HFSR_VECTTBL (1 << 1)
502#if defined(__ARM_ARCH_7EM__)
505#define SCB_CTR_FORMAT_SHIFT 29
506#define SCB_CTR_FORMAT_MASK 0x7
508#define SCB_CTR_CWG_SHIFT 24
509#define SCB_CTR_CWG_MASK 0xf
511#define SCB_CTR_ERG_SHIFT 20
512#define SCB_CTR_ERG_MASK 0xf
514#define SCB_CTR_DMINLINE_SHIFT 16
515#define SCB_CTR_DMINLINE_MASK 0x1f
517#define SCB_CTR_IMINLINE_SHIFT 0
518#define SCB_CTR_IMINLINE_MASK 0xf
525#define SCB_CPACR_NONE 0
526#define SCB_CPACR_PRIV 1
527#define SCB_CPACR_FULL 3
530#define SCB_CPACR_CP10 (1 << 20)
532#define SCB_CPACR_CP11 (1 << 22)
548} __attribute__((packed));
550#define SCB_GET_EXCEPTION_STACK_FRAME(f) \
552 __asm__ volatile ("mov %[frameptr], sp" \
553 : [frameptr]"=r" (f)); \
559#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
void scb_set_priority_grouping(uint32_t prigroup)
void scb_reset_core(void)
void scb_reset_system(void)