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

Subversion Repositories astron_fifo

[/] [astron_fifo/] [trunk/] [common_fifo_sc.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 danv
-------------------------------------------------------------------------------
2
--
3 3 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 3 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
-- Purpose: Single clock FIFO
22
 
23 4 danv
LIBRARY IEEE, common_pkg_lib, common_components_lib;
24 2 danv
USE IEEE.STD_LOGIC_1164.ALL;
25
USE common_pkg_lib.common_pkg.ALL;
26 4 danv
--USE technology_lib.technology_select_pkg.ALL;
27 2 danv
 
28
ENTITY common_fifo_sc IS
29
  GENERIC (
30 4 danv
    g_technology  : NATURAL := 0; --c_tech_select_default;
31 2 danv
    g_note_is_ful : BOOLEAN := TRUE;   -- when TRUE report NOTE when FIFO goes full, fifo overflow is always reported as FAILURE
32
    g_fail_rd_emp : BOOLEAN := FALSE;  -- when TRUE report FAILURE when read from an empty FIFO
33
    g_use_lut     : BOOLEAN := FALSE;  -- when TRUE then force using LUTs via Altera eab="OFF",
34
                                       -- else use default eab="ON" and ram_block_type="AUTO", default ram_block_type="AUTO" is sufficient, because
35
                                       --      there seems no need to force using RAM and there are two types of Stratix IV RAM (M9K and M144K)
36
    g_reset       : BOOLEAN := FALSE;  -- when TRUE release FIFO reset some cycles after rst release, else use rst directly
37
    g_init        : BOOLEAN := FALSE;  -- when TRUE force wr_req inactive for some cycles after FIFO reset release, else use wr_req as is
38
    g_dat_w       : NATURAL := 36;     -- 36 * 256 = 1 M9K
39
    g_nof_words   : NATURAL := c_bram_m9k_fifo_depth;
40
    g_af_margin   : NATURAL := 0       -- FIFO almost full margin for wr_aful flagging
41
  );
42
  PORT (
43
    rst      : IN  STD_LOGIC;
44
    clk      : IN  STD_LOGIC;
45
    wr_dat   : IN  STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0);
46
    wr_req   : IN  STD_LOGIC;
47
    wr_ful   : OUT STD_LOGIC;
48
    wr_aful  : OUT STD_LOGIC;          -- registered FIFO almost full flag
49
    rd_dat   : OUT STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0);
50
    rd_req   : IN  STD_LOGIC;
51
    rd_emp   : OUT STD_LOGIC;
52
    rd_val   : OUT STD_LOGIC;
53
    usedw    : OUT STD_LOGIC_VECTOR(ceil_log2(g_nof_words)-1 DOWNTO 0)
54
  );
55
END common_fifo_sc;
56
 
57
 
58
ARCHITECTURE str OF common_fifo_sc IS
59
 
60
  CONSTANT c_use_eab          : STRING := sel_a_b(g_use_lut, "OFF", "ON");  -- when g_use_lut=TRUE then force using LUTs via Altera eab="OFF", else default to ram_block_type = "AUTO"
61
 
62
  CONSTANT c_fifo_af_latency  : NATURAL := 1;                               -- pipeline register wr_aful
63
  CONSTANT c_fifo_af_margin   : NATURAL := g_af_margin+c_fifo_af_latency;   -- FIFO almost full level
64
 
65
  SIGNAL fifo_rst        : STD_LOGIC;
66
  SIGNAL fifo_init       : STD_LOGIC;
67
  SIGNAL fifo_wr_en      : STD_LOGIC;
68
  SIGNAL nxt_fifo_wr_en  : STD_LOGIC;
69
  SIGNAL fifo_wr_dat     : STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0);
