panic in debug mode if sleep methods are called in an exception handler (unless PICO_ALLOW_SLEEP_IN_EXCEPTION is set)
This commit is contained in:
parent
fb5a847026
commit
9fdf87f729
@ -325,6 +325,11 @@ static int64_t sev_callback(__unused alarm_id_t id, __unused void *user_data) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void sleep_until(absolute_time_t t) {
|
void sleep_until(absolute_time_t t) {
|
||||||
|
#if PICO_ON_DEVICE && !PICO_ALLOW_SLEEP_IN_EXCEPTION && !defined(NDEBUG)
|
||||||
|
if (__get_current_exception()) {
|
||||||
|
panic("Attempted to sleep inside of an exception handler");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#if !PICO_TIME_DEFAULT_ALARM_POOL_DISABLED
|
#if !PICO_TIME_DEFAULT_ALARM_POOL_DISABLED
|
||||||
uint64_t t_us = to_us_since_boot(t);
|
uint64_t t_us = to_us_since_boot(t);
|
||||||
uint64_t t_before_us = t_us - PICO_TIME_SLEEP_OVERHEAD_ADJUST_US;
|
uint64_t t_before_us = t_us - PICO_TIME_SLEEP_OVERHEAD_ADJUST_US;
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
#include "pico/assert.h"
|
#include "pico/assert.h"
|
||||||
|
|
||||||
extern void __unhandled_user_irq(void);
|
extern void __unhandled_user_irq(void);
|
||||||
extern uint __get_current_exception(void);
|
|
||||||
|
|
||||||
static inline irq_handler_t *get_vtable(void) {
|
static inline irq_handler_t *get_vtable(void) {
|
||||||
return (irq_handler_t *) scb_hw->vtor;
|
return (irq_handler_t *) scb_hw->vtor;
|
||||||
|
@ -163,6 +163,12 @@ return a;
|
|||||||
|
|
||||||
#define __check_type_compatible(type_a, type_b) static_assert(__builtin_types_compatible_p(type_a, type_b), __STRING(type_a) " is not compatible with " __STRING(type_b));
|
#define __check_type_compatible(type_a, type_b) static_assert(__builtin_types_compatible_p(type_a, type_b), __STRING(type_a) " is not compatible with " __STRING(type_b));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current exception level on this core
|
||||||
|
* \return the exception number if the CPU is handling an exception, or 0 otherwise
|
||||||
|
*/
|
||||||
|
extern uint __get_current_exception(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -124,9 +124,7 @@ void runtime_init(void) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
uint32_t xpsr;
|
if (__get_current_exception()) {
|
||||||
__asm volatile ("mrs %0, XPSR" : "=r" (xpsr)::);
|
|
||||||
if (xpsr & 0xffu) {
|
|
||||||
// crap; started in exception handler
|
// crap; started in exception handler
|
||||||
__asm ("bkpt #0");
|
__asm ("bkpt #0");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user