1 |
2 |
dimamali |
------------------------------------------------------------------------------
|
2 |
|
|
-- This file is a part of the GRLIB VHDL IP LIBRARY
|
3 |
|
|
-- Copyright (C) 2003, Gaisler Research
|
4 |
|
|
--
|
5 |
|
|
-- This program is free software; you can redistribute it and/or modify
|
6 |
|
|
-- it under the terms of the GNU General Public License as published by
|
7 |
|
|
-- the Free Software Foundation; either version 2 of the License, or
|
8 |
|
|
-- (at your option) any later version.
|
9 |
|
|
--
|
10 |
|
|
-- This program is distributed in the hope that it will be useful,
|
11 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
|
|
-- GNU General Public License for more details.
|
14 |
|
|
--
|
15 |
|
|
-- You should have received a copy of the GNU General Public License
|
16 |
|
|
-- along with this program; if not, write to the Free Software
|
17 |
|
|
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18 |
|
|
-----------------------------------------------------------------------------
|
19 |
|
|
-- Entity: atahost_dma_fifo
|
20 |
|
|
-- File: atahost_dma_fifo.vhd
|
21 |
|
|
-- Author: Erik Jagre - Gaisler Research
|
22 |
|
|
-- Description: Generic FIFO, based on syncram in grlib
|
23 |
|
|
-----------------------------------------------------------------------------
|
24 |
|
|
|
25 |
|
|
library IEEE;
|
26 |
|
|
use IEEE.std_logic_1164.all;
|
27 |
|
|
library techmap;
|
28 |
|
|
use techmap.gencomp.all;
|
29 |
|
|
library grlib;
|
30 |
|
|
use grlib.stdlib.all;
|
31 |
|
|
|
32 |
|
|
entity atahost_dma_fifo is
|
33 |
|
|
generic(tech : integer:=0; abits : integer:=3;
|
34 |
|
|
dbits : integer:=32; depth : integer:=8);
|
35 |
|
|
port( clk : in std_logic;
|
36 |
|
|
reset : in std_logic;
|
37 |
|
|
write_enable : in std_logic;
|
38 |
|
|
read_enable : in std_logic;
|
39 |
|
|
data_in : in std_logic_vector(dbits-1 downto 0);
|
40 |
|
|
data_out : out std_logic_vector(dbits-1 downto 0);
|
41 |
|
|
write_error : out std_logic:='0';
|
42 |
|
|
read_error : out std_logic:='0';
|
43 |
|
|
level : out natural range 0 to depth;
|
44 |
|
|
empty : out std_logic:='1';
|
45 |
|
|
full : out std_logic:='0');
|
46 |
|
|
end;
|
47 |
|
|
|
48 |
|
|
architecture rtl of atahost_dma_fifo is
|
49 |
|
|
type state_type is (full_state, empty_state, idle_state);
|
50 |
|
|
type reg_type is record
|
51 |
|
|
state : state_type;
|
52 |
|
|
level : integer range 0 to depth;
|
53 |
|
|
aw : integer range 0 to depth;
|
54 |
|
|
ar : integer range 0 to depth;
|
55 |
|
|
data_o : std_logic_vector(dbits-1 downto 0);
|
56 |
|
|
rd : std_logic;
|
57 |
|
|
wr : std_logic;
|
58 |
|
|
erd : std_logic;
|
59 |
|
|
ewr : std_logic;
|
60 |
|
|
reset : std_logic;
|
61 |
|
|
adr : std_logic_vector(abits-1 downto 0);
|
62 |
|
|
end record;
|
63 |
|
|
|
64 |
|
|
constant zerod : std_logic_vector(dbits-1 downto 0) := (others => '0');
|
65 |
|
|
constant zeroa : std_logic_vector(abits-1 downto 0) := (others => '0');
|
66 |
|
|
constant RESET_VECTOR : reg_type := (empty_state,0,0,0,
|
67 |
|
|
zerod,'0','0','0','0','0', zeroa);
|
68 |
|
|
|
69 |
|
|
signal r,ri : reg_type;
|
70 |
|
|
signal s_ram_adr : std_logic_vector(abits-1 downto 0);
|
71 |
|
|
|
72 |
|
|
begin
|
73 |
|
|
-- comb:process(write_enable, read_enable, data_in,reset, r) Erik 2007-02-08
|
74 |
|
|
comb:process(write_enable, read_enable, reset, r)
|
75 |
|
|
variable v : reg_type;
|
76 |
|
|
variable vfull, vempty : std_logic;
|
77 |
|
|
|
78 |
|
|
begin
|
79 |
|
|
v:=r;
|
80 |
|
|
v.wr:=write_enable; v.rd:=read_enable; v.reset:=reset;
|
81 |
|
|
|
82 |
|
|
case r.state is
|
83 |
|
|
when full_state=>
|
84 |
|
|
if write_enable='1' and read_enable='0' and reset='0' then
|
85 |
|
|
v.ewr:='1'; v.state:=full_state;
|
86 |
|
|
elsif write_enable='0' and read_enable='1' and reset='0' then
|
87 |
|
|
v.adr:=conv_std_logic_vector(r.ar,abits);
|
88 |
|
|
if r.ar=depth-1 then v.ar:=0; else v.ar:=r.ar+1; end if;
|
89 |
|
|
v.level:=r.level-1;
|
90 |
|
|
if r.aw=v.ar then v.state:=empty_state;
|
91 |
|
|
else v.state:=idle_state; end if;
|
92 |
|
|
v.ewr:='0';
|
93 |
|
|
end if;
|
94 |
|
|
|
95 |
|
|
when empty_state=>
|
96 |
|
|
if write_enable='1' and read_enable='0' and reset='0' then
|
97 |
|
|
v.adr:=conv_std_logic_vector(r.aw,abits);
|
98 |
|
|
if r.aw=depth-1 then v.aw:=0; else v.aw:=r.aw+1; end if;
|
99 |
|
|
v.level:=r.level+1;
|
100 |
|
|
if v.aw=r.ar then v.state:=full_state;
|
101 |
|
|
else v.state:=idle_state; end if;
|
102 |
|
|
v.erd:='0';
|
103 |
|
|
elsif write_enable='0' and read_enable='1' and reset='0' then
|
104 |
|
|
v.erd:='1'; v.state:=empty_state;
|
105 |
|
|
end if;
|
106 |
|
|
|
107 |
|
|
when idle_state=>
|
108 |
|
|
if write_enable='1' and read_enable='0' and reset='0' then
|
109 |
|
|
v.adr:=conv_std_logic_vector(r.aw,abits);
|
110 |
|
|
if r.aw=depth-1 then v.aw:=0; else v.aw:=r.aw+1; end if;
|
111 |
|
|
v.level:=r.level+1;
|
112 |
|
|
if v.level=depth then v.state:=full_state;
|
113 |
|
|
else v.state:=idle_state; end if;
|
114 |
|
|
elsif write_enable='0' and read_enable='1' and reset='0' then
|
115 |
|
|
v.adr:=conv_std_logic_vector(r.ar,abits);
|
116 |
|
|
if r.ar=depth-1 then v.ar:=0; else v.ar:=r.ar+1; end if;
|
117 |
|
|
v.level:=r.level-1;
|
118 |
|
|
if v.level=0 then v.state:=empty_state;
|
119 |
|
|
else v.state:=idle_state; end if;
|
120 |
|
|
end if;
|
121 |
|
|
end case;
|
122 |
|
|
|
123 |
|
|
if r.level=0 then vempty:='1'; vfull:='0';
|
124 |
|
|
elsif r.level=depth then vempty:='0'; vfull:='1';
|
125 |
|
|
else vempty:='0'; vfull:='0'; end if;
|
126 |
|
|
|
127 |
|
|
--reset logic
|
128 |
|
|
if (reset='1') then v:=RESET_VECTOR; end if;
|
129 |
|
|
|
130 |
|
|
ri<=v;
|
131 |
|
|
s_ram_adr<=v.adr;
|
132 |
|
|
|
133 |
|
|
--assigning outport
|
134 |
|
|
write_error<=v.ewr; read_error<=v.erd; level<=v.level;
|
135 |
|
|
empty<=vempty; full<=vfull;
|
136 |
|
|
end process;
|
137 |
|
|
|
138 |
|
|
ram : syncram
|
139 |
|
|
generic map(tech=>tech, abits=>abits, dbits=>dbits)
|
140 |
|
|
port map (
|
141 |
|
|
clk => clk,
|
142 |
|
|
address => s_ram_adr,
|
143 |
|
|
datain => data_in,
|
144 |
|
|
dataout => data_out,
|
145 |
|
|
enable => read_enable,
|
146 |
|
|
write => write_enable
|
147 |
|
|
);
|
148 |
|
|
|
149 |
|
|
sync:process(clk) --Activate on clock & reset
|
150 |
|
|
begin
|
151 |
|
|
if clk'event and clk='1' then r<=ri; end if;
|
152 |
|
|
end process;
|
153 |
|
|
end;
|