提交 9f842a1a 编写于 作者: Y Yinan Xu

device,sdcard: fix inline SDHelper read behavior

上级 46951036
...@@ -32,23 +32,22 @@ class SDHelper extends BlackBox with HasBlackBoxInline { ...@@ -32,23 +32,22 @@ class SDHelper extends BlackBox with HasBlackBoxInline {
setInline("SDHelper.v", setInline("SDHelper.v",
s""" s"""
|import "DPI-C" function void sd_setaddr(input int addr); |import "DPI-C" function void sd_setaddr(input int addr);
|import "DPI-C" function int sd_read(input bit ren); |import "DPI-C" function void sd_read(output int data);
| |
|module SDHelper ( |module SDHelper (
| input clk, | input clk,
| input setAddr, | input setAddr,
| input [31:0] addr, | input [31:0] addr,
| input ren, | input ren,
| output [31:0] data | output reg [31:0] data
|); |);
| |
| always @(posedge clk) begin | always @(negedge clk) begin
| if (setAddr) begin | if (ren) sd_read(data);
| sd_setaddr(addr); | end
| end | always@(posedge clk) begin
| if (setAddr) sd_setaddr(addr);
| end | end
|
| assign data = sd_read(ren);
| |
|endmodule |endmodule
""".stripMargin) """.stripMargin)
......
...@@ -11,18 +11,14 @@ void sd_setaddr(uint32_t addr) { ...@@ -11,18 +11,14 @@ void sd_setaddr(uint32_t addr) {
//assert(0); //assert(0);
} }
uint32_t sd_read(int ren) { void sd_read(uint32_t *data) {
if (ren) { fread(data, 4, 1, fp);
uint32_t data; //printf("read data = 0x%08x\n", *data);
fread(&data, 4, 1, fp); //assert(0);
//printf("read data = 0x%08x\n", *data);
return data;
}
return 0xdeadbeaf;
} }
void init_sd(void) { void init_sd(void) {
fp = fopen("/home/xyn/debian/debian.img", "r"); fp = fopen("/home/xyn/workloads/debian/riscv-debian.img", "r");
if(!fp) if(!fp)
{ {
eprintf(ANSI_COLOR_MAGENTA "[warning] sdcard img not found\n"); eprintf(ANSI_COLOR_MAGENTA "[warning] sdcard img not found\n");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册