-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtlast_gen.v
64 lines (53 loc) · 1.58 KB
/
tlast_gen.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
`timescale 1ns / 1ps
module tlast_gen
#(
parameter TDATA_WIDTH = 8,
parameter MAX_PKT_LENGTH = 256
)
(
// Clocks and resets
input aclk,
input resetn,
// Control signals
input [$clog2(MAX_PKT_LENGTH):0] pkt_length,
// Slave interface
input s_axis_tvalid,
output s_axis_tready,
input [TDATA_WIDTH-1:0] s_axis_tdata,
// Master interface
output m_axis_tvalid,
input m_axis_tready,
output m_axis_tlast,
output [TDATA_WIDTH-1:0] m_axis_tdata,
output [$clog2(MAX_PKT_LENGTH):0] o_cnt
);
// Internal signals
wire new_sample;
reg [$clog2(MAX_PKT_LENGTH):0] cnt;
initial begin
cnt = 0;
end
// Pass through control signals
assign s_axis_tready = m_axis_tready;
assign m_axis_tvalid = s_axis_tvalid;
assign m_axis_tdata = s_axis_tdata;
// Count samples
assign new_sample = s_axis_tvalid & s_axis_tready;
always @ (posedge aclk) begin
if (~resetn)
cnt <= 0;
else begin
if (new_sample) begin
if (m_axis_tlast) begin
cnt <= 1'b1;
end
else begin
cnt <= cnt + 1'b1;
end
end
end
end
// Generate tlast
assign m_axis_tlast = (cnt == pkt_length) & new_sample;
assign o_cnt = cnt;
endmodule