xv6-65oo2/uart.c
2019-06-03 14:13:07 -04:00

63 lines
954 B
C

#include "types.h"
#include "param.h"
#include "memlayout.h"
#include "riscv.h"
#include "proc.h"
#include "spinlock.h"
#include "defs.h"
//
// qemu -machine virt has a 16550a UART
// qemu/hw/riscv/virt.c
// http://byterunner.com/16550.html
//
// caller should lock.
//
// address of one of the registers
#define R(reg) ((volatile unsigned char *)(UART0 + reg))
void
uartinit(void)
{
// disable interrupts -- IER
*R(1) = 0x00;
// special mode to set baud rate
*R(3) = 0x80;
// LSB for baud rate of 38.4K
*R(0) = 0x03;
// MSB for baud rate of 38.4K
*R(1) = 0x00;
// leave set-baud mode,
// and set word length to 8 bits, no parity.
*R(3) = 0x03;
// reset and enable FIFOs -- FCR.
*R(2) = 0x07;
// enable receive interrupts -- IER.
*R(1) = 0x01;
}
void
uartputc(int c)
{
*R(0) = c;
}
uint
uartgetc(void)
{
// XXX this isn't right, must check there's data in the FIFO.
return *R(0);
}
void
uartintr(void)
{
}