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

Subversion Repositories cde

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

powered by: WebSVN 2.1.0

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