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

Subversion Repositories xge_mac

[/] [xge_mac/] [trunk/] [rtl/] [verilog/] [generic_mem_small.v] - Blame information for rev 21

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 antanguay
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name "generic_mem_small.v"                             ////
4
////                                                              ////
5
////  This file is part of the "10GE MAC" project                 ////
6
////  http://www.opencores.org/cores/xge_mac/                     ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - A. Tanguay (antanguay@opencores.org)                  ////
10
////                                                              ////
11
//////////////////////////////////////////////////////////////////////
12
////                                                              ////
13
//// Copyright (C) 2008 AUTHORS. All rights reserved.             ////
14
////                                                              ////
15
//// This source file may be used and distributed without         ////
16
//// restriction provided that this copyright statement is not    ////
17
//// removed from the file and that any derivative work contains  ////
18
//// the original copyright notice and the associated disclaimer. ////
19
////                                                              ////
20
//// This source file is free software; you can redistribute it   ////
21
//// and/or modify it under the terms of the GNU Lesser General   ////
22
//// Public License as published by the Free Software Foundation; ////
23
//// either version 2.1 of the License, or (at your option) any   ////
24
//// later version.                                               ////
25
////                                                              ////
26
//// This source is distributed in the hope that it will be       ////
27
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
28
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
29
//// PURPOSE.  See the GNU Lesser General Public License for more ////
30
//// details.                                                     ////
31
////                                                              ////
32
//// You should have received a copy of the GNU Lesser General    ////
33
//// Public License along with this source; if not, download it   ////
34
//// from http://www.opencores.org/lgpl.shtml                     ////
35
////                                                              ////
36
//////////////////////////////////////////////////////////////////////
37
 
38
/* synthesis ramstyle = "M512" */
39
 
40
module generic_mem_small(
41
 
42
    wclk,
43
    wrst_n,
44
    wen,
45
    waddr,
46
    wdata,
47
 
48
    rclk,
49
    rrst_n,
50
    ren,
51
    roen,
52
    raddr,
53
    rdata
54
);
55
 
56
//---
57
// Parameters
58
 
59
parameter DWIDTH = 32;
60
parameter AWIDTH = 3;
61
parameter RAM_DEPTH = (1 << AWIDTH);
62
parameter REGISTER_READ = 0;
63
 
64
//---
65
// Ports
66
 
67
input               wclk;
68
input               wrst_n;
69
input               wen;
70 20 antanguay
input  [AWIDTH-1:0] waddr;
71 2 antanguay
input  [DWIDTH-1:0] wdata;
72
 
73
input               rclk;
74
input               rrst_n;
75
input               ren;
76
input               roen;
77 20 antanguay
input  [AWIDTH-1:0] raddr;
78 2 antanguay
output [DWIDTH-1:0] rdata;
79
 
80
// Registered outputs
81
reg    [DWIDTH-1:0] rdata;
82
 
83
 
84
//---
85
// Local declarations
86
 
87
// Registers
88
 
89
reg  [DWIDTH-1:0] mem_rdata;
90 21 antanguay
reg  [AWIDTH-1:0] raddr_d1;
91 2 antanguay
 
92
 
93
// Memory
94
 
95
reg  [DWIDTH-1:0] mem [0:RAM_DEPTH-1];
96
 
97
// Variables
98
 
99
integer         i;
100
 
101
 
102
//---
103
// Memory Write
104
 
105 20 antanguay
// Generate synchronous write
106
always @(posedge wclk)
107
begin
108
    if (wen) begin
109
        mem[waddr[AWIDTH-1:0]] <= wdata;
110 2 antanguay
    end
111 20 antanguay
end
112 2 antanguay
 
113
//---
114
// Memory Read
115
 
116 20 antanguay
// Generate registered memory read
117 21 antanguay
 
118
`ifdef XIL
119
 
120
//always @(posedge rclk)
121
//begin
122
//    if (ren) begin
123
//        raddr_d1 <= raddr;
124
//    end
125
//end
126
//always @(raddr_d1, rclk)
127
//begin
128
//    mem_rdata = mem[raddr_d1[AWIDTH-1:0]];
129
//end
130
 
131
always @(posedge rclk)
132
begin
133
    if (!rrst_n) begin
134
        mem_rdata <= {(DWIDTH){1'b0}};
135
    end else if (ren) begin
136
        mem_rdata <= mem[raddr[AWIDTH-1:0]];
137
    end
138
end
139
 
140
`else
141
 
142 20 antanguay
always @(posedge rclk or negedge rrst_n)
143
begin
144
    if (!rrst_n) begin
145
        mem_rdata <= {(DWIDTH){1'b0}};
146
    end else if (ren) begin
147
        mem_rdata <= mem[raddr[AWIDTH-1:0]];
148 2 antanguay
    end
149 20 antanguay
end
150 2 antanguay
 
151 21 antanguay
`endif
152
 
153 2 antanguay
generate
154
    if (REGISTER_READ) begin
155
 
156
        // Generate registered output
157
        always @(posedge rclk or negedge rrst_n)
158
        begin
159
            if (!rrst_n) begin
160
                rdata <= {(DWIDTH){1'b0}};
161
            end else if (roen) begin
162
                rdata <= mem_rdata;
163
            end
164
        end
165
 
166
    end
167
    else begin
168
 
169
        // Generate unregisters output
170
        always @(mem_rdata)
171
        begin
172
            rdata = mem_rdata;
173
        end
174
 
175
    end
176
endgenerate
177
 
178
endmodule

powered by: WebSVN 2.1.0

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