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: ahbslv_em
|
20 |
|
|
-- File: ahbslv_em.vhd
|
21 |
|
|
-- Author: Alf Vaerneus, Gaisler Research
|
22 |
|
|
-- Description: AMBA AHB Slave emulator for simulation purposes only
|
23 |
|
|
------------------------------------------------------------------------------
|
24 |
|
|
|
25 |
|
|
-- pragma translate_off
|
26 |
|
|
library ieee;
|
27 |
|
|
use ieee.std_logic_1164.all;
|
28 |
|
|
library grlib;
|
29 |
|
|
use grlib.amba.all;
|
30 |
|
|
use grlib.stdlib.all;
|
31 |
|
|
library gaisler;
|
32 |
|
|
use grlib.devices.all;
|
33 |
|
|
use gaisler.ambatest.all;
|
34 |
|
|
library std;
|
35 |
|
|
use std.textio.all;
|
36 |
|
|
|
37 |
|
|
entity ahbslv_em is
|
38 |
|
|
generic(
|
39 |
|
|
hindex : integer := 0;
|
40 |
|
|
abits : integer := 10;
|
41 |
|
|
waitcycles : integer := 2;
|
42 |
|
|
retries : integer := 0;
|
43 |
|
|
memaddr : integer := 16#E00#;
|
44 |
|
|
memmask : integer := 16#F00#;
|
45 |
|
|
ioaddr : integer := 16#000#;
|
46 |
|
|
timeoutc : integer := 100;
|
47 |
|
|
dbglevel : integer := 1
|
48 |
|
|
);
|
49 |
|
|
port(
|
50 |
|
|
rst : in std_logic;
|
51 |
|
|
clk : in std_logic;
|
52 |
|
|
-- AMBA signals
|
53 |
|
|
ahbsi : in ahb_slv_in_type;
|
54 |
|
|
ahbso : out ahb_slv_out_type;
|
55 |
|
|
-- TB signals
|
56 |
|
|
tbi : in tb_in_type;
|
57 |
|
|
tbo : out tb_out_type
|
58 |
|
|
);
|
59 |
|
|
end;
|
60 |
|
|
|
61 |
|
|
architecture tb of ahbslv_em is
|
62 |
|
|
|
63 |
|
|
constant VERSION : integer := 1;
|
64 |
|
|
constant hconfig : ahb_config_type := (
|
65 |
|
|
|
66 |
|
|
4 => ahb_membar(memaddr, '0', '0', memmask),
|
67 |
|
|
others => zero32);
|
68 |
|
|
|
69 |
|
|
constant T_O : integer := timeoutc;
|
70 |
|
|
|
71 |
|
|
type mem_type is array(0 to ((2**abits)-1)) of std_logic_vector(31 downto 0);
|
72 |
|
|
|
73 |
|
|
type state_type is(idle,w,write,read,retry1,retry2);
|
74 |
|
|
type reg_type is record
|
75 |
|
|
state : state_type;
|
76 |
|
|
ad : std_logic_vector(abits-1 downto 0);
|
77 |
|
|
di : std_logic_vector(31 downto 0);
|
78 |
|
|
waitc : integer;
|
79 |
|
|
nretry : integer;
|
80 |
|
|
write : std_logic;
|
81 |
|
|
end record;
|
82 |
|
|
|
83 |
|
|
signal r,rin : reg_type;
|
84 |
|
|
signal do : std_logic_vector(31 downto 0);
|
85 |
|
|
|
86 |
|
|
begin
|
87 |
|
|
|
88 |
|
|
cont : process
|
89 |
|
|
file readfile,writefile : text;
|
90 |
|
|
variable first : boolean := true;
|
91 |
|
|
variable mem : mem_type;
|
92 |
|
|
variable L : line;
|
93 |
|
|
variable datahex : string(1 to 8);
|
94 |
|
|
variable count : integer;
|
95 |
|
|
begin
|
96 |
|
|
if first then
|
97 |
|
|
for i in 0 to ((2**abits)-1) loop
|
98 |
|
|
mem(i) := (others => '0');
|
99 |
|
|
end loop;
|
100 |
|
|
first := false;
|
101 |
|
|
elsif tbi.start = '1' then
|
102 |
|
|
if tbi.usewfile then
|
103 |
|
|
file_open(writefile, external_name => tbi.wfile(18 downto trimlen(tbi.wfile)), open_kind => write_mode);
|
104 |
|
|
count := conv_integer(tbi.address(abits-1 downto 0));
|
105 |
|
|
for i in 0 to tbi.no_words-1 loop
|
106 |
|
|
write(L,printhex(mem(count),32));
|
107 |
|
|
writeline(writefile,L);
|
108 |
|
|
count := count+4;
|
109 |
|
|
end loop;
|
110 |
|
|
file_close(writefile);
|
111 |
|
|
end if;
|
112 |
|
|
elsif r.ad(0) /= 'U' then
|
113 |
|
|
do <= mem(conv_integer(to_x01(r.ad)));
|
114 |
|
|
if r.write = '1' then mem(conv_integer(to_x01(r.ad))) := ahbsi.hwdata; end if;
|
115 |
|
|
end if;
|
116 |
|
|
tbo.ready <= tbi.start;
|
117 |
|
|
wait for 1 ns;
|
118 |
|
|
end process;
|
119 |
|
|
|
120 |
|
|
comb : process(ahbsi, rst, r)
|
121 |
|
|
variable v : reg_type;
|
122 |
|
|
variable vahbso : ahb_slv_out_type;
|
123 |
|
|
begin
|
124 |
|
|
v := r; v.write := '0';
|
125 |
|
|
v.di := ahbsi.hwdata;
|
126 |
|
|
vahbso.hready := '1'; vahbso.hresp := HRESP_OKAY;
|
127 |
|
|
vahbso.hrdata := do; vahbso.hsplit := (others => '0');
|
128 |
|
|
vahbso.hcache := '0'; vahbso.hirq := (others => '0');
|
129 |
|
|
vahbso.hconfig := hconfig;
|
130 |
|
|
|
131 |
|
|
if ahbsi.hready = '1' then v.ad := ahbsi.haddr(abits-1 downto 0); end if;
|
132 |
|
|
|
133 |
|
|
case r.state is
|
134 |
|
|
when idle =>
|
135 |
|
|
if (ahbsi.hsel(hindex) and ahbsi.hready and ahbsi.htrans(1)) = '1' then
|
136 |
|
|
if r.waitc > 0 then v.state := w; v.waitc := r.waitc-1;
|
137 |
|
|
elsif r.nretry > 0 then v.state := retry1;
|
138 |
|
|
elsif ahbsi.hwrite = '1' then v.state := write; v.write := '1';
|
139 |
|
|
else v.state := read; end if;
|
140 |
|
|
end if;
|
141 |
|
|
when w =>
|
142 |
|
|
vahbso.hready := '0';
|
143 |
|
|
if r.waitc = 0 then
|
144 |
|
|
v.waitc := waitcycles;
|
145 |
|
|
if r.nretry > 0 then v.state := retry1;
|
146 |
|
|
elsif ahbsi.hwrite = '1' then v.state := write; v.write := '1';
|
147 |
|
|
else v.state := read; end if;
|
148 |
|
|
else v.waitc := r.waitc-1; end if;
|
149 |
|
|
when write =>
|
150 |
|
|
v.nretry := retries;
|
151 |
|
|
if (ahbsi.hsel(hindex) and ahbsi.htrans(1)) = '0' then v.state := idle;
|
152 |
|
|
elsif r.waitc > 0 then v.state := w; v.waitc := r.waitc-1;
|
153 |
|
|
elsif ahbsi.hwrite = '0' then v.state := read;
|
154 |
|
|
else v.write := '1'; end if;
|
155 |
|
|
when read =>
|
156 |
|
|
v.nretry := retries;
|
157 |
|
|
if (ahbsi.hsel(hindex) and ahbsi.htrans(1)) = '0' then v.state := idle;
|
158 |
|
|
elsif r.waitc > 0 then v.state := w; v.waitc := r.waitc-1;
|
159 |
|
|
elsif ahbsi.hwrite = '1' then v.state := write; end if;
|
160 |
|
|
when retry1 =>
|
161 |
|
|
vahbso.hready := '0'; v.nretry := r.nretry-1;
|
162 |
|
|
vahbso.hresp := HRESP_RETRY;
|
163 |
|
|
v.state := retry2;
|
164 |
|
|
when retry2 =>
|
165 |
|
|
vahbso.hresp := HRESP_RETRY;
|
166 |
|
|
if (ahbsi.hsel(hindex) and ahbsi.hready and ahbsi.htrans(1)) = '1' then
|
167 |
|
|
if r.waitc > 0 then v.state := w; v.waitc := r.waitc-1;
|
168 |
|
|
elsif r.nretry > 0 then v.state := retry1;
|
169 |
|
|
elsif ahbsi.hwrite = '1' then v.state := write; v.write := '1';
|
170 |
|
|
else v.state := read; end if;
|
171 |
|
|
end if;
|
172 |
|
|
when others =>
|
173 |
|
|
end case;
|
174 |
|
|
|
175 |
|
|
vahbso.hindex := hindex;
|
176 |
|
|
|
177 |
|
|
if rst = '0' then
|
178 |
|
|
v.state := idle;
|
179 |
|
|
v.waitc := waitcycles;
|
180 |
|
|
v.nretry := retries;
|
181 |
|
|
v.ad := (others => '0');
|
182 |
|
|
v.di := (others => '0');
|
183 |
|
|
end if;
|
184 |
|
|
|
185 |
|
|
rin <= v;
|
186 |
|
|
ahbso <= vahbso;
|
187 |
|
|
|
188 |
|
|
end process;
|
189 |
|
|
|
190 |
|
|
clockreg : process(clk)
|
191 |
|
|
begin
|
192 |
|
|
if rising_edge(clk) then
|
193 |
|
|
r <= rin;
|
194 |
|
|
end if;
|
195 |
|
|
end process;
|
196 |
|
|
|
197 |
|
|
bootmsg : report_version
|
198 |
|
|
generic map ("pcislv_em" & tost(hindex) &
|
199 |
|
|
": PCI Slave Emulator rev " & tost(VERSION) &
|
200 |
|
|
" for simulation purpose only." &
|
201 |
|
|
" NOT syntheziseable.");
|
202 |
|
|
|
203 |
|
|
end;
|
204 |
|
|
-- pragma translate_on
|