22#ifndef _mcci_arm_cm0plus_h_
23#define _mcci_arm_cm0plus_h_
27#ifndef _mcci_bootloader_bits_h_
46#define MCCI_CM0PLUS_SYSM_APSR UINT32_C(0x00)
47#define MCCI_CM0PLUS_SYSM_IAPSR UINT32_C(0x01)
48#define MCCI_CM0PLUS_SYSM_EAPSR UINT32_C(0x02)
49#define MCCI_CM0PLUS_SYSM_XPSR UINT32_C(0x03)
50#define MCCI_CM0PLUS_SYSM_IPSR UINT32_C(0x05)
51#define MCCI_CM0PLUS_SYSM_EPSR UINT32_C(0x06)
52#define MCCI_CM0PLUS_SYSM_IEPSR UINT32_C(0x07)
53#define MCCI_CM0PLUS_SYSM_MSP UINT32_C(0x08)
54#define MCCI_CM0PLUS_SYSM_PSP UINT32_C(0x09)
55#define MCCI_CM0PLUS_SYSM_PRIMASK UINT32_C(0x10)
56#define MCCI_CM0PLUS_SYSM_CONTROL UINT32_C(0x14)
60#define MCCI_CM0PLUS_SR_PRIMASK_DISABLE (UINT32_C(1) << 0)
72#define MCCI_CM0PLUS_SCS_BASE UINT32_C(0xE000E000)
76#define MCCI_CM0PLUS_SYSTICK UINT32_C(0xE000E010)
77#define MCCI_CM0PLUS_SYSTICK_CSR (MCCI_CM0PLUS_SYSTICK + 0x0)
78#define MCCI_CM0PLUS_SYSTICK_RVR (MCCI_CM0PLUS_SYSTICK + 0x4)
79#define MCCI_CM0PLUS_SYSTICK_CVR (MCCI_CM0PLUS_SYSTICK + 0x8)
80#define MCCI_CM0PLUS_SYSTICK_CALIB (MCCI_CM0PLUS_SYSTICK + 0xC)
85#define MCCI_CM0PLUS_NVIC UINT32_C(0xE000E100)
86#define MCCI_CM0PLUS_NVIC_ISER (MCCI_CM0PLUS_NVIC + 0x000)
87#define MCCI_CM0PLUS_NVIC_ICER (MCCI_CM0PLUS_NVIC + 0x080)
88#define MCCI_CM0PLUS_NVIC_ISPR (MCCI_CM0PLUS_NVIC + 0x100)
89#define MCCI_CM0PLUS_NVIC_ICPR (MCCI_CM0PLUS_NVIC + 0x180)
90#define MCCI_CM0PLUS_NVIC_IP0 (MCCI_CM0PLUS_NVIC + 0x300)
91#define MCCI_CM0PLUS_NVIC_IP1 (MCCI_CM0PLUS_NVIC + 0x304)
92#define MCCI_CM0PLUS_NVIC_IP2 (MCCI_CM0PLUS_NVIC + 0x308)
93#define MCCI_CM0PLUS_NVIC_IP3 (MCCI_CM0PLUS_NVIC + 0x30C)
94#define MCCI_CM0PLUS_NVIC_IP4 (MCCI_CM0PLUS_NVIC + 0x310)
95#define MCCI_CM0PLUS_NVIC_IP5 (MCCI_CM0PLUS_NVIC + 0x314)
96#define MCCI_CM0PLUS_NVIC_IP6 (MCCI_CM0PLUS_NVIC + 0x318)
97#define MCCI_CM0PLUS_NVIC_IP7 (MCCI_CM0PLUS_NVIC + 0x31C)
102#define MCCI_CM0PLUS_SCB UINT32_C(0xE000ED00)
103#define MCCI_CM0PLUS_SCB_CPUID (MCCI_CM0PLUS_SCB + 0x00)
104#define MCCI_CM0PLUS_SCB_ICSR (MCCI_CM0PLUS_SCB + 0x04)
105#define MCCI_CM0PLUS_SCB_VTOR (MCCI_CM0PLUS_SCB + 0x08)
106#define MCCI_CM0PLUS_SCB_AIRCR (MCCI_CM0PLUS_SCB + 0x0C)
107#define MCCI_CM0PLUS_SCB_SCR (MCCI_CM0PLUS_SCB + 0x10)
108#define MCCI_CM0PLUS_SCB_CCR (MCCI_CM0PLUS_SCB + 0x14)
109#define MCCI_CM0PLUS_SCB_SHPR2 (MCCI_CM0PLUS_SCB + 0x1C)
110#define MCCI_CM0PLUS_SCB_SHPR3 (MCCI_CM0PLUS_SCB + 0x20)
111#define MCCI_CM0PLUS_SCB_SHCSR (MCCI_CM0PLUS_SCB + 0x24)
112#define MCCI_CM0PLUS_SCB_DFSR (MCCI_CM0PLUS_SCB + 0x30)
117#define MCCI_CM0PLUS_MPU UINT32_C(0xE000ED90)
118#define MCCI_CM0PLUS_MPU_TYPE (MCCI_CM0PLUS_MPU + 0x00)
119#define MCCI_CM0PLUS_MPU_CTRL (MCCI_CM0PLUS_MPU + 0x04)
120#define MCCI_CM0PLUS_MPU_RNR (MCCI_CM0PLUS_MPU + 0x08)
121#define MCCI_CM0PLUS_MPU_RBAR (MCCI_CM0PLUS_MPU + 0x0C)
122#define MCCI_CM0PLUS_MPU_RASR (MCCI_CM0PLUS_MPU + 0x10)
133#define MCCI_CM0PLUS_SYSTICK_CSR_RSV17 UINT32_C(0xFFFE0000)
134#define MCCI_CM0PLUS_SYSTICK_CSR_COUNTFLAG (UINT32_C(1) << 16)
135#define MCCI_CM0PLUS_SYSTICK_CSR_RSV3 UINT32_C(0x0000FFF8)
136#define MCCI_CM0PLUS_SYSTICK_CSR_CLKSOURCE (UINT32_C(1) << 2)
137#define MCCI_CM0PLUS_SYSTICK_CSR_TICKINT (UINT32_C(1) << 1)
138#define MCCI_CM0PLUS_SYSTICK_CSR_ENABLE (UINT32_C(1) << 0)
143#define MCCI_CM0PLUS_SYSTICK_RVR_RSV24 UINT32_C(0xFF000000)
144#define MCCI_CM0PLUS_SYSTICK_RVR_RELOAD UINT32_C(0x00FFFFFF)
149#define MCCI_CM0PLUS_SYSTICK_CVR_RSV24 UINT32_C(0xFF000000)
150#define MCCI_CM0PLUS_SYSTICK_CVR_CURRENT UINT32_C(0x00FFFFFF)
155#define MCCI_CM0PLUS_SYSTICK_CALIB_NOREF (UINT32_C(1) << 31)
156#define MCCI_CM0PLUS_SYSTICK_CALIB_SKEW (UINT32_C(1) << 30)
157#define MCCI_CM0PLUS_SYSTICK_CALIB_RSV24 (UINT32_C(0x3F) << 24)
158#define MCCI_CM0PLUS_SYSTICK_CALIB_TENMS UINT32_C(0x00FFFFFF)
165#define MCCI_CM0PLUS_SCB_CPUID_IMPLEMENTER (UINT32_C(0xFF) << 24)
166#define MCCI_CM0PLUS_SCB_CPUID_VARIANT (UINT32_C(0xF) << 20)
167#define MCCI_CM0PLUS_SCB_CPUID_ARCHITECTURE (UINT32_C(0xF) << 16)
168#define MCCI_CM0PLUS_SCB_CPUID_PARTNO (UINT32_C(0xFFF) << 4)
169#define MCCI_CM0PLUS_SCB_CPUID_REVISION (UINT32_C(0xF) << 0)
174#define MCCI_CM0PLUS_SCB_ICSR_NMIPENDSET (UINT32_C(1) << 31)
175#define MCCI_CM0PLUS_SCB_ICSR_RSV29 (UINT32_C(3) << 29)
176#define MCCI_CM0PLUS_SCB_ICSR_PENDSVSET (UINT32_C(1) << 28)
177#define MCCI_CM0PLUS_SCB_ICSR_PENDSVCLR (UINT32_C(1) << 27)
178#define MCCI_CM0PLUS_SCB_ICSR_PENDSTSET (UINT32_C(1) << 26)
179#define MCCI_CM0PLUS_SCB_ICSR_PENDSTCLR (UINT32_C(1) << 25)
180#define MCCI_CM0PLUS_SCB_ICSR_RSV24 (UINT32_C(1) << 24)
181#define MCCI_CM0PLUS_SCB_ICSR_ISRPREEMPT (UINT32_C(1) << 23)
182#define MCCI_CM0PLUS_SCB_ICSR_ISRPENDING (UINT32_C(1) << 22)
183#define MCCI_CM0PLUS_SCB_ICSR_VECTPENDING (UINT32_C(0x1FF) << 12)
184#define MCCI_CM0PLUS_SCB_ICSR_VECTACTIVE (UINT32_C(0x1FF) << 0)
189#define MCCI_CM0PLUS_SCB_VTOR_TBLOFF UINT32_C(0xFFFFFF00)
194#define MCCI_CM0PLUS_SCB_AIRCR_VECTKEY (UINT32_C(0xFFFF) << 16)
195#define MCCI_CM0PLUS_SCB_AIRCR_VECTKEY_VALUE (UINT32_C(0x05FA) << 16)
196#define MCCI_CM0PLUS_SCB_AIRCR_ENDIANNESS (UINT32_C(1) << 15)
197#define MCCI_CM0PLUS_SCB_AIRCR_SYSRESETREQ (UINT32_C(1) << 2)
198#define MCCI_CM0PLUS_SCB_AIRCR_VECTCLRACTIVE (UINT32_C(1) << 1)
203#define MCCI_CM0PLUS_SCB_SCR_SEVONPEND (UINT32_C(1) << 4)
204#define MCCI_CM0PLUS_SCB_SCR_SLEEPDEEP (UINT32_C(1) << 2)
205#define MCCI_CM0PLUS_SCB_SCR_SLEEPONEXIT (UINT32_C(1) << 1)
210#define MCCI_CM0PLUS_SCB_CCR_STKALIGN (UINT32_C(1) << 9)
211#define MCCI_CM0PLUS_SCB_CCR_UNALIGNED (UINT32_C(1) << 3)
216#define MCCI_CM0PLUS_SCB_SHPR_PRI (UINT32_C(3) << 6)
218#define MCCI_CM0PLUS_PRI_INDEX_SVC UINT32_C(11)
219#define MCCI_CM0PLUS_PRI_INDEX_PENDSV UINT32_C(14)
220#define MCCI_CM0PLUS_PRI_INDEX_SYSTICK UINT32_C(15)
223static inline uint32_t
225 uint32_t handlerIndex
233static inline uint32_t
235 uint32_t handlerIndex
239 return UINT32_C(0xE0) << (8 * (handlerIndex & 3));
245#define MCCI_CM0PLUS_SCB_SHCSR_SVCALLPENDED (UINT32_C(1) << 15)
255__attribute__((__always_inline__))
256static inline uint32_t
259 *(
volatile uint32_t *)reg = val;
264__attribute__((__always_inline__))
265static inline uint32_t
268 return *(
volatile uint32_t *)reg;
272__attribute__((__always_inline__))
273static inline uint32_t
280 (rValue & andVal) | orVal
285__attribute__((__always_inline__))
286static inline uint32_t
298__attribute__((__always_inline__))
299static inline uint32_t
325__attribute__((__always_inline__))
326static inline uint32_t
333 (rValue & ~clearVal) | setVal
351__attribute__((__always_inline__))
352static inline uint32_t
359 rValue ^ ((rValue ^ modVal) & maskVal)
380__attribute__((__always_inline__))
static inline
386 __asm
volatile (
"MSR msp,%0\n" ::
"r"(stack): );
397__attribute__((__always_inline__))
static inline
405 __asm
volatile (
"MRS %0,primask" :
"=r"(primask));
417__attribute__((__always_inline__))
static inline
423 __asm
volatile (
"MSR primask,%0" ::
"r"(primask) :
"memory");
431__attribute__((__always_inline__))
static inline
433McciArm_disableInterrupts(
437 uint32_t
const primask = McciArm_getPRIMASK();
438 __asm
volatile (
"cpsid i" :::
"memory");
449__attribute__((always_inline))
static inline
450void McciArm_DataSynchBarrier(
454 __asm
volatile (
"dsb 0xF" :::
"memory");
466__attribute__((always_inline))
static inline
467uint32_t McciArm_getIPSR(
473 __asm
volatile (
"MRS %0, ipsr" :
"=r"(ipsr));
478# error "Compiler not supported"
530 uint32_t
const shprbits = (shpr3 >> (24 + 6));
532 return shprbits & 3u;
544 uint32_t
const shprbits = (shpr2 >> (24 + 6));
546 return shprbits & 3u;
558 uint32_t
const shprbits = (shpr3 >> (16 + 6));
560 return shprbits & 3u;
576 if (irq < 0 || irq >= 32)
593 uint32_t
const ipbits = ip >> (8 * (irq & 3u) + 6);
615typedef struct Mcci_CortexAppEntryContents_s
628typedef union Mcci_CortexAppEntry_u
639typedef struct Mcci_CortexVectorsContents_s
641 uint32_t vectors[192/4];
652typedef union Mcci_CortexVectors_u
#define MCCI_CM0PLUS_NVIC_IP0
static uint32_t McciArm_putRegOr(uint32_t reg, uint32_t orVal)
or 32-bit values to a cm0plus register
static uint32_t McciArm_getReg(uint32_t reg)
read a 32-bit value from a cm0plus register
static uint32_t McciArm_getSvcPriority(void)
return priority of SVC exception.
static uint32_t McciArm_putReg(uint32_t reg, uint32_t val)
write a 32-bit value to a cm0plus register
#define MCCI_CM0PLUS_SCB_SHPR2
static uint32_t McciArm_getPendSvPriority(void)
return priority of PendSv exception.
static uint32_t McciArm_putRegClear(uint32_t reg, uint32_t clearVal)
clear out 32-bit values to a cm0plus register
#define MCCI_CM0PLUS_SCB_SHPR3
static uint32_t McciArm_putRegClearSet(uint32_t reg, uint32_t clearVal, uint32_t setVal)
clear and set 32-bit values to a cm0plus register
static bool McciArmIPSR_queryIrqHandler(uint32_t ipsr)
test IPSR to see if Cortex-M0+ is in an IRQ handler
static uint32_t McciCm0Plus_SCB_SHPR_getRegister(uint32_t handlerIndex)
return register for a given handler index
static bool McciArmIPSR_queryThreadMode(uint32_t ipsr)
test IPSR to see if Cortex-M0+ is in thread mode.
static int32_t McciArmNvic_getPriority(int32_t irq)
return priority of speciified IRQ
static uint32_t McciArm_putRegMasked(uint32_t reg, uint32_t maskVal, uint32_t modVal)
store to cm0plus register under mask
static uint32_t McciArm_getSysTickPriority(void)
return priority of SysTick exception.
static int32_t McciArmIPSR_toIRQ(uint32_t ipsr)
convert IPSR value to IRQ number, if in handler.
static uint32_t McciArm_putRegAndOr(uint32_t reg, uint32_t andVal, uint32_t orVal)
and/or 32-bit values to a cm0plus register
static uint32_t McciCm0Plus_SCB_SHPR_getMask(uint32_t handlerIndex)
return byte mask for a given handler index
application entry contents
Cortex M0 interrupt vectors (low level view)
Mcci_CortexAppEntryContents_t CortexAppEntry
Cortex M0 interrupt vector object.
Mcci_CortexAppEntry_t CortexAppEntryCast
Mcci_CortexVectorsContents_t CortexVectors
Mcci_CortexAppEntryContents_t CortexAppEntry