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 22

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

powered by: WebSVN 2.1.0

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