diff options
Diffstat (limited to 'big-little/lib/uart.c')
-rw-r--r-- | big-little/lib/uart.c | 68 |
1 files changed, 31 insertions, 37 deletions
diff --git a/big-little/lib/uart.c b/big-little/lib/uart.c index fe88a11..26d00e5 100644 --- a/big-little/lib/uart.c +++ b/big-little/lib/uart.c @@ -27,7 +27,7 @@ * Call config_uart first. * Implements fputc() so you can use printf() in your code. */ - + #include "misc.h" #include "hyp_vmmap.h" #include "virt_helpers.h" @@ -57,69 +57,63 @@ static unsigned uart_base = NULL; #define write32(addr, val) (*(volatile unsigned int *)(addr) = (val)) #define read32(addr) (*(volatile unsigned int *)(addr)) - void config_uart(void) { - uart_base = UART1_PHY_BASE; - write32(uart_base + PL011_CR, 0); - write32(uart_base + PL011_FBRD, 0x01); - write32(uart_base + PL011_IBRD, 0x27); - write32(uart_base + PL011_LCRH, 0x70); - write32(uart_base + PL011_CR, 0xf01); /* TXE|RXE|En|DTR|CTS */ + uart_base = UART1_PHY_BASE; + write32(uart_base + PL011_CR, 0); + write32(uart_base + PL011_FBRD, 0x01); + write32(uart_base + PL011_IBRD, 0x27); + write32(uart_base + PL011_LCRH, 0x70); + write32(uart_base + PL011_CR, 0xf01); /* TXE|RXE|En|DTR|CTS */ } void drain_uart_fifo(void) { - while (!(read32(uart_base + PL011_FR) & PL011_TXFE)) - { - /* Do nothing */ - } + while (!(read32(uart_base + PL011_FR) & PL011_TXFE)) { + /* Do nothing */ + } } static __inline void wait_for_space(void) { - while ((read32(uart_base + PL011_FR) & PL011_TXFF)) - { - /* Do nothing */ - } + while ((read32(uart_base + PL011_FR) & PL011_TXFF)) { + /* Do nothing */ + } } void output_char(int c) { - if (c == '\n') - { - wait_for_space(); - write32(uart_base + PL011_DR, '\r'); - } - wait_for_space(); - write32(uart_base + PL011_DR, c); + if (c == '\n') { + wait_for_space(); + write32(uart_base + PL011_DR, '\r'); + } + wait_for_space(); + write32(uart_base + PL011_DR, c); } void output_string(const char *string) { - int i; - - for (i=0; string[i]; ++i) - { - output_char(string[i]); - } + int i; + + for (i = 0; string[i]; ++i) { + output_char(string[i]); + } } void hexword(unsigned value) { - printf(" 0x%8.8x", value); - drain_uart_fifo(); + printf(" 0x%8.8x", value); + drain_uart_fifo(); } -typedef struct __FILE -{ - int dummy; +typedef struct __FILE { + int dummy; } FILE; FILE __stdout; -int fputc(int c, FILE *f) +int fputc(int c, FILE * f) { - output_char(c); - return c; + output_char(c); + return c; } |