-
Notifications
You must be signed in to change notification settings - Fork 380
/
fifo_combiner.sv
174 lines (147 loc) · 4.51 KB
/
fifo_combiner.sv
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//------------------------------------------------------------------------------
// fifo_combiner.sv
// published as part of https://github.com/pConst/basic_verilog
// Konstantin Pavlov, pavlovconst@gmail.com
//------------------------------------------------------------------------------
// INFO ------------------------------------------------------------------------
// Combines / accumulates data words from multiple FIFOs to a single output FIFO.
// Features three different element enumeration strategies.
// Reads if ANY input FIFO has data.
//
// See also fifo_operator.sv
//
/* --- INSTANTIATION TEMPLATE BEGIN ---
fifo_combiner #(
.WIDTH( 2 ),
.ENCODER_MODE( "ROUND_ROBIN" ),
.FWFT_MODE( "TRUE" ),
.DATA_W( 32 )
) FC1 (
.clk( ),
.nrst( ),
.r_empty( ),
.r_req( ),
.r_data( ),
.w_full( ), // connect to "almost_full" if FWFT_MODE="FALSE"
.w_req( ),
.w_data( )
);
--- INSTANTIATION TEMPLATE END ---*/
module fifo_combiner #( parameter
WIDTH = 2, // number of input fifo ports to combine
WIDTH_W = clogb2(WIDTH), // input port index width
ENCODER_MODE = "ROUND_ROBIN", // "ROUND_ROBIN", "ROUND_ROBIN_PERFORMANCE" or "PRIORITY"
FWFT_MODE = "TRUE", // "TRUE" - first word fall-trrough" mode
// "FALSE" - normal fifo mode
DATA_W = 32 // data field width
)(
input clk, // clock
input nrst, // inverted reset
// input ports
input [WIDTH-1:0] r_empty,
output [WIDTH-1:0] r_req,
input [WIDTH-1:0][DATA_W-1:0] r_data,
// output port
input w_full,
output logic w_req,
output logic [DATA_W-1:0] w_data
);
logic enc_valid;
logic [WIDTH-1:0] enc_filt;
logic [WIDTH_W-1:0] enc_bin;
logic [WIDTH-1:0] r_empty_rev;
reverse_vector #(
.WIDTH( WIDTH ) // WIDTH must be >=2
) empty_rev (
.in( r_empty[WIDTH-1:0] ),
.out( r_empty_rev[WIDTH-1:0] )
);
generate
if( ENCODER_MODE == "ROUND_ROBIN" ) begin
round_robin_enc #(
.WIDTH( WIDTH )
) rr_enc (
.clk( clk ),
.nrst( nrst ),
.id( ~r_empty[WIDTH-1:0] ),
.od_valid( enc_valid ),
.od_filt( enc_filt[WIDTH-1:0] ),
.od_bin( enc_bin[WIDTH_W-1:0] )
);
end else if( ENCODER_MODE == "ROUND_ROBIN_PERFORMANCE" ) begin
round_robin_performance_enc #(
.WIDTH( WIDTH )
) rr_perf_enc (
.clk( clk ), // !!
.nrst( nrst ),
.id(~r_empty[WIDTH-1:0] ),
.od_valid( enc_valid ),
.od_filt( enc_filt[WIDTH-1:0] ),
.od_bin( enc_bin[WIDTH_W-1:0] )
);
end else if( ENCODER_MODE == "PRIORITY" ) begin
priority_enc #(
.WIDTH( WIDTH ) // WIDTH must be >=2
) pri_enc (
.id( ~r_empty[WIDTH-1:0] ),
.od_valid( enc_valid ),
.od_filt( enc_filt[WIDTH-1:0] ),
.od_bin( enc_bin[WIDTH_W-1:0] )
);
end // ENCODER_MODE
endgenerate
logic r_valid;
assign r_valid = enc_valid && ~w_full;
assign r_req[WIDTH-1:0] = {WIDTH{r_valid}} &&
enc_filt[WIDTH-1:0];
// buffering read data
logic r_valid_d1 = 1'b0;
logic [WIDTH_W-1:0] enc_bin_d1;
logic [WIDTH-1:0][DATA_W-1:0] r_data_d1 = '0;
always_ff @(posedge clk) begin
if ( ~nrst ) begin
r_valid_d1 <= 1'b0;
enc_bin_d1[WIDTH_W-1:0] <= '0;
r_data_d1[WIDTH-1:0] <= '0;
end else begin
r_valid_d1 <= r_valid;
enc_bin_d1[WIDTH_W-1:0] <= enc_bin[WIDTH_W-1:0];
r_data_d1[WIDTH-1:0] <= r_data[WIDTH-1:0];
end
end
// routing data to write port
generate
if( FWFT_MODE == "TRUE" ) begin
always_comb begin
if ( ~nrst ) begin
w_req = 1'b0;
w_data[DATA_W-1:0] = '0;
end else begin
if( r_valid ) begin
w_req = 1'b1;
w_data[DATA_W-1:0] = r_data[enc_bin[WIDTH_W-1:0]][DATA_W-1:0];
end else begin
w_req = 1'b0;
w_data[DATA_W-1:0] = '0;
end
end
end
end else if( FWFT_MODE == "FALSE" ) begin
always_comb begin
if ( ~nrst ) begin
w_req = 1'b0;
w_data[DATA_W-1:0] = '0;
end else begin
if( r_valid_d1 ) begin
w_req = 1'b1;
w_data[DATA_W-1:0] = r_data_d1[enc_bin_d1[WIDTH_W-1:0]][DATA_W-1:0];
end else begin
w_req = 1'b0;
w_data[DATA_W-1:0] = '0;
end
end
end
end // FWFT_MODE
endgenerate
`include "clogb2.svh"
endmodule