70
  SIGNAL nxt_fifo_wr_dat : STD_LOGIC_VECTOR(fifo_wr_dat'RANGE);
71
  SIGNAL fifo_rd_en      : STD_LOGIC;
72
  SIGNAL fifo_full       : STD_LOGIC;
73
  SIGNAL fifo_empty      : STD_LOGIC;
74
  SIGNAL fifo_usedw      : STD_LOGIC_VECTOR(usedw'RANGE);
75
 
76
  SIGNAL nxt_wr_aful     : STD_LOGIC;
77
  SIGNAL nxt_rd_val      : STD_LOGIC;
78
 
79
BEGIN
80
 
81
  -- Control logic copied from common_fifo_sc(virtex4).vhd
82
 
83
  gen_fifo_rst : IF g_reset=TRUE GENERATE
84
    -- Make sure the reset lasts at least 3 cycles (see fifo_generator_ug175.pdf). This is necessary in case
85
    -- the FIFO reset is also used functionally to flush it, so not only after power up.
86
    u_fifo_rst : ENTITY common_components_lib.common_areset
87
    GENERIC MAP (
88
      g_rst_level => '1',
89
      g_delay_len => 4
90
    )
91
    PORT MAP (
92
      in_rst    => rst,
93
      clk       => clk,
94
      out_rst   => fifo_rst
95
    );
96
  END GENERATE;
97
  no_fifo_rst : IF g_reset=FALSE GENERATE
98
    fifo_rst <= rst;
99
  END GENERATE;
100
 
101
  gen_init : IF g_init=TRUE GENERATE
102
    -- Wait at least 3 cycles after reset release before allowing fifo_wr_en (see fifo_generator_ug175.pdf)
103
    u_fifo_init : ENTITY common_components_lib.common_areset
104
    GENERIC MAP (
105
      g_rst_level => '1',
106
      g_delay_len => 4
107
    )
108
    PORT MAP (
109
      in_rst    => fifo_rst,
110
      clk       => clk,
111
      out_rst   => fifo_init
112
    );
113
 
114
    p_init_reg : PROCESS(fifo_rst, clk)
115
    BEGIN
116
      IF fifo_rst='1' THEN
117
        fifo_wr_en  <= '0';
118
      ELSIF rising_edge(clk) THEN
119
        fifo_wr_dat <= nxt_fifo_wr_dat;
120
        fifo_wr_en  <= nxt_fifo_wr_en;
121
      END IF;
122
    END PROCESS;
123
 
124
    nxt_fifo_wr_dat <= wr_dat;
125
    nxt_fifo_wr_en  <= wr_req AND NOT fifo_init;  -- check on NOT full is not necessary according to fifo_generator_ug175.pdf
126
  END GENERATE;
127
  no_init : IF g_init=FALSE GENERATE
128
    fifo_wr_dat <= wr_dat;
129
    fifo_wr_en  <= wr_req;                        -- check on NOT full is not necessary according to fifo_generator_ug175.pdf
130
  END GENERATE;
131
 
132
  wr_ful <= fifo_full;
133
  rd_emp <= fifo_empty;
134
  usedw  <= fifo_usedw;
135
 
136
  fifo_rd_en <= rd_req;                         -- check on NOT empty is not necessary according to fifo_generator_ds317.pdf, so skip it to easy synthesis timing
137
 
138
  nxt_rd_val <= fifo_rd_en AND NOT fifo_empty;  -- check on NOT empty is necessary for rd_val
139
 
140
  nxt_wr_aful <= '0' WHEN TO_UINT(fifo_usedw)<g_nof_words-c_fifo_af_margin ELSE '1';
141
 
142
  p_clk : PROCESS(fifo_rst, clk)
143
  BEGIN
144
    IF fifo_rst='1' THEN
145
      wr_aful <= '0';
146
      rd_val  <= '0';
147
    ELSIF rising_edge(clk) THEN
148
      wr_aful <= nxt_wr_aful;
149
      rd_val  <= nxt_rd_val;
150
    END IF;
151
  END PROCESS;
152
 
153
  -- 0 < some threshold < usedw          < g_nof_words can be used as FIFO almost_full
154
  -- 0 <          usedw < some threshold < g_nof_words can be used as FIFO almost_empty
155 4 danv
  u_fifo : ENTITY work.tech_fifo_sc
156 2 danv
  GENERIC MAP (
157
    g_technology => g_technology,
158
    g_use_eab    => c_use_eab,
159
    g_dat_w      => g_dat_w,
160
    g_nof_words  => g_nof_words
161
  )
162
  PORT MAP (
163
    aclr    => fifo_rst,
164
    clock   => clk,
165
    data    => fifo_wr_dat,
166
    rdreq   => fifo_rd_en,
167
    wrreq   => fifo_wr_en,
168
    empty   => fifo_empty,
169
    full    => fifo_full,
170
    q       => rd_dat,
171
    usedw   => fifo_usedw
172
  );
173
 
174
  proc_common_fifo_asserts("common_fifo_sc", g_note_is_ful, g_fail_rd_emp, fifo_rst, clk, fifo_full, fifo_wr_en, clk, fifo_empty, fifo_rd_en);
175
 
176
END str;

powered by: WebSVN 2.1.0

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