Guest User

gd control 16-7-12 OzOnE

a guest
Jul 15th, 2012
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VeriLog 16.92 KB | None | 0 0
  1. module control (
  2.     SYSCLK, SDRAM_CLK_100M, RST_n,
  3.     gd_sector_type, gd_start_sector, gd_sector_count, trig_block_read, block_dma_done,
  4.     sector_data,
  5.     cont_dma_rq, gd_dma_ack_n, gd_rd_n,
  6.    
  7.     SRAM_ADDR,
  8.     SRAM_OE_n,
  9.     SRAM_WE_n,
  10.     SRAM_DATA,
  11.    
  12.     SDRAM_CLK,//connected to the clk port of SDRAM
  13.     SDRAM_CKE,//connected to the cke port of SDRAM
  14.     SDRAM_CS_n,//connected to the CS_n port of SDRAM
  15.     SDRAM_RAS_n,//connected to the RAS_n port of SDRAM
  16.     SDRAM_CAS_n,//connected to the CAS_n port of SDRAM
  17.     SDRAM_WE_n,//connected to the WE_n port of SDRAM
  18.     SDRAM_DQM,//connected to the LDQM port of SDRAM
  19.     SDRAM_BA,//connected to the BA port of SDRAM
  20.     SDRAM_ADDR,//connected to the ADDR port of SDRAM
  21.     SDRAM_DQ,//connected to the DQ port of SDRAM
  22.     SD_CS_n, SD_CLK, SD_DATA_IN, SD_DATA_OUT,
  23.     AUD_BCLK,AUD_DACLRC,AUD_DACDAT,
  24.     SEG_S, SEG,
  25.     USB_TXE_n, USB_RXF_n, USB_RD_n, USB_WR, USB_DATA,
  26.     error);
  27.  
  28.     input SYSCLK;
  29.     input SDRAM_CLK_100M;
  30.  
  31.     input RST_n;
  32.  
  33.     output wire [18:0] SRAM_ADDR = (cont_dma_rq) ? DMA_ADDR : SRAM_ADDR_REG;
  34.     output reg SRAM_WE_n;
  35.     inout wire [15:0] SRAM_DATA = (!SRAM_WE_n) ? SRAM_DATA_WRITE : 19'hzzzzz;
  36.  
  37.     reg [18:0] DMA_ADDR;
  38.     reg [18:0] SRAM_ADDR_REG;
  39.     reg [15:0] SRAM_DATA_WRITE;
  40.  
  41.  
  42. //  output wire SRAM_OE_n = (SRAM_WE_n) ? 1'b0 : 1'b1;      // Assert SRAM OE if SRAM_WE_n is NOT asserted!
  43.     output reg SRAM_OE_n;
  44.  
  45.     input wire AUD_BCLK;
  46.     input wire AUD_DACLRC;
  47.     output wire AUD_DACDAT;
  48.  
  49.     input USB_TXE_n;
  50.     input USB_RXF_n;
  51.     output reg USB_RD_n;
  52.     output reg USB_WR;
  53.     inout [7:0] USB_DATA;
  54.  
  55.     output [3:0] SEG_S;
  56.     output [7:0] SEG;
  57.    
  58.     output reg error;
  59.  
  60. // SDRAM pins and stuff...
  61.     output SDRAM_CLK = SDRAM_CLK_100M;
  62.     output SDRAM_CKE;
  63.     output SDRAM_CS_n;
  64.     output SDRAM_RAS_n;
  65.     output SDRAM_CAS_n;
  66.     output SDRAM_WE_n;
  67.     output [1: 0] SDRAM_DQM;
  68.     output [1 :0] SDRAM_BA;
  69.     output [12:0] SDRAM_ADDR;
  70.     inout  [15:0] SDRAM_DQ;
  71.  
  72. //  wire [1:0] Host_DQM = 2'b00;
  73. //  wire [8:0] Host_Burst_Length = 2'b00;
  74.  
  75.     reg [23:0] Host_ADDR;           // SDRAM Address.
  76.  
  77.     reg Host_RD0_WR1;               // SDRAM Read / Write mode.
  78.     reg SDRAM_trig_Host_command;
  79.  
  80.     reg SDRAM_Tx_fifo_clear;
  81.     reg SDRAM_Tx_fifo_wrreq;
  82.     reg [15:0] SDRAM_Tx_fifo_data;
  83.  
  84.     input wire [11:0] gd_sector_type;
  85.     input wire [31:0] gd_start_sector;
  86.     input wire [31:0] gd_sector_count;
  87.    
  88.     reg [31:0] gd_bytecount;        // Storage for bytecount, for current block of sector(s).
  89.  
  90.     reg [31:0] sd_bytecount/* synthesis noprune */;
  91.     reg [31:0] dc_bytecount/* synthesis noprune */;
  92.  
  93.     input trig_block_read;
  94.     output reg block_dma_done;
  95.    
  96. //  output reg [15:0] sector_data;
  97.  
  98.     output wire [15:0] sector_data = SRAM_DATA;
  99.  
  100.     output reg cont_dma_rq;     // When we're ready with the sector data, we assert "cont_dma_rq" (active high)...
  101.  
  102.     input gd_dma_ack_n;         // The Dreamcast will setup the IDE bus for DMA transfer, then assert "gd_dma_ack_n" (active low) when
  103.                                 // it's ready to receive the sector data.
  104.                                
  105.     input gd_rd_n;              // We need this signal for counting the word transfers during DMA.
  106.  
  107. // SD interface pins and regs...
  108.     output SD_CS_n;
  109.     output SD_CLK;
  110.     input  SD_DATA_IN;
  111.     output SD_DATA_OUT;
  112.    
  113.     reg sd_rst_n;
  114.    
  115.     reg [2:0] Host_Command_Type;
  116.     reg [31:0] Host_Command_Arg;
  117.     reg trig_Host_Command;
  118.    
  119.     reg stop_mbr;       // My new signal for manually stopping the SD card Multiple Block Read.
  120.    
  121.     reg Rx_fifo_sclr;
  122.     reg Rx_fifo_rdrq;
  123.     reg Tx_fifo_wrrq;
  124.    
  125.     reg [9:0] state/* synthesis noprune */;
  126.  
  127.   parameter [2:0]//the definition of CMD Type
  128.     CMD_Single_Block_Read     = 3'b000,
  129.     CMD_Single_Block_Write    = 3'b001,
  130.     CMD_Multiple_Block_Read   = 3'b010,
  131.     CMD_Multiple_Block_Write  = 3'b011,
  132.     CMD_Erase                 = 3'b100,
  133.     CMD_Pre_Erase             = 3'b101,
  134.     CMD_Read_CSD_CID_Rigister = 3'b110;
  135.  
  136. // GD Interface pins and regs...
  137. //  reg gd_wr_n_1, gd_wr_n_2;   // Flip-flops for detecting async edges.
  138.     reg gd_rd_n_1, gd_rd_n_2;
  139.  
  140. //  wire gd_wr_rising = gd_wr_n_1 & ~gd_wr_n_2;
  141.     wire gd_rd_rising = gd_rd_n_1 & ~gd_rd_n_2;
  142.    
  143.     reg cont_dma_rq_1, cont_dma_rq_2;
  144.     wire cont_dma_rq_rising = cont_dma_rq_1 & ~cont_dma_rq_2;
  145.  
  146.     reg gd_dma_ack_n_1, gd_dma_ack_n_2;
  147.     wire gd_dma_ack_n_rising = gd_dma_ack_n_1 & ~gd_dma_ack_n_2;
  148.  
  149. //  wire gd_wr_falling = ~gd_wr_n_1 & gd_wr_n_2;
  150.     wire gd_rd_falling = ~gd_rd_n_1 & gd_rd_n_2;
  151.  
  152. initial begin
  153.     gd_bytecount <= 32'd0;  // Storage for requested bytecount, for current block of sector(s).
  154.  
  155.     sd_bytecount <= 32'd0;  // BYTE count from SD Card to SRAM.
  156.     dc_bytecount <= 32'd0;  // BYTE count from SRAM to DC.
  157.    
  158.     stop_mbr <= 1'b0;
  159.  
  160.     az_rd_n_reg <= 1'b1;        // De-assert SDRAM block Read at power up! (active low)
  161.     az_wr_n_reg <= 1'b1;        // De-assert SDRAM block WRite at power up! (active low)
  162.  
  163.     SDRAM_Rx_fifo_rdreq <= 1'b0;
  164.     SDRAM_Rx_fifo_wrreq <= 1'b0;
  165.     SDRAM_Rx_fifo_sclr <= 1'b0;
  166.  
  167.     cont_dma_rq <= 1'b0;
  168.     block_dma_done <= 1'b0;
  169.    
  170.     trig_Host_Command <= 1'b0;
  171.        
  172.     sd_rst_n <= 1'b0;       // Reset the SD Card driver.
  173.        
  174.     Rx_fifo_sclr <= 1'b0;
  175.     Rx_fifo_rdrq <= 1'b0;
  176.     Tx_fifo_wrrq <= 1'b0;
  177.    
  178.     USB_RD_n <= 1'b1;
  179.     USB_WR <= 1'b0;
  180.    
  181.     SRAM_ADDR_REG <= 19'b0;
  182.     SRAM_OE_n <= 1'b1;          // De-assert SRAM Output Enable!
  183.     SRAM_WE_n <= 1'b1;          // De-assert SRAM Write Enable!
  184.    
  185.     error <= 1'b0;
  186. end
  187.  
  188. /*
  189. always @(posedge cont_dma_rq_rising or posedge gd_rd_falling)
  190. begin
  191.     if (cont_dma_rq_rising) begin
  192. //      DMA_ADDR <= 19'b1111111111111111111;    // Intentional wrap-around, so DMA_ADDR starts at zero on first falling edge of "gd_rd_n".
  193.         dc_bytecount <= 32'hFFFFFFFE;           // Intentional wrap-around, so "dc_bytecount" starts at zero on first falling edge of "gd_rd_n".
  194.     end
  195.     else if (gd_rd_falling)
  196.     begin
  197. //      DMA_ADDR <= DMA_ADDR + 1;               // negedge of "gd_rd_n".
  198.         dc_bytecount <= dc_bytecount + 2;   // Remember, a WORD is transferred from SRAM !!!
  199.     end
  200. end
  201.  
  202. assign DMA_ADDR = dc_bytecount[31:1];
  203. */
  204.  
  205. always @(posedge SYSCLK or negedge RST_n)
  206.     if (!RST_n) begin
  207.         state <= 10'd0;
  208.        
  209.         sd_bytecount <= 32'd0;  // BYTE count from SD Card to SRAM.
  210.         dc_bytecount <= 32'd0;  // BYTE count from SRAM to DC.
  211.        
  212.         gd_bytecount <= 32'd0;  // Storage for requested bytecount, for current block of sector(s).
  213.        
  214.         stop_mbr <= 1'b0;
  215.  
  216.         az_rd_n_reg <= 1'b1;        // De-assert SDRAM block Read! (active low)
  217.         az_wr_n_reg <= 1'b1;        // De-assert SDRAM block WRite! (active low)
  218.  
  219.         SDRAM_Rx_fifo_rdreq <= 1'b0;
  220.         SDRAM_Rx_fifo_wrreq <= 1'b0;
  221.         SDRAM_Rx_fifo_sclr <= 1'b0;
  222.  
  223.         cont_dma_rq <= 1'b0;
  224.         block_dma_done <= 1'b0;
  225.  
  226.         trig_Host_Command <= 1'b0;
  227.        
  228.         sd_rst_n <= 1'b0;       // Reset the SD Card driver.
  229.        
  230.         Rx_fifo_sclr <= 1'b0;
  231.         Rx_fifo_rdrq <= 1'b0;
  232.         Tx_fifo_wrrq <= 1'b0;
  233.        
  234.         USB_RD_n <= 1'b1;
  235.         USB_WR <= 1'b0;
  236.  
  237.         SRAM_ADDR_REG <= 19'b0;
  238.         SRAM_OE_n <= 1'b1;          // De-assert SRAM Output Enable!
  239.         SRAM_WE_n <= 1'b1;          // De-assert SRAM Write Enable!
  240.    
  241.         error <= 1'b0;
  242.     end
  243.     else begin
  244.  
  245.     gd_rd_n_1 <= gd_rd_n;       // Update edge regs on every clock.
  246.     gd_rd_n_2 <= gd_rd_n_1;
  247.  
  248.     cont_dma_rq_1 <= cont_dma_rq;
  249.     cont_dma_rq_2 <= cont_dma_rq_1;
  250.    
  251.     gd_dma_ack_n_1 <= gd_dma_ack_n;
  252.     gd_dma_ack_n_2 <= gd_dma_ack_n_1;
  253.  
  254.     case (state)
  255.             0: begin
  256.                 if (Error_Occur) error <= 1'b1;
  257.  
  258.                 block_dma_done <= 1'b0;
  259.                 cont_dma_rq <= 1'b0;
  260.                
  261.                 stop_mbr <= 1'b0;
  262.  
  263.                 sd_rst_n <= 1'b1;       // Bring the SD Card driver out of reset!
  264.                 Rx_fifo_sclr <= 1'b1;   // Clear the SD Card receive FIFO.
  265.  
  266.                 if (!trig_block_read) state <= 10'd1;   // Make sure "trig_block_read" is low before starting!
  267. //              state <= 10'd1;             // TESTING audio streaming !!
  268.             end
  269.  
  270.             1: begin
  271.                 Rx_fifo_sclr <= 1'b0;
  272.                 Rx_fifo_rdrq <= 1'b0;       // Sanity check.
  273.  
  274.                 if (trig_block_read) state <= 10'd2;
  275.  
  276. //              Host_Command_Arg <= 32'd0;  // TESTING audio streaming !!
  277. //              state <= 10'd2;             // TESTING audio streaming !!
  278.             end
  279.  
  280.             2: if (!SD_driver_busy) begin
  281.                 gd_bytecount <= gd_sector_count * 2048; // 2048 Bytes per GD sector.
  282.  
  283. //              gd_bytecount <= 7056000;                // TESTING audio streaming !! (20 seconds worth at 44100Hz).
  284.  
  285.                 sd_bytecount <= 32'd0;
  286.                 dc_bytecount <= 32'd0;
  287.  
  288. //              Host_ADDR <= 24'h000000;        // Set SDRAM start Address.
  289.    
  290.                 SRAM_ADDR_REG <= 19'h000000;        // Set SRAM start Address.
  291.  
  292.             if (CCS)    // This should be HIGH if SD Card is SDHC.
  293.                 Host_Command_Arg <= (gd_start_sector - 45150) * 4;  // SDHC cards use 512-byte SECTOR addressing - Need to multiply the GD sector offset by 4.
  294.             else
  295.                 Host_Command_Arg <= (gd_start_sector - 45150) * 2048;   // Low-density SD Cards use BYTE addressing - Need to multiply the GD sector offset by 2048.
  296.  
  297.                 Host_Command_Type <= CMD_Multiple_Block_Read;
  298.                 trig_Host_Command <= 1'b1;
  299.                
  300.                 state <= 10'd3;
  301.             end
  302.  
  303.             3: begin
  304.                 trig_Host_Command <= 1'b0;      // Remember to only strobe "trig_Host_command" for ONE clock!!
  305.                 state <= 10'd4;
  306.             end
  307.  
  308.             4: if (Rx_fifo_almost_full) begin       // Wait until SD Card Rx FIFO is almost full before starting DMA.
  309.  
  310.                 Rx_fifo_rdrq <= 1'b1;               // SKIP first byte from SD Card! ???
  311.                 state <= 10'd5;
  312.             end
  313.  
  314.             5: begin
  315.                 Rx_fifo_rdrq <= 1'b0;
  316.  
  317.                 state <= 10'd6;
  318. //              state <= 10'd12;                // TESTING audio streaming !!
  319.             end
  320.  
  321.             6: if (!Rx_fifo_empty) begin
  322.                     Rx_fifo_rdrq <= 1'b1;
  323.                     state <= 10'd7;
  324.                 end
  325.  
  326. // Grab the MSB Byte from SD Card...
  327.             7: begin                                        // SD Card Rx FIFO should contain some bytes at this point!
  328.                 SRAM_DATA_WRITE[15:8] <= Rx_fifo_q;         // Read MSB byte from SD Card into SRAM data reg. (don't write yet!)
  329.                 sd_bytecount <= sd_bytecount + 1'b1;        // Increment SD Card byte count.
  330.                
  331.                 Rx_fifo_rdrq <= 1'b0;                       // De-assert SD Card FIFO Read ReQuest.
  332.                 state <= 10'd8;
  333.             end
  334.  
  335.             8: if (!Rx_fifo_empty) begin
  336.                     Rx_fifo_rdrq <= 1'b1;
  337.                     state <= 10'd9;
  338.                 end
  339.  
  340. // Grab the LSB Byte from SD Card...
  341.             9: begin
  342.                 SRAM_DATA_WRITE[7:0] <= Rx_fifo_q;          // Read LSB byte from SD Card into SRAM data reg...
  343.                 sd_bytecount <= sd_bytecount + 1'b1;        // Increment byte count.
  344.  
  345.                 SRAM_WE_n <= 1'b0;                          // Write the WORD to SRAM...
  346.  
  347.                 Rx_fifo_rdrq <= 1'b0;                       // De-assert SD Card FIFO Read ReQuest.
  348.                 state <= 10'd10;
  349.             end
  350.  
  351.             10: begin
  352.                 SRAM_WE_n <= 1'b1;                          // De-assert SRAM Write Enable (Data is latched on RISING edge).
  353.        
  354.                 if (sd_bytecount == gd_bytecount) begin     // Check if all bytes / words transferred from SD Card to SRAM...
  355.                     DMA_ADDR <= 19'h00000;                  // Let DC start reading from start of SRAM.
  356.                     SRAM_OE_n <= 1'b0;                      // Assert SRAM Output Enable!
  357.                     state <= 10'd11;
  358.                 end
  359.                 else begin                                  // Else, keep reading in bytes from SD.
  360.                     SRAM_ADDR_REG <= SRAM_ADDR_REG + 1'b1;
  361.                     state <= 10'd6;
  362.                 end
  363.             end
  364.  
  365.             11: begin
  366.                 cont_dma_rq <= 1'b1;            // Start the DMA transfer.
  367.  
  368.                 if (gd_rd_falling) begin    // Skip first falling edge! (so SRAM / DMA addr starts at zero!)
  369.                     dc_bytecount <= dc_bytecount + 2'd2;    // Inc "dc_bytecount" anyway (so it's not zero-based)
  370.                     state <= 10'd12;
  371.                 end
  372.             end
  373.  
  374.             12: begin
  375.                 if (gd_rd_falling) begin    // If "gd_rd_n" is asserted...
  376.                     DMA_ADDR <= DMA_ADDR + 1'b1;
  377.                     dc_bytecount <= dc_bytecount + 2'd2;    // Remember, a WORD is transferred from SRAM !!!
  378.                 end
  379.  
  380.                 // NOTE: Byte / Word counting definitely does NOT work reliably when running at 100MHz SYSCLK! 50MHz seems better. OzOnE.
  381.                 if (gd_dma_ack_n_rising && !(dc_bytecount[4:0] == 5'b00000) ) begin // "dc_bytecount" should be multiple of 32 when "gd_dma_ack_n" goes high!
  382.                     error <= 1'b1;
  383.                     sd_bytecount <= dc_bytecount;   // DEBUG - Use "sd_bytecount" to store the position (ie. the chunk of 16 Words) where the error occured.
  384.                 end
  385.  
  386.                 if (dc_bytecount == gd_bytecount) begin     // Have all Words / Sectors been transferred?...
  387.                     state <= 10'd13;
  388.                 end
  389.             end
  390.  
  391. // Finish the DMA transfer...
  392.             13: if (gd_dma_ack_n) begin     // Wait for DC to de-assert "gd_dma_ack_n" (HIGH).
  393.                 cont_dma_rq <= 1'b0;        // Finish DMA transfer!
  394.                 block_dma_done <= 1'b1;     // Tell the GD_EMU block that we're finished.
  395.                
  396.                 SRAM_OE_n <= 1'b1;          // De-assert SRAM Output Enable.
  397.  
  398.                 stop_mbr <= 1'b1;
  399.                 sd_rst_n <= 1'b0;           // Reset the SD Card driver.
  400.                 Rx_fifo_rdrq <= 1'b0;       // Sanity check.
  401.  
  402.                 state <= 10'd0;             // All Words transferred! - back to idle.
  403.             end
  404.  
  405.  
  406.     default: state <= 10'd1;
  407.     endcase
  408. end     // End for main loop!
  409.  
  410.  
  411. wire Tx_fifo_sclr;
  412. wire [7:0] Tx_fifo_data;
  413. wire Tx_fifo_empty;
  414. wire Tx_fifo_full;
  415. wire [7:0] Rx_fifo_q;
  416. wire Rx_fifo_almost_empty;
  417. wire Rx_fifo_empty;
  418. wire Rx_fifo_almost_full;
  419. wire Rx_fifo_full;
  420. wire [8:0] Rx_fifo_usedw;
  421. wire CCS;
  422. wire SD_driver_busy;
  423. wire Error_Occur;
  424.  
  425.   SD_Card_driver U_SD_Card_driver(
  426.     .CLK50M(SYSCLK),//Main clock
  427.     .RST_n(sd_rst_n),//reset signal
  428.    
  429.     .trig_Host_Command(trig_Host_Command),//Used for the host to trig a command,synchronous to "SYSCLK"
  430.     .Host_Command_Type(Host_Command_Type),//Express the command type,synchronous to "SYSCLK"
  431.     .Host_Command_Arg(Host_Command_Arg),//The argument of a certain command(if needed),synchronous to "SYSCLK"
  432.     .Tx_fifo_sclr(Tx_fifo_sclr),//the Host's synchronous clear to the Tx_fifo,synchronous to "SYSCLK"
  433.     .Tx_fifo_wrrq(Tx_fifo_wrrq),//the Host's write require to the Tx_fifo,synchronous to "SYSCLK"
  434.     .Tx_fifo_data(Tx_fifo_data),//the Host's write data to the Tx_fifo,synchronous to "SYSCLK"
  435.     .Tx_fifo_empty(Tx_fifo_empty),//output signal to tell the Host that the Tx_fifo is empty,synchronous to "SYSCLK"
  436.     .Tx_fifo_full(Tx_fifo_full),//output signal to tell the Host that the Tx_fifo is full,synchronous to "SYSCLK"
  437.     .Rx_fifo_sclr(Rx_fifo_sclr),//the Host's synchronous clear to the Rx_fifo,synchronous to "SYSCLK"
  438.     .Rx_fifo_rdrq(Rx_fifo_rdrq),//the Host's read require to the Rx_fifo,synchronous to "SYSCLK"
  439.     .Rx_fifo_q(Rx_fifo_q),//the Rx_fifo output data to the Host,synchronous to "SYSCLK"
  440.     .Rx_fifo_almost_empty(Rx_fifo_almost_empty),
  441.     .Rx_fifo_empty(Rx_fifo_empty),//output signal to tell the Host that the Rx_fifo is empty,synchronous to "SYSCLK"
  442.     .Rx_fifo_almost_full(Rx_fifo_almost_full),
  443.     .Rx_fifo_full(Rx_fifo_full),//output signal to tell the Host that the Rx_fifo is full,synchronous to "SYSCLK"
  444.     .Rx_fifo_usedw(Rx_fifo_usedw),
  445.    
  446.     .stop_mbr(stop_mbr),
  447.    
  448.     .SD_CS_n(SD_CS_n),//
  449.     .SD_CLK(SD_CLK),//
  450.     .SD_DATA_IN(SD_DATA_IN),//
  451.     .SD_DATA_OUT(SD_DATA_OUT),//
  452.    
  453.     .CCS(CCS),
  454.     .SD_driver_busy(SD_driver_busy),
  455.     .Error_Occur(Error_Occur)
  456.   );
  457.  
  458.  
  459.  
  460. wire SDRAM_BUSY;
  461. wire SDRAM_data_valid;
  462. wire [15:0] SDRAM_RD_data;
  463.  
  464. reg [15:0] az_data;
  465. reg az_rd_n_reg;
  466. reg az_wr_n_reg;
  467. wire [12:0] SDRAM_ADDR;
  468.  
  469.   sdram sdram_inst
  470. (                                       // ** Control inputs to SDRAM block. **
  471.     .az_addr(Host_ADDR) ,               // input [23:0] az_addr
  472.     .az_be_n(2'b00) ,                   // input [1:0] az_be_n
  473.     .az_cs(1'b1) ,                      // input  az_cs
  474.     .az_data(az_data) ,                 // input [15:0] az_data FROM SD Card.
  475.     .az_rd_n(az_rd_n_reg) ,             // input  az_rd_n
  476.     .az_wr_n(az_wr_n_reg) ,             // input  az_wr_n
  477.  
  478.                                         // ** Clock and reset for SDRAM (controller!) **
  479.     .clk(SYSCLK) ,                      // input  clk
  480.     .reset_n(RST_n) ,                   // input  reset_n
  481.  
  482.                                         // ** Control outputs from SDRAM block. **
  483.     .za_data(SDRAM_RD_data) ,           // output [15:0] za_data TO Rx FIFO.
  484.     .za_valid(SDRAM_data_valid) ,       // output  za_valid
  485.     .za_waitrequest(SDRAM_BUSY) ,       // output  za_waitrequest
  486.  
  487.                                         // ** Connections to SDRAM itself. **
  488.     .zs_addr(SDRAM_ADDR) ,                  // output [12:0] zs_addr
  489.     .zs_ba(SDRAM_BA) ,                      // output [1:0] zs_ba
  490.     .zs_cas_n(SDRAM_CAS_n) ,                // output  zs_cas_n
  491.     .zs_cke(SDRAM_CKE) ,                    // output  zs_cke
  492.     .zs_cs_n(SDRAM_CS_n) ,                  // output  zs_cs_n
  493.     .zs_dq(SDRAM_DQ) ,                      // inout [15:0] zs_dq
  494.     .zs_dqm(SDRAM_DQM) ,                    // output [1:0] zs_dqm
  495.     .zs_ras_n(SDRAM_RAS_n) ,                // output  zs_ras_n
  496.     .zs_we_n(SDRAM_WE_n)                    // output  zs_we_n
  497. );
  498.  
  499.  
  500. reg SDRAM_Rx_fifo_rdreq;
  501. reg SDRAM_Rx_fifo_sclr;
  502. reg SDRAM_Rx_fifo_wrreq;
  503. wire SDRAM_Rx_fifo_empty;
  504. wire SDRAM_Rx_fifo_full;
  505. wire [15:0] SDRAM_Rx_data;
  506. wire [8:0] SDRAM_Rx_used;
  507. SDRAM_Rx_fifo sdram_rx_fifo_inst
  508. (
  509.     .clock(SYSCLK),
  510.     .data(SDRAM_RD_data),           // Input data FROM SDRAM.
  511.     .rdreq(SDRAM_Rx_fifo_rdreq),
  512.     .sclr(SDRAM_Rx_fifo_sclr),
  513.     .wrreq(SDRAM_Rx_fifo_wrreq),
  514.     .empty(SDRAM_Rx_fifo_empty),
  515.     .full(SDRAM_Rx_fifo_full),
  516.     .q(SDRAM_Rx_data),              // Output data TO DC.
  517.     .usedw(SDRAM_Rx_used)
  518. );
  519.  
  520.  
  521. reg [15:0] DAC_Left_channel_data;
  522. reg [15:0] DAC_Right_channel_data;
  523. wire [31:0] DAC_fifo_data = {DAC_Left_channel_data ,DAC_Right_channel_data};
  524.  
  525. reg DAC_fifo_wrreq;
  526. wire DAC_fifo_empty;
  527. wire DAC_fifo_full;
  528. Audio_DAC_DSP_Control Audio_DAC_DSP_Control_inst (
  529.    .CLK50M(SYSCLK),
  530.    .RST_n(RST_n),
  531.    
  532.    .BCLK(AUD_BCLK),
  533.    .DACLRC(AUD_DACLRC),
  534.    .DACDAT(AUD_DACDAT),
  535.    
  536.    .DAC_fifo_wrreq(DAC_fifo_wrreq),
  537.    .DAC_fifo_data(DAC_fifo_data),
  538.    .DAC_fifo_empty(DAC_fifo_empty),
  539.    .DAC_fifo_full(DAC_fifo_full)
  540. );
  541.  
  542. //wire [15:0] seg_data = dc_bytecount[15:0];    // Note, can only see 16-bits on 7-SEG display!
  543. wire [15:0] seg_data = {Rx_fifo_usedw[8:0], state[6:0]};    // Note, can only see 16-bits on 7-SEG display!
  544. wire [3:0] dp = 4'b0;
  545.   DYN_SEG U_DYN_SEG(
  546.     .clk(SYSCLK),
  547.     .data(seg_data),
  548.     .dp(dp),
  549.     .SEG_S(SEG_S),
  550.     .SEG(SEG)
  551.   );
  552.  
  553. endmodule
Advertisement
Add Comment
Please, Sign In to add comment