From 256db0fba03232ab4ad9a151487677f8d538e69a Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Sat, 7 Dec 2019 17:18:37 +0100 Subject: addded uart driver and cell stub driver --- code/fe310/eos/uart.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 code/fe310/eos/uart.c (limited to 'code/fe310/eos/uart.c') diff --git a/code/fe310/eos/uart.c b/code/fe310/eos/uart.c new file mode 100644 index 0000000..88931ab --- /dev/null +++ b/code/fe310/eos/uart.c @@ -0,0 +1,100 @@ +#include +#include +#include + +#include "encoding.h" +#include "platform.h" + +#include "eos.h" +#include "interrupt.h" +#include "event.h" + +#include "uart.h" +#include "irq_def.h" + +static eos_uart_fptr_t uart_handler[EOS_UART_MAX_ETYPE]; + +static void uart_handler_evt(unsigned char type, unsigned char *buffer, uint16_t len) { + unsigned char idx = (type & ~EOS_EVT_MASK) - 1; + + if ((idx < EOS_UART_MAX_ETYPE) && uart_handler[idx]) { + uart_handler[idx](type); + } else { + eos_evtq_bad_handler(type, buffer, len); + } +} + +static void uart_handler_intr(void) { + if (UART0_REG(UART_REG_IP) & UART_IP_TXWM) { + UART0_REG(UART_REG_IE) &= ~UART_IP_TXWM; + eos_evtq_push_isr(EOS_EVT_UART | EOS_UART_ETYPE_TX, NULL, 0); + } + if (UART0_REG(UART_REG_IP) & UART_IP_RXWM) { + UART0_REG(UART_REG_IE) &= ~UART_IP_RXWM; + eos_evtq_push_isr(EOS_EVT_UART | EOS_UART_ETYPE_RX, NULL, 0); + } +} + +void eos_uart_init(void) { + int i; + + for (i=0; i