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/Makefile | 2 +- code/fe310/eos/cell.c | 46 ++++++++++++++++++++++ code/fe310/eos/cell.h | 16 ++++++++ code/fe310/eos/uart.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ code/fe310/eos/uart.h | 18 +++++++++ 5 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 code/fe310/eos/cell.c create mode 100644 code/fe310/eos/cell.h create mode 100644 code/fe310/eos/uart.c create mode 100644 code/fe310/eos/uart.h (limited to 'code') diff --git a/code/fe310/eos/Makefile b/code/fe310/eos/Makefile index 485cd3c..36eefd7 100644 --- a/code/fe310/eos/Makefile +++ b/code/fe310/eos/Makefile @@ -2,7 +2,7 @@ include ../common.mk CFLAGS += -I../include -I../drivers -obj = trap_entry.o eos.o msgq.o event.o interrupt.o timer.o i2s.o spi.o net.o wifi.o sock.o eve.o +obj = trap_entry.o eos.o msgq.o event.o interrupt.o timer.o i2s.o uart.o spi.o net.o wifi.o cell.o sock.o eve.o %.o: %.c %.h diff --git a/code/fe310/eos/cell.c b/code/fe310/eos/cell.c new file mode 100644 index 0000000..b2d62f8 --- /dev/null +++ b/code/fe310/eos/cell.c @@ -0,0 +1,46 @@ +#include +#include +#include + +#include "eos.h" +#include "event.h" +#include "net.h" + +#include "cell.h" + +static eos_evt_fptr_t evt_handler[EOS_CELL_MAX_MTYPE]; +static uint16_t evt_handler_flags_buf_free = 0; +static uint16_t evt_handler_flags_buf_acq = 0; + +static void cell_handler_evt(unsigned char type, unsigned char *buffer, uint16_t len) { + if ((buffer == NULL) || (len < 1)) { + eos_evtq_bad_handler(type, buffer, len); + eos_net_free(buffer, 0); + return; + } + + uint8_t mtype = buffer[0]; + if (mtype >= EOS_CELL_MAX_MTYPE) { + eos_evtq_bad_handler(type, buffer, len); + eos_net_free(buffer, 0); + return; + } + + _eos_net_handle(type, buffer, len, mtype, evt_handler, &evt_handler_flags_buf_free, &evt_handler_flags_buf_acq); +} + +void eos_cell_init(void) { + int i; + + for (i=0; i= EOS_CELL_MAX_MTYPE) { + return; + } + _eos_net_set_handler(mtype, handler, evt_handler, flags, &evt_handler_flags_buf_free, &evt_handler_flags_buf_acq); +} diff --git a/code/fe310/eos/cell.h b/code/fe310/eos/cell.h new file mode 100644 index 0000000..badce3d --- /dev/null +++ b/code/fe310/eos/cell.h @@ -0,0 +1,16 @@ +#include +#include "event.h" + +#define EOS_CELL_MTYPE_DATA 0 +#define EOS_CELL_MTYPE_AUDIO 1 + +#define EOS_CELL_MTYPE_DATA_START 2 +#define EOS_CELL_MTYPE_DATA_STOP 3 + +#define EOS_CELL_MTYPE_AUDIO_START 2 +#define EOS_CELL_MTYPE_AUDIO_STOP 3 + +#define EOS_CELL_MAX_MTYPE 2 + +void eos_cell_init(void); +void eos_cell_set_handler(int mtype, eos_evt_fptr_t handler, uint8_t flags); \ No newline at end of file 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 + +#define EOS_UART_ETYPE_TX 1 +#define EOS_UART_ETYPE_RX 2 + +#define EOS_UART_MAX_ETYPE 2 + +typedef void (*eos_uart_fptr_t) (unsigned char); + +void eos_uart_init(void); +void eos_uart_set_handler(unsigned char type, eos_uart_fptr_t handler, uint8_t flags); + +void eos_uart_txwm_set(uint8_t wm); +void eos_uart_txwm_clear(void); +void eos_uart_rxwm_set(uint8_t wm); +void eos_uart_rxwm_clear(void); +int eos_uart_putc(int c, char b); +int eos_uart_getc(char b); \ No newline at end of file -- cgit v1.2.3