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

Subversion Repositories xge_mac

[/] [xge_mac/] [trunk/] [rtl/] [verilog/] [generic_mem_medium.v] - Blame information for rev 25

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 antanguay
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name "generic_mem_medium.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 22 antanguay
`include "defines.v"
39
 
40 2 antanguay
/* synthesis ramstyle = "M4K" */
41
 
42
module generic_mem_medium(
43
 
44
    wclk,
45
    wrst_n,
46
    wen,
47
    waddr,
48
    wdata,
49
 
50
    rclk,
51
    rrst_n,
52
    ren,
53
    roen,
54
    raddr,
55
    rdata
56
);
57
 
58
//---
59
// Parameters
60
 
61
parameter DWIDTH = 32;
62
parameter AWIDTH = 3;
63
parameter RAM_DEPTH = (1 << AWIDTH);
64
parameter REGISTER_READ = 0;
65
 
66
//---
67
// Ports
68
 
69
input               wclk;
70
input               wrst_n;
71
input               wen;
72 20 antanguay
input  [AWIDTH-1:0] waddr;
73 2 antanguay
input  [DWIDTH-1:0] wdata;
74
 
75
input               rclk;
76
input               rrst_n;
77
input               ren;
78
input               roen;
79 20 antanguay
input  [AWIDTH-1:0] raddr;
80 2 antanguay
output [DWIDTH-1:0] rdata;
81
 
82
// Registered outputs
83
reg    [DWIDTH-1:0] rdata;
84
 
85
 
86
//---
87
// Local declarations
88
 
89
// Registers
90
 
91
reg  [DWIDTH-1:0] mem_rdata;
92 21 antanguay
reg  [AWIDTH-1:0] raddr_d1;
93 2 antanguay
 
94
// Memory
95
 
96
reg  [DWIDTH-1:0] mem [0:RAM_DEPTH-1];
97
 
98
// Variables
99
 
100
integer         i;
101
 
102
 
103
//---
104
// Memory Write
105
 
106 20 antanguay
// Generate synchronous write
107
always @(posedge wclk)
108
begin
109
    if (wen) begin
110
        mem[waddr[AWIDTH-1:0]] <= wdata;
111 2 antanguay
    end
112 20 antanguay
end
113 2 antanguay
 
114
//---
115
// Memory Read
116
 
117 20 antanguay
// Generate registered memory read
118 21 antanguay
 
119
`ifdef XIL
120
 
121
//always @(posedge rclk)
122
//begin
123
//    if (ren) begin
124
//        raddr_d1 <= raddr;
125
//    end
126
//end
127
//always @(raddr_d1, rclk)
128
//begin
129
//    mem_rdata = mem[raddr_d1[AWIDTH-1:0]];
130
//end
131
 
132
always @(posedge rclk)
133
begin
134
    if (!rrst_n) begin
135
        mem_rdata <= {(DWIDTH){1'b0}};
136
    end else if (ren) begin
137
        mem_rdata <= mem[raddr[AWIDTH-1:0]];
138
    end
139
end
140
 
141
`else
142
 
143 25 antanguay
//always @(posedge rclk or negedge rrst_n)
144
//begin
145
//    if (!rrst_n) begin
146
//        mem_rdata <= {(DWIDTH){1'b0}};
147
//    end else if (ren) begin
148
//        mem_rdata <= mem[raddr[AWIDTH-1:0]];
149
//    end
150
//end
151
 
152
always @(posedge rclk)
153 20 antanguay
begin
154 25 antanguay
    if (ren) begin
155
        raddr_d1 <= raddr;
156 2 antanguay
    end
157 20 antanguay
end
158 25 antanguay
always @(raddr_d1, rclk)
159
begin
160
    mem_rdata = mem[raddr_d1[AWIDTH-1:0]];
161
end
162 2 antanguay
 
163 21 antanguay
`endif
164
 
165 2 antanguay
generate
166
    if (REGISTER_READ) begin
167
 
168
        // Generate registered output
169
        always @(posedge rclk or negedge rrst_n)
170
        begin
171
            if (!rrst_n) begin
172
                rdata <= {(DWIDTH){1'b0}};
173
            end else if (roen) begin
174
                rdata <= mem_rdata;
175
            end
176
        end
177
 
178
    end
179
    else begin
180
 
181
        // Generate unregisters output
182
        always @(mem_rdata)
183
        begin
184
            rdata = mem_rdata;
185
        end
186
 
187
    end
188
endgenerate
189
 
190
endmodule

powered by: WebSVN 2.1.0

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