#include <config.h>
#include <stdint.h>
#include <util.h>
#include <machine/io.h>
#include <plat/machine/devices.h>
#define ULCON 0x0000
#define UCON 0x0004
#define UFCON 0x0008
#define UMCON 0x000C
#define UTRSTAT 0x0010
#define UERSTAT 0x0014
#define UFSTAT 0x0018
#define UMSTAT 0x001C
#define UTXH 0x0020
#define URXH 0x0024
#define UBRDIV 0x0028
#define UFRACVAL 0x002C
#define UINTP 0x0030
#define UINTSP 0x0034
#define UINTM 0x0038
#define UART_REG(X) ((volatile uint32_t *)(UART_PPTR + (X)))
#define TX_EMPTY BIT(2)
#define TXBUF_EMPTY BIT(1)
#define RXBUF_READY BIT(0)
#if defined(CONFIG_DEBUG_BUILD) || defined(CONFIG_PRINTING)
void
putDebugChar(unsigned char c)
{
while ( (*UART_REG(UTRSTAT) & TXBUF_EMPTY) == 0 );
*UART_REG(UTXH) = (c & 0xff);
}
#endif
#ifdef CONFIG_DEBUG_BUILD
unsigned char
getDebugChar(void)
{
if ( (*UART_REG(UTRSTAT) & RXBUF_READY)) {
return (unsigned char) * UART_REG(URXH);
} else {
return -1;
}
}
#endif