2019-05-31 15:45:59 +02:00
|
|
|
#include "memlayout.h"
|
2009-05-31 02:24:11 +02:00
|
|
|
|
2019-05-31 15:45:59 +02:00
|
|
|
//
|
|
|
|
// qemu -machine virt has a 16550a UART
|
|
|
|
// qemu/hw/riscv/virt.c
|
|
|
|
// http://byterunner.com/16550.html
|
|
|
|
//
|
|
|
|
// caller should lock.
|
|
|
|
//
|
2009-05-31 02:24:11 +02:00
|
|
|
|
2019-05-31 15:45:59 +02:00
|
|
|
// address of one of the registers
|
|
|
|
#define R(reg) ((unsigned int*)(UART0 + 4*(reg)))
|
2009-05-31 02:24:11 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
uartinit(void)
|
|
|
|
{
|
2019-05-31 15:45:59 +02:00
|
|
|
// disable interrupts
|
|
|
|
*R(1) = 0x00;
|
2009-05-31 02:24:11 +02:00
|
|
|
|
2019-05-31 15:45:59 +02:00
|
|
|
// special mode to set baud rate
|
|
|
|
*R(3) = 0x80;
|
2016-08-25 15:13:00 +02:00
|
|
|
|
2019-05-31 15:45:59 +02:00
|
|
|
// LSB for baud rate of 38.4K
|
|
|
|
*R(0) = 0x03;
|
2009-05-31 02:24:11 +02:00
|
|
|
|
2019-05-31 15:45:59 +02:00
|
|
|
// MSB for baud rate of 38.4K
|
|
|
|
*R(1) = 0x00;
|
2009-05-31 02:24:11 +02:00
|
|
|
|
2019-05-31 15:45:59 +02:00
|
|
|
// leave set-baud mode,
|
|
|
|
// and set word length to 8 bits, no parity.
|
|
|
|
*R(3) = 0x03;
|
2016-08-25 15:13:00 +02:00
|
|
|
|
2019-05-31 15:45:59 +02:00
|
|
|
// reset and enable FIFOs.
|
|
|
|
*R(2) = 0x07;
|
2009-05-31 02:24:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
uartputc(int c)
|
|
|
|
{
|
2019-05-31 15:45:59 +02:00
|
|
|
*R(0) = c;
|
2009-05-31 02:24:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
uartgetc(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
uartintr(void)
|
|
|
|
{
|
|
|
|
}
|