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/] [vhd/] [fifo_shift.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- File        : fifo_shift.vhdl
3
-- Description : Fifo buffer for hibi interface
4
--
5
-- Author      : Erno Salminen
6
-- Date        : 29.05.2003
7
-- Modified    : 
8
--
9
-------------------------------------------------------------------------------
10
library ieee;
11
use ieee.std_logic_1164.all;
12
use ieee.std_logic_arith.all;
13
use ieee.std_logic_unsigned.all;
14
 
15
entity fifo is
16
 
17
  generic (
18
    width : integer := 0;
19
    depth : integer := 0);
20
 
21
  port (
22
    Clk            : in  std_logic;
23
    Rst_n          : in  std_logic;
24
    Data_In        : in  std_logic_vector (width-1 downto 0);
25
    Write_Enable   : in  std_logic;
26
    One_Place_Left : out std_logic;
27
    Full           : out std_logic;
28
    Data_Out       : out std_logic_vector (width-1 downto 0);
29
    Read_Enable    : in  std_logic;
30
    Empty          : out std_logic;
31
    One_Data_Left  : out std_logic
32
    );
33
 
34
end fifo;
35
 
36
 
37
 
38
architecture shift_reg of fifo is
39
 
40
  type Fifo_slot_type is record
41
                           Valid : std_logic;
42
                           Data  : std_logic_vector ( width-1 downto 0);
43
                         end record;
44
 
45
  type data_array is array (depth-1 downto 0) of Fifo_slot_type;
46
  signal Fifo_Buffer : data_array;
47
 
48
  -- Registers
49
  --signal Data_Amount        : integer range 0 to depth-1;
50
 
51
  signal WE_RE : std_logic_vector ( 1 downto 0);
52
 
53
begin  -- shift_reg
54
 
55
 
56
 
57
  -- Continuous assignments
58
  -- Assigns register values to outputs
59
  WE_RE <= Write_Enable & Read_Enable;  -- yhdistetaan case-lausetta varten
60
 
61
  assert depth > 1 report "Fifo depth must be more than one!" severity WARNING;
62
  Full           <= Fifo_Buffer (depth-1).Valid;  -- ylin paikka varattu
63
  Empty          <= not (Fifo_Buffer (0).Valid);  -- alin paikka tyhja
64
 
65
  -- Yksi data=alin taynna, toiseksi alin tyhja
66
  One_Data_Left  <= not (Fifo_Buffer (1).Valid) and Fifo_Buffer (0).Valid;
67
 
68
  -- Yksi paikka=ylin tyhja, toiseksi ylin taynna
69
  One_Place_Left <= not (Fifo_Buffer (depth-1).Valid) and Fifo_Buffer (depth-2).Valid;
70
 
71
  Data_Out       <= Fifo_Buffer (0).Data;  --alin data ulostuloon
72
  -- Note! There is some old value in data output when fifo is empty.
73
 
74
 
75
 
76
 
77
 
78
 
79
  Sync: process (Clk, Rst_n)
80
  begin  -- process Sync
81
    if Rst_n = '0' then                 -- asynchronous reset (active low)
82
 
83
      -- Reset all registers
84
      --Data_Amount             <= 0;
85
      for i in 0 to depth-1 loop
86
        Fifo_Buffer (i).Data  <= (others => '0');  --'Z');
87
        Fifo_Buffer (i).Valid <= '0';
88
      end loop;  -- i
89
 
90
 
91
    elsif Clk'event and Clk = '1' then  -- rising clock edge
92
 
93
      -- Vaihdetaan if-elsif-else case-lauseeksi
94
      case WE_RE is
95
 
96
        when "10" =>
97
          -- Kirjoitus
98
          if Fifo_Buffer (depth-1).Valid = '1' then
99
            -- Fifo taynna, kirjoitus ei onnistu
100
            Fifo_Buffer <= Fifo_Buffer;
101
            assert false report "Cannot write to full fifo" severity note;
102
 
103
          else
104
            -- Fifossa tilaa
105
            --30.05 
106
            -- !!! Huom jos tassa ei sijoita muihin paikkoihin vanhoja
107
            -- arvoja, max. viive kasvaa!!
108
            -- Esim. 50x1b (ilman sijoitusta) 1.5ns
109
            -- 50x1b (sijoituksen kanssa) 0.88ns
110
            -- be careful out there!
111
            Fifo_Buffer                 <= Fifo_Buffer;  --30.05
112
            Fifo_Buffer (depth-1).Valid <= '1';  --paikka kaytossa
113
            Fifo_Buffer (depth-1).Data  <= Data_In;
114
          end if;
115
 
116
 
117
        when "01" =>
118
          -- Luku
119
          -- Shiftaus (isoista indekseista kohti indeksia nolla)
120
          for i in 0 to depth-2 loop
121
            Fifo_Buffer (i)           <= Fifo_Buffer (i+1);
122
          end loop;  -- i
123
          --ylin paikka tyhjenee
124
          Fifo_Buffer (depth-1).Valid <= '0';
125
          Fifo_Buffer (depth-1).Data  <= (others => '0');  --'Z');
126
 
127
 
128
        when "11" =>
129
          -- Seka kirjoitus etta luku
130
 
131
          if Fifo_Buffer (depth-1).Valid = '1' then
132
            -- Fifo taynna, kirjoitus ei onnistu mutta luku onnistuu
133
            -- Ylin (sisaantulo)paikka tyhjenee
134
            Fifo_Buffer (depth-1).Data  <= (others => '0');  --'Z';
135
            Fifo_Buffer (depth-1).Valid <= '0';
136
          else
137
            -- Seka luku etta kirjoitus onnistuvat
138
            Fifo_Buffer (depth-1).Valid <= '1';  --paikka kaytossa
139
            Fifo_Buffer (depth-1).Data  <= Data_In;
140
          end if;
141
 
142
          -- Shiftataan joka tapauksessa (isoista indekseista kohti indeksia nolla)
143
          for i in 0 to depth-2 loop
144
            Fifo_Buffer (i) <= Fifo_Buffer (i+1);
145
          end loop;  -- i
146
 
147
        when others =>
148
          -- Ei tehda mitaan
149
          Fifo_Buffer <= Fifo_Buffer;
150
      end case;
151
    end if;                             --rst/clk
152
  end process Sync;
153
 
154
end shift_reg;

powered by: WebSVN 2.1.0

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