2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
7 use work.wishbone_types.all;
10 use unisim.vcomponents.all;
15 architecture behave of dmi_dtm_tb is
16 signal clk : std_ulogic;
17 signal rst : std_ulogic;
18 constant clk_period : time := 10 ns;
19 constant jclk_period : time := 30 ns;
21 -- DMI debug bus signals
22 signal dmi_addr : std_ulogic_vector(7 downto 0);
23 signal dmi_din : std_ulogic_vector(63 downto 0);
24 signal dmi_dout : std_ulogic_vector(63 downto 0);
25 signal dmi_req : std_ulogic;
26 signal dmi_wr : std_ulogic;
27 signal dmi_ack : std_ulogic;
29 -- Global JTAG signals (used by BSCANE2 inside dmi_dtm
30 alias j : glob_jtag_t is glob_jtag;
32 -- Wishbone interfaces
33 signal wishbone_ram_in : wishbone_slave_out;
34 signal wishbone_ram_out : wishbone_master_out;
37 dtm: entity work.dmi_dtm
53 simple_ram_0: entity work.wishbone_bram_wrapper
54 generic map(RAM_INIT_FILE => "main_ram.bin",
55 MEMORY_SIZE => 524288)
56 port map(clk => clk, rst => rst,
57 wishbone_in => wishbone_ram_out,
58 wishbone_out => wishbone_ram_in);
60 wishbone_debug_0: entity work.wishbone_debug_master
61 port map(clk => clk, rst => rst,
62 dmi_addr => dmi_addr(1 downto 0),
68 wb_in => wishbone_ram_in,
69 wb_out => wishbone_ram_out);
75 wait for clk_period / 2;
77 wait for clk_period / 2;
80 -- system sim: just reset and wait
91 procedure clock(count: in INTEGER) is
93 for i in 1 to count loop
95 wait for jclk_period/2;
97 wait for jclk_period/2;
101 procedure shift_out(val: in std_ulogic_vector) is
103 for i in 0 to val'length-1 loop
107 end procedure shift_out;
109 procedure shift_in(val: out std_ulogic_vector) is
111 for i in val'length-1 downto 0 loop
112 val := j.tdo & val(val'length-1 downto 1);
115 end procedure shift_in;
117 procedure send_command(
118 addr : in std_ulogic_vector(7 downto 0);
119 data : in std_ulogic_vector(63 downto 0);
120 op : in std_ulogic_vector(1 downto 0)) is
135 end procedure send_command;
138 op : out std_ulogic_vector(1 downto 0);
139 data : out std_ulogic_vector(63 downto 0)) is
141 variable addr : std_ulogic_vector(7 downto 0);
156 end procedure read_resp;
158 procedure dmi_write(addr : in std_ulogic_vector(7 downto 0);
159 data : in std_ulogic_vector(63 downto 0)) is
160 variable resp_op : std_ulogic_vector(1 downto 0);
161 variable resp_data : std_ulogic_vector(63 downto 0);
162 variable timeout : integer;
164 send_command(addr, data, "10");
166 read_resp(resp_op, resp_data);
171 timeout := timeout + 1;
173 report "dmi_write timed out !" severity error;
175 assert 0 > 1 report "dmi_write got odd status: " &
176 to_hstring(resp_op) severity error;
179 end procedure dmi_write;
182 procedure dmi_read(addr : in std_ulogic_vector(7 downto 0);
183 data : out std_ulogic_vector(63 downto 0)) is
184 variable resp_op : std_ulogic_vector(1 downto 0);
185 variable timeout : integer;
187 send_command(addr, (others => '0'), "01");
189 read_resp(resp_op, data);
194 timeout := timeout + 1;
196 report "dmi_read timed out !" severity error;
198 assert 0 > 1 report "dmi_read got odd status: " &
199 to_hstring(resp_op) severity error;
202 end procedure dmi_read;
204 variable data : std_ulogic_vector(63 downto 0);
224 dmi_read(x"00", data);
225 report "Read addr reg:" & to_hstring(data);
226 report "Writing addr reg to all 1's";
227 dmi_write(x"00", (others => '1'));
228 dmi_read(x"00", data);
229 report "Read addr reg:" & to_hstring(data);
231 report "Writing ctrl reg to all 1's";
232 dmi_write(x"02", (others => '1'));
233 dmi_read(x"02", data);
234 report "Read ctrl reg:" & to_hstring(data);
236 report "Read memory at 0...\n";
237 dmi_write(x"00", x"0000000000000000");
238 dmi_write(x"02", x"00000000000007ff");
239 dmi_read(x"01", data);
240 report "00:" & to_hstring(data);
241 dmi_read(x"01", data);
242 report "08:" & to_hstring(data);
243 dmi_read(x"01", data);
244 report "10:" & to_hstring(data);
245 dmi_read(x"01", data);
246 report "18:" & to_hstring(data);