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: net
|
20 |
|
|
-- File: net.vhd
|
21 |
|
|
-- Author: Erik Jagre - Gaisler Research
|
22 |
|
|
-- Description: Generic FIFO, based on syncram in grlib
|
23 |
|
|
-----------------------------------------------------------------------------
|
24 |
|
|
|
25 |
|
|
--ATA controller, bus-master
|
26 |
|
|
--Erik Jagre 2006-10-04
|
27 |
|
|
|
28 |
|
|
Library ieee;
|
29 |
|
|
Use ieee.std_logic_1164.all;
|
30 |
|
|
use work.ata_inf.all;
|
31 |
|
|
Library gaisler;
|
32 |
|
|
Use gaisler.ata.all;
|
33 |
|
|
Library grlib;
|
34 |
|
|
Use grlib.stdlib.all;
|
35 |
|
|
|
36 |
|
|
--************************ENTITY************************************************
|
37 |
|
|
Entity atahost_ahbmst is
|
38 |
|
|
generic(fdepth: integer := 8);
|
39 |
|
|
Port(clk : in std_logic;
|
40 |
|
|
rst : in std_logic; --active low
|
41 |
|
|
i : in bmi_type;
|
42 |
|
|
o : out bmo_type
|
43 |
|
|
);
|
44 |
|
|
end;
|
45 |
|
|
|
46 |
|
|
--************************ARCHITECTURE******************************************
|
47 |
|
|
Architecture rtl of atahost_ahbmst is
|
48 |
|
|
constant abits : integer := Log2(fdepth);
|
49 |
|
|
|
50 |
|
|
type state_type is (IDLE,INIT,PREPARE,BURST_TO_ATA,BURST_TO_MEM,BURST_WAIT);
|
51 |
|
|
|
52 |
|
|
type reg_type is record
|
53 |
|
|
state : state_type;
|
54 |
|
|
o : bmo_type;
|
55 |
|
|
adr_cnt : std_logic_vector(abits-1 downto 0);
|
56 |
|
|
cur_base : std_logic_vector(31 downto 0);
|
57 |
|
|
cur_length : std_logic_vector(15 downto 0);
|
58 |
|
|
cur_cnt : std_logic_vector(15 downto 0);
|
59 |
|
|
prdtb_offset : std_logic_vector(15 downto 0);
|
60 |
|
|
edt : std_logic;
|
61 |
|
|
bmen : std_logic;
|
62 |
|
|
adr_set : std_logic;
|
63 |
|
|
end record;
|
64 |
|
|
|
65 |
|
|
constant RESET_VECTOR : reg_type := (IDLE, BMO_RESET_VECTOR, zero32(abits-1 downto 0),
|
66 |
|
|
zero32, X"0000", X"0000", X"0000", '0', '0', '0');
|
67 |
|
|
|
68 |
|
|
signal r,ri : reg_type;
|
69 |
|
|
begin
|
70 |
|
|
--**********************COMBINATORIAL LGOIC***********************************
|
71 |
|
|
comb: process(rst,r,i)
|
72 |
|
|
variable v : reg_type;
|
73 |
|
|
variable v_diff : std_logic_vector(15 downto 0);
|
74 |
|
|
variable v_temp : std_logic_vector(31 downto 0);
|
75 |
|
|
begin
|
76 |
|
|
v:=r;
|
77 |
|
|
|
78 |
|
|
v.bmen:=i.fr_slv.en;
|
79 |
|
|
v.o.we:=not i.fr_slv.dir;
|
80 |
|
|
case v.state is
|
81 |
|
|
when IDLE => -------------------IDLE STATE---------------------------
|
82 |
|
|
if i.fr_slv.en='1' and r.bmen='0' then
|
83 |
|
|
v.state:=INIT; v.o.to_slv.done:='0';
|
84 |
|
|
v.adr_cnt:=conv_std_logic_vector(0,abits); end if;
|
85 |
|
|
|
86 |
|
|
when INIT => -------------------INIT STATE---------------------------
|
87 |
|
|
v.o.to_mst.write:='0'; v.o.to_ctr.sel:='0';
|
88 |
|
|
---------------------- nytt test
|
89 |
|
|
v.o.to_mst.address:=i.fr_slv.prdtb+v.prdtb_offset; v.adr_set:='1';
|
90 |
|
|
if i.fr_mst.active='0' and r.adr_set='1' then
|
91 |
|
|
v.o.to_mst.burst:='1'; v.o.to_mst.start:='1'; end if;
|
92 |
|
|
----------------------- slut test
|
93 |
|
|
-- if i.fr_mst.active='0' then
|
94 |
|
|
-- v.o.to_mst.burst:='1'; v.o.to_mst.start:='1'; end if;
|
95 |
|
|
-- v.o.to_mst.address:=i.fr_slv.prdtb+v.prdtb_offset;
|
96 |
|
|
if i.fr_mst.ready='1' then
|
97 |
|
|
if r.adr_cnt=conv_std_logic_vector(0,abits) then
|
98 |
|
|
if i.fr_slv.prd_belec='1' then --prd in mem is big endian
|
99 |
|
|
v.cur_base(31 downto 24):=i.fr_mst.rdata(7 downto 0);
|
100 |
|
|
v.cur_base(23 downto 16):=i.fr_mst.rdata(15 downto 8);
|
101 |
|
|
v.cur_base(15 downto 8):=i.fr_mst.rdata(23 downto 16);
|
102 |
|
|
v.cur_base(7 downto 0):=i.fr_mst.rdata(31 downto 24);
|
103 |
|
|
else --prd in mem is little endian
|
104 |
|
|
v.cur_base:=i.fr_mst.rdata;
|
105 |
|
|
end if;
|
106 |
|
|
v.adr_cnt:=conv_std_logic_vector(1,abits);
|
107 |
|
|
elsif r.adr_cnt=conv_std_logic_vector(1,abits) then
|
108 |
|
|
if i.fr_slv.prd_belec='1' then --prd in mem is big endian
|
109 |
|
|
v.edt:=i.fr_mst.rdata(7); v.cur_cnt:=(others=>'0');
|
110 |
|
|
v.cur_length(15 downto 8):=i.fr_mst.rdata(23 downto 16);
|
111 |
|
|
v.cur_length(7 downto 0):=i.fr_mst.rdata(31 downto 24);
|
112 |
|
|
else --prd in mem is little endian
|
113 |
|
|
v.edt:=i.fr_mst.rdata(31); v.cur_cnt:=(others=>'0');
|
114 |
|
|
v.cur_length:=i.fr_mst.rdata(15 downto 0);
|
115 |
|
|
end if;
|
116 |
|
|
v.state:=PREPARE; v.adr_set:='0';
|
117 |
|
|
v.o.to_mst.address:=v.cur_base;
|
118 |
|
|
end if;
|
119 |
|
|
end if;
|
120 |
|
|
if v.o.to_mst.start='1' and r.adr_cnt=conv_std_logic_vector(1,abits)
|
121 |
|
|
and i.fr_mst.start='1' then
|
122 |
|
|
v.o.to_mst.start:='0'; v.o.to_mst.burst:='0'; end if;
|
123 |
|
|
|
124 |
|
|
when PREPARE =>
|
125 |
|
|
v.o.to_ctr.ack:='0'; v.o.to_ctr.force_rdy:='0';
|
126 |
|
|
v.o.to_mst.address:=v.cur_base+v.cur_cnt;
|
127 |
|
|
v.adr_cnt:=conv_std_logic_vector(0,abits);
|
128 |
|
|
if ((v.edt='1' and v.cur_cnt>=v.cur_length) or i.fr_ctr.irq='1')
|
129 |
|
|
and i.fr_ctr.tip='0' then
|
130 |
|
|
v.state:=IDLE;
|
131 |
|
|
if (v.edt='1' and v.cur_cnt>=v.cur_length) then
|
132 |
|
|
v.o.to_slv.done:='1'; v.o.to_ctr.ack:='1'; end if;
|
133 |
|
|
end if;
|
134 |
|
|
if not(v.edt='1' and v.cur_cnt>=v.cur_length) then
|
135 |
|
|
if i.fr_ctr.fifo_rdy='0' and i.fr_slv.dir='0' then
|
136 |
|
|
--might fail for AHB ram?
|
137 |
|
|
v.o.to_mst.burst:='1'; v.o.to_mst.write:='0';
|
138 |
|
|
v.o.to_mst.start:='1'; v.state:=BURST_TO_ATA;
|
139 |
|
|
elsif i.fr_ctr.fifo_rdy='0' and i.fr_slv.dir='1' then
|
140 |
|
|
--might fail for AHB ram?
|
141 |
|
|
v.o.to_ctr.sel:='1';
|
142 |
|
|
v.o.to_mst.burst:='1'; v.o.to_mst.write:='1';
|
143 |
|
|
v.o.to_mst.start:='1'; v.state:=BURST_TO_MEM;
|
144 |
|
|
end if;
|
145 |
|
|
end if;
|
146 |
|
|
|
147 |
|
|
when BURST_TO_ATA =>
|
148 |
|
|
if i.fr_mst.start='1' and v.o.to_ctr.force_rdy='0' then
|
149 |
|
|
v_temp:=r.o.to_mst.address+4;
|
150 |
|
|
--abort burst due to PRD exhausted --------------------new
|
151 |
|
|
if r.cur_cnt+4>=r.cur_length then
|
152 |
|
|
v.o.to_mst.start:='0'; v.o.to_mst.burst:='0'; end if;
|
153 |
|
|
--...due to fifo full
|
154 |
|
|
if r.adr_cnt=conv_std_logic_vector(fdepth-1,abits) then
|
155 |
|
|
v.o.to_mst.start:='0'; v.o.to_mst.burst:='0'; end if;
|
156 |
|
|
--...due to AMBA 1k limit
|
157 |
|
|
if not(v_temp(11 downto 10) = v.o.to_mst.address(11 downto 10))
|
158 |
|
|
and not(r.edt='1' and r.cur_cnt>=r.cur_length) then
|
159 |
|
|
v.o.to_mst.start:='0'; v.o.to_mst.burst:='0';
|
160 |
|
|
end if;
|
161 |
|
|
end if;
|
162 |
|
|
if i.fr_mst.ready='1' and v.o.to_ctr.force_rdy='0' then
|
163 |
|
|
v.o.to_mst.address:=r.o.to_mst.address+4; o.d<=i.fr_mst.rdata;
|
164 |
|
|
v.adr_cnt:=r.adr_cnt+1; v.cur_cnt:=r.cur_cnt+4; v.o.to_ctr.sel:='1';
|
165 |
|
|
if r.adr_cnt=conv_std_logic_vector(fdepth-1,abits) then
|
166 |
|
|
v.o.to_ctr.force_rdy:='1'; end if;
|
167 |
|
|
--state transition when AMBA 1k limit
|
168 |
|
|
if not(v.o.to_mst.address(11 downto 10) =
|
169 |
|
|
r.o.to_mst.address(11 downto 10))
|
170 |
|
|
and v.o.to_ctr.force_rdy='0'
|
171 |
|
|
and not(r.edt='1' and r.cur_cnt>=r.cur_length) then
|
172 |
|
|
v.state:=BURST_WAIT; end if;
|
173 |
|
|
else v.o.to_ctr.sel:='0'; end if;
|
174 |
|
|
--state transition when FIFO filled
|
175 |
|
|
if v.cur_cnt>=v.cur_length and v.edt='0'
|
176 |
|
|
-- and i.fr_ctr.fifo_rdy='1' then
|
177 |
|
|
and (i.fr_ctr.fifo_rdy='1'or r.cur_cnt+4>=r.cur_length) then
|
178 |
|
|
v.prdtb_offset:=v.prdtb_offset+X"0008"; v.cur_cnt:=X"0000";
|
179 |
|
|
v.adr_cnt:=conv_std_logic_vector(0,abits); v.state:=INIT;
|
180 |
|
|
elsif i.fr_ctr.fifo_rdy='1' then v.state:=PREPARE; end if;
|
181 |
|
|
|
182 |
|
|
when BURST_TO_MEM =>
|
183 |
|
|
v.o.to_ctr.sel:='0';
|
184 |
|
|
if i.fr_mst.start='1' and v.o.to_ctr.force_rdy='0' then
|
185 |
|
|
v_temp:=r.o.to_mst.address+4; o.to_mst.wdata<=i.fr_ctr.q;
|
186 |
|
|
--abort burst due to PRD exhausted
|
187 |
|
|
if r.cur_cnt+4>=r.cur_length then
|
188 |
|
|
v.o.to_mst.start:='0'; v.o.to_mst.burst:='0'; end if;
|
189 |
|
|
--...due to fifo empty
|
190 |
|
|
if r.adr_cnt=conv_std_logic_vector(fdepth-1,abits) then
|
191 |
|
|
v.o.to_mst.start:='0'; v.o.to_mst.burst:='0'; end if;
|
192 |
|
|
--...due to AMBA 1k limit
|
193 |
|
|
if not(v_temp(11 downto 10) = v.o.to_mst.address(11 downto 10))
|
194 |
|
|
and not(r.edt='1' and r.cur_cnt>=r.cur_length) then
|
195 |
|
|
v.o.to_mst.start:='0'; v.o.to_mst.burst:='0';
|
196 |
|
|
end if;
|
197 |
|
|
end if;
|
198 |
|
|
if i.fr_mst.ready='1' and v.o.to_ctr.force_rdy='0' then
|
199 |
|
|
v.o.to_mst.address:=r.o.to_mst.address+4;
|
200 |
|
|
v.adr_cnt:=r.adr_cnt+1; v.cur_cnt:=r.cur_cnt+4;
|
201 |
|
|
--fifo emptied, set ready
|
202 |
|
|
if r.adr_cnt=conv_std_logic_vector(fdepth-1,abits) then
|
203 |
|
|
v.o.to_ctr.force_rdy:='1'; end if;
|
204 |
|
|
--fifo NOT emptied, keep reading
|
205 |
|
|
if r.adr_cnt < conv_std_logic_vector(fdepth-1,abits)
|
206 |
|
|
and r.cur_cnt+4<r.cur_length then
|
207 |
|
|
v.o.to_ctr.sel:='1'; else v.o.to_ctr.sel:='0'; end if;
|
208 |
|
|
--state transition when AMBA 1k limit
|
209 |
|
|
if not(v.o.to_mst.address(11 downto 10) =
|
210 |
|
|
r.o.to_mst.address(11 downto 10))
|
211 |
|
|
and v.o.to_ctr.force_rdy='0'
|
212 |
|
|
and not(r.edt='1' and r.cur_cnt>=r.cur_length) then
|
213 |
|
|
v.state:=BURST_WAIT; end if;
|
214 |
|
|
else v.o.to_ctr.sel:='0'; --2007-1-15
|
215 |
|
|
end if;
|
216 |
|
|
if i.fr_mst.active='0' then
|
217 |
|
|
if v.cur_cnt>=v.cur_length and v.edt='0'
|
218 |
|
|
and (i.fr_ctr.fifo_rdy='1'or r.cur_cnt+4>=r.cur_length) then
|
219 |
|
|
v.prdtb_offset:=v.prdtb_offset+X"0008"; v.cur_cnt:=X"0000";
|
220 |
|
|
v.adr_cnt:=conv_std_logic_vector(0,abits); v.state:=INIT;
|
221 |
|
|
elsif i.fr_ctr.fifo_rdy='1' then v.state:=PREPARE; end if;
|
222 |
|
|
end if;
|
223 |
|
|
|
224 |
|
|
when BURST_WAIT =>
|
225 |
|
|
if i.fr_mst.active='0' then
|
226 |
|
|
v.o.to_ctr.sel:='0'; v.o.to_mst.burst:='1'; v.o.to_mst.start:='1';
|
227 |
|
|
if i.fr_slv.dir='1' then
|
228 |
|
|
v.o.to_mst.write:='1'; v.state:=BURST_TO_MEM;
|
229 |
|
|
else
|
230 |
|
|
v.o.to_mst.write:='0'; v.state:=BURST_TO_ATA;
|
231 |
|
|
end if;
|
232 |
|
|
end if;
|
233 |
|
|
|
234 |
|
|
when others => ----------------------------------------------------------
|
235 |
|
|
v.state:=IDLE;
|
236 |
|
|
end case;
|
237 |
|
|
|
238 |
|
|
if rst='0' or (i.fr_slv.en='0' and r.bmen='1') or i.fr_mst.mexc='1' then
|
239 |
|
|
v:=RESET_VECTOR; end if;
|
240 |
|
|
|
241 |
|
|
----------------------ASSIGN OUTPUTS----------------------------------------
|
242 |
|
|
v.o.to_slv.cur_base:=v.cur_base; v.o.to_slv.cur_cnt:=v.cur_cnt; --2006-11-13
|
243 |
|
|
o.to_slv<=r.o.to_slv;
|
244 |
|
|
o.we<=r.o.we;
|
245 |
|
|
o.to_mst.address<=r.o.to_mst.address;
|
246 |
|
|
o.to_mst.start<=v.o.to_mst.start;
|
247 |
|
|
o.to_mst.burst<=v.o.to_mst.burst;
|
248 |
|
|
o.to_mst.write<=v.o.to_mst.write;
|
249 |
|
|
o.to_mst.busy<=r.o.to_mst.busy;
|
250 |
|
|
o.to_mst.irq<=r.o.to_mst.irq;
|
251 |
|
|
o.to_mst.size<=r.o.to_mst.size;
|
252 |
|
|
o.to_ctr.force_rdy<=r.o.to_ctr.force_rdy;
|
253 |
|
|
o.to_ctr.ack<=r.o.to_ctr.ack;
|
254 |
|
|
o.to_ctr.sel<=v.o.to_ctr.sel;
|
255 |
|
|
o.to_slv.err<=i.fr_mst.mexc; --2007-02-06
|
256 |
|
|
|
257 |
|
|
o.to_mst.wdata<=i.fr_ctr.q; --2006-11-16
|
258 |
|
|
o.d<=i.fr_mst.rdata; --2006-11-16
|
259 |
|
|
|
260 |
|
|
ri<=v;
|
261 |
|
|
end process comb;
|
262 |
|
|
|
263 |
|
|
--**********************FLIP FLOPS********************************************
|
264 |
|
|
sync: process(clk)
|
265 |
|
|
begin
|
266 |
|
|
if rising_edge(clk) then r<=ri; end if;
|
267 |
|
|
end process sync;
|
268 |
|
|
end;
|
269 |
|
|
|
270 |
|
|
--************************END OF FILE*******************************************
|