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

Subversion Repositories astron_fifo

[/] [astron_fifo/] [trunk/] [dp_fifo_core.vhd] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 danv
-------------------------------------------------------------------------------
2
--
3
-- Copyright (C) 2014
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:
23
--   Provide input ready control and use output ready control to the FIFO.
24
--   Pass sop and eop along with the data through the FIFO if g_use_ctrl=TRUE.
25
--   Default the RL=1, use g_fifo_rl=0 for a the show ahead FIFO.
26
-- Description:
27
--   Provide the sink ready for FIFO write control and use source ready for
28
--   FIFO read access. The sink ready output is derived from FIFO almost full.
29
--   Data without framing can use g_use_ctrl=FALSE to avoid implementing two
30
--   data bits for sop and eop in the FIFO word width. Idem for g_use_sync,
31
--   g_use_empty, g_use_channel and g_use_error.
32
-- Remark:
33
-- . The bsn, empty, channel and error fields are valid at the sop and or eop.
34
--   Therefore alternatively these fields can be passed on through a separate
35
--   FIFO, with only one entry per frame, to save FIFO memory in case
36
--   concatenating them makes the FIFO word width larger than a standard
37
--   memory data word width.
38
-- . The FIFO makes that the src_in.ready and snk_out.ready are not
39
--   combinatorially connected, so this can ease the timing closure for the
40
--   ready signal.
41
 
42
LIBRARY IEEE, common_pkg_lib, dp_components_lib, common_fifo_lib, dp_pkg_lib, technology_lib;
43
USE IEEE.STD_LOGIC_1164.ALL;
44
USE IEEE.numeric_std.ALL;
45
USE common_pkg_lib.common_pkg.ALL;
46
USE dp_pkg_lib.dp_stream_pkg.ALL;
47
USE technology_lib.technology_select_pkg.ALL;
48
 
49
ENTITY dp_fifo_core IS
50
  GENERIC (
51
    g_technology     : NATURAL := c_tech_select_default;
52
    g_note_is_ful    : BOOLEAN := TRUE;   -- when TRUE report NOTE when FIFO goes full, fifo overflow is always reported as FAILURE
53
    g_use_dual_clock : BOOLEAN := FALSE;
54
    g_use_lut_sc     : BOOLEAN := FALSE;  -- when TRUE then force using LUTs instead of block RAM for single clock FIFO (bot available for dual clock FIFO)
55
    g_data_w         : NATURAL := 16; -- Should be 2 times the c_complex_w if g_use_complex = TRUE
56
    g_data_signed    : BOOLEAN := FALSE; -- TRUE extends g_data_w bits with the sign bit, FALSE pads g_data_w bits with zeros.
57
    g_bsn_w          : NATURAL := 1;
58
    g_empty_w        : NATURAL := 1;
59
    g_channel_w      : NATURAL := 1;
60
    g_error_w        : NATURAL := 1;
61
    g_use_bsn        : BOOLEAN := FALSE;
62
    g_use_empty      : BOOLEAN := FALSE;
63
    g_use_channel    : BOOLEAN := FALSE;
64
    g_use_error      : BOOLEAN := FALSE;
65
    g_use_sync       : BOOLEAN := FALSE;
66
    g_use_ctrl       : BOOLEAN := TRUE;  -- sop & eop
67
    g_use_complex    : BOOLEAN := FALSE; -- TRUE feeds the concatenated complex fields (im & re) through the FIFO instead of the data field.
68
    g_fifo_size      : NATURAL := 512;   -- (16+2) * 512 = 1 M9K, g_data_w+2 for sop and eop
69
    g_fifo_af_margin : NATURAL := 4;     -- >=4, Nof words below max (full) at which fifo is considered almost full
70
    g_fifo_rl        : NATURAL := 1
71
  );
