diff --git a/software/bios/isr.c b/software/bios/isr.c index 25badec3b..21c480aae 100644 --- a/software/bios/isr.c +++ b/software/bios/isr.c @@ -16,10 +16,16 @@ */ #include +#include #include +#include void isr(void) { unsigned int irqs; + irqs = irq_pending() & irq_getmask(); + + if(irqs & IRQ_UART) + uart_isr(); } diff --git a/software/bios/main.c b/software/bios/main.c index b2f90e3b3..36e21c628 100644 --- a/software/bios/main.c +++ b/software/bios/main.c @@ -1,16 +1,14 @@ -#include - -static void print(const char *s) -{ - while(*s) { - while(CSR_UART_EV_STAT & UART_EV_TX); - CSR_UART_RXTX = *s; - s++; - } -} +#include +#include +#include int main(void) { - print("Hello World\n"); + irq_setmask(0); + irq_setie(1); + uart_init(); + + printf("Hello World with IRQs\n"); + while(1); } diff --git a/software/include/base/irq.h b/software/include/base/irq.h index 43e447344..37cf73fd0 100644 --- a/software/include/base/irq.h +++ b/software/include/base/irq.h @@ -18,9 +18,16 @@ #ifndef __IRQ_H #define __IRQ_H -static inline void irq_enable(unsigned int en) +static inline unsigned int irq_getie(void) { - __asm__ __volatile__("wcsr IE, %0" : : "r" (en)); + unsigned int ie; + __asm__ __volatile__("rcsr %0, IE" : "=r" (ie)); + return ie; +} + +static inline void irq_setie(unsigned int ie) +{ + __asm__ __volatile__("wcsr IE, %0" : : "r" (ie)); } static inline unsigned int irq_getmask(void) @@ -47,16 +54,4 @@ static inline void irq_ack(unsigned int mask) __asm__ __volatile__("wcsr IP, %0" : : "r" (mask)); } -static inline unsigned int irq_getie(void) -{ - unsigned int ie; - __asm__ __volatile__("rcsr %0, IE" : "=r" (ie)); - return ie; -} - -static inline void irq_setie(unsigned int ie) -{ - __asm__ __volatile__("wcsr IE, %0" : : "r" (ie)); -} - #endif /* __IRQ_H */ diff --git a/software/libbase/uart.c b/software/libbase/uart.c index 6ca28629f..8490bcdf8 100644 --- a/software/libbase/uart.c +++ b/software/libbase/uart.c @@ -44,7 +44,9 @@ static volatile int tx_cts; void uart_isr(void) { - unsigned int stat = CSR_UART_EV_PENDING; + unsigned int stat; + + stat = CSR_UART_EV_PENDING; if(stat & UART_EV_RX) { rx_buf[rx_produce] = CSR_UART_RXTX;