forked from xuos/xiuos
Support imx6q-sabrelite userland timer driver.
This commit is contained in:
@@ -23,6 +23,7 @@ void Xil_Out32(intptr_t Addr, uint32_t Value)
|
||||
uint32_t* LocalAddr = (uint32_t*)Addr;
|
||||
*LocalAddr = Value;
|
||||
}
|
||||
|
||||
#define XUartPs_IsTransmitFull(BaseAddress) \
|
||||
((*(volatile uint32_t*)((BaseAddress) + 0x002CU) & (uint32_t)0x00000010U) == (uint32_t)0x00000010U)
|
||||
#define XUartPs_WriteReg(BaseAddress, RegOffset, RegisterValue) \
|
||||
@@ -47,7 +48,7 @@ uint8_t XUartPs_RecvByte(uint32_t BaseAddress)
|
||||
|
||||
#define USER_UART_BASE 0x6FFFF000
|
||||
|
||||
static bool init_uart_mmio()
|
||||
bool init_uart_mmio()
|
||||
{
|
||||
static int mapped = 0;
|
||||
if (mapped == 0) {
|
||||
@@ -59,7 +60,7 @@ static bool init_uart_mmio()
|
||||
return true;
|
||||
}
|
||||
|
||||
static void putc(char c)
|
||||
void putc(char c)
|
||||
{
|
||||
if (c == '\n') {
|
||||
while (XUartPs_IsTransmitFull(USER_UART_BASE)) {
|
||||
@@ -83,80 +84,3 @@ char getc(void)
|
||||
}
|
||||
return XUartPs_RecvByte(USER_UART_BASE);
|
||||
}
|
||||
|
||||
static void printint(int xx, int base, int sgn)
|
||||
{
|
||||
static char digits[] = "0123456789ABCDEF";
|
||||
char buf[16];
|
||||
int i, neg;
|
||||
uint32_t x;
|
||||
|
||||
neg = 0;
|
||||
if (sgn && xx < 0) {
|
||||
neg = 1;
|
||||
x = -xx;
|
||||
} else {
|
||||
x = xx;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
do {
|
||||
buf[i++] = digits[x % base];
|
||||
} while ((x /= base) != 0);
|
||||
if (neg)
|
||||
buf[i++] = '-';
|
||||
|
||||
while (--i >= 0)
|
||||
putc(buf[i]);
|
||||
}
|
||||
|
||||
// Print to usart. Only understands %d, %x, %p, %s.
|
||||
void printf(char* fmt, ...)
|
||||
{
|
||||
if (!init_uart_mmio()) {
|
||||
return;
|
||||
}
|
||||
char* s;
|
||||
int c, i, state;
|
||||
uint32_t* ap;
|
||||
|
||||
state = 0;
|
||||
ap = (uint32_t*)(void*)&fmt + 1;
|
||||
for (i = 0; fmt[i]; i++) {
|
||||
c = fmt[i] & 0xff;
|
||||
if (state == 0) {
|
||||
if (c == '%') {
|
||||
state = '%';
|
||||
} else {
|
||||
putc(c);
|
||||
}
|
||||
} else if (state == '%') {
|
||||
if (c == 'd') {
|
||||
printint(*ap, 10, 1);
|
||||
ap++;
|
||||
} else if (c == 'x' || c == 'p') {
|
||||
printint(*ap, 16, 0);
|
||||
ap++;
|
||||
} else if (c == 's') {
|
||||
s = (char*)*ap;
|
||||
ap++;
|
||||
if (s == 0)
|
||||
s = "(null)";
|
||||
while (*s != 0) {
|
||||
putc(*s);
|
||||
s++;
|
||||
}
|
||||
} else if (c == 'c') {
|
||||
putc(*ap);
|
||||
ap++;
|
||||
} else if (c == '%') {
|
||||
putc(c);
|
||||
} else {
|
||||
// Unknown % sequence. Print it to draw attention.
|
||||
putc('%');
|
||||
putc(c);
|
||||
}
|
||||
state = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user