1 |
49 |
qaztronic |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// Copyright (C) 2019 Authors and OPENCORES.ORG ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// This source file may be used and distributed without ////
|
6 |
|
|
//// restriction provided that this copyright statement is not ////
|
7 |
|
|
//// removed from the file and that any derivative work contains ////
|
8 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
9 |
|
|
//// ////
|
10 |
|
|
//// This source file is free software; you can redistribute it ////
|
11 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
12 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
13 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
14 |
|
|
//// later version. ////
|
15 |
|
|
//// ////
|
16 |
|
|
//// This source is distributed in the hope that it will be ////
|
17 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
18 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
19 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
20 |
|
|
//// details. ////
|
21 |
|
|
//// ////
|
22 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
23 |
|
|
//// Public License along with this source; if not, download it ////
|
24 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
25 |
|
|
//// ////
|
26 |
|
|
//////////////////////////////////////////////////////////////////////
|
27 |
|
|
|
28 |
|
|
module
|
29 |
|
|
avf_line_buffer #(N, U, L, AW)
|
30 |
|
|
(
|
31 |
|
|
axis_if axis_in,
|
32 |
|
|
axis_if axis_out,
|
33 |
|
|
input aclk,
|
34 |
|
|
input aresetn
|
35 |
|
|
);
|
36 |
|
|
|
37 |
|
|
// --------------------------------------------------------------------
|
38 |
|
|
localparam W = (N*8) + U + 1; // tdata + tuser + tlast
|
39 |
|
|
localparam F = 2; // fanout for the buffer row output
|
40 |
|
|
|
41 |
|
|
// --------------------------------------------------------------------
|
42 |
|
|
axis_if #(.N(N), .U(U)) row_out[L][F](.*);
|
43 |
|
|
axis_if #(.N(N), .U(U)) buffer_out[L-1](.*);
|
44 |
|
|
wire [L-2:0] zero_pad;
|
45 |
|
|
wire [L-2:0] initialized;
|
46 |
|
|
wire all_initialized = &initialized;
|
47 |
|
|
wire enable;
|
48 |
|
|
wire eof_trailing = row_out[0][0].tready & row_out[0][0].tvalid & row_out[0][0].tuser[2];
|
49 |
|
|
wire eof_leading = row_out[L-1][0].tready & row_out[L-1][0].tvalid & row_out[L-1][0].tuser[2];
|
50 |
|
|
|
51 |
|
|
// --------------------------------------------------------------------
|
52 |
|
|
generate
|
53 |
|
|
for(genvar j = 0; j < L-1; j++)
|
54 |
|
|
begin: buffer_gen
|
55 |
|
|
avf_line_buffer_row #(N, W, AW, j)
|
56 |
|
|
row_i
|
57 |
|
|
(
|
58 |
|
|
.axis_in(row_out[j+1][1]),
|
59 |
|
|
.axis_out(buffer_out[j]),
|
60 |
|
|
.zero_pad(zero_pad[j]),
|
61 |
|
|
.initialized(initialized[j]),
|
62 |
|
|
.*
|
63 |
|
|
);
|
64 |
|
|
end
|
65 |
|
|
endgenerate
|
66 |
|
|
|
67 |
|
|
// --------------------------------------------------------------------
|
68 |
|
|
generate
|
69 |
|
|
for(genvar j = 1; j < L-1; j++)
|
70 |
|
|
begin: middle_fanout_gen
|
71 |
|
|
axis_fanout #(F)
|
72 |
|
|
fanout_i(.axis_in(buffer_out[j]), .axis_out(row_out[j]), .*);
|
73 |
|
|
end
|
74 |
|
|
endgenerate
|
75 |
|
|
|
76 |
|
|
// --------------------------------------------------------------------
|
77 |
|
|
axis_fanout #(F) trailing_row_i(.axis_out(row_out[L-1]), .*);
|
78 |
|
|
axis_alias leading_row_i(buffer_out[0], row_out[0][0]);
|
79 |
|
|
|
80 |
|
|
// --------------------------------------------------------------------
|
81 |
|
|
enum reg [3:0]
|
82 |
|
|
{
|
83 |
|
|
INITIALIZE = 4'b0001,
|
84 |
|
|
ACTIVE = 4'b0010,
|
85 |
|
|
// READY = 4'b0100,
|
86 |
|
|
FLUSH = 4'b1000
|
87 |
|
|
} state, next_state;
|
88 |
|
|
|
89 |
|
|
// --------------------------------------------------------------------
|
90 |
|
|
always_ff @(posedge aclk)
|
91 |
|
|
if(~aresetn)
|
92 |
|
|
state <= INITIALIZE;
|
93 |
|
|
else
|
94 |
|
|
state <= next_state;
|
95 |
|
|
|
96 |
|
|
// --------------------------------------------------------------------
|
97 |
|
|
always_comb
|
98 |
|
|
case(state)
|
99 |
|
|
INITIALIZE: if(all_initialized)
|
100 |
|
|
next_state = ACTIVE;
|
101 |
|
|
else
|
102 |
|
|
next_state = INITIALIZE;
|
103 |
|
|
|
104 |
|
|
ACTIVE: if(eof_leading)
|
105 |
|
|
next_state = FLUSH;
|
106 |
|
|
else
|
107 |
|
|
next_state = ACTIVE;
|
108 |
|
|
|
109 |
|
|
FLUSH: if(eof_trailing)
|
110 |
|
|
next_state = INITIALIZE;
|
111 |
|
|
else
|
112 |
|
|
next_state = FLUSH;
|
113 |
|
|
|
114 |
|
|
default: next_state = INITIALIZE;
|
115 |
|
|
endcase
|
116 |
|
|
|
117 |
|
|
// --------------------------------------------------------------------
|
118 |
|
|
assign enable = (state == ACTIVE);
|
119 |
|
|
|
120 |
|
|
// --------------------------------------------------------------------
|
121 |
|
|
wire init = ((state == INITIALIZE) & (next_state == INITIALIZE));
|
122 |
|
|
wire flush = ((state == FLUSH) & (next_state == FLUSH));
|
123 |
|
|
axis_if #(.N(N), .U(U)) merge_in[L](.*);
|
124 |
|
|
|
125 |
|
|
generate
|
126 |
|
|
for(genvar j = 0; j < L; j++)
|
127 |
|
|
begin: merge_gen
|
128 |
|
|
axis_alias row_i(row_out[j][0], merge_in[j]);
|
129 |
|
|
end
|
130 |
|
|
endgenerate
|
131 |
|
|
|
132 |
|
|
avf_line_buffer_merge #(N, U, L) merge_i(.*);
|
133 |
|
|
|
134 |
|
|
// --------------------------------------------------------------------
|
135 |
|
|
endmodule
|
136 |
|
|
|
137 |
|
|
|