Advertisement
Guest User

GD_EMU DMA (OzOnE) 8-12-11

a guest
Dec 9th, 2011
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // Note: "cf_state" normally sits at state 7 after the CF card is initialized... The main GD part of the code kicks off the DMA transfer by setting "cf_state" to 8 after "gd_start_sector" and "gd_sector_count" parameters have been grabbed...
  3.  
  4.  
  5. 8: begin
  6.     cf_lba <= ((gd_start_sector - 32'd45150) * 4) + 32'd45150;  // Need to multiply the sector offset by 4 (starting from the track offset).
  7.     cf_sec_count_32 <= {gd_sector_count[29:0], 2'b00};  // GD-ROM sectors are normally 2048 bytes instead of 512, so need to multiply by 4.
  8.     cf_state <= 10'd9;
  9. end
  10.  
  11. 9: begin
  12.     cf_addr <= 3'h07;               // Select Command / Status reg.
  13.     cf_rd_n_reg <= 1'b0;            // Assert IDE Read...
  14.     if (~cf_data[7] && cf_data[6]) begin // Wait until BUSY bit goes low and DRDY bit goes high...
  15.         cf_rd_n_reg <= 1'b1;            // De-assert IDE Read.
  16.         cf_state <= 10'd10;
  17.     end
  18. end
  19.  
  20. 10: begin
  21.         if (cf_sec_count_32 >= 32'd256) begin
  22.             cf_sec_count <= 8'h00;              // Transfer 256 sectors for this block (CF transfers 256 sectors when sec_count == 0!).
  23.             cf_data_write <= 8'h00;             // Write sector count to drive.
  24.         end
  25.         else begin                                  // Else, 255 (or less) sectors left to transfer...
  26.             cf_sec_count <= cf_sec_count_32[7:0];   // Use lower 8 bits of 32-bit sector count for the CF card (hacky)...
  27.             cf_data_write <= cf_sec_count_32[7:0];  // Write sector count to drive.
  28.         end
  29.     cf_addr <= 3'h02;                       // Select "Sector Count" reg.
  30.     cf_wr_n_reg <= 1'b0;                    // Pulse IDE WRite pin.
  31.     cf_state <= 10'd11;
  32. end
  33.  
  34. 11: begin
  35.     cf_wr_n_reg <= 1'b1;        // De-assert IDE WRite pin (data latched on RISING edge!).
  36.     cf_state <= 10'd12;
  37. end
  38.  
  39. // Next part of code (cf_state 12 to 19) not shown for clarity - all it does it write the LBA values to the CF card. Should be working OK...
  40.  
  41.  
  42. 20: begin
  43.     cf_addr <= 3'h07;               // Select Command / Status reg.
  44.     cf_rd_n_reg <= 1'b0;            // Assert IDE Read...
  45.     cf_state <= 10'd21;
  46. end
  47.  
  48. 21:if (~cf_data[7] && cf_data[6]) begin // Wait until BUSY bit goes low and DRDY bit goes high...
  49.         cf_rd_n_reg <= 1'b1;            // De-assert IDE Read.
  50.         cf_addr <= 3'h07;           // Select Command / Status reg.
  51. //      cf_data_write <= 8'h20;     // Send "Read Sector(s)" (PIO) command.
  52.         cf_data_write <= 8'hC8;     // Send "Read DMA" command.
  53.         cf_wr_n_reg <= 1'b0;        // Pulse IDE WRite pin.
  54.         cf_state <= 10'd22;
  55.     end
  56.  
  57. 22: begin
  58.     cf_wr_n_reg <= 1'b1;        // De-assert IDE WRite pin (data latched on RISING edge!).
  59.     cf_state <= 10'd24;
  60. end
  61.  
  62. 24: //if (cf_dma_rq == 1'b1 && cf_data[3]) begin        // Wait for DRQ (Data ready for transfer) high.
  63.     begin
  64. //  cf_rd_n_reg <= 1'b1;                    // De-assert read.
  65.     cf_wordcount <= 8'd0;                   // Start "cf_wordcount" at zero (will wrap, then decrement after each transfer).
  66.     cf_addr <= 8'h00;                       // Zero the CF address pins (ready for DMA transfer).
  67.     cf_state <= 10'd25;
  68. end
  69.  
  70. 25: begin
  71.         if (gd_rd_falling) begin                            // If "gd_dma_ack_n" is asserted, on rising edge of "gd_rd_n"...
  72.             cf_wordcount <= cf_wordcount + 8'd1;        // Increment word count (WORD just transferred via DMA).
  73.                                                         // Note: "gd_rd_n" drives "cf_rd_n" when "gd_dma_ack_n" is asserted (during DMA!).
  74.             if (cf_wordcount == 8'd255) begin
  75.                 cf_sec_count <= cf_sec_count - 8'd1;        // Decrement sector count when wordcount == 255 (driven by "gd_rd_rising"!)
  76.                 cf_sec_count_32 <= cf_sec_count_32 - 32'd1;
  77.                 cf_lba <= cf_lba + 32'd1;                   // Increment LBA ready for the next block (if there is one!).
  78.             end
  79.         end
  80.  
  81.         if (gd_rd_rising) begin
  82.             if (cf_sec_count == 8'h00) cf_state <= 10'd26;  // Finished current block when sector count is zero...
  83.         end
  84. end
  85.  
  86. 26: if (cf_sec_count_32 == 0) begin     // Have all sectors been transferred?...
  87.         gds_procpacketdone();           // Yes, Will also set "gd_state" back to idle.
  88.         cf_state <= 10'd7;              // All sectors transferred! - back to idle.
  89.     end
  90.     else begin
  91.         cf_state <= 10'd9;              // Still more sectors left to transfer, loop!              
  92.     end
  93.  
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement