2018-12-28 10:30:39 +00:00
|
|
|
#include <dbg.h>
|
2018-12-30 21:44:14 +00:00
|
|
|
#include <stdint.h>
|
2018-12-28 10:30:39 +00:00
|
|
|
|
|
|
|
/* Never call this function directly: always use the printk,
|
|
|
|
* which disables and reenables interrupts */
|
|
|
|
extern "C" int c_printk(const char* msg) {
|
|
|
|
while (*msg != '\0') {
|
|
|
|
while ((*dbg::UART_LSR & 0x20) == 0); /* Wait for transmission */
|
|
|
|
*dbg::UART_THR = *msg;
|
|
|
|
msg++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int printkl(const char* msg) {
|
|
|
|
printk(msg);
|
|
|
|
printk("\r\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-30 21:44:14 +00:00
|
|
|
static char string[11];
|
|
|
|
/* TODO: WARNING: this is not thread safe!! */
|
|
|
|
extern "C" const char* itoa(uint32_t n) {
|
|
|
|
string[10] = '\0';
|
|
|
|
string[0] = '0'; string[1] = 'x';
|
|
|
|
|
|
|
|
for (short i = 0; i < 8; ++i) {
|
|
|
|
string[9 - i] = "0123456789abcdef"[n & 0xF];
|
|
|
|
n = n >> 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &string[0];
|
|
|
|
}
|
|
|
|
|
2018-12-30 22:45:46 +00:00
|
|
|
|