-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgather.sv
52 lines (48 loc) · 1.03 KB
/
gather.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
module gather
#(
parameter int width = 40
)
(
input clock,
input reset,
input wire [width-1:0] m0_data,
input wire m0_valid,
output wire m0_ready,
input wire [width-1:0] m1_data,
input wire m1_valid,
output wire m1_ready,
output wire [width-1:0] s_data,
output wire s_valid,
input wire s_ready
);
logic [width-1:0] buffer;
logic valid;
logic select;
assign s_data = buffer;
assign s_valid = valid;
assign m0_ready = !valid && select == 1'b0;
assign m1_ready = !valid && select == 1'b1;
always_ff@(posedge clock or posedge reset) begin
if (reset) begin
valid <= 1'b0;
select <= 1'b0;
end else begin
if (s_valid && s_ready) begin
valid <= 1'b0;
end else if (!valid) begin
if (m0_valid && m0_ready) begin
buffer <= m0_data;
valid <= 1'b1;
end else if (m1_valid && m1_ready) begin
buffer <= m1_data;
valid <= 1'b1;
end else begin
valid <= 1'b0;
end
end else begin
valid <= 1'b1;
end
select <= !select;
end
end
endmodule