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

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.hwp.storage/] [fifos/] [synch_fifos/] [1.0/] [tb/] [tb_fifo_stratix.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- title      : tb_fifo_stratix
3
-- project    : 
4
-------------------------------------------------------------------------------
5
-- file       : tb_fifo_stratix.vhdl
6
-- author     : kulmala3
7
-- created    : 08.09.2004
8
-- last update: 31.05.2005
9
-- description: tests that fifo_stratix works in fpga. synthesizable test bench
10
-------------------------------------------------------------------------------
11
-- revisions  :
12
-- date        version  author  description
13
-- 08.09.2004  1.0      ak      created
14
-------------------------------------------------------------------------------
15
 
16
library ieee;
17
use ieee.std_logic_1164.all;
18
use ieee.std_logic_arith.all;
19
use ieee.std_logic_unsigned.all;
20
 
21
entity tb_fifo_stratix is
22
 
23
  port (
24
    clk           : in  std_logic;
25
    rst_n         : in  std_logic;
26
    led_state_out : out std_logic_vector(3 downto 0);
27
    led_error_out : out std_logic_vector(3 downto 0)
28
    );
29
 
30
end tb_fifo_stratix;
31
 
32
architecture rtl of tb_fifo_stratix is
33
 
34
  component fifo
35
    generic (
36
      data_width_g : integer;
37
      depth_g      : integer);
38
    port (
39
      clk       : in  std_logic;
40
      rst_n     : in  std_logic;
41
      data_in   : in  std_logic_vector (data_width_g-1 downto 0);
42
      we_in     : in  std_logic;
43
      one_p_out : out std_logic;
44
      full_out  : out std_logic;
45
      data_out  : out std_logic_vector (data_width_g-1 downto 0);
46
      re_in     : in  std_logic;
47
      empty_out : out std_logic;
48
      one_d_out : out std_logic);
49
  end component;
50
 
51
  type ctrl_state is (initial, write_fifo, read_fifo);
52
 
53
  signal control_r       : ctrl_state;
54
  signal write_counter_r : integer range 0 to 2**16-1;
55
  signal read_counter_r  : integer range 0 to 2**16-1;
56
  signal read_data_r     : integer range 0 to 2**16-1;
57
  signal error_counter_r : integer range 0 to 2**16-1;
58
 
59
  constant initial_c : std_logic_vector := "0001";
60
  constant write_c   : std_logic_vector := "0010";
61
  constant read_c    : std_logic_vector := "0100";
62
 
63
 
64
  constant width : integer := 16;
65
  constant depth : integer := 5;
66
 
67
  signal data_to_fifo     : std_logic_vector (width-1 downto 0);
68
  signal write_enable     : std_logic;
69
  signal one_place_left_r : std_logic;
70
  signal full_r           : std_logic;
71
  signal data_from_fifo   : std_logic_vector (width-1 downto 0);
72
  signal read_enable      : std_logic;
73
  signal empty_r          : std_logic;
74
  signal one_data_left_r  : std_logic;
75
 
76
  signal ef_r : std_logic_vector(1 downto 0);
77
  signal temp : std_logic;
78
begin  -- rtl
79
 
80
  data_to_fifo  <= conv_std_logic_vector(write_counter_r, width);
81
  read_data_r   <= conv_integer(data_from_fifo);
82
  ef_r          <= empty_r & full_r;
83
  led_error_out <= conv_std_logic_vector(error_counter_r, 4);
84
  temp          <= one_data_left_r and one_place_left_r;
85
 
86
  fifo_1 : fifo
87
    generic map (
88
      data_width_g => width,
89
      depth_g      => depth)
90
    port map (
91
      clk       => clk,
92
      rst_n     => rst_n,
93
      data_in   => data_to_fifo,
94
      we_in     => write_enable,
95
      one_p_out => one_place_left_r,
96
      full_out  => full_r,
97
      data_out  => data_from_fifo,
98
      re_in     => read_enable,
99
      empty_out => empty_r,
100
      one_d_out => one_data_left_r);
101
 
102
  process (clk, rst_n)
103
  begin  -- process
104
    if rst_n = '0' then                 -- asynchronous reset (active low)
105
      control_r       <= initial;
106
      write_enable    <= '0';
107
      read_enable     <= '0';
108
      write_counter_r <= 0;
109
      read_counter_r  <= 1;
110
      -- just to use one_data_left_r and one_place_left_r
111
      led_state_out   <= temp & temp & temp & temp;
112
      error_counter_r <= 0;
113
 
114
    elsif clk'event and clk = '1' then  -- rising clock edge
115
 
116
      case control_r is
117
        when initial =>
118
          case ef_r is
119
            when "00" | "01" =>  -- not empty, not full or full-> read              
120
              control_r    <= read_fifo;
121
              write_enable <= '0';
122
              read_enable  <= '0';
123
            when "10" =>                -- empty, write
124
              control_r    <= write_fifo;
125
              write_enable <= '0';
126
              read_enable  <= '0';
127
            when others => null;        --empty and full, not possible...
128
          end case;
129
          led_state_out <= initial_c;
130
 
131
        when write_fifo =>
132
          read_enable <= '0';
133
          if full_r = '0' then          -- not yet full
134
            write_enable    <= '1';
135
            write_counter_r <= write_counter_r+1;
136
            control_r       <= write_fifo;
137
          else
138
            -- fifo full
139
            write_enable    <= '0';
140
            -- write_counter_r+1 always written, so we do -1 here.
141
            write_counter_r <= write_counter_r-1;
142
            control_r       <= read_fifo;
143
          end if;
144
          led_state_out <= write_c;
145
 
146
        when read_fifo =>
147
          write_enable <= '0';
148
          if empty_r = '0' then
149
            read_enable <= '1';
150
            if read_enable = '1' then
151
              if read_data_r /= read_counter_r then
152
                -- error!
153
                assert false report "fifo read error, wrong data" severity error;
154
                if error_counter_r >= 2**4-1 then
155
                  error_counter_r <= 0;
156
                else
157
                  error_counter_r <= error_counter_r +1;
158
                end if;
159
                -- if something was missing, start from the new data value
160
                read_counter_r <= read_data_r+1;
161
              else
162
                error_counter_r <= error_counter_r;
163
                read_counter_r  <= read_counter_r+1;
164
              end if;
165
              control_r <= read_fifo;
166
            end if;
167
          else
168
            -- empty
169
            read_enable     <= '0';
170
            read_counter_r  <= read_counter_r;
171
            error_counter_r <= error_counter_r;
172
            control_r       <= initial;
173
          end if;
174
 
175
          led_state_out <= read_c;
176
 
177
 
178
        when others => null;
179
 
180
 
181
      end case;
182
 
183
 
184
    end if;
185
  end process;
186
 
187
 
188
end rtl;

powered by: WebSVN 2.1.0

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