software: interrupt driven UART working
This commit is contained in:
parent
58f4f78d2c
commit
4aaf48afb0
|
@ -16,10 +16,16 @@
|
|||
*/
|
||||
|
||||
#include <hw/interrupts.h>
|
||||
#include <hw/uart.h>
|
||||
#include <irq.h>
|
||||
#include <uart.h>
|
||||
|
||||
void isr(void)
|
||||
{
|
||||
unsigned int irqs;
|
||||
|
||||
irqs = irq_pending() & irq_getmask();
|
||||
|
||||
if(irqs & IRQ_UART)
|
||||
uart_isr();
|
||||
}
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
#include <hw/uart.h>
|
||||
|
||||
static void print(const char *s)
|
||||
{
|
||||
while(*s) {
|
||||
while(CSR_UART_EV_STAT & UART_EV_TX);
|
||||
CSR_UART_RXTX = *s;
|
||||
s++;
|
||||
}
|
||||
}
|
||||
#include <stdio.h>
|
||||
#include <irq.h>
|
||||
#include <uart.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
print("Hello World\n");
|
||||
irq_setmask(0);
|
||||
irq_setie(1);
|
||||
uart_init();
|
||||
|
||||
printf("Hello World with IRQs\n");
|
||||
|
||||
while(1);
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue