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 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_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
/* synthesis ramstyle = "M4K" */
39
 
40
module generic_mem_medium(
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
// Memory
93
 
94
reg  [DWIDTH-1:0] mem [0:RAM_DEPTH-1];
95
 
96
// Variables
97
 
98
integer         i;
99
 
100
 
101
//---
102
// Memory Write
103
 
104 20 antanguay
// Generate synchronous write
105
always @(posedge wclk)
106
begin
107
    if (wen) begin
108
        mem[waddr[AWIDTH-1:0]] <= wdata;
109 2 antanguay
    end
110 20 antanguay
end
111 2 antanguay
 
112
//---
113
// Memory Read
114
 
115 20 antanguay
// Generate registered memory read
116 21 antanguay
 
117
`ifdef XIL
118
 
119
//always @(posedge rclk)
120
//begin
121
//    if (ren) begin
122
//        raddr_d1 <= raddr;
123
//    end
124
//end
125
//always @(raddr_d1, rclk)
126
//begin
127
//    mem_rdata = mem[raddr_d1[AWIDTH-1:0]];
128
//end
129
 
130
always @(posedge rclk)
131
begin
132
    if (!rrst_n) begin
133
        mem_rdata <= {(DWIDTH){1'b0}};
134
    end else if (ren) begin
135
        mem_rdata <= mem[raddr[AWIDTH-1:0]];
136
    end
137
end
138
 
139
`else
140
 
141 20 antanguay
always @(posedge rclk or negedge rrst_n)
142
begin
143
    if (!rrst_n) begin
144
        mem_rdata <= {(DWIDTH){1'b0}};
145
    end else if (ren) begin
146
        mem_rdata <= mem[raddr[AWIDTH-1:0]];
147 2 antanguay
    end
148 20 antanguay
end
149 2 antanguay
 
150 21 antanguay
`endif
151
 
152 2 antanguay
generate
153
    if (REGISTER_READ) begin
154
 
155
        // Generate registered output
156
        always @(posedge rclk or negedge rrst_n)
157
        begin
158
            if (!rrst_n) begin
159
                rdata <= {(DWIDTH){1'b0}};
160
            end else if (roen) begin
161
                rdata <= mem_rdata;
162
            end
163
        end
164
 
165
    end
166
    else begin
167
 
168
        // Generate unregisters output
169
        always @(mem_rdata)
170
        begin
171
            rdata = mem_rdata;
172
        end
173
 
174
    end
175
endgenerate
176
 
177
endmodule

powered by: WebSVN 2.1.0

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