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

Subversion Repositories cde

[/] [cde/] [trunk/] [ip/] [sram/] [doc/] [Geda/] [src/] [cde_sram_def.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 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
      DEFAULT={WIDTH{1'b1}},
29
      INIT_FILE="NONE",
30
      INSTANCE_NAME="U1")
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( INIT_FILE  == "NONE")
45
     begin
46
     end
47
   else
48
        begin
49
        $readmemh(INIT_FILE, mem);
50
        end
51
  end
52
 
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
  reg                       l_cycle;
63
 
64
  always@(posedge clk)
65
    begin
66
       l_raddr    <= addr;
67
       l_cycle    <=  rd && cs  ;
68
     end
69
 
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
  assign            tmp_rdata  =      (l_cycle )?mem[{l_raddr[ADDR-1:0]}]:DEFAULT;
73
  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
        else           rdata             <= DEFAULT;
81
  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.