Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case (state)
- // *** INIT SD Card / Driver ***
- 0: begin
- sd_rst_i <= 1'b0; // Bring the SD Card driver out of reset (active HIGH)!
- sd_address_i <= `TRANS_TYPE_REG; // Select the SD Transmission Type reg.
- sd_data_i <= `INIT_SD; // Initialize the SD Card.
- sd_we_i <= 1'b1; // WRITE (1).
- sd_strobe_i <= 1'b1; // Select the SD Driver.
- state <= 10'd1;
- end
- 1: if (sd_ack_o) begin // Wait for SD Driver ack (for previous WRITE).
- sd_address_i <= `TRANS_CTRL_REG; // Select the SD Transmission Control reg.
- sd_data_i <= `TRANS_START; // Initialize the SD Card.
- sd_we_i <= 1'b1; // WRITE (1).
- // sd_strobe_i <= 1'b1; // Select the SD Driver. (still set from previous state!)
- state <= 10'd2;
- end
- 2: if (sd_ack_o) begin // Wait for SD Driver ack (for previous WRITE).
- sd_address_i <= `TRANS_STS_REG; // Read the SD Transmission Status reg.
- sd_we_i <= 1'b0; // READ (0).
- // sd_strobe_i <= 1'b1; // Select the SD Driver. (still set from previous state!)
- state <= 10'd3;
- end
- 3: if (sd_ack_o && !(sd_data_o == `TRANS_BUSY)) begin // Wait for SD Driver ack, and check if NOT busy...
- sd_address_i <= `TRANS_ERROR_REG; // Read the SD Transmission Error reg.
- sd_we_i <= 1'b0; // READ (0).
- // sd_strobe_i <= 1'b1; // Select the SD Driver. (still set from previous state!)
- state <= 10'd4;
- end
- 4: if (sd_ack_o) begin // Wait for SD Driver ack (for previous READ).
- if (sd_data_o[1:0] == `INIT_NO_ERROR) begin
- error <= 1'b0;
- sd_strobe_i <= 1'b0; // De-select the SD Driver.
- state <= 5;
- end
- else
- error <= 1'b1;
- end
- // *** IDLE State (wait for "trig_block_read")... ***
- 5: begin
- block_read_done <= 1'b0;
- if (trig_block_read) begin
- gd_bytecount <= gd_sector_count * 2048; // 2048 Bytes per GD sector.
- // gd_bytecount <= 7056000; // TESTING audio streaming !! (20 seconds worth at 44100Hz).
- sd_bytecount <= 32'd0;
- dc_bytecount <= 32'd0;
- // Host_ADDR <= 24'h000000; // Set SDRAM start Address.
- SRAM_ADDR_REG <= 19'h000000; // Set SRAM start Address.
- SRAM_OE_n <= 1'b1; // De-assert SRAM Output Enable (allow writing)!
- // if (CCS) // This should be HIGH if SD Card is SDHC.
- // sd_sector_addr <= (gd_start_sector - 45150) * 4; // SDHC cards use 512-byte SECTOR addressing - Need to multiply the GD sector offset by 4.
- // else
- sd_sector_addr <= (gd_start_sector - 45150) * 2048; // Low-density SD Cards use BYTE addressing - Need to multiply the GD sector offset by 2048.
- sd_address_i <= `SD_ADDR_31_24_REG; // Select the SD Sector Address reg (bits 31:24).
- sd_data_i <= sd_sector_addr[31:24]; // Set the address bits.
- sd_we_i <= 1'b1; // WRITE (1).
- sd_strobe_i <= 1'b1; // Select the SD Driver.
- state <= 10'd6;
- end
- end
- 6: if (sd_ack_o) begin // Wait for SD Driver ack (for previous WRITE).
- sd_address_i <= `SD_ADDR_23_16_REG; // Select the SD Sector Address reg (bits 23:16).
- sd_data_i <= sd_sector_addr[23:16]; // Set the address bits.
- sd_we_i <= 1'b1; // WRITE (1).
- sd_strobe_i <= 1'b1; // Select the SD Driver.
- state <= 10'd7;
- // state <= 10'd12; // TESTING audio streaming !!
- end
- 7: if (sd_ack_o) begin // Wait for SD Driver ack (for previous WRITE).
- sd_address_i <= `SD_ADDR_15_8_REG; // Select the SD Sector Address reg (bits 15:8).
- sd_data_i <= sd_sector_addr[15:8]; // Set the address bits.
- sd_we_i <= 1'b1; // WRITE (1).
- sd_strobe_i <= 1'b1; // Select the SD Driver.
- state <= 10'd8;
- end
- 8: if (sd_ack_o) begin // Wait for SD Driver ack (for previous WRITE).
- sd_address_i <= `SD_ADDR_7_0_REG; // Select the SD Sector Address reg (bits 7:0).
- sd_data_i <= sd_sector_addr[7:0]; // Set the address bits.
- sd_we_i <= 1'b81; // WRITE (1).
- sd_strobe_i <= 1'b1; // Select the SD Driver.
- state <= 10'd9;
- end
- 9: if (sd_ack_o) begin // Wait for SD Driver ack (for previous WRITE).
- sd_address_i <= `SD_ADDR_7_0_REG; // Select the SD Sector Address reg (bits 7:0).
- sd_data_i <= sd_sector_addr[7:0]; // Set the address bits.
- sd_we_i <= 1'b1; // WRITE (1).
- sd_strobe_i <= 1'b1; // Select the SD Driver.
- state <= 10'd10;
- end
- 10: if (sd_ack_o) begin // Wait for SD Driver ack (for previous WRITE).
- sd_address_i <= `TRANS_TYPE_REG; // Select the SD Transmission Type reg.
- sd_data_i <= `RW_READ_SD_BLOCK; // "Block Read" command.
- sd_we_i <= 1'b1; // WRITE (1).
- sd_strobe_i <= 1'b1; // Select the SD Driver.
- state <= 10'd11;
- end
- 11: if (sd_ack_o) begin // Wait for SD Driver ack (for previous WRITE).
- sd_address_i <= `TRANS_CTRL_REG; // Select the SD Transmission Control reg.
- sd_data_i <= `TRANS_START; // Transmit the command.
- sd_we_i <= 1'b1; // WRITE (1).
- sd_strobe_i <= 1'b1; // Select the SD Driver.
- state <= 10'd12;
- end
- 12: if (sd_ack_o && sd_data_o !== `TRANS_BUSY) begin // Wait for SD Driver ack, and check if NOT busy...
- sd_address_i <= `TRANS_ERROR_REG; // Read the SD Transmission Error reg.
- sd_we_i <= 1'b0; // READ (0).
- // sd_strobe_i <= 1'b1; // Select the SD Driver. (still set from previous state!)
- state <= 10'd13;
- end
- 13: if (sd_ack_o) begin // Wait for SD Driver ack (for previous READ), and check if NOT busy...
- if (sd_data_o[3:2] == `READ_NO_ERROR) begin
- error <= 1'b0;
- sd_strobe_i <= 1'b0; // De-select the SD Driver.
- state <= 14;
- end
- else
- error <= 1'b1;
- end
- 14: begin
- end
- // Grab the MSB Byte from SD Card...
Advertisement
Add Comment
Please, Sign In to add comment