OpenCores
URL https://opencores.org/ocsvn/openjtag-project/openjtag-project/trunk

Subversion Repositories openjtag-project

[/] [openjtag-project/] [trunk/] [OpenJTAG/] [Quartus_II/] [serializer.vhd] - Blame information for rev 18

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 18 rmileca
-- Created by Ruben H. Mileca - May-16-2010
2
 
3
 
4
library ieee;
5
USE ieee.std_logic_1164.ALL;
6
USE ieee.numeric_std.all;
7
 
8
entity serializer IS
9
 
10
                port (
11
 
12
-- Internal
13
 
14
                clk:    in std_logic;                                           -- External 24 MHz oscillator
15
 
16
-- FT245BM
17
 
18
                txe:    in std_logic;                                           -- From FT245BM TXE# pin
19
                rxf:    in std_logic;                                           -- From FT245BM RXF pin
20
                pwr:    in std_logic;                                           -- From FT245BM PWREN# pin
21
                rst:    in std_logic;                                           -- From FT245BM RSTOUT# pin
22
                wrk:    in std_logic;                                           -- From tap_sm working signal
23
                wr:             out std_logic := '1';                           -- To FT245BM WR pin
24
                rd:             out std_logic := '1';                           -- To FT245BM RD# pin
25
                siwu:   out std_logic := '1';                           -- To FT245BM SI/WU pin
26
                db:             inout std_logic_vector(7 downto 0);      -- From/To FT245BM data bus
27
 
28
-- JTAG
29
 
30
                tdo:    in std_logic;                                           -- TDO Jtag pin
31
                tck:    out std_logic := '0';                            -- TCK Jtag pin
32
                tms:    out std_logic := '0';                            -- TMS Jtag pin
33
                tdi:    out std_logic := '0';                            -- TDI Jtag pin
34
                trst:   out std_logic := '1';                           -- TRST Jtag pin
35
 
36
-- Clock and SM setting
37
 
38
                new_state:      out std_logic_vector(3 downto 0);        -- tap_sm new state
39
                cks:            out std_logic_vector(2 downto 0) -- Clock divider
40
 
41
        );
42
 
43
end serializer;
44
 
45
architecture rtl of serializer is
46
 
47
        signal count:           integer range 0 to 8 := 0;
48
        signal state:           integer range 0 to 15 := 0;
49
        signal rclk:            integer range 0 to 1 := 0;
50
        signal sclk:            integer range 0 to 1 := 0;
51
 
52
        signal instr:           integer range 0 to 1 := 0;                -- 0=Instruction, 1=Data, 2=Shift out, 3/4 shift in
53
        signal ssm:                     integer range 0 to 15 := 0;               -- Shift and data state machine
54
        signal dir:                     std_logic := '1';                               -- '0' = MSB, '1' = LSB
55
        signal rtms:            std_logic := '0';                                -- TMS state at last shift bit
56
 
57
        signal shift:           std_logic_vector(7 downto 0);
58
        signal rbyte:           std_logic_vector(7 downto 0);
59
 
60
begin
61
 
62
 
63
changestate: process(clk, rclk, rxf, txe, pwr, rst)
64
begin
65
        if (rising_edge(clk)) then
66
                if rclk = 1 then
67
                        rclk <= 0;
68
                else
69
                        rclk <= 1;
70
                end if;
