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

Subversion Repositories socgen

[/] [socgen/] [trunk/] [common/] [opencores.org/] [cde/] [ip/] [sram/] [rtl/] [verilog/] [sram_def] - Blame information for rev 135

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 134 jt_eaton
// Memory Array
2 135 jt_eaton
reg [WIDTH-1:0] mem [0:WORDS-1];
3 134 jt_eaton
// If used as Rom then load a memory image at startup
4
initial
5
  begin
6
  $display("SRAM def %m.mem");
7
  $display("  AddrBits=%d DataBits = %d  Words = %d  ",ADDR,WIDTH,WORDS);
8
  end
9
 
10
// Write function
11
always@(posedge clk)
12
        if( wr && cs ) mem[addr[ADDR-1:0]] <= wdata[WIDTH-1:0];
13
generate
14
if( WRITETHRU)
15
  begin
16
  // Read function gets new data if also a write cycle
17
  // latch the read addr for next cycle
18
  reg   [ADDR-1:0]          l_raddr;
19
  reg                       l_cycle;
20
 
21
  always@(posedge clk)
22
    begin
23
       l_raddr    <= addr;
24
       l_cycle    <=  rd && cs  ;
25
     end
26
 
27
  // Read into a wire and then pass to rdata because some synth tools can't handle a memory in a always block
28
  wire  [WIDTH-1:0] tmp_rdata;
29
  assign            tmp_rdata  =      (l_cycle )?mem[{l_raddr[ADDR-1:0]}]:{WIDTH{1'b1}};
30
  always@(*)            rdata  =      tmp_rdata;
31
  end
32
else
33
  begin
34
  // Read function gets old data if also a write cycle
35
  always@(posedge clk)
36
        if( rd && cs ) rdata             <= mem[{addr[ADDR-1:0]}];
37
        else           rdata             <= {WIDTH{1'b1}};
38
  end
39
endgenerate
40
 
41
 

powered by: WebSVN 2.1.0

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