提交 9a5b5207 编写于 作者: Z Zihao Yu

test,SimMMIO: remove DeviceHelper

上级 f9e2478f
......@@ -3,18 +3,12 @@
#include <SDL2/SDL.h>
void send_key(uint8_t, bool);
uint32_t read_key(void);
void init_sdl(void);
void update_screen(void *vmem);
uint32_t screen_size(void);
void set_abort(void);
int uart_getc(void);
void uart_putc(char c);
void init_uart(void);
static struct timeval boot = {};
static uint32_t vmem[800 * 600];
void init_device(void) {
init_sdl();
......@@ -54,44 +48,3 @@ uint32_t uptime(void) {
return s * 1000 + (us + 500) / 1000;
}
extern "C" void put_pixel(uint32_t pixel) {
static int i = 0;
vmem[i++] = pixel;
if (i >= 800 * 600) i = 0;
}
extern "C" void vmem_sync(void) {
update_screen(vmem);
}
extern "C" void device_helper(
uint8_t req_wen, uint64_t req_addr, uint64_t req_wdata, uint8_t req_wmask, uint64_t *resp_rdata) {
switch (req_addr) {
// read uartlite stat register
case 0x40600008: *resp_rdata = 0x01; break; // set UARTLITE_RX_VALID
// read uartlite ctrl register
case 0x4060000c: *resp_rdata = 0; break;
// write uartlite tx fifo
case 0x40600004: if (req_wen) uart_putc((char)req_wdata); break;
// read uartlite rx fifo
//case 0x40600000: *resp_rdata = uart_getc(); break;
// read RTC
case 0x40700000: *resp_rdata = uptime(); break;
// read key
case 0x40900000: *resp_rdata = read_key(); break;
// read screen size
case 0x40800000: *resp_rdata = screen_size(); break;
// write vga sync
case 0x40800004: update_screen(vmem); break;
default:
if (req_addr >= 0x40000000 && req_addr < 0x40400000 && req_wen) {
// write to vmem
vmem[(req_addr - 0x40000000) / sizeof(uint64_t)] = req_wdata;
}
else {
eprintf("bad address = 0x%08x, wen = %d\n", (uint32_t)req_addr, req_wen);
assert(0);
}
}
}
......@@ -7,22 +7,25 @@
#define SCREEN_H 600
#define SCREEN_W 800
static uint32_t vmem[800 * 600];
static SDL_Window *window;
static SDL_Renderer *renderer;
static SDL_Texture *texture;
void update_screen(void *vmem) {
extern "C" void put_pixel(uint32_t pixel) {
static int i = 0;
vmem[i++] = pixel;
if (i >= 800 * 600) i = 0;
}
extern "C" void vmem_sync(void) {
SDL_UpdateTexture(texture, NULL, vmem, SCREEN_W * sizeof(uint32_t));
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
}
uint32_t screen_size(void) {
return ((SCREEN_W) << 16) | (SCREEN_H);
}
void init_sdl() {
SDL_Init(SDL_INIT_VIDEO);
SDL_CreateWindowAndRenderer(SCREEN_W, SCREEN_H, 0, &window, &renderer);
......
......@@ -6,19 +6,6 @@ import chisel3.util._
import bus.simplebus._
import device._
class DeviceHelper extends BlackBox {
val io = IO(new Bundle {
val clk = Input(Clock())
val reset = Input(Bool())
val reqValid = Input(Bool())
val reqWen = Input(Bool())
val reqAddr = Input(UInt(64.W))
val reqWdata = Input(UInt(64.W))
val reqWmask = Input(UInt(8.W))
val respRdata = Output(UInt(64.W))
})
}
class SimMMIO extends Module {
val io = IO(new Bundle {
val rw = Flipped(new SimpleBusUC)
......@@ -45,20 +32,4 @@ class SimMMIO extends Module {
vga.io.vga := DontCare
io.mtip := timer.io.extra.get.mtip
//val helper = Module(new DeviceHelper)
//val helperIO = xbar.io.out(0)
//helper.io.clk := clock
//helper.io.reset := reset.asBool
//helper.io.reqValid := helperIO.req.valid
//helper.io.reqWen := helperIO.isWrite()
//helper.io.reqAddr := helperIO.req.bits.addr
//helper.io.reqWdata := helperIO.req.bits.wdata
//helper.io.reqWmask := helperIO.req.bits.wmask
//helperIO.resp.bits.rdata := helper.io.respRdata
//helperIO.resp.bits.cmd := 0.U
//helperIO.resp.bits.user := 0.U
//helperIO.req.ready := true.B
//helperIO.resp.valid := RegNext(helperIO.req.valid)
}
import "DPI-C" function void device_helper
(
input bit req_wen,
input longint req_addr,
input longint req_wdata,
input byte req_wmask,
output longint resp_rdata
);
module DeviceHelper(
input clk,
input reset,
input reqValid,
input reqWen,
input [63:0] reqAddr,
input [63:0] reqWdata,
input [7:0] reqWmask,
output [63:0] respRdata
);
always @(posedge clk) begin
if (reqValid && !reset) device_helper(reqWen, reqAddr, reqWdata, reqWmask, respRdata);
end
endmodule
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册