Subversion Repositories ngs

Rev

Rev 97 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

  1. // part of NeoGS project
  2. //
  3. // (c) NedoPC 2007-2013
  4. //
  5. // this is dma "one-shot" fifo: after each 512 bytes both written and read back, it must be initialized by means of 'init'
  6. //
  7.  
  8. module dma_fifo_oneshot(
  9.  
  10.         input  wire clk,
  11.         input  wire rst_n,
  12.  
  13.         input  wire wr_stb, // write strobe: writes data from wd to the current wptr, increments wptr
  14.         input  wire rd_stb, // read strobe: increments rptr
  15.  
  16.         output wire wdone, // write done - all 512 bytes are written (end of write operation)
  17.         output wire w511,  // write almost done -- at address 511
  18.         output wire rdone, // read done - all 512 bytes are read (end of read operation)
  19.         output wire empty, // fifo empty: when wptr==rptr (rd_stb must not be issued when empty is active, otherwise everytrhing desyncs)
  20.  
  21.         input  wire [7:0] wd, // data to be written
  22.         output wire [7:0] rd  // data just read from rptr address
  23. );
  24.  
  25.         reg [9:0] wptr;
  26.         reg [9:0] rptr;
  27.  
  28.         always @(posedge clk, negedge rst_n)
  29.         if( !rst_n )
  30.                 wptr = 10'd0;
  31.         else if( wr_stb )
  32.                 wptr <= wptr + 10'd1;
  33.  
  34.         assign w511 = &wptr[8:0];
  35.  
  36.         always @(posedge clk, negedge rst_n)
  37.         if( !rst_n )
  38.                 rptr = 10'd0;
  39.         else if( rd_stb )
  40.                 rptr <= rptr + 10'd1;
  41.  
  42.         assign wdone = wptr[9];
  43.         assign rdone = rptr[9];
  44.         assign empty = ( wptr==rptr );
  45.  
  46.  
  47.  
  48.         mem512b fifo512_oneshot_mem512b
  49.         (
  50.                 .clk(clk),
  51.  
  52.                 .rdaddr(rptr[8:0]),
  53.                 .dataout(rd),
  54.                 .re(rd_stb),
  55.  
  56.                 .wraddr(wptr[8:0]),
  57.                 .datain(wd),
  58.                 .we(wr_stb)
  59.         );
  60.  
  61.  
  62. endmodule
  63.  
  64.