Import the JTAG interface code as used for the Chips4Maker pilot Retro-uC
[c4m-jtag.git] / rtl / vhdl / c4m_jtag_ioblock.vhdl
1 -- The block of io cells with JTAG boundary scan support
2
3 library ieee;
4 use ieee.std_logic_1164.ALL;
5
6 use work.c4m_jtag.ALL;
7
8 entity c4m_jtag_ioblock is
9 generic (
10 IR_WIDTH: integer := 2;
11 IOS: integer := 1
12 );
13 port (
14 -- needed TAP signals
15 TCK: in std_logic;
16 TDI: in std_logic;
17 TDO: out std_logic;
18
19 -- JTAG state
20 STATE: in TAPSTATE_TYPE;
21 NEXT_STATE: in TAPSTATE_TYPE;
22 DRSTATE: in std_logic;
23
24 -- The instruction
25 IR: in std_logic_vector(IR_WIDTH-1 downto 0);
26
27 -- The I/O access ports
28 CORE_OUT: in std_logic_vector(IOS-1 downto 0);
29 CORE_IN: out std_logic_vector(IOS-1 downto 0);
30 CORE_EN: in std_logic_vector(IOS-1 downto 0);
31
32 -- The pad connections
33 PAD_OUT: out std_logic_vector(IOS-1 downto 0);
34 PAD_IN: in std_logic_vector(IOS-1 downto 0);
35 PAD_EN: out std_logic_vector(IOS-1 downto 0)
36 );
37 end c4m_jtag_ioblock;
38
39 architecture rtl of c4m_jtag_ioblock is
40 signal IOMODE: SRIOMODE_TYPE;
41 signal SAMPLEMODE: SRSAMPLEMODE_TYPE;
42 signal ISSAMPLECMD: boolean;
43
44 signal BDSR_IN: std_logic_vector(IOS-1 downto 0);
45 signal BDSR_OUT: std_logic_vector(IOS-1 downto 0);
46
47 constant CMD_SAMPLEPRELOAD: std_logic_vector(IR_WIDTH-1 downto 0) := c4m_jtag_cmd_samplepreload(IR_WIDTH);
48 constant CMD_EXTEST: std_logic_vector(IR_WIDTH-1 downto 0) := c4m_jtag_cmd_extest(IR_WIDTH);
49 begin
50 -- JTAG baundary scan IO cells
51 IOGEN: for i in 0 to IOS-1 generate
52 begin
53 IOCELL: c4m_jtag_iocell
54 port map (
55 CORE_IN => CORE_IN(i),
56 CORE_OUT => CORE_OUT(i),
57 CORE_EN => CORE_EN(i),
58 PAD_IN => PAD_IN(i),
59 PAD_OUT => PAD_OUT(i),
60 PAD_EN => PAD_EN(i),
61 BDSR_IN => BDSR_IN(i),
62 BDSR_OUT => BDSR_OUT(i),
63 IOMODE => IOMODE,
64 SAMPLEMODE => SAMPLEMODE,
65 TCK => TCK
66 );
67 end generate;
68 BDSRCONN: for i in 0 to IOS-2 generate
69 begin
70 BDSR_IN(i) <= BDSR_OUT(i+1);
71 end generate;
72 BDSR_IN(IOS-1) <= TDI;
73
74 -- Set IOMODE
75 -- Currently SR_2Core or SR_Z are not used
76 IOMODE <= SR_2Pad when IR = CMD_EXTEST else
77 SR_Through;
78
79 -- Set SAMPLEMODE
80 ISSAMPLECMD <= (IR = CMD_SAMPLEPRELOAD or IR = CMD_EXTEST) and DRSTATE = '1';
81 SAMPLEMODE <= SR_Sample when ISSAMPLECMD and STATE = Capture else
82 SR_Update when ISSAMPLECMD and STATE = Update else
83 SR_Shift when ISSAMPLECMD and STATE = Shift else
84 SR_Normal;
85
86 TDO <= BDSR_OUT(0) when ISSAMPLECMD and STATE = Shift else
87 'Z';
88 end rtl;