summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/soc/uart.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2022-08-09 22:23:08 +0200
committerUros Majstorovic <majstor@majstor.org>2022-08-09 22:23:08 +0200
commit3f913efda03fd840cd526ef72e6f397c7da61bd7 (patch)
tree08f62c93e0e0660fdb7beba32276ff1ceb7a8a3c /fw/fe310/eos/soc/uart.c
parent810dde21ee65653c15606917b19566cfbaaf165e (diff)
code layout
Diffstat (limited to 'fw/fe310/eos/soc/uart.c')
-rw-r--r--fw/fe310/eos/soc/uart.c31
1 files changed, 20 insertions, 11 deletions
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
+}