1 /* 2 * Copyright 2014, General Dynamics C4 Systems 3 * 4 * SPDX-License-Identifier: GPL-2.0-only 5 */ 6 7 #include <config.h> 8 #include <stdint.h> 9 #include <util.h> 10 #include <machine/io.h> 11 12 #define USR 0x08 13 #define UTF 0x70 14 #define UNTX 0x40 15 16 #define USR_RXRDY BIT(0) 17 #define USR_RXFUL BIT(1) 18 #define USR_TXRDY BIT(2) 19 #define USR_TXEMP BIT(3) 20 21 #define UART_REG(X) ((volatile uint32_t *)(UART_PPTR + (X))) 22 23 #ifdef CONFIG_PRINTING uart_drv_putchar(unsigned char c)24void uart_drv_putchar(unsigned char c) 25 { 26 while ((*UART_REG(USR) & USR_TXEMP) == 0); 27 /* Tell the peripheral how many characters to send */ 28 *UART_REG(UNTX) = 1; 29 /* Write the character into the FIFO */ 30 *UART_REG(UTF) = c & 0xff; 31 } 32 #endif /* CONFIG_PRINTING */ 33 34 #ifdef CONFIG_DEBUG_BUILD uart_drv_getchar(void)35unsigned char uart_drv_getchar(void) 36 { 37 while ((*UART_REG(USR) & USR_RXRDY) == 0); 38 39 return *UART_REG(UTF) & 0xff; 40 } 41 #endif /* CONFIG_DEBUG_BUILD */ 42