-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQueue.sv
55 lines (48 loc) · 1.34 KB
/
Queue.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
module Queue (
input logic clk, rst,
input logic [7:0] data_in,
input logic ready_in,
output logic [31:0] data_out,
output logic [31:0] addr_out
);
reg [31:0] data_queue = 0;
reg [2:0] cnt = 0;
reg [4:0] clk_cnt = 0;
reg [31:0] addr_out_ = 0;
wire full;
assign data_out = data_queue;
assign full = (cnt == 4);
assign addr_out = addr_out_;
always_ff @(posedge clk) begin : addr
if (rst) begin
addr_out_ <= 0;
end else if (full && clk_cnt == 0) begin
addr_out_ <= addr_out_ + 4;
end else begin
addr_out_ <= addr_out_;
end
end
always_ff @(posedge clk) begin : cnt_for_mem
if (rst) begin
clk_cnt <= 0;
end else if (clk_cnt == 15) begin
clk_cnt <= 0;
end else if (full) begin
clk_cnt <= clk_cnt + 1;
end else begin
clk_cnt <= clk_cnt;
end
end
always_ff @(posedge clk) begin : write
if (rst || (full && clk_cnt == 15)) begin
cnt <= 0;
data_queue <= 0;
end else if (ready_in) begin
cnt <= cnt + 1;
data_queue <= {data_in, data_queue[31:8]};
end else begin
cnt <= cnt;
data_queue <= data_queue;
end
end
endmodule