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 2

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

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

powered by: WebSVN 2.1.0

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