From 290d784950b6248782b049cd9831bd6e034fd538 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Tue, 30 Sep 2025 13:06:16 -0600 Subject: Add a bunch. Neglected doing commits. 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. --- src/exc.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'src/exc.c') diff --git a/src/exc.c b/src/exc.c index 657ddb8..9b7242b 100644 --- a/src/exc.c +++ b/src/exc.c @@ -1,43 +1,50 @@ #include +#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); } -- cgit