1
1
// ------------------------------------------------------------------------------
2
2
// true_dual_port_write_first_2_clock_ram.sv
3
+ // published as part of https://github.com/pConst/basic_verilog
3
4
// Konstantin Pavlov, [email protected]
4
5
// ------------------------------------------------------------------------------
5
6
14
15
true_dual_port_write_first_2_clock_ram #(
15
16
.RAM_WIDTH( DATA_W ),
16
17
.RAM_DEPTH( DEPTH ),
18
+ .RAM_STYLE( "init.mem" ), // "block","register","M10K","logic",...
17
19
.INIT_FILE( "" )
18
- ) bram (
20
+ ) DR1 (
19
21
.clka( w_clk ),
20
22
.addra( w_ptr[DEPTH_W-1:0] ),
21
23
.ena( w_req ),
@@ -37,6 +39,7 @@ true_dual_port_write_first_2_clock_ram #(
37
39
module true_dual_port_write_first_2_clock_ram # ( parameter
38
40
RAM_WIDTH = 16 ,
39
41
RAM_DEPTH = 8 ,
42
+ RAM_STYLE = " " ,
40
43
INIT_FILE = " "
41
44
)(
42
45
input clka,
@@ -54,26 +57,33 @@ module true_dual_port_write_first_2_clock_ram #( parameter
54
57
output [RAM_WIDTH - 1 : 0 ] doutb
55
58
);
56
59
60
+ // Xilinx:
61
+ // ram_style = "{ auto | block | distributed | register | ultra }"
62
+ // "ram_style" is equivalent to "ramstyle" in Vivado
57
63
58
-
59
- logic [RAM_WIDTH - 1 : 0 ] BRAM [RAM_DEPTH - 1 : 0 ];
60
- logic [RAM_WIDTH - 1 : 0 ] ram_data_a = { RAM_WIDTH { 1'b0 }} ;
61
- logic [RAM_WIDTH - 1 : 0 ] ram_data_b = { RAM_WIDTH { 1'b0 }} ;
64
+ // Altera:
65
+ // ramstyle = "{ logic | M9K | MLAB }" and other variants
62
66
63
67
// ONLY FOR QUARTUS IDE
64
68
// You can provide initialization in convinient .mif format
65
- // (* ram_init_file = INIT_FILE *) logic [RAM_WIDTH-1:0] BRAM [RAM_DEPTH-1:0];
69
+ // (* ram_init_file = INIT_FILE *) logic [RAM_WIDTH-1:0] data_mem [RAM_DEPTH-1:0];
70
+
71
+ (* ramstyle = RAM_STYLE * ) logic [RAM_WIDTH - 1 : 0 ] data_mem [RAM_DEPTH - 1 : 0 ];
72
+
73
+
74
+ logic [RAM_WIDTH - 1 : 0 ] ram_data_a = { RAM_WIDTH { 1'b0 }} ;
75
+ logic [RAM_WIDTH - 1 : 0 ] ram_data_b = { RAM_WIDTH { 1'b0 }} ;
66
76
67
77
// either initializes the memory values to a specified file or to all zeros
68
78
generate
69
79
if (INIT_FILE != " " ) begin : use_init_file
70
80
initial
71
- $readmemh (INIT_FILE , BRAM , 0 , RAM_DEPTH - 1 );
81
+ $readmemh (INIT_FILE , data_mem , 0 , RAM_DEPTH - 1 );
72
82
end else begin : init_bram_to_zero
73
- integer ram_index ;
83
+ integer i ;
74
84
initial begin
75
- for (ram_index = 0 ; ram_index < RAM_DEPTH ; ram_index = ram_index + 1 ) begin
76
- BRAM [ram_index ] = { RAM_WIDTH { 1'b0 }} ;
85
+ for (i = 0 ; i < RAM_DEPTH ; i = i + 1 ) begin
86
+ data_mem[i ] = { RAM_WIDTH { 1'b0 }} ;
77
87
end
78
88
end
79
89
end
@@ -82,21 +92,21 @@ module true_dual_port_write_first_2_clock_ram #( parameter
82
92
always @ (posedge clka) begin
83
93
if (ena) begin
84
94
if (wea) begin
85
- BRAM [addra] <= dina;
95
+ data_mem [addra] <= dina;
86
96
ram_data_a <= dina;
87
97
end else begin
88
- ram_data_a <= BRAM [addra];
98
+ ram_data_a <= data_mem [addra];
89
99
end
90
100
end
91
101
end
92
102
93
103
always @ (posedge clkb) begin
94
104
if (enb) begin
95
105
if (web) begin
96
- BRAM [addrb] <= dinb;
106
+ data_mem [addrb] <= dinb;
97
107
ram_data_b <= dinb;
98
108
end else begin
99
- ram_data_b <= BRAM [addrb];
109
+ ram_data_b <= data_mem [addrb];
100
110
end
101
111
end
102
112
end
@@ -105,12 +115,7 @@ module true_dual_port_write_first_2_clock_ram #( parameter
105
115
assign douta = ram_data_a;
106
116
assign doutb = ram_data_b;
107
117
108
- // calculates the address width based on specified RAM depth
109
- function integer clogb2 ;
110
- input integer depth;
111
- for (clogb2= 0 ; depth> 0 ; clogb2= clogb2+ 1 )
112
- depth = depth >> 1 ;
113
- endfunction
118
+ `include " clogb2.svh"
114
119
115
120
endmodule
116
121
0 commit comments