Skip to content

Commit f32d5ed

Browse files
committed
Set SVC one lower in priority
Setting the SVC as one lower in priority allows us to combine MPU recovery in one place, and not have to recover from a hard fault. We also use this commit as an opportunity to make the priorities of all system interrupts explicit.
1 parent ad9eb48 commit f32d5ed

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

api/inc/unvic_exports.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
/* this value refers to the minimum allowable priority in the physical NVIC
2323
* module, but not in the virtualised one (vIRQ) */
24-
#define __UVISOR_NVIC_MIN_PRIORITY ((uint32_t) 1)
24+
#define __UVISOR_NVIC_MIN_PRIORITY ((uint32_t) 2)
2525

2626
/* this is the maximum priority allowed for the vIRQ module */
2727
/* users of uVisor APIs can use this to determine the maximum level of

core/system/src/unvic.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,21 @@ void unvic_init(void)
583583
* levels. */
584584
assert(__UVISOR_NVIC_MIN_PRIORITY < UVISOR_VIRQ_MAX_PRIORITY);
585585

586+
/* Set the priority of each exception. SVC is lower priority than
587+
* MemManage, BusFault, and UsageFault, so that we can recover from
588+
* stacking MemManage faults more simply. */
589+
static const uint32_t priority_0 = __UVISOR_NVIC_MIN_PRIORITY - 2;
590+
static const uint32_t priority_1 = __UVISOR_NVIC_MIN_PRIORITY - 1;
591+
assert(priority_0 < __UVISOR_NVIC_MIN_PRIORITY);
592+
assert(priority_1 < __UVISOR_NVIC_MIN_PRIORITY);
593+
NVIC_SetPriority(MemoryManagement_IRQn, priority_0);
594+
NVIC_SetPriority(BusFault_IRQn, priority_0);
595+
NVIC_SetPriority(UsageFault_IRQn, priority_0);
596+
NVIC_SetPriority(SVCall_IRQn, priority_1);
597+
NVIC_SetPriority(DebugMonitor_IRQn, __UVISOR_NVIC_MIN_PRIORITY);
598+
NVIC_SetPriority(PendSV_IRQn, UVISOR_VIRQ_MAX_PRIORITY);
599+
NVIC_SetPriority(SysTick_IRQn, UVISOR_VIRQ_MAX_PRIORITY);
600+
586601
/* By setting the priority group to 0 we make sure that all priority levels
587602
* are available for pre-emption and that interrupts with the same priority
588603
* level occurring at the same time are served in the default way, that is,

0 commit comments

Comments
 (0)