Skip to content

Commit d2df971

Browse files
committed
Add AXI stream frame length measurement module and testbenches
1 parent e0f7404 commit d2df971

File tree

5 files changed

+1136
-0
lines changed

5 files changed

+1136
-0
lines changed

rtl/axis_frame_len.v

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
3+
Copyright (c) 2019 Alex Forencich
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
22+
23+
*/
24+
25+
// Language: Verilog 2001
26+
27+
`timescale 1ns / 1ps
28+
29+
/*
30+
* AXI4-Stream frame length measurement
31+
*/
32+
module axis_frame_len #
33+
(
34+
parameter DATA_WIDTH = 64,
35+
parameter KEEP_ENABLE = (DATA_WIDTH>8),
36+
parameter KEEP_WIDTH = (DATA_WIDTH/8),
37+
parameter LEN_WIDTH = 16
38+
)
39+
(
40+
input wire clk,
41+
input wire rst,
42+
43+
/*
44+
* AXI monitor
45+
*/
46+
input wire [KEEP_WIDTH-1:0] monitor_axis_tkeep,
47+
input wire monitor_axis_tvalid,
48+
input wire monitor_axis_tready,
49+
input wire monitor_axis_tlast,
50+
51+
/*
52+
* Status
53+
*/
54+
output wire [LEN_WIDTH-1:0] frame_len,
55+
output wire frame_len_valid
56+
);
57+
58+
reg [LEN_WIDTH-1:0] frame_len_reg = 0, frame_len_next;
59+
reg frame_len_valid_reg = 1'b0, frame_len_valid_next;
60+
reg frame_reg = 1'b0, frame_next;
61+
62+
assign frame_len = frame_len_reg;
63+
assign frame_len_valid = frame_len_valid_reg;
64+
65+
integer offset, i, bit_cnt;
66+
67+
always @* begin
68+
frame_len_next = frame_len_reg;
69+
frame_len_valid_next = 1'b0;
70+
frame_next = frame_reg;
71+
72+
if (monitor_axis_tready && monitor_axis_tvalid) begin
73+
// valid transfer cycle
74+
75+
if (monitor_axis_tlast) begin
76+
// end of frame
77+
frame_len_valid_next = 1'b1;
78+
frame_next = 1'b0;
79+
end else if (!frame_reg) begin
80+
// first word after end of frame
81+
frame_len_next = 0;
82+
frame_next = 1'b1;
83+
end
84+
85+
// increment frame length by number of words transferred
86+
if (KEEP_ENABLE) begin
87+
bit_cnt = 0;
88+
for (i = 0; i <= KEEP_WIDTH; i = i + 1) begin
89+
if (monitor_axis_tkeep == ({KEEP_WIDTH{1'b1}}) >> (KEEP_WIDTH-i)) bit_cnt = i;
90+
end
91+
frame_len_next = frame_len_next + bit_cnt;
92+
end else begin
93+
frame_len_next = frame_len_next + 1;
94+
end
95+
end
96+
end
97+
98+
always @(posedge clk) begin
99+
if (rst) begin
100+
frame_len_reg <= 0;
101+
frame_len_valid_reg <= 0;
102+
frame_reg <= 1'b0;
103+
end else begin
104+
frame_len_reg <= frame_len_next;
105+
frame_len_valid_reg <= frame_len_valid_next;
106+
frame_reg <= frame_next;
107+
end
108+
end
109+
110+
endmodule

0 commit comments

Comments
 (0)