71
--              st <= std_logic_vector(to_unsigned(state, st'length));
72
 
73
                if wrk = '0' then
74
                        case ssm is
75
                                when 0 =>
76
                                        tck <= '0';
77
                                        tms <= '0';
78
                                        tdi <= '0';
79
                                        if rxf = '0' then                        -- Start byte read from FT245BM
80
                                                rd <= '0';                               -- Send RD# to FT245BM
81
                                                ssm <= 1;                               -- Change to next state
82
                                        end if;
83
                                when 1 =>
84
                                        rbyte <= db;                            -- Read byte from FT245BM
85
                                        db <= "ZZZZZZZZ";
86
                                        rd <= '1';                                      -- Select next byte from FT245BM
87
                                        ssm <= 2;                                       -- Change state;
88
                                when 2 =>
89
                                        case instr is
90
                                                when 0 =>                                -- Is an instruction byte
91
                                                        case rbyte(3 downto 0) is
92
                                                                when "0000" =>                  -- rbyte(7 downto 4) have the new clock divisor
93
                                                                        cks <= rbyte(7 downto 5);       -- Set clock divisor
94
 
95
                                                                when "0001" =>                  -- rbyte(7 downto 4) have then new state
96
                                                                        new_state <= rbyte(7 downto 4);
97
                                                                        ssm <= 3;                       -- Reset state machine
98
                                                                when "0010" =>                  -- Get current TAP state
99
                                                                        rbyte(3 downto 0) <= std_logic_vector(to_unsigned(state, rbyte(3 downto 0)'length));
100
                                                                        rbyte(4) <= dir;
101
                                                                        ssm <= 5;
102
                                                                when "0011" =>                  -- Software reset TAP
103
                                                                        count <= to_integer(unsigned(rbyte(7 downto 4)));
104
                                                                        ssm <= 9;
105
                                                                        tms <= '1';
106
 
107
 
108
 
109
                                                                when "0100" =>                  -- Hardware reset TAP
110
                                                                        count <= to_integer(unsigned(rbyte(7 downto 4)) - 1);
111
                                                                        ssm <= 8;
112
                                                                when "0101" =>                  -- Set MSB/LSB shift direction
113
                                                                        dir <= rbyte(4);        -- Set shift direction
114
                                                                        sclk <= 0;
115
                                                                        ssm <= 0;                        -- Reset state machine
116
                                                                when "0110" =>                  -- Latch the next byte as shift data
117
                                                                        if state = 0 or state = 4 or state = 11 then
118
                                                                                count <= to_integer(unsigned(rbyte(7 downto 5)));
119
                                                                                rtms <= rbyte(4);       -- TMS state at last shifted bit
120
                                                                                instr <= 1;                     -- Next is data to send
121
                                                                                sclk <= 0;
122
                                                                                ssm <= 0;                        -- Reset state machine
123
                                                                        end if;
124
 
125
                                                                when others =>
126
                                                                        ssm <= 0;                        -- Error, reset state machine
127
                                                        end case;
128
                                                when 1 =>                               -- There is a count bits to shift in/out
129
--                                                      st <= std_logic_vector(to_unsigned(count, st'length));
130
                                                        if sclk = 0 then
131
                                                                tck <= '0';
132
                                                                if dir = '0' then
133
                                                                        tdi <= rbyte(7);
134
                                                                        rbyte(7 downto 1) <= rbyte(6 downto 0);
135
                                                                else
136
                                                                        tdi <= rbyte(0);
137
                                                                        rbyte(6 downto 0) <= rbyte(7 downto 1);
138
                                                                end if;
139
                                                                sclk <= 1;
140
                                                                if count = 0 then
141
                                                                        tms <= rtms;
142
                                                                end if;
143
                                                        else
144
                                                                tck <= '1';
145
 
146
--      Read TDO
147
 
148
                                                                if dir = '1' then
149
                                                                        shift(6 downto 0) <= shift(7 downto 1);
150
                                                                        shift(7) <= tdo;
151
                                                                else
152
                                                                        shift(7 downto 1) <= shift(6 downto 0);
153
                                                                        shift(0) <= tdo;
154
                                                                end if;
155
 
156
                                                                if count > 0 then
157
                                                                        count <= count - 1;
158
                                                                else
159
                                                                        ssm <= 5;
160
                                                                        instr <= 0;
161
                                                                end if;
162
                                                                sclk <= 0;
163
                                                        end if;
164
                                                when others =>
165
                                        end case;
166
 
167
-- Delay for SM state start to work
168
 
169
                                when 3 =>
170
                                        ssm <= 4;
171
                                when 4 =>
172
                                        ssm <= 0;
173
 
174
-- Write rbyte to data bus
175
 
176
                                when 5 =>
177
                                        tck <= '0';
178
                                        tms <= '0';
179
                                        tdi <= '0';
180
                                        if txe = '0' then
181
                                                ssm <= 6;
182
                                                db <= shift;
183
                                        end if;
184
                                when 6 =>
185
                                        wr <= '0';
186
                                        ssm <= 7;
187
                                when 7 =>
188
                                        wr <= '1';
189
                                        ssm <= 0;
190
                                        db <= "ZZZZZZZZ";
191
 
192
                                        if rtms = '1' then
193
                                                if state = 4 or state = 11 then
194
                                                        state <= state + 1;
195
                                                end if;
196
                                        else
197
                                                if state = 0 then
198
                                                        state <= state + 1;
199
                                                end if;
200
                                        end if;
201
 
202
                                when 8 =>
203
                                        if count = 0 then
204
                                                trst <= '1';
205
                                                ssm <= 0;
206
                                        else
207
                                                trst <= '0';
208
                                                count <= count - 1;
209
                                        end if;
210
                                when 9 =>
211
                                        if sclk = 0 then
212
                                                tck <= '1';
213
                                        else
214
                                                tck <= '0';
215
                                                if count > 0 then
216
                                                        count <= count - 1;
217
                                                else
218
                                                        tms <= '0';
219
                                                        ssm <= 0;
220
                                                end if;
221
                                        end if;
222
                                when others =>
223
 
224
                        end case;
225
                end if;
226
        end if;
227
 
228
end process changestate;
229
end rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.