diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-11-30 23:55:45 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-11-30 23:55:45 -0700 |
commit | 7df284ea01ea0015770d626a1eb7ae7f62d48bb3 (patch) | |
tree | 46ac2b11101fa1359a4e04ab311b204c53846fcf /src | |
parent | 281672d418bdc093716b069198c8852ad87eabb2 (diff) | |
download | ch573-7df284ea01ea0015770d626a1eb7ae7f62d48bb3.tar.gz ch573-7df284ea01ea0015770d626a1eb7ae7f62d48bb3.tar.bz2 ch573-7df284ea01ea0015770d626a1eb7ae7f62d48bb3.zip |
Implement serial input.
Diffstat (limited to 'src')
-rw-r--r-- | src/io.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -32,9 +32,10 @@ static int uart1_FILE_put(char ch, FILE* unused) return 1; } -static int uart1_FILE_get(FILE* f) +int uart1_FILE_get(FILE* unused) { - return -1; + while (!UART.rfc.get(UART1)); + return UART.rbr.get(UART1); } static int uart1_FILE_flush(FILE* f) @@ -46,10 +47,11 @@ FILE _uart1_FILE = (FILE){ .put = uart1_FILE_put, .get = uart1_FILE_get, .flush = uart1_FILE_flush, - .flags = __SWR, + .flags = __SWR | __SRD, }; FILE* const stdout = &_uart1_FILE; +FILE* const stdin = &_uart1_FILE; static int uart1_init_for_stdout = 0; @@ -62,6 +64,13 @@ void init_uart1_for_stdout(void) UART.fcr.set(UART1, 0x07); UART.ier.txd_en.set(UART1, ON); UART.lcr.word_sz.set(UART1, WORD_SZ_8_BITS); + UART.fcr.fifo_en.set(UART1, 1); + + UART.div.set(UART1, 1); + UART.fcr.set(UART1, 0x07); + UART.ier.txd_en.set(UART1, ON); + UART.lcr.word_sz.set(UART1, WORD_SZ_8_BITS); + volatile uint32_t dl = (10 * 6400000 / 8 / BAUD_RATE + 5) / 10; UART.dl.set(UART1, dl); |