72
  PORT (
73
    wr_rst      : IN  STD_LOGIC;
74
    wr_clk      : IN  STD_LOGIC;
75
    rd_rst      : IN  STD_LOGIC;
76
    rd_clk      : IN  STD_LOGIC;
77
    -- Monitor FIFO filling
78
    wr_ful      : OUT STD_LOGIC;  -- corresponds to the carry bit of wr_usedw when FIFO is full
79
    wr_usedw    : OUT STD_LOGIC_VECTOR(ceil_log2(g_fifo_size)-1 DOWNTO 0);
80
    rd_usedw    : OUT STD_LOGIC_VECTOR(ceil_log2(g_fifo_size)-1 DOWNTO 0);
81
    rd_emp      : OUT STD_LOGIC;
82
    -- ST sink
83
    snk_out     : OUT t_dp_siso;
84
    snk_in      : IN  t_dp_sosi;
85
    -- ST source
86
    src_in      : IN  t_dp_siso;
87
    src_out     : OUT t_dp_sosi
88
  );
89
END dp_fifo_core;
90
 
91
 
92
ARCHITECTURE str OF dp_fifo_core IS
93
 
94
  CONSTANT c_use_data         : BOOLEAN := TRUE;
95
  CONSTANT c_ctrl_w           : NATURAL := 2;  -- sop and eop
96
 
97
  CONSTANT c_complex_w        : NATURAL := smallest(c_dp_stream_dsp_data_w, g_data_w/2);  -- needed to cope with g_data_w > 2*c_dp_stream_dsp_data_w
98
 
99
  CONSTANT c_fifo_almost_full : NATURAL := g_fifo_size-g_fifo_af_margin;  -- FIFO almost full level for snk_out.ready
100
  CONSTANT c_fifo_dat_w       : NATURAL := func_slv_concat_w(c_use_data, g_use_bsn, g_use_empty, g_use_channel, g_use_error, g_use_sync, g_use_ctrl,
101
                                                             g_data_w,   g_bsn_w,   g_empty_w,   g_channel_w,   g_error_w,   1,          c_ctrl_w);  -- concat via FIFO
102
 
103
  SIGNAL nxt_snk_out   : t_dp_siso := c_dp_siso_rst;
104
 
105
  SIGNAL arst          : STD_LOGIC;
106
 
107
  SIGNAL wr_data_complex : STD_LOGIC_VECTOR(2*c_complex_w-1 DOWNTO 0);
108
  SIGNAL wr_data         : STD_LOGIC_VECTOR(g_data_w-1 DOWNTO 0);
109
  SIGNAL rd_data         : STD_LOGIC_VECTOR(g_data_w-1 DOWNTO 0);
110
 
111
  SIGNAL fifo_wr_dat   : STD_LOGIC_VECTOR(c_fifo_dat_w-1 DOWNTO 0);
112
  SIGNAL fifo_wr_req   : STD_LOGIC;
113
  SIGNAL fifo_wr_ful   : STD_LOGIC;
