OpenCores
URL https://opencores.org/ocsvn/socgen/socgen/trunk

Subversion Repositories socgen

[/] [socgen/] [trunk/] [common/] [opencores.org/] [cde/] [ip/] [sram/] [rtl/] [verilog/] [sram_def] - Rev 135

Compare with Previous | Blame | View Log

// Memory Array
reg [WIDTH-1:0] mem [0:WORDS-1];
// If used as Rom then load a memory image at startup
initial 
  begin
  $display("SRAM def %m.mem");
  $display("  AddrBits=%d DataBits = %d  Words = %d  ",ADDR,WIDTH,WORDS);
  end

// Write function   
always@(posedge clk)
        if( wr && cs ) mem[addr[ADDR-1:0]] <= wdata[WIDTH-1:0];
generate
if( WRITETHRU) 
  begin
  // Read function gets new data if also a write cycle
  // latch the read addr for next cycle   
  reg   [ADDR-1:0]          l_raddr;
  reg                       l_cycle;     

  always@(posedge clk)   
    begin
       l_raddr    <= addr;   
       l_cycle    <=  rd && cs  ;   
     end  

  // Read into a wire and then pass to rdata because some synth tools can't handle a memory in a always block
  wire  [WIDTH-1:0] tmp_rdata;
  assign            tmp_rdata  =      (l_cycle )?mem[{l_raddr[ADDR-1:0]}]:{WIDTH{1'b1}};
  always@(*)            rdata  =      tmp_rdata;   
  end
else
  begin 
  // Read function gets old data if also a write cycle
  always@(posedge clk)
        if( rd && cs ) rdata             <= mem[{addr[ADDR-1:0]}];
        else           rdata             <= {WIDTH{1'b1}};
  end              
endgenerate


Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.