提交 eccb333d 编写于 作者: W wangkaifan

device: support uartlite

* note that serial input is not supported currently
上级 3f072846
......@@ -9,6 +9,7 @@
void init_alarm();
void init_serial();
void init_uartlite();
void init_timer();
void init_vga();
void init_i8042();
......@@ -56,9 +57,12 @@ void sdl_clear_event_queue() {
}
void init_device() {
init_serial();
#ifdef XIANGSHAN
init_vga();
init_uartlite();
#else
init_vga();
#ifndef XIANGSHAN
init_serial();
init_timer();
init_i8042();
init_audio();
......
#include <device/map.h>
#define CH_OFFSET 0
#define UARTLITE_RX_FIFO 0x0
#define UARTLITE_TX_FIFO 0x4
#define UARTLITE_STAT_REG 0x8
#define UARTLITE_CTRL_REG 0xc
#define UARTLITE_RST_FIFO 0x03
#define UARTLITE_TX_FULL 0x08
#define UARTLITE_RX_VALID 0x01
// #define QUEUE_SIZE 1024
// static char queue[QUEUE_SIZE] = {};
// static int f = 0, r = 0;
static uint8_t *serial_base = NULL;
// static void serial_enqueue(char ch) {
// int next = (r + 1) % QUEUE_SIZE;
// if (next != f) {
// // not full
// queue[r] = ch;
// r = next;
// }
// }
// static char serial_dequeue() {
// char ch = 0xff;
// extern uint32_t uptime();
// static uint32_t last = 0;
// uint32_t now = uptime();
// if (now > last) {
// Log("now = %d", now);
// last = now;
// }
// // 90s after starting
// if (now > 90) {
// if (f != r) {
// ch = queue[f];
// f = (f + 1) % QUEUE_SIZE;
// }
// }
// return ch;
// }
static void serial_io_handler(uint32_t offset, int len, nemu_bool is_write) {
assert(len == 1);
switch (offset) {
/* We bind the serial port with the host stdout in NEMU. */
case UARTLITE_TX_FIFO:
if (is_write) putc(serial_base[UARTLITE_TX_FIFO], stderr);
else panic("Cannot read UARTLITE_TX_FIFO");
break;
case UARTLITE_STAT_REG:
if (!is_write) serial_base[UARTLITE_STAT_REG] = 0x0;
break;
}
}
// #define rt_thread_cmd "memtrace\n"
// #define busybox_cmd "ls\n" \
// "cd /root\n" \
// "echo hello2\n" \
// "cd /root/benchmark\n" \
// "./stream\n" \
// "echo hello3\n" \
// "cd /root/redis\n" \
// "ls\n" \
// "ifconfig -a\n" \
// "ls\n" \
// "./redis-server\n" \
// #define debian_cmd "root\n" \
// static void preset_input() {
// char buf[] = debian_cmd;
// int i;
// for (i = 0; i < strlen(buf); i ++) {
// serial_enqueue(buf[i]);
// }
// }
void init_uartlite() {
serial_base = new_space(0xd);
add_pio_map("uartlite", SERIAL_PORT, serial_base, 0xd, serial_io_handler);
add_mmio_map("uartlite", SERIAL_MMIO, serial_base, 0xd, serial_io_handler);
preset_input();
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册