From: Sebastien Bourdeauducq Date: Mon, 6 Feb 2012 22:53:29 +0000 (+0100) Subject: software: interrupt driven UART working X-Git-Tag: 24jan2021_ls180~3257 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4aaf48afb0bae3a39bcb59f22537eb3f0802e829;p=litex.git software: interrupt driven UART working --- diff --git a/software/bios/isr.c b/software/bios/isr.c index 25badec3..21c480aa 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 b2f90e3b..36e21c62 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 43e44734..37cf73fd 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 6ca28629..8490bcdf 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;