From 3f913efda03fd840cd526ef72e6f397c7da61bd7 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Tue, 9 Aug 2022 22:23:08 +0200 Subject: code layout --- fw/fe310/eos/soc/uart.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'fw/fe310/eos/soc/uart.c') diff --git a/fw/fe310/eos/soc/uart.c b/fw/fe310/eos/soc/uart.c index 30f76d9..589832a 100644 --- a/fw/fe310/eos/soc/uart.c +++ b/fw/fe310/eos/soc/uart.c @@ -9,6 +9,7 @@ #include "eos.h" #include "interrupt.h" #include "event.h" +#include "i2s.h" #include "uart.h" @@ -44,22 +45,30 @@ int eos_uart_init(uint8_t wakeup_cause) { eos_evtq_set_handler(EOS_EVT_UART, uart_handle_evt); eos_intr_set(INT_UART0_BASE, IRQ_PRIORITY_UART, uart_handle_intr); - UART0_REG(UART_REG_TXCTRL) |= UART_TXEN; - UART0_REG(UART_REG_RXCTRL) |= UART_RXEN; - eos_uart_speed(EOS_UART_SPEED); - eos_uart_start(); + + eos_uart_enable(); return EOS_OK; } -void eos_uart_start(void) { +void eos_uart_enable(void) { + UART0_REG(UART_REG_TXCTRL) |= UART_TXEN; + UART0_REG(UART_REG_RXCTRL) |= UART_RXEN; + GPIO_REG(GPIO_IOF_SEL) &= ~IOF0_UART0_MASK; GPIO_REG(GPIO_IOF_EN) |= IOF0_UART0_MASK; } -void eos_uart_stop(void) { +void eos_uart_disable(void) { GPIO_REG(GPIO_IOF_EN) &= ~IOF0_UART0_MASK; + + UART0_REG(UART_REG_TXCTRL) &= ~UART_TXEN; + UART0_REG(UART_REG_RXCTRL) &= ~UART_RXEN; +} + +int eos_uart_enabled(void) { + return !!(GPIO_REG(GPIO_IOF_EN) & IOF0_UART0_MASK); } void eos_uart_speed(uint32_t baud_rate) { @@ -90,8 +99,8 @@ void eos_uart_rxwm_clear(void) { UART0_REG(UART_REG_IE) &= ~UART_IP_RXWM; } -int eos_uart_putc(int c, char b) { - if (b) { +int eos_uart_putc(int c, int block) { + if (block) { while (UART0_REG(UART_REG_TXFIFO) & 0x80000000); UART0_REG(UART_REG_TXFIFO) = c & 0xff; } else { @@ -101,14 +110,14 @@ int eos_uart_putc(int c, char b) { return EOS_OK; } -int eos_uart_getc(char b) { +int eos_uart_getc(int block) { volatile uint32_t r; - if (b) { + if (block) { while ((r = UART0_REG(UART_REG_RXFIFO)) & 0x80000000); } else { r = UART0_REG(UART_REG_RXFIFO); if (r & 0x80000000) return EOS_ERR_EMPTY; } return r & 0xff; -} \ No newline at end of file +} -- cgit v1.2.3