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

Subversion Repositories socgen

[/] [socgen/] [trunk/] [Projects/] [digilentinc.com/] [Nexys2/] [ip/] [sram/] [rtl/] [verilog/] [sram_def.v] - Blame information for rev 134

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 131 jt_eaton
/**********************************************************************/
2
/*                                                                    */
3
/*                                                                    */
4
/*   Copyright (c) 2012 Ouabache Design Works                         */
5
/*                                                                    */
6
/*          All Rights Reserved Worldwide                             */
7
/*                                                                    */
8
/*   Licensed under the Apache License,Version2.0 (the'License');     */
9
/*   you may not use this file except in compliance with the License. */
10
/*   You may obtain a copy of the License at                          */
11
/*                                                                    */
12
/*       http://www.apache.org/licenses/LICENSE-2.0                   */
13
/*                                                                    */
14
/*   Unless required by applicable law or agreed to in                */
15
/*   writing, software distributed under the License is               */
16
/*   distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES              */
17
/*   OR CONDITIONS OF ANY KIND, either express or implied.            */
18
/*   See the License for the specific language governing              */
19
/*   permissions and limitations under the License.                   */
20
/**********************************************************************/
21
 module
22
  cde_sram_def
23
    #( parameter
24
      ADDR=10,
25
      WIDTH=8,
26
      WORDS=1024,
27
      WRITETHRU=0,
28
      INIT_FILE="NONE",
29
      MEM="NONE",
30
      INSTANCE_NAME="../../../../../children/")
31
     (
32
 input   wire                 clk,
33
 input   wire                 cs,
34
 input   wire                 rd,
35
 input   wire                 wr,
36
 input   wire    [ ADDR-1 :  0]        addr,
37
 input   wire    [ WIDTH-1 :  0]        wdata,
38
 output   reg    [ WIDTH-1 :  0]        rdata);
39
// Memory Array
40
reg [WIDTH-1:0] mem[0:WORDS-1];
41
// If used as Rom then load a memory image at startup
42
initial
43
  begin
44
   if( MEM  == "NONE")
45
     begin
46
     end
47
   else
48
        begin
49
        $readmemh(MEM, mem);
50
        end
51
  end
52
// Write function   
53
// Write function   
54
always@(posedge clk)
55
        if( wr && cs ) mem[addr[ADDR-1:0]] <= wdata[WIDTH-1:0];
56
generate
57
if( WRITETHRU)
58
  begin
59
  // Read function gets new data if also a write cycle
60
  // latch the read addr for next cycle   
61
  reg   [ADDR-1:0]          l_raddr;
62
 
63
  reg                       l_cycle;
64
 
65
  always@(posedge clk)
66
        l_cycle    <=  rd && cs  ;
67
 
68
 
69
  always@(posedge clk)      l_raddr    <= addr;
70
  // Read into a wire and then pass to rdata because some synth tools can't handle a memory in a always block
71
  wire  [WIDTH-1:0] tmp_rdata;
72 134 jt_eaton
  assign                    tmp_rdata  =      (l_cycle )?mem[{l_raddr[ADDR-1:0]}]:{WIDTH{1'b1}};
73 131 jt_eaton
  always@(*)                rdata  =      tmp_rdata;
74
  end
75
else
76
  begin
77
  // Read function gets old data if also a write cycle
78
  always@(posedge clk)
79
        if( rd && cs ) rdata             <= mem[{addr[ADDR-1:0]}];
80 134 jt_eaton
        else           rdata             <= {WIDTH{1'b1}};
81 131 jt_eaton
  end
82
endgenerate
83
  endmodule

powered by: WebSVN 2.1.0

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