2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
6 use work.sim_jtag_socket.all;
9 use unisim.vcomponents.all;
14 architecture behaviour of sim_jtag is
17 -- Global JTAG signals (used by BSCANE2 inside dmi_dtm
18 alias j : glob_jtag_t is glob_jtag;
20 -- Super fast JTAG clock for sim. For debugging the JTAG module,
21 -- change this to something much larger, for example 60ns, to reflect
22 -- more realistic conditions.
23 constant jclk_period : time := 1 ns;
25 -- Polling the socket... this could be made slower when nothing
26 -- is connected once we have that indication from the C code.
27 constant poll_period : time := 100 ns;
29 -- Number of dummy JTAG clocks to inject after a command. (I haven't
30 -- got that working with UrJtag but at least with sim, having the
31 -- right number here allows the synchronizers time to complete a
32 -- command on the first message exchange, thus avoiding the need
33 -- for two full shifts for a response.
34 constant dummy_clocks : integer := 80;
36 procedure clock(count: in INTEGER) is
38 for i in 1 to count loop
40 wait for jclk_period/2;
42 wait for jclk_period/2;
46 procedure clock_command(cmd: in std_ulogic_vector;
47 rsp: out std_ulogic_vector) is
54 for i in 0 to cmd'length-1 loop
56 rsp := rsp(1 to rsp'length-1) & j.tdo;
64 end procedure clock_command;
66 variable cmd : std_ulogic_vector(0 to 247);
67 variable rsp : std_ulogic_vector(0 to 247);
68 variable msize : std_ulogic_vector(7 downto 0);
69 variable size : integer;
87 -- XXX TODO: Send that via protocol instead
88 -- XXX TODO: Also maybe have the C code tell us if connected or not
89 -- and clock when connected.
92 rsp := (others => '0');
95 sim_jtag_read_msg(cmd, msize);
96 size := to_integer(unsigned(msize));
97 if size /= 0 and size < 248 then
98 clock_command(cmd(0 to size-1),
100 sim_jtag_write_msg(rsp, msize);