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#if defined(CONFIG_DEBUG_BUILD) || defined(CONFIG_PRINTING) 24void putDebugChar(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 33 34#ifdef CONFIG_DEBUG_BUILD 35unsigned char getDebugChar(void) 36{ 37 while ((*UART_REG(USR) & USR_RXRDY) == 0); 38 39 return *UART_REG(UTF) & 0xff; 40} 41#endif /* CONFIG_DEBUG_BUILD */ 42