1 |
5 |
danv |
-------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
|
|
-- Copyright (C) 2011
|
4 |
|
|
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
|
5 |
|
|
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
6 |
|
|
--
|
7 |
|
|
-- This program is free software: you can redistribute it and/or modify
|
8 |
|
|
-- it under the terms of the GNU General Public License as published by
|
9 |
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
10 |
|
|
-- (at your option) any later version.
|
11 |
|
|
--
|
12 |
|
|
-- This program is distributed in the hope that it will be useful,
|
13 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
|
|
-- GNU General Public License for more details.
|
16 |
|
|
--
|
17 |
|
|
-- You should have received a copy of the GNU General Public License
|
18 |
|
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19 |
|
|
--
|
20 |
|
|
-------------------------------------------------------------------------------
|
21 |
|
|
|
22 |
|
|
-- Purpose : Generate the sosi control for a block of data under flow control
|
23 |
|
|
-- Description:
|
24 |
|
|
-- When enabled a block of g_nof_data words is output via src_out under flow
|
25 |
|
|
-- control by the ready. The ready depends on g_use_src_in:
|
26 |
|
|
--
|
27 |
|
|
-- . If g_use_src_in=TRUE then the src_in.ready is used and snk_in is
|
28 |
|
|
-- ignored. This can be used as a block reference input parallel to a
|
29 |
|
|
-- group of user inputs.
|
30 |
|
|
-- The g_preserve_* generics do not apply, because the snk_in is ignored.
|
31 |
|
|
--
|
32 |
|
|
-- . If g_use_src_in=FALSE then the src_in is not used and the snk_in data,
|
33 |
|
|
-- re, im are passed on and the snk_in.valid is used as ready. This can
|
34 |
|
|
-- be used as a BSN source that creates sync, bsn, sop and eop from
|
35 |
|
|
-- snk_in.valid for snk_in.data that has data not valid gaps. The
|
36 |
|
|
-- dp_bsn_source is similar but only supports data that is always valid.
|
37 |
|
|
-- The g_preserve_* generics can be used to preserve the corresponding
|
38 |
|
|
-- snk_in fields or to use the local generated values for this fields.
|
39 |
|
|
--
|
40 |
|
|
-- The first active ready starts the dp_block_gen. The first output block
|
41 |
|
|
-- will have a src_out.sync and every g_nof_blk_per_sync another
|
42 |
|
|
-- src_out.sync. Each block is marked by src_out.sop and src_out.eop. The
|
43 |
|
|
-- sop also marks the BSN. The BSN is the block sequence number that
|
44 |
|
|
-- increments for every block.
|
45 |
|
|
--
|
46 |
|
|
-- The snk_in.sop and snk_in.eop are always ignored, because g_nof_data
|
47 |
|
|
-- will set the src_out.sop/eop blocks.
|
48 |
|
|
--
|
49 |
|
|
-- If g_preserve_sync=TRUE then src_out.sync = snk_in.sync, else the
|
50 |
|
|
-- src_out.sync is depends on the first ready and on g_nof_blk_per_sync.
|
51 |
|
|
--
|
52 |
|
|
-- If g_preserve_bsn=TRUE then src_out.bsn = snk_in.bsn, else the
|
53 |
|
|
-- src_out.bsn is depends on the first ready and the initial g_bsn. If
|
54 |
|
|
-- g_preserve_bsn=TRUE then g_nof_data needs to match the snk_in.sop/eop
|
55 |
|
|
-- blocks.
|
56 |
|
|
--
|
57 |
|
|
-- If g_preserve_channel=TRUE then src_out.channel = snk_in.channel, else
|
58 |
|
|
-- the src_out.channel = g_channel.
|
59 |
|
|
--
|
60 |
|
|
-- Remarks:
|
61 |
|
|
-- . Ready latency (RL) = 1
|
62 |
|
|
-- . Alternatively consider using dp_block_gen_valid_arr.vhd or
|
63 |
|
|
-- dp_block_reshape.vhd.
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
LIBRARY IEEE, common_pkg_lib, dp_pkg_lib;
|
67 |
|
|
USE IEEE.STD_LOGIC_1164.ALL;
|
68 |
|
|
USE IEEE.NUMERIC_STD.ALL;
|
69 |
|
|
USE common_pkg_lib.common_pkg.ALL;
|
70 |
|
|
USE dp_pkg_lib.dp_stream_pkg.ALL;
|
71 |
|
|
|
72 |
|
|
ENTITY dp_block_gen IS
|
73 |
|
|
GENERIC (
|
74 |
|
|
g_use_src_in : BOOLEAN := TRUE; -- when true use src_in.ready else use snk_in.valid for flow control
|
75 |
|
|
g_nof_data : POSITIVE := 1; -- nof data per block
|
76 |
|
|
g_nof_blk_per_sync : POSITIVE := 8;
|
77 |
|
|
g_empty : NATURAL := 0;
|
78 |
|
|
g_channel : NATURAL := 0;
|
79 |
|
|
g_error : NATURAL := 0;
|
80 |
|
|
g_bsn : NATURAL := 0;
|
81 |
|
|
g_preserve_sync : BOOLEAN := FALSE;
|
82 |
|
|
g_preserve_bsn : BOOLEAN := FALSE;
|
83 |
|
|
g_preserve_channel : BOOLEAN := FALSE
|
84 |
|
|
);
|
85 |
|
|
PORT (
|
86 |
|
|
rst : IN STD_LOGIC;
|
87 |
|
|
clk : IN STD_LOGIC;
|
88 |
|
|
-- Streaming sink
|
89 |
|
|
snk_out : OUT t_dp_siso; -- pass on src_in.xon, pass on or force snk_out.ready dependend on g_use_src_in
|
90 |
|
|
snk_in : IN t_dp_sosi := c_dp_sosi_rst;
|
91 |
|
|
-- Streaming source
|
92 |
|
|
src_in : IN t_dp_siso := c_dp_siso_rdy;
|
93 |
|
|
src_out : OUT t_dp_sosi;
|
94 |
|
|
-- MM control
|
95 |
|
|
en : IN STD_LOGIC := '1'
|
96 |
|
|
);
|
97 |
|
|
END dp_block_gen;
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
ARCHITECTURE rtl OF dp_block_gen IS
|
101 |
|
|
|
102 |
|
|
TYPE t_state IS (s_sop, s_data, s_eop);
|
103 |
|
|
|
104 |
|
|
TYPE t_reg IS RECORD -- local registers
|
105 |
|
|
state : t_state;
|
106 |
|
|
data_cnt : NATURAL RANGE 0 TO g_nof_data;
|
107 |
|
|
blk_cnt : NATURAL RANGE 0 TO g_nof_blk_per_sync;
|
108 |
|
|
bsn : STD_LOGIC_VECTOR(c_dp_stream_bsn_w-1 DOWNTO 0);
|
109 |
|
|
src_out : t_dp_sosi;
|
110 |
|
|
END RECORD;
|
111 |
|
|
|
112 |
|
|
CONSTANT c_reg_rst : t_reg := (s_sop, 0, 0, TO_DP_BSN(g_bsn), c_dp_sosi_rst);
|
113 |
|
|
|
114 |
|
|
SIGNAL ready : STD_LOGIC;
|
115 |
|
|
|
116 |
|
|
-- Define the local registers in t_reg record
|
117 |
|
|
SIGNAL r : t_reg;
|
118 |
|
|
SIGNAL nxt_r : t_reg;
|
119 |
|
|
|
120 |
|
|
BEGIN
|
121 |
|
|
|
122 |
|
|
snk_out.ready <= src_in.ready WHEN g_use_src_in=TRUE ELSE '1'; -- force snk_out.ready = '1' when src_in.ready is not used
|
123 |
|
|
snk_out.xon <= src_in.xon; -- always pass on siso.xon
|
124 |
|
|
|
125 |
|
|
src_out <= r.src_out;
|
126 |
|
|
|
127 |
|
|
p_clk : PROCESS(rst, clk)
|
128 |
|
|
BEGIN
|
129 |
|
|
IF rst='1' THEN
|
130 |
|
|
r <= c_reg_rst;
|
131 |
|
|
ELSIF rising_edge(clk) THEN
|
132 |
|
|
r <= nxt_r;
|
133 |
|
|
END IF;
|
134 |
|
|
END PROCESS;
|
135 |
|
|
|
136 |
|
|
ready <= src_in.ready WHEN g_use_src_in=TRUE ELSE snk_in.valid;
|
137 |
|
|
|
138 |
|
|
p_state : PROCESS(r, en, ready, snk_in)
|
139 |
|
|
BEGIN
|
140 |
|
|
nxt_r <= r;
|
141 |
|
|
|
142 |
|
|
IF g_use_src_in=FALSE THEN
|
143 |
|
|
nxt_r.src_out.data <= snk_in.data;
|
144 |
|
|
nxt_r.src_out.re <= snk_in.re;
|
145 |
|
|
nxt_r.src_out.im <= snk_in.im;
|
146 |
|
|
END IF;
|
147 |
|
|
|
148 |
|
|
IF g_preserve_sync = FALSE THEN
|
149 |
|
|
nxt_r.src_out.sync <= '0';
|
150 |
|
|
ELSE
|
151 |
|
|
nxt_r.src_out.sync <= snk_in.sync;
|
152 |
|
|
END IF;
|
153 |
|
|
|
154 |
|
|
nxt_r.src_out.valid <= '0';
|
155 |
|
|
nxt_r.src_out.sop <= '0';
|
156 |
|
|
nxt_r.src_out.eop <= '0';
|
157 |
|
|
|
158 |
|
|
IF g_preserve_bsn=TRUE THEN
|
159 |
|
|
nxt_r.src_out.bsn <= snk_in.bsn;
|
160 |
|
|
END IF;
|
161 |
|
|
|
162 |
|
|
IF g_preserve_channel=TRUE THEN
|
163 |
|
|
nxt_r.src_out.channel <= snk_in.channel;
|
164 |
|
|
END IF;
|
165 |
|
|
|
166 |
|
|
CASE r.state IS
|
167 |
|
|
WHEN s_sop =>
|
168 |
|
|
nxt_r.data_cnt <= 0; -- for clarity init data count to 0 (because it will become 1 anyway at sop)
|
169 |
|
|
IF en='0' THEN -- if disabled then reset block generator and remain in this state
|
170 |
|
|
nxt_r.blk_cnt <= 0;
|
171 |
|
|
nxt_r.bsn <= TO_DP_BSN(g_bsn);
|
172 |
|
|
ELSE -- enabled block generator
|
173 |
|
|
IF ready='1' THEN -- once enabled the complete block will be output dependent on the flow control
|
174 |
|
|
-- use input sync or create local sync
|
175 |
|
|
IF g_preserve_sync = FALSE THEN
|
176 |
|
|
IF r.blk_cnt=0 THEN
|
177 |
|
|
nxt_r.src_out.sync <= '1'; -- use local sync for this block, local sync starts at first ready
|
178 |
|
|
END IF;
|
179 |
|
|
IF r.blk_cnt>=g_nof_blk_per_sync-1 THEN -- maintain local sync interval
|
180 |
|
|
nxt_r.blk_cnt <= 0;
|
181 |
|
|
ELSE
|
182 |
|
|
nxt_r.blk_cnt <= r.blk_cnt+1;
|
183 |
|
|
END IF;
|
184 |
|
|
END IF;
|
185 |
|
|
nxt_r.src_out.valid <= '1';
|
186 |
|
|
nxt_r.src_out.sop <= '1';
|
187 |
|
|
|
188 |
|
|
-- use input bsn or create local bsn
|
189 |
|
|
IF g_preserve_bsn=FALSE THEN
|
190 |
|
|
nxt_r.bsn <= INCR_UVEC(r.bsn, 1); -- increment local bsn for next block
|
191 |
|
|
nxt_r.src_out.bsn <= r.bsn; -- use local bsn for this block
|
192 |
|
|
END IF;
|
193 |
|
|
|
194 |
|
|
-- use input channel or create fixed local channel
|
195 |
|
|
IF g_preserve_channel=FALSE THEN
|
196 |
|
|
nxt_r.src_out.channel <= TO_DP_CHANNEL(g_channel);
|
197 |
|
|
END IF;
|
198 |
|
|
|
199 |
|
|
IF g_nof_data=1 THEN
|
200 |
|
|
nxt_r.src_out.eop <= '1'; -- single word block
|
201 |
|
|
nxt_r.src_out.empty <= TO_DP_EMPTY(g_empty);
|
202 |
|
|
nxt_r.src_out.err <= TO_DP_ERROR(g_error);
|
203 |
|
|
ELSIF g_nof_data=2 THEN
|
204 |
|
|
nxt_r.data_cnt <= 1; -- start of two word block
|
205 |
|
|
nxt_r.state <= s_eop;
|
206 |
|
|
ELSE
|
207 |
|
|
nxt_r.data_cnt <= 1; -- start of multi word block
|
208 |
|
|
nxt_r.state <= s_data;
|
209 |
|
|
END IF;
|
210 |
|
|
END IF;
|
211 |
|
|
END IF;
|
212 |
|
|
WHEN s_data =>
|
213 |
|
|
IF ready='1' THEN
|
214 |
|
|
nxt_r.data_cnt <= r.data_cnt+1;
|
215 |
|
|
nxt_r.src_out.valid <= '1';
|
216 |
|
|
IF r.data_cnt=g_nof_data-2 THEN
|
217 |
|
|
nxt_r.state <= s_eop;
|
218 |
|
|
END IF;
|
219 |
|
|
END IF;
|
220 |
|
|
WHEN OTHERS => -- s_eop
|
221 |
|
|
IF ready='1' THEN
|
222 |
|
|
nxt_r.src_out.valid <= '1';
|
223 |
|
|
nxt_r.src_out.eop <= '1';
|
224 |
|
|
nxt_r.src_out.empty <= TO_DP_EMPTY(g_empty);
|
225 |
|
|
nxt_r.src_out.err <= TO_DP_ERROR(g_error);
|
226 |
|
|
nxt_r.state <= s_sop;
|
227 |
|
|
END IF;
|
228 |
|
|
END CASE;
|
229 |
|
|
END PROCESS;
|
230 |
|
|
|
231 |
|
|
END rtl;
|