114
  SIGNAL fifo_wr_usedw : STD_LOGIC_VECTOR(wr_usedw'RANGE);
115
 
116
  SIGNAL fifo_rd_dat   : STD_LOGIC_VECTOR(c_fifo_dat_w-1 DOWNTO 0) := (OTHERS=>'0');
117
  SIGNAL fifo_rd_val   : STD_LOGIC;
118
  SIGNAL fifo_rd_req   : STD_LOGIC;
119
  SIGNAL fifo_rd_emp   : STD_LOGIC;
120
  SIGNAL fifo_rd_usedw : STD_LOGIC_VECTOR(rd_usedw'RANGE);
121
 
122
  SIGNAL wr_sync       : STD_LOGIC_VECTOR(0 DOWNTO 0);
123
  SIGNAL rd_sync       : STD_LOGIC_VECTOR(0 DOWNTO 0);
124
  SIGNAL wr_ctrl       : STD_LOGIC_VECTOR(1 DOWNTO 0);
125
  SIGNAL rd_ctrl       : STD_LOGIC_VECTOR(1 DOWNTO 0);
126
 
127
  SIGNAL rd_siso       : t_dp_siso;
128
  SIGNAL rd_sosi       : t_dp_sosi := c_dp_sosi_rst;  -- initialize default values for unused sosi fields
129
 
130
BEGIN
131
 
132
  -- Output monitor FIFO filling
133
  wr_ful   <= fifo_wr_ful;
134
  wr_usedw <= fifo_wr_usedw;
135
  rd_usedw <= fifo_rd_usedw;
136
  rd_emp   <= fifo_rd_emp;
137
 
138
  p_wr_clk: PROCESS(wr_clk, wr_rst)
139
  BEGIN
140
    IF wr_rst='1' THEN
141
      snk_out <= c_dp_siso_rst;
142
    ELSIF rising_edge(wr_clk) THEN
143
      snk_out <= nxt_snk_out;
144
    END IF;
145
  END PROCESS;
146
 
147
  wr_sync(0) <= snk_in.sync;
148
  wr_ctrl    <= snk_in.sop & snk_in.eop;
149
 
150
  -- Assign the snk_in data field or concatenated complex fields to the FIFO wr_data depending on g_use_complex
151
  wr_data_complex <= snk_in.im(c_complex_w-1 DOWNTO 0) & snk_in.re(c_complex_w-1 DOWNTO 0);
152
  wr_data         <= snk_in.data(g_data_w-1 DOWNTO 0) WHEN g_use_complex = FALSE ELSE RESIZE_UVEC(wr_data_complex, g_data_w);
153
 
154
  -- fifo wr wires
155
  fifo_wr_req <= snk_in.valid;
156
  fifo_wr_dat <= func_slv_concat(c_use_data, g_use_bsn, g_use_empty, g_use_channel, g_use_error, g_use_sync, g_use_ctrl,
157
                                 wr_data,
158
                                 snk_in.bsn(        g_bsn_w-1 DOWNTO 0),
159
                                 snk_in.empty(    g_empty_w-1 DOWNTO 0),
160
                                 snk_in.channel(g_channel_w-1 DOWNTO 0),
161
                                 snk_in.err(      g_error_w-1 DOWNTO 0),
162
                                 wr_sync,
163
                                 wr_ctrl);
164
 
165
  -- pass on frame level flow control
166
  nxt_snk_out.xon <= src_in.xon;
167
 
168
  -- up stream use fifo almost full to control snk_out.ready
169
  nxt_snk_out.ready <= '1' WHEN UNSIGNED(fifo_wr_usedw)<c_fifo_almost_full ELSE '0';
170
 
171
  gen_common_fifo_sc : IF g_use_dual_clock=FALSE GENERATE
172
    u_common_fifo_sc : ENTITY common_fifo_lib.common_fifo_sc
173
    GENERIC MAP (
174
      g_technology => g_technology,
175
      g_note_is_ful => g_note_is_ful,
176
      g_use_lut   => g_use_lut_sc,
177
      g_dat_w     => c_fifo_dat_w,
178
      g_nof_words => g_fifo_size
179
    )
180
    PORT MAP (
181
      rst      => rd_rst,
182
      clk      => rd_clk,
183
      wr_dat   => fifo_wr_dat,
184
      wr_req   => fifo_wr_req,
185
      wr_ful   => fifo_wr_ful,
186
      rd_dat   => fifo_rd_dat,
187
      rd_req   => fifo_rd_req,
188
      rd_emp   => fifo_rd_emp,
189
      rd_val   => fifo_rd_val,
190
      usedw    => fifo_rd_usedw
191
    );
192
 
193
    fifo_wr_usedw <= fifo_rd_usedw;
194
  END GENERATE;
195
 
196
  gen_common_fifo_dc : IF g_use_dual_clock=TRUE GENERATE
197
    u_common_fifo_dc : ENTITY common_fifo_lib.common_fifo_dc
198
    GENERIC MAP (
199
      g_technology => g_technology,
200
      g_dat_w     => c_fifo_dat_w,
201
      g_nof_words => g_fifo_size
202
    )
203
    PORT MAP (
204
      rst     => arst,
205
      wr_clk  => wr_clk,
206
      wr_dat  => fifo_wr_dat,
207
      wr_req  => fifo_wr_req,
208
      wr_ful  => fifo_wr_ful,
209
      wrusedw => fifo_wr_usedw,
210
      rd_clk  => rd_clk,
211
      rd_dat  => fifo_rd_dat,
212
      rd_req  => fifo_rd_req,
213
      rd_emp  => fifo_rd_emp,
214
      rdusedw => fifo_rd_usedw,
215
      rd_val  => fifo_rd_val
216
    );
217
 
218
    arst <= wr_rst OR rd_rst;
219
  END GENERATE;
220
 
221
  -- Extract the data from the wide FIFO output SLV. rd_data will be assigned to rd_sosi.data or rd_sosi.im & rd_sosi.re depending on g_use_complex.
222
  rd_data <= func_slv_extract(c_use_data, g_use_bsn, g_use_empty, g_use_channel, g_use_error, g_use_sync, g_use_ctrl, g_data_w, g_bsn_w, g_empty_w, g_channel_w, g_error_w, 1, c_ctrl_w, fifo_rd_dat, 0);
223
 
224
  -- fifo rd wires
225
  -- SISO
226
  fifo_rd_req <= rd_siso.ready;
227
 
228
  -- SOSI
229
  rd_sosi.data    <= RESIZE_DP_SDATA(rd_data) WHEN g_data_signed=TRUE ELSE RESIZE_DP_DATA(rd_data);
230
  rd_sosi.re      <= RESIZE_DP_DSP_DATA(rd_data(  c_complex_w-1 DOWNTO 0));
231
  rd_sosi.im      <= RESIZE_DP_DSP_DATA(rd_data(2*c_complex_w-1 DOWNTO c_complex_w));
232
  rd_sosi.bsn     <= RESIZE_DP_BSN(func_slv_extract(c_use_data, g_use_bsn, g_use_empty, g_use_channel, g_use_error, g_use_sync, g_use_ctrl, g_data_w, g_bsn_w, g_empty_w, g_channel_w, g_error_w, 1, c_ctrl_w, fifo_rd_dat, 1));
233
  rd_sosi.empty   <= RESIZE_DP_EMPTY(func_slv_extract(c_use_data, g_use_bsn, g_use_empty, g_use_channel, g_use_error, g_use_sync, g_use_ctrl, g_data_w, g_bsn_w, g_empty_w, g_channel_w, g_error_w, 1, c_ctrl_w, fifo_rd_dat, 2));
234
  rd_sosi.channel <= RESIZE_DP_CHANNEL(func_slv_extract(c_use_data, g_use_bsn, g_use_empty, g_use_channel, g_use_error, g_use_sync, g_use_ctrl, g_data_w, g_bsn_w, g_empty_w, g_channel_w, g_error_w, 1, c_ctrl_w, fifo_rd_dat, 3));
235
  rd_sosi.err     <= RESIZE_DP_ERROR(func_slv_extract(c_use_data, g_use_bsn, g_use_empty, g_use_channel, g_use_error, g_use_sync, g_use_ctrl, g_data_w, g_bsn_w, g_empty_w, g_channel_w, g_error_w, 1, c_ctrl_w, fifo_rd_dat, 4));
236
  rd_sync         <= func_slv_extract(c_use_data, g_use_bsn, g_use_empty, g_use_channel, g_use_error, g_use_sync, g_use_ctrl, g_data_w, g_bsn_w, g_empty_w, g_channel_w, g_error_w, 1, c_ctrl_w, fifo_rd_dat, 5);
237
  rd_ctrl         <= func_slv_extract(c_use_data, g_use_bsn, g_use_empty, g_use_channel, g_use_error, g_use_sync, g_use_ctrl, g_data_w, g_bsn_w, g_empty_w, g_channel_w, g_error_w, 1, c_ctrl_w, fifo_rd_dat, 6);
238
 
239
  rd_sosi.sync    <= fifo_rd_val AND rd_sync(0);
240
  rd_sosi.valid   <= fifo_rd_val;
241
  rd_sosi.sop     <= fifo_rd_val AND rd_ctrl(1);
242
  rd_sosi.eop     <= fifo_rd_val AND rd_ctrl(0);
243
 
244
  u_ready_latency : ENTITY dp_components_lib.dp_latency_adapter
245
  GENERIC MAP (
246
    g_in_latency  => 1,
247
    g_out_latency => g_fifo_rl
248
  )
249
  PORT MAP (
250
    rst       => rd_rst,
251
    clk       => rd_clk,
252
    -- ST sink
253
    snk_out   => rd_siso,
254
    snk_in    => rd_sosi,
255
    -- ST source
256
    src_in    => src_in,
257
    src_out   => src_out
258
  );
259
 
260
END str;

powered by: WebSVN 2.1.0

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