Subversion Repositories pentevo

Rev

Rev 4 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. `include "../include/tune.v"
  2.  
  3. module drammem(
  4.         input   [9:0] ma,
  5.         inout [15:0] d,
  6.         input ras_n,
  7.         input ucas_n,
  8.         input lcas_n,
  9.         input we_n
  10. );
  11.  
  12.         parameter _verbose_ = 1;
  13.         parameter _add_to_addr_ = 0;
  14.         parameter _filter_out_ = 32'h91;
  15.  
  16.         reg [15:0] array [0:1048575];
  17.         reg [15:0] dout;
  18.  
  19.         reg [19:0] addr;
  20.  
  21.         wire cas_n;
  22.  
  23.         wire idle;
  24.  
  25.         reg was_ras;
  26.         reg was_cas;
  27.         reg ready;
  28.  
  29.  
  30.  
  31.         initial
  32.         begin : clear_mem
  33.                 integer i;
  34.  
  35.                 for(i=0;i<1048576;i=i+1)
  36.                         array[i] = 16'hDEAD;
  37.         end
  38.  
  39.  
  40.  
  41.  
  42.  
  43.         always @(negedge ras_n)
  44.                 addr[9:0] <= ma[9:0];
  45.  
  46.         assign cas_n = ucas_n & lcas_n;
  47.         always @(negedge cas_n)
  48.         begin
  49.                 addr[19:10] <= ma[9:0];
  50.         end
  51.  
  52.         always @(posedge cas_n, negedge cas_n)
  53.                 ready <= ~cas_n; // to introduce delta-cycle in ready to allow capturing of CAS address before proceeding data
  54.  
  55.  
  56.         assign idle = ras_n & cas_n;
  57.  
  58.         always @(negedge ras_n, posedge idle)
  59.         begin
  60.                 if( idle )
  61.                         was_ras <= 1'b0;
  62.                 else // negedge ras_n
  63.                         was_ras <= 1'b1;
  64.         end
  65.  
  66.         always @(negedge cas_n, posedge idle)
  67.         begin
  68.                 if( idle )
  69.                         was_cas <= 1'b0;
  70.                 else
  71.                         if( was_ras )
  72.                                 was_cas <= 1'b1;
  73.         end
  74.  
  75.  
  76.  
  77.  
  78.  
  79.         assign d = dout;
  80.  
  81.         always @*
  82.         begin
  83.                 if( ready && was_ras && was_cas && we_n && (~idle) ) // idle here is to prevent races at the end of all previous signals, which cause redundant read at the end of write
  84.                 begin
  85.                         dout = array[addr];
  86. `ifdef DRAMMEM_VERBOSE
  87.                         if( _verbose_ == 1 )
  88.                         begin
  89.                                 if( addr != _filter_out_ )
  90.                                         $display("DRAM read at %t: ($%h)=>$%h",$time,addr*2+_add_to_addr_,dout);
  91.                         end
  92. `endif
  93.                 end
  94.                 else
  95.                 begin
  96.                         dout = 16'hZZZZ;
  97.                 end
  98.         end
  99.  
  100.  
  101.         always @*
  102.                 if( ready && was_ras && was_cas && (~we_n) && (~idle) )
  103.                 begin
  104.                         if( ~ucas_n )
  105.                                 array[addr][15:8] = d[15:8];
  106.  
  107.                         if( ~lcas_n )
  108.                                 array[addr][7:0] = d[7:0];
  109.  
  110. `ifdef DRAMMEM_VERBOSE
  111.                         if( _verbose_ == 1 )
  112.                         begin
  113.                                 if( addr != _filter_out_ )
  114.                                         $display("DRAM written at %t: ($%h)<=$%h.$%h",$time,addr*2+_add_to_addr_,ucas_n?8'hXX:d[15:8],lcas_n?8'hXX:d[7:0]);
  115.                         end
  116. `endif
  117.                 end
  118.  
  119.  
  120.  
  121.  
  122. endmodule
  123.  
  124.