-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdual_clk_ram.v
140 lines (135 loc) · 3.64 KB
/
dual_clk_ram.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// SPDX-License-Identifier: BSD-2-Clause
// Copyright (c) 2015 miya All rights reserved.
/*
ver. 2024/04/21
write delay: immediately
read delay: 2 clock cycle
*/
module dual_clk_ram
#(
parameter DATA_WIDTH = 8,
parameter ADDR_WIDTH = 12,
parameter RAM_TYPE = "auto"
)
(
input wire [(DATA_WIDTH-1):0] data_in,
input wire [(ADDR_WIDTH-1):0] read_addr,
input wire [(ADDR_WIDTH-1):0] write_addr,
input wire we,
input wire read_clock,
input wire write_clock,
output reg [(DATA_WIDTH-1):0] data_out
);
reg [(ADDR_WIDTH-1):0] read_addr_reg;
always @(posedge read_clock)
begin
read_addr_reg <= read_addr;
end
generate
if (RAM_TYPE == "xi_distributed")
begin: gen
(* ram_style = "distributed" *) reg [DATA_WIDTH-1:0] ram [0:(1 << ADDR_WIDTH)-1];
always @(posedge read_clock)
begin
data_out <= ram[read_addr_reg];
end
always @(posedge write_clock)
begin
if (we)
begin
ram[write_addr] <= data_in;
end
end
end
else if (RAM_TYPE == "xi_block")
begin: gen
(* ram_style = "block" *) reg [DATA_WIDTH-1:0] ram [0:(1 << ADDR_WIDTH)-1];
always @(posedge read_clock)
begin
data_out <= ram[read_addr_reg];
end
always @(posedge write_clock)
begin
if (we)
begin
ram[write_addr] <= data_in;
end
end
end
else if (RAM_TYPE == "xi_register")
begin: gen
(* ram_style = "register" *) reg [DATA_WIDTH-1:0] ram [0:(1 << ADDR_WIDTH)-1];
always @(posedge read_clock)
begin
data_out <= ram[read_addr_reg];
end
always @(posedge write_clock)
begin
if (we)
begin
ram[write_addr] <= data_in;
end
end
end
else if (RAM_TYPE == "xi_ultra")
begin: gen
(* ram_style = "ultra" *) reg [DATA_WIDTH-1:0] ram [0:(1 << ADDR_WIDTH)-1];
always @(posedge read_clock)
begin
data_out <= ram[read_addr_reg];
end
always @(posedge write_clock)
begin
if (we)
begin
ram[write_addr] <= data_in;
end
end
end
else if (RAM_TYPE == "al_logic")
begin: gen
(* ramstyle = "logic" *) reg [DATA_WIDTH-1:0] ram [0:(1 << ADDR_WIDTH)-1];
always @(posedge read_clock)
begin
data_out <= ram[read_addr_reg];
end
always @(posedge write_clock)
begin
if (we)
begin
ram[write_addr] <= data_in;
end
end
end
else if (RAM_TYPE == "al_mlab")
begin: gen
(* ramstyle = "MLAB" *) reg [DATA_WIDTH-1:0] ram [0:(1 << ADDR_WIDTH)-1];
always @(posedge read_clock)
begin
data_out <= ram[read_addr_reg];
end
always @(posedge write_clock)
begin
if (we)
begin
ram[write_addr] <= data_in;
end
end
end
else
begin: gen
reg [DATA_WIDTH-1:0] ram [0:(1 << ADDR_WIDTH)-1];
always @(posedge read_clock)
begin
data_out <= ram[read_addr_reg];
end
always @(posedge write_clock)
begin
if (we)
begin
ram[write_addr] <= data_in;
end
end
end
endgenerate
endmodule