diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2025-09-30 13:06:16 -0600 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2025-09-30 13:06:16 -0600 |
commit | 290d784950b6248782b049cd9831bd6e034fd538 (patch) | |
tree | c231c02e92ed83a02b234a85b3c07bcc5e44b168 /src/exc.c | |
parent | f89f75b5616de99865448f41b068a2783cd3648e (diff) | |
download | ch573-290d784950b6248782b049cd9831bd6e034fd538.tar.gz ch573-290d784950b6248782b049cd9831bd6e034fd538.tar.bz2 ch573-290d784950b6248782b049cd9831bd6e034fd538.zip |
Add many different patterns, and organize it.
Add a voltage discovery subsystem to allow the ch573 to detect if it's
on 12v or 5v lights.
Diffstat (limited to 'src/exc.c')
-rw-r--r-- | src/exc.c | 47 |
1 files changed, 27 insertions, 20 deletions
@@ -1,43 +1,50 @@ #include <stdio.h> +#include "ch573/gpio.h" #include "isr_vector.h" #include "panic.h" - -#include "ch573/gpio.h" +#include "risc-v.h" #define GPIO_PORT_A ch573_gpio__gpio_port_a #define GPIO_PORT CH573_GPIO__GPIO_PORT_T_INTF void delay(); -IRQ(exc) +struct exc_info { + uint32_t mtval; + uint32_t mepc; + uint32_t mcause; +}; + +static inline void get_exc_info(struct exc_info* out) { - uint32_t mcause, mepc, mtval, *sp; + out->mtval = MTVAL; + out->mepc = MEPC; + out->mcause = MCAUSE; +} - asm volatile("csrr %0, mcause" : "=r"(mcause)); - asm volatile("csrr %0, mepc" : "=r"(mepc)); - asm volatile("csrr %0, mtval" : "=r"(mtval)); +IRQ(exc) +{ + struct exc_info ei; + get_exc_info(&ei); printf("Hardware Exception Caught:\n"); - printf(" mcause: 0x%08x\n", mcause); - printf(" mepc: 0x%08x\n", mepc); - printf(" mtval: 0x%08x\n", mtval); + printf(" mcause: 0x%08x\n", ei.mcause); + printf(" mepc: 0x%08x\n", ei.mepc); + printf(" mtval: 0x%08x\n", ei.mtval); - panic(mcause); + panic(ei.mcause); } IRQ(nmi) { - uint32_t mcause, mepc, mtval, *sp; - - asm volatile("csrr %0, mcause" : "=r"(mcause)); - asm volatile("csrr %0, mepc" : "=r"(mepc)); - asm volatile("csrr %0, mtval" : "=r"(mtval)); + struct exc_info ei; + get_exc_info(&ei); printf("Unhandled NMI Caught:\n"); - printf(" mcause: 0x%08x\n", mcause); - printf(" mepc: 0x%08x\n", mepc); - printf(" mtval: 0x%08x\n", mtval); + printf(" mcause: 0x%08x\n", ei.mcause); + printf(" mepc: 0x%08x\n", ei.mepc); + printf(" mtval: 0x%08x\n", ei.mtval); - panic(mcause); + panic(ei.mcause); } |