You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.9 KiB
68 lines
1.9 KiB
![]()
5 years ago
|
// supervisor call functions
|
||
|
|
||
|
#define SVC_ENABLE_IRQ 0
|
||
|
#define SVC_DISABLE_IRQ 1
|
||
|
#define SVC_SET_PRIORITY 2
|
||
![]()
3 years ago
|
#define SVC_SHUTDOWN 4
|
||
![]()
2 years ago
|
#define SVC_REBOOT_TO_BOOTLOADER 5
|
||
![]()
3 years ago
|
|
||
|
// from util.s
|
||
|
extern void shutdown_privileged(void);
|
||
![]()
2 years ago
|
extern void reboot_to_bootloader(void);
|
||
![]()
5 years ago
|
|
||
![]()
5 years ago
|
static inline uint32_t is_mode_unprivileged(void) {
|
||
|
uint32_t r0;
|
||
|
__asm__ volatile("mrs %0, control" : "=r"(r0));
|
||
|
return r0 & 1;
|
||
![]()
5 years ago
|
}
|
||
|
|
||
![]()
2 years ago
|
static inline uint32_t is_mode_handler(void) {
|
||
|
uint32_t r0;
|
||
|
__asm__ volatile("mrs %0, ipsr" : "=r"(r0));
|
||
|
return (r0 & 0x1FF) != 0;
|
||
|
}
|
||
|
|
||
![]()
5 years ago
|
static inline void svc_enableIRQ(uint32_t IRQn) {
|
||
![]()
2 years ago
|
if (is_mode_unprivileged() && !is_mode_handler()) {
|
||
![]()
5 years ago
|
register uint32_t r0 __asm__("r0") = IRQn;
|
||
|
__asm__ __volatile__("svc %0" ::"i"(SVC_ENABLE_IRQ), "r"(r0) : "memory");
|
||
|
} else {
|
||
|
HAL_NVIC_EnableIRQ(IRQn);
|
||
|
}
|
||
![]()
5 years ago
|
}
|
||
|
|
||
![]()
5 years ago
|
static inline void svc_disableIRQ(uint32_t IRQn) {
|
||
![]()
2 years ago
|
if (is_mode_unprivileged() && !is_mode_handler()) {
|
||
![]()
5 years ago
|
register uint32_t r0 __asm__("r0") = IRQn;
|
||
|
__asm__ __volatile__("svc %0" ::"i"(SVC_DISABLE_IRQ), "r"(r0) : "memory");
|
||
|
} else {
|
||
|
HAL_NVIC_DisableIRQ(IRQn);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static inline void svc_setpriority(uint32_t IRQn, uint32_t priority) {
|
||
![]()
2 years ago
|
if (is_mode_unprivileged() && !is_mode_handler()) {
|
||
![]()
5 years ago
|
register uint32_t r0 __asm__("r0") = IRQn;
|
||
|
register uint32_t r1 __asm__("r1") = priority;
|
||
|
__asm__ __volatile__("svc %0" ::"i"(SVC_SET_PRIORITY), "r"(r0), "r"(r1)
|
||
![]()
5 years ago
|
: "memory");
|
||
![]()
5 years ago
|
} else {
|
||
|
NVIC_SetPriority(IRQn, priority);
|
||
|
}
|
||
![]()
5 years ago
|
}
|
||
![]()
3 years ago
|
|
||
|
static inline void svc_shutdown(void) {
|
||
![]()
2 years ago
|
if (is_mode_unprivileged() && !is_mode_handler()) {
|
||
![]()
3 years ago
|
__asm__ __volatile__("svc %0" ::"i"(SVC_SHUTDOWN) : "memory");
|
||
|
} else {
|
||
|
shutdown_privileged();
|
||
|
}
|
||
|
}
|
||
![]()
2 years ago
|
static inline void svc_reboot_to_bootloader(void) {
|
||
![]()
2 years ago
|
if (is_mode_unprivileged() && !is_mode_handler()) {
|
||
![]()
2 years ago
|
__asm__ __volatile__("svc %0" ::"i"(SVC_REBOOT_TO_BOOTLOADER) : "memory");
|
||
|
} else {
|
||
|
reboot_to_bootloader();
|
||
|
}
|
||
|
}
|