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

Subversion Repositories ahb_system_generator

[/] [ahb_system_generator/] [trunk/] [src/] [fifo.vhd] - Blame information for rev 5

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

Line No. Rev Author Line
1 2 federico.a
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.std_logic_unsigned.all;
4
use ieee.std_logic_misc.all;
5
use ieee.std_logic_arith.all;
6
 
7
use work.ahb_funct.all;
8
use work.ahb_package.all;
9
 
10
entity fifo is
11
generic (
12
  fifohempty_level: in integer:= 1;
13
  fifohfull_level: in integer:= 3;
14
  fifo_length: in integer:= 4);
15
port (
16
  hresetn: in std_logic;
17
  clk: in std_logic;
18
  fifo_reset: in std_logic;
19
  fifo_write: in std_logic;
20
  fifo_read: in std_logic;
21
  fifo_count: out std_logic_vector(nb_bits(fifo_length)-1 downto 0);
22
  fifo_full: out std_logic;
23
  fifo_hfull: out std_logic;
24
  fifo_empty: out std_logic;
25
  fifo_hempty: out std_logic;
26
  fifo_datain: in std_logic_vector(31 downto 0);
27
  fifo_dataout: out std_logic_vector(31 downto 0)
28
  );
29
end fifo;
30
 
31
architecture rtl of fifo is
32
 
33
 
34
 
35
signal fifo_full_s, fifo_empty_s: std_logic;
36
signal fifo_count_s : std_logic_vector(nb_bits(fifo_length)-1 downto 0);--log2 fifo_length + 1
37
signal rptr, wptr: std_logic_vector(nb_bits(fifo_length)-1 downto 0);
38
type vect_fifo_32 is array (fifo_length-1 downto 0) of std_logic_vector (31 downto 0);
39
signal fifo : vect_fifo_32;
40
 
41
 
42
begin
43
 
44
fifo_wr_pr:process(clk, hresetn)
45
begin
46
  if hresetn='0' then
47
    wptr <= (others => '0');
48
  elsif clk'event and clk='1' then
49
    if fifo_reset='1' then
50
      wptr <= (others => '0') after 1 ns;
51
    elsif (fifo_write='1') then
52
      fifo(conv_integer(wptr(wptr'length-2 downto 0))) <= fifo_datain after 1 ns;
53
      wptr <= wptr+1 after 1 ns;
54
    end if;
55
  end if;
56
end process;
57
 
58
fifo_rd_pr:process(clk, hresetn)
59
begin
60
  if hresetn='0' then
61
    rptr <= (others => '0');
62
  elsif clk'event and clk='1' then
63
    if fifo_reset='1' then
64
      rptr <= (others => '0') after 1 ns;
65
    elsif (fifo_read='1') then
66
      rptr <= rptr+1 after 1 ns;
67
    end if;
68
  end if;
69
end process;
70
 
71
 
72
fifo_dataout <= fifo(conv_integer(rptr(rptr'length-2 downto 0)));--data from fifo visible 
73
 
74
fifo_count_s <= wptr(wptr'length-1 downto 0) - rptr(rptr'length-1 downto 0);
75
 
76
fifo_full_s     <= '1' when (fifo_count_s=fifo_length) else '0';--same value,/=msb
77
fifo_empty_s <= '1' when (fifo_count_s=0) else '0';--same value,==msb
78
 
79
fifo_hfull <= '1' when (fifo_count_s>=fifohfull_level) else '0';
80
fifo_hempty <= '1' when (fifo_count_s<=fifohempty_level) else '0';
81
fifo_full <= fifo_full_s;
82
fifo_empty <= fifo_empty_s;
83
fifo_count <= fifo_count_s;
84
 
85
end rtl;

powered by: WebSVN 2.1.0

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