提交 43002b01 编写于 作者: Z Zihao Yu

device,AXI4VGA: add FBHelper for emu

上级 096a786a
......@@ -52,7 +52,36 @@ class VGACtrl extends AXI4SlaveModule(new AXI4Lite, new VGACtrlBundle) with HasV
io.extra.get.sync := sync
}
class AXI4VGA extends Module with HasVGAConst {
class FBHelper extends BlackBox with HasBlackBoxInline {
val io = IO(new Bundle {
val clk = Input(Clock())
val valid = Input(Bool())
val pixel = Input(UInt(32.W))
val sync = Input(Bool())
})
setInline("FBHelper.v",
s"""
|import "DPI-C" function void put_pixel(input int pixel);
|import "DPI-C" function void vmem_sync();
|
|module FBHelper (
| input clk,
| input valid,
| input [31:0] pixel,
| input sync
|);
|
| always@(posedge clk) begin
| if (valid) put_pixel(pixel);
| if (sync) vmem_sync();
| end
|
|endmodule
""".stripMargin)
}
class AXI4VGA(sim: Boolean = false) extends Module with HasVGAConst {
val AXIidBits = 2
// need a 50MHz clock
val io = IO(new Bundle {
......@@ -108,4 +137,12 @@ class AXI4VGA extends Module with HasVGAConst {
io.vga.r := Mux(videoValid, color(23, 20), 0.U)
io.vga.g := Mux(videoValid, color(15, 12), 0.U)
io.vga.b := Mux(videoValid, color(7, 4), 0.U)
if (sim) {
val fbHelper = Module(new FBHelper)
fbHelper.io.clk := clock
fbHelper.io.valid := videoValid
fbHelper.io.pixel := color
fbHelper.io.sync := ctrl.io.extra.get.sync
}
}
......@@ -14,7 +14,7 @@ void uart_putc(char c);
void init_uart(void);
static struct timeval boot = {};
static uint64_t vmem[0x400000 / sizeof(uint64_t)];
static uint32_t vmem[800 * 600];
void init_device(void) {
init_sdl();
......@@ -55,6 +55,16 @@ 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) {
......
......@@ -4,8 +4,8 @@
#define SCREEN_PORT 0x100 // Note that this is not the standard
#define SCREEN_MMIO 0x4100
#define SCREEN_H 320
#define SCREEN_W 400
#define SCREEN_H 600
#define SCREEN_W 800
static SDL_Window *window;
......@@ -25,7 +25,7 @@ uint32_t screen_size(void) {
void init_sdl() {
SDL_Init(SDL_INIT_VIDEO);
SDL_CreateWindowAndRenderer(SCREEN_W * 2, SCREEN_H * 2, 0, &window, &renderer);
SDL_CreateWindowAndRenderer(SCREEN_W, SCREEN_H, 0, &window, &renderer);
SDL_SetWindowTitle(window, "NOOP");
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STATIC, SCREEN_W, SCREEN_H);
......
......@@ -36,7 +36,7 @@ class SimMMIO extends Module {
val uart = Module(new AXI4UART)
val timer = Module(new AXI4Timer)
val vga = Module(new AXI4VGA)
val vga = Module(new AXI4VGA(sim = true))
uart.io.in <> xbar.io.out(0).toAXI4Lite()
timer.io.in <> xbar.io.out(1).toAXI4Lite()
vga.io.in.fb <> xbar.io.out(2).toAXI4Lite()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册