OpenCores
URL https://opencores.org/ocsvn/dp_components/dp_components/trunk

Subversion Repositories dp_components

[/] [dp_components/] [trunk/] [dp_latency_adapter.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 danv
-------------------------------------------------------------------------------
2
--
3 4 danv
-- Copyright 2020
4 2 danv
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
5
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
6 4 danv
-- 
7
-- Licensed under the Apache License, Version 2.0 (the "License");
8
-- you may not use this file except in compliance with the License.
9
-- You may obtain a copy of the License at
10
-- 
11
--     http://www.apache.org/licenses/LICENSE-2.0
12
-- 
13
-- Unless required by applicable law or agreed to in writing, software
14
-- distributed under the License is distributed on an "AS IS" BASIS,
15
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
-- See the License for the specific language governing permissions and
17
-- limitations under the License.
18 2 danv
--
19
-------------------------------------------------------------------------------
20
 
21
LIBRARY IEEE, common_pkg_lib, dp_pkg_lib;
22
USE IEEE.std_logic_1164.ALL;
23
USE IEEE.numeric_std.ALL;
24
USE common_pkg_lib.common_pkg.ALL;
25
USE dp_pkg_lib.dp_stream_pkg.ALL;
26
 
27
-- Purpose:
28
--   Adapt the g_in_latency input ready to the g_out_latency output latency.
29
--   A typical application is to use this latency adapter to provide a read
30
--   ahead interface to a default FIFO with e.g. read latency 1 or 2.
31
-- Description:
32
--   If g_in_latency > g_out_latency then the input latency is first adapted
33
--   to zero latency by means of a latency FIFO. After that a delay line for
34
--   src_in.ready yields the g_out_latency output latency.
35
--   If g_in_latency < g_out_latency, then a delay line for src_in.ready yields
36
--   the g_out_latency output latency.
37
--   The sync input is also passed on, only if it occurs during valid. The
38
--   constant c_pass_sync_during_not_valid is defined to preserve the
39
--   corresponding section of code for passing the sync also during not valid.
40
-- Remark:
41
-- . The snk_out.ready is derived combinatorially from the src_in.ready. If for
42
--   timing performance it is needed to register snk_out.ready, then this can
43
--   be done by first increasing the ready latency using this adapter with
44
--   g_in_latency = g_out_latency + 1, followed by a second adapter to reach
45
--   the required output ready latency latency.
46
 
47
ENTITY dp_latency_adapter IS
48
  GENERIC (
49
    g_in_latency   : NATURAL := 3;
50
    g_out_latency  : NATURAL := 1
51
  );
52
  PORT (
53
    rst          : IN  STD_LOGIC;
54
    clk          : IN  STD_LOGIC;
55
    -- Monitor internal FIFO filling
56
    fifo_usedw   : OUT STD_LOGIC_VECTOR(ceil_log2(2+g_in_latency)-1 DOWNTO 0);  -- see description of c_fifo_size, c_usedw_w for explanation of why +2
57
    fifo_ful     : OUT STD_LOGIC;
58
    fifo_emp     : OUT STD_LOGIC;
59
    -- ST sink
60
    snk_out      : OUT t_dp_siso;
61
    snk_in       : IN  t_dp_sosi;
62
    -- ST source
63
    src_in       : IN  t_dp_siso;
64
    src_out      : OUT t_dp_sosi
65
  );
66
END dp_latency_adapter;
67
 
68
 
69
ARCHITECTURE rtl OF dp_latency_adapter IS
70
 
71
  -- The difference between the input ready latency and the output ready latency
72
  CONSTANT c_diff_latency               : INTEGER := g_out_latency - g_in_latency;
73
 
74
  -- Define constant to preserve the corresponding section of code, but default keep it at FALSE
75
  CONSTANT c_pass_sync_during_not_valid : BOOLEAN := FALSE;
76
 
77
  -- Use g_in_latency+1 words for the FIFO data array, to go to zero latency
78
  CONSTANT c_high           : NATURAL := g_in_latency;
79
  CONSTANT c_fifo_size      : NATURAL := g_in_latency+1;            -- +1 because RL=0 also requires a word
80
  CONSTANT c_usedw_w        : NATURAL := ceil_log2(c_fifo_size+1);  -- +1 because to store value 2**n requires n+1 bits
81
 
82
  SIGNAL fifo_reg           : t_dp_sosi_arr(c_high DOWNTO 0);
83
  SIGNAL nxt_fifo_reg       : t_dp_sosi_arr(c_high DOWNTO 0);
84
  SIGNAL fifo_reg_valid     : STD_LOGIC_VECTOR(c_high DOWNTO 0);    -- debug signal for Wave window
85
 
86
  SIGNAL nxt_fifo_usedw     : STD_LOGIC_VECTOR(c_usedw_w-1 DOWNTO 0);
87
  SIGNAL nxt_fifo_ful       : STD_LOGIC;
88
  SIGNAL nxt_fifo_emp       : STD_LOGIC;
89
 
90
  SIGNAL ff_siso            : t_dp_siso;  -- SISO ready
91
  SIGNAL ff_sosi            : t_dp_sosi;  -- SOSI
92
 
93
  SIGNAL i_snk_out          : t_dp_siso := c_dp_siso_rdy;
94
 
95
BEGIN
96
 
97
  -- Use i_snk_out with defaults to force unused snk_out bits and fields to '0'
98
  snk_out <= i_snk_out;
99
 
100
  gen_wires : IF c_diff_latency = 0 GENERATE  -- g_out_latency = g_in_latency
101
    i_snk_out <= src_in;  -- SISO
102
    src_out   <= snk_in;  -- SOSI
103
  END GENERATE gen_wires;
104
 
105
 
106
  no_fifo : IF c_diff_latency > 0 GENERATE  -- g_out_latency > g_in_latency
107
    -- Go from g_in_latency to required larger g_out_latency
108
    u_latency : ENTITY work.dp_latency_increase
109
    GENERIC MAP (
110
      g_in_latency   => g_in_latency,
111
      g_incr_latency => c_diff_latency
112
    )
113
    PORT MAP (
114
      rst       => rst,
115
      clk       => clk,
116
      -- ST sink
117
      snk_out   => i_snk_out,
118
      snk_in    => snk_in,
119
      -- ST source
120
      src_in    => src_in,
121
      src_out   => src_out
122
    );
123
  END GENERATE no_fifo;
124
 
125
 
126
  gen_fifo : IF c_diff_latency < 0 GENERATE  -- g_out_latency < g_in_latency
127
    -- Register [0] contains the FIFO output with zero ready latency
128
    ff_sosi <= fifo_reg(0);
129
 
130
    p_clk_fifo : PROCESS(rst, clk)
131
    BEGIN
132
      IF rst='1' THEN
133
        fifo_reg   <= (OTHERS=>c_dp_sosi_rst);
134
        fifo_usedw <= (OTHERS=>'0');
135
        fifo_ful   <= '0';
136
        fifo_emp   <= '1';
137
      ELSIF rising_edge(clk) THEN
138
        fifo_reg   <= nxt_fifo_reg;
139
        fifo_usedw <= nxt_fifo_usedw;
140
        fifo_ful   <= nxt_fifo_ful;
141
        fifo_emp   <= nxt_fifo_emp;
142
      END IF;
143
    END PROCESS;
144
 
145
    -- Pass on frame level flow control
146
    i_snk_out.xon <= src_in.xon;
147
 
148
    p_snk_out_ready : PROCESS(fifo_reg, ff_siso, snk_in)
149
    BEGIN
150
      i_snk_out.ready <= '0';
151
      IF ff_siso.ready='1' THEN
152
        -- Default snk_out ready when the source is ready.
153
        i_snk_out.ready <= '1';
154
      ELSE
155
        -- Extra snk_out ready to look ahead for src_in RL = 0.
156
        -- The fifo_reg[h:0] size is g_in_latency+1 number of SOSI values.
157
        -- . The fifo_reg[h:1] provide free space for h=g_in_latency nof data
158
        --   when snk_out.ready is pulled low, because then there can still
159
        --   arrive g_in_latency nof new data with snk_in.valid asserted.
160
        -- . The [0] is the registered output SOSI value with RL=0. Therefore
161
        --   fifo_reg[0] can still accept a new input when ff_siso.ready is
162
        --   low. If this assignment is omitted then the functionallity is
163
        --   still OK, but the throughtput sligthly reduces.
164
        IF fifo_reg(0).valid='0' THEN
165
          i_snk_out.ready <= '1';
166
        ELSIF fifo_reg(1).valid='0' THEN
167
          i_snk_out.ready <= NOT(snk_in.valid);
168
        END IF;
169
      END IF;
170
    END PROCESS;
171
 
172
    p_fifo_reg : PROCESS(fifo_reg, ff_siso, snk_in)
173
    BEGIN
174
      -- Keep or shift the fifo_reg dependent on ff_siso.ready, no need to explicitly check fifo_reg().valid
175
      nxt_fifo_reg <= fifo_reg;
176
      IF ff_siso.ready='1' THEN
177
        nxt_fifo_reg(c_high-1 DOWNTO 0) <= fifo_reg(c_high DOWNTO 1);
178
        nxt_fifo_reg(c_high).valid <= '0';
179
        nxt_fifo_reg(c_high).sync  <= '0';
180
        nxt_fifo_reg(c_high).sop   <= '0';
181
        nxt_fifo_reg(c_high).eop   <= '0';
182
        -- Forcing the nxt_fifo_reg[h] control fields to '0' is robust, but not
183
        -- strictly necessary, because the control fields in fifo_reg[h] will
184
        -- have been set to '0' already earlier due to the snk_in when
185
        -- ff_siso.ready was '0'.
186
      END IF;
187
 
188
      -- Put input data at the first available location dependent on ff_siso.ready, no need to explicitly check snk_in.valid
189
      IF fifo_reg(0).valid='0' THEN
190
        nxt_fifo_reg(0) <= snk_in;               -- fifo_reg is empty
191
      ELSE
192
        -- The fifo_reg is not empty, so filled to some extend
193
        FOR I IN 1 TO c_high LOOP
194
          IF fifo_reg(I).valid='0' THEN
195
            IF ff_siso.ready='0' THEN
196
              nxt_fifo_reg(I)   <= snk_in;
197
            ELSE
198
              nxt_fifo_reg(I-1) <= snk_in;
199
            END IF;
200
            EXIT;
201
          END IF;
202
        END LOOP;
203
 
204
        -- Default the input sync during input data valid is only passed on with the valid input data.
205
        -- When c_pass_sync_during_not_valid is enabled then the input sync during input data not valid is passed on via the head fifo_reg(0) if the fifo_reg is empty.
206
        IF c_pass_sync_during_not_valid=TRUE AND snk_in.sync='1' AND snk_in.valid='0' THEN
207
          -- Otherwise for input sync during input data not valid we need to insert the input sync at the last location with valid data independent of ff_siso.ready, to avoid that it gets lost.
208
          -- For streams that do not use the sync this logic will be void and optimize away by synthesis, because then snk_in.sync = '0' fixed.
209
          IF fifo_reg(c_high).valid='1' THEN     -- fifo_reg is full
210
            nxt_fifo_reg(c_high).sync <= '1';    -- insert input sync
211
          ELSE
212
            FOR I IN c_high-1 DOWNTO 0 LOOP      -- fifo_reg is filled to some extend, so not full and not empty
213
              IF fifo_reg(I).valid='1' THEN
214
                nxt_fifo_reg(I+1).sync <= '0';   -- overrule default sync assignment
215
                nxt_fifo_reg(I).sync   <= '1';   -- insert input sync
216
                EXIT;
217
              END IF;
218
            END LOOP;
219
          END IF;
220
        END IF;
221
      END IF;
222
    END PROCESS;
223
 
224
    p_fifo_usedw : PROCESS(nxt_fifo_reg)
225
    BEGIN
226
      nxt_fifo_usedw <= (OTHERS=>'0');
227
      FOR I IN c_high DOWNTO 0 LOOP
228
        IF nxt_fifo_reg(I).valid='1' THEN
229
          nxt_fifo_usedw <= TO_UVEC(I+1, c_usedw_w);
230
          EXIT;
231
        END IF;
232
      END LOOP;
233
    END PROCESS;
234
 
235
    fifo_reg_valid <= func_dp_stream_arr_get(fifo_reg, "VALID");
236
 
237
    nxt_fifo_ful <= '1' WHEN TO_UINT(nxt_fifo_usedw)>=c_high+1 ELSE '0';  -- using >= or = is equivalent here
238
    nxt_fifo_emp <= '1' WHEN TO_UINT(nxt_fifo_usedw) =0        ELSE '0';
239
 
240
    -- Go from 0 FIFO latency to required g_out_latency (only wires when g_out_latency=0)
241
    u_latency : ENTITY work.dp_latency_increase
242
    GENERIC MAP (
243
      g_in_latency   => 0,
244
      g_incr_latency => g_out_latency
245
    )
246
    PORT MAP (
247
      rst       => rst,
248
      clk       => clk,
249
      -- ST sink
250
      snk_out   => ff_siso,
251
      snk_in    => ff_sosi,
252
      -- ST source
253
      src_in    => src_in,
254
      src_out   => src_out
255
    );
256
  END GENERATE gen_fifo;
257
 
258
END rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.