bugfixes for SD card compatibility in DMA mode
This commit is contained in:
@@ -188,5 +188,7 @@ NET "SRAM_OE" IOSTANDARD = LVCMOS33;
|
||||
NET "SRAM_WE" IOSTANDARD = LVCMOS33;
|
||||
NET "SPI_DMA_CTRL" LOC = P41;
|
||||
NET "SPI_DMA_CTRL" IOSTANDARD = LVCMOS33;
|
||||
NET "SPI_DMA_CTRL" PULLUP;
|
||||
NET "SPI_SCK" IOSTANDARD = LVCMOS33;
|
||||
NET "SPI_SCK" PULLDOWN;
|
||||
NET "SPI_SCK" DRIVE = 16;
|
||||
NET "SPI_SCK" PULLUP;
|
||||
|
||||
@@ -41,7 +41,7 @@ reg [9:0] spi_dma_bytecnt;
|
||||
reg [3:0] spi_dma_clkcnt;
|
||||
reg [3:0] spi_dma_sck_int_r;
|
||||
reg [5:0] spi_dma_trig_r;
|
||||
reg [1:0] spi_dma_miso_r;
|
||||
reg [4:0] spi_dma_miso_r;
|
||||
reg spi_dma_sck_out_r;
|
||||
reg spi_dma_sck_out_r2;
|
||||
|
||||
@@ -62,23 +62,24 @@ end
|
||||
// synthesize clock
|
||||
wire spi_dma_sck_int = spi_dma_clkcnt[1];
|
||||
assign spi_dma_sck = spi_dma_sck_out_r & spi_dma_sck_out_r2;
|
||||
|
||||
always @(posedge clk) begin
|
||||
spi_dma_clkcnt <= spi_dma_clkcnt + 1;
|
||||
spi_dma_sck_int_r <= {spi_dma_sck_int_r[2:0], spi_dma_sck_int};
|
||||
spi_dma_trig_r <= {spi_dma_trig_r[4:0], spi_dma_trig};
|
||||
spi_dma_miso_r <= {spi_dma_miso_r[0], spi_dma_miso};
|
||||
spi_dma_miso_r <= {spi_dma_miso_r[3:0], spi_dma_miso};
|
||||
end
|
||||
|
||||
wire spi_dma_trig_rising = (spi_dma_trig_r[5:1] == 5'b00011);
|
||||
wire spi_dma_trig_falling = (spi_dma_trig_r[5:1] == 5'b11100);
|
||||
wire spi_dma_sck_rising = (spi_dma_sck_int_r[1:0] == 2'b01);
|
||||
wire spi_dma_sck_falling = (spi_dma_sck_int_r[1:0] == 2'b10);
|
||||
wire spi_dma_sck_rising2 = (spi_dma_sck_int_r[1:0] == 2'b01);
|
||||
wire spi_dma_sck_falling2 = (spi_dma_sck_int_r[1:0] == 2'b10);
|
||||
wire spi_dma_sck_rising = (spi_dma_sck_int_r[2:1] == 2'b01);
|
||||
wire spi_dma_sck_falling = (spi_dma_sck_int_r[2:1] == 2'b10);
|
||||
wire spi_dma_sck_rising2 = (spi_dma_sck_int_r[2:1] == 2'b01);
|
||||
wire spi_dma_sck_falling2 = (spi_dma_sck_int_r[2:1] == 2'b10);
|
||||
|
||||
assign spi_dma_nextaddr = spi_dma_nextaddr_r;
|
||||
assign spi_dma_nextaddr = spi_dma_nextaddr_r & (spi_dma_bytecnt < 512);
|
||||
assign spi_dma_sram_data = spi_dma_sram_data_r;
|
||||
assign spi_dma_sram_we = spi_dma_sram_we_r;
|
||||
assign spi_dma_sram_we = spi_dma_sram_we_r | (spi_dma_bytecnt > 511);
|
||||
assign spi_dma_done = spi_dma_done_r;
|
||||
assign spi_dma_ovr = spi_dma_ovr_r;
|
||||
|
||||
@@ -86,7 +87,7 @@ always @(posedge clk) begin
|
||||
if (spi_dma_trig_falling & !spi_dma_ovr_r) begin
|
||||
spi_dma_done_r <= 0;
|
||||
spi_dma_ovr_r <= 1;
|
||||
end else if (spi_dma_bitcnt == 0 && spi_dma_bytecnt == 512) begin
|
||||
end else if (spi_dma_bitcnt == 0 && spi_dma_bytecnt == 514) begin
|
||||
spi_dma_done_r <= 1;
|
||||
spi_dma_ovr_r <= 0;
|
||||
end
|
||||
@@ -99,30 +100,33 @@ always @(posedge clk) begin
|
||||
spi_dma_sck_out_r2 <= 1;
|
||||
end
|
||||
|
||||
always @(posedge clk) begin
|
||||
if (spi_dma_sck_rising & spi_dma_ovr_r & spi_dma_bitcnt < 8)
|
||||
spi_dma_sram_data_r <= {spi_dma_sram_data_r[6:0], spi_dma_miso};
|
||||
end
|
||||
// fetch a little later
|
||||
//always @(posedge spi_dma_sck) begin
|
||||
// if (/*spi_dma_sck_rising & */spi_dma_ovr_r & spi_dma_bitcnt <= 8)
|
||||
// spi_dma_sram_data_r <= {spi_dma_sram_data_r[6:0], spi_dma_miso_r[0]};
|
||||
//end
|
||||
|
||||
always @(posedge clk) begin
|
||||
if(spi_dma_sck_rising & spi_dma_ovr_r) begin
|
||||
if (spi_dma_bitcnt < 8) begin
|
||||
spi_dma_sck_out_r <= 1;
|
||||
spi_dma_bitcnt <= spi_dma_bitcnt + 1;
|
||||
spi_dma_sram_data_r <= {spi_dma_sram_data_r[6:0], spi_dma_miso_r[0]};
|
||||
end else if (spi_dma_bitcnt == 8) begin
|
||||
spi_dma_sck_out_r <= 0;
|
||||
spi_dma_bitcnt <= spi_dma_bitcnt + 1;
|
||||
spi_dma_sram_we_r <= 0;
|
||||
spi_dma_sram_data_r <= {spi_dma_sram_data_r[6:0], spi_dma_miso_r[0]};
|
||||
end else if (spi_dma_bitcnt == 9) begin
|
||||
spi_dma_sck_out_r <= 0;
|
||||
spi_dma_sram_we_r <= 1;
|
||||
spi_dma_bytecnt <= spi_dma_bytecnt + 1;
|
||||
spi_dma_sram_we_r <= 0;
|
||||
spi_dma_bitcnt <= 10;
|
||||
end else if (spi_dma_bitcnt == 10) begin
|
||||
spi_dma_sram_we_r <= 1;
|
||||
spi_dma_nextaddr_r <= 1;
|
||||
spi_dma_bitcnt <= spi_dma_bitcnt + 1;
|
||||
end else if (spi_dma_bitcnt == 11) begin
|
||||
spi_dma_nextaddr_r <= 0;
|
||||
spi_dma_bytecnt <= spi_dma_bytecnt + 1;
|
||||
spi_dma_bitcnt <= spi_dma_bitcnt + 1;
|
||||
end else if (spi_dma_bitcnt == 12) begin
|
||||
spi_dma_bitcnt <= 0;
|
||||
@@ -134,7 +138,7 @@ always @(posedge clk) begin
|
||||
end else if (spi_dma_bitcnt == 4'b1111) begin
|
||||
spi_dma_bitcnt <= 0;
|
||||
end
|
||||
end else if (spi_dma_sck_rising & !spi_dma_ovr_r) begin
|
||||
end else if (spi_dma_trig_falling & !spi_dma_ovr_r) begin
|
||||
spi_dma_bitcnt <= 4'b1101;
|
||||
spi_dma_bytecnt <= 10'b0000000000;
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user