summaryrefslogtreecommitdiffstats
path: root/sdcard.v
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2010-10-28 21:50:10 -0700
committerH. Peter Anvin <hpa@zytor.com>2014-02-10 18:07:49 -0800
commite69f7efce11a2e4af396835fade0517271bd10fb (patch)
tree9e086025e4b334baf67dd445ba0cddfffecc68b0 /sdcard.v
parentb6c4df01b757d62703f42316b3600558dc2ef2fa (diff)
downloadabc8000-e69f7efce11a2e4af396835fade0517271bd10fb.tar.gz
abc8000-e69f7efce11a2e4af396835fade0517271bd10fb.tar.xz
abc8000-e69f7efce11a2e4af396835fade0517271bd10fb.zip
sdcard: fix sequencing of data on read
We need to latch the data after an ongoing transaction has completed, but before we start a new one.
Diffstat (limited to 'sdcard.v')
-rw-r--r--sdcard.v51
1 files changed, 37 insertions, 14 deletions
diff --git a/sdcard.v b/sdcard.v
index e470048..008011b 100644
--- a/sdcard.v
+++ b/sdcard.v
@@ -207,20 +207,43 @@ module sdcard (
sd_crc16[3:0], sd_crc16in};
// Data out to CPU
-
reg [15:0] sd_cpu_rd;
- always @(*)
- casex (cpu_a[1:0])
- 2'b00:
- sd_cpu_rd = sd_shr_in;
- 2'b01:
- sd_cpu_rd = {12'b0, ~sd_we_n, ~sd_cd_n, sd_cs_n_reg, sd_slow};
- 2'b10:
- sd_cpu_rd = {8'b0, sd_crc7, 1'b1};
- 2'b11:
- sd_cpu_rd = sd_crc16;
- endcase // casex(cpu_a[1:0])
-
- assign cpu_di = (msel & cpu_r_wn) ? sd_cpu_rd : 16'hffff;
+ reg rd_q;
+
+ always @(negedge rst_n or posedge clk)
+ if (~rst_n)
+ begin
+ sd_cpu_rd <= 16'hxxxx;
+ rd_q <= 1'b0;
+ end
+ else
+ begin
+ if (msel & cpu_r_wn)
+ begin
+ if (~sd_active & ~rd_q)
+ begin
+ rd_q <= 1'b1;
+
+ casex (cpu_a[1:0])
+ 2'b00:
+ sd_cpu_rd <= sd_shr_in;
+ 2'b01:
+ sd_cpu_rd <= {12'b0, ~sd_we_n, ~sd_cd_n,
+ sd_cs_n_reg, sd_slow};
+ 2'b10:
+ sd_cpu_rd <= {8'b0, sd_crc7, 1'b1};
+ 2'b11:
+ sd_cpu_rd <= sd_crc16;
+ endcase // casex(cpu_a[1:0])
+ end // if (~sd_active & ~rd_q)
+ end // if (msel & cpu_r_wn)
+ else
+ begin
+ sd_cpu_rd <= 16'hffff;
+ rd_q <= 1'b0;
+ end // else: !if(msel & cpu_r_wn)
+ end // else: !if(~rst_n)
+
+ assign cpu_di = sd_cpu_rd;
endmodule // sdcard