|
|
|
@ -128,11 +128,16 @@ void __attribute__((noreturn)) error_throb(uint32_t num){
@@ -128,11 +128,16 @@ void __attribute__((noreturn)) error_throb(uint32_t num){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern void __go_next_task(); |
|
|
|
|
extern void hal_try_kill_task_or_reboot(uint8_t num); |
|
|
|
|
extern void hal_stop_multitask(); |
|
|
|
|
extern void hal_go_next_task(); |
|
|
|
|
#define NVIC_CCR (*(volatile uint32_t *)0xE000ED14) |
|
|
|
|
|
|
|
|
|
// new common exception code
|
|
|
|
|
// TODO: we have task switching so if fault occures in task we can just remove task from queue
|
|
|
|
|
//
|
|
|
|
|
void __attribute__((noreturn)) __error(uint32_t num, uint32_t pc, uint32_t lr) |
|
|
|
|
void __attribute__((noreturn)) __error(uint32_t num, uint32_t pc, uint32_t lr, uint32_t flag) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_BUILD |
|
|
|
@ -148,7 +153,7 @@ void __attribute__((noreturn)) __error(uint32_t num, uint32_t pc, uint32_t lr)
@@ -148,7 +153,7 @@ void __attribute__((noreturn)) __error(uint32_t num, uint32_t pc, uint32_t lr)
|
|
|
|
|
"", // 8
|
|
|
|
|
"", // 9
|
|
|
|
|
"", // 10
|
|
|
|
|
"PureVirtual function call", // 11
|
|
|
|
|
"Pure Virtual function call", // 11
|
|
|
|
|
"failed to setup clock", // 12
|
|
|
|
|
"exit from main()", // 13
|
|
|
|
|
"", // 14
|
|
|
|
@ -156,14 +161,23 @@ void __attribute__((noreturn)) __error(uint32_t num, uint32_t pc, uint32_t lr)
@@ -156,14 +161,23 @@ void __attribute__((noreturn)) __error(uint32_t num, uint32_t pc, uint32_t lr)
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Turn off peripheral interrupts */ |
|
|
|
|
/* Turn off peripheral interrupts */ |
|
|
|
|
__disable_irq(); |
|
|
|
|
|
|
|
|
|
timer_disable_all(); // turn off all PWM
|
|
|
|
|
|
|
|
|
|
extern bool hal_is_armed(); |
|
|
|
|
if((flag & 0x4) && hal_is_armed()){ // not in interrupt and is armed - try to save aircraft
|
|
|
|
|
hal_try_kill_task_or_reboot(num); |
|
|
|
|
// returned - task killed, resume normal operations
|
|
|
|
|
NVIC_CCR &= ~1; // reset flag NONEBASETHRDENA in NVIC CCR
|
|
|
|
|
__enable_irq(); |
|
|
|
|
hal_go_next_task(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(is_bare_metal()) // bare metal build without bootloader should reboot to DFU after any fault
|
|
|
|
|
board_set_rtc_register(DFU_RTC_SIGNATURE, RTC_SIGNATURE_REG); |
|
|
|
|
|
|
|
|
|
timer_disable_all(); // turn off all PWM
|
|
|
|
|
|
|
|
|
|
/* Turn the USB interrupt back on so "the reboot to bootloader" keeps on functioning */ |
|
|
|
|
NVIC_EnableIRQ(OTG_HS_EP1_OUT_IRQn); |
|
|
|
@ -172,10 +186,11 @@ void __attribute__((noreturn)) __error(uint32_t num, uint32_t pc, uint32_t lr)
@@ -172,10 +186,11 @@ void __attribute__((noreturn)) __error(uint32_t num, uint32_t pc, uint32_t lr)
|
|
|
|
|
NVIC_EnableIRQ(OTG_HS_IRQn); |
|
|
|
|
NVIC_EnableIRQ(OTG_FS_IRQn); |
|
|
|
|
|
|
|
|
|
__enable_irq(); |
|
|
|
|
|
|
|
|
|
if(boardEmergencyHandler) boardEmergencyHandler(); // call emergency handler
|
|
|
|
|
|
|
|
|
|
hal_stop_multitask(); |
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
#ifdef ERROR_USART |
|
|
|
|
usart_putstr(ERROR_USART, "\r\n!!! Exception: "); |
|
|
|
@ -201,7 +216,7 @@ void __attribute__((noreturn)) __error(uint32_t num, uint32_t pc, uint32_t lr)
@@ -201,7 +216,7 @@ void __attribute__((noreturn)) __error(uint32_t num, uint32_t pc, uint32_t lr)
|
|
|
|
|
error_throb(num); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
uint32_t systick_micros(void) |
|
|
|
|
{ |
|
|
|
|
volatile uint32_t fms, lms; |
|
|
|
@ -224,3 +239,4 @@ uint32_t systick_micros(void)
@@ -224,3 +239,4 @@ uint32_t systick_micros(void)
|
|
|
|
|
return res; |
|
|
|
|
#undef US_PER_MS |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|