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

Subversion Repositories socgen

[/] [socgen/] [trunk/] [Projects/] [digilentinc.com/] [Nexys2/] [ip/] [sram/] [rtl/] [verilog/] [sram_be.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_be
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                 be,
33
 input   wire                 clk,
34
 input   wire                 cs,
35
 input   wire                 rd,
36
 input   wire                 wr,
37
 input   wire    [ ADDR-1 :  0]        addr,
38
 input   wire    [ WIDTH-1 :  0]        wdata,
39
 output   reg    [ WIDTH-1 :  0]        rdata);
40
// Memory Array
41
reg [WIDTH-1:0] mem[0:WORDS-1];
42
// If used as Rom then load a memory image at startup
43
initial
44
  begin
45
   if( MEM  == "NONE")
46
     begin
47
     end
48
   else
49
        begin
50
        $readmemh(MEM, mem);
51
        end
52
  end
53
// Write function   
54
// Write function   
55
always@(posedge clk)
56
        if( wr && cs && be ) mem[addr[ADDR-1:0]] <= wdata[WIDTH-1:0];
57
generate
58
if( WRITETHRU)
59
  begin
60
  // Read function gets new data if also a write cycle
61
  // latch the read addr for next cycle   
62
  reg   [ADDR-1:0]          l_raddr;
63
 
64
 
65
  reg                       l_cycle;
66
 
67
  always@(posedge clk)
68
        l_cycle    <=  rd && cs ;
69
 
70
 
71
 
72
  always@(posedge clk)
73
        if( rd && cs ) l_raddr    <= addr;
74
        else           l_raddr    <= l_raddr;
75
 
76
 
77
  // Read into a wire and then pass to rdata because some synth tools can't handle a memory in a always block
78
  wire  [7:0] tmp_rdata;
79 134 jt_eaton
  assign                    tmp_rdata  =      (l_cycle )?mem[{l_raddr[ADDR-1:0]}]:{WIDTH{1'b1}};
80 131 jt_eaton
  always@(*)                rdata  =      tmp_rdata;
81
  end
82
else
83
  begin
84
  // Read function gets old data if also a write cycle
85
  always@(posedge clk)
86
        if( rd && cs ) rdata             <= mem[{addr[ADDR-1:0]}];
87 134 jt_eaton
        else           rdata             <= {WIDTH{1'b1}};
88 131 jt_eaton
  end
89
endgenerate
90
  endmodule

powered by: WebSVN 2.1.0

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