diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2020-11-24 15:15:11 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2020-11-24 15:22:42 -0700 |
commit | ecbcb2509f4b811bce0a56e07de9737d14815251 (patch) | |
tree | f96492fb6db5d26c133dc3ab2993a9df3f224ea2 /src/kern/panic.c | |
parent | 351ff7059a5bacb322664412a8c62ee4640b33bf (diff) | |
download | stm32l4-ecbcb2509f4b811bce0a56e07de9737d14815251.tar.gz stm32l4-ecbcb2509f4b811bce0a56e07de9737d14815251.tar.bz2 stm32l4-ecbcb2509f4b811bce0a56e07de9737d14815251.zip |
Add better logging capabilities, including the ability to panic.
Diffstat (limited to 'src/kern/panic.c')
-rw-r--r-- | src/kern/panic.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/kern/panic.c b/src/kern/panic.c new file mode 100644 index 0000000..8708456 --- /dev/null +++ b/src/kern/panic.c @@ -0,0 +1,36 @@ +#include "arch.h" +#include "kern/panic.h" +#include "kern/log.h" +#include "kern/init.h" +#include "arch/stm32l4xxx/peripherals/clock.h" +#include "kern/gpio/sysled.h" +#include "kern/gpio/gpio_manager.h" +#include "kern/delay.h" + +#include <stdarg.h> + +#ifdef ARCH_STM32L4 +_Noreturn void panic(const char* fmt, ...) +{ + + if (get_system_init_level() > INIT_LEVEL_2) { + va_list l; + va_start(l, fmt); + + kerr_logf("** Kernel Panic! **\n"); + kerr_vlogf(fmt, l); + + set_system_clock_MHz(4); /* reduce power usage while we do nothing. */ + for(;;); + } else { + set_system_clock_MHz(4); /* reduce power usage while we do nothing. */ + gpio_reserved_pin_t pin3 = get_sysled(); + for (;;) { + set_gpio_pin_high(pin3); + delay(100000); + set_gpio_pin_low(pin3); + delay(100000); + } + } +} +#endif |