OpenCores
URL https://opencores.org/ocsvn/opb_usblite/opb_usblite/trunk

Subversion Repositories opb_usblite

[/] [opb_usblite/] [trunk/] [pcores/] [opb_usblite_v1_00_a/] [hdl/] [vhdl/] [usb_transact.vhdl] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 rehnmaak
--
2
--  USB 2.0 Transaction-level logic
3
--
4
--  This entity deals with transactions. A transaction consists of up to
5
--  three packets: token, data, handshake. This component supports four
6
--  transaction types:
7
--    * IN    (device-to-host bulk/interrupt/control transfer)
8
--    * OUT   (host-to-device bulk/interrupt/control transfer)
9
--    * SETUP (host-to-device control operation)
10
--    * PING  (flow control for host-to-device bulk/control transfer, HS only)
11
--  Isochronous transactions are not supported.
12
--
13
--  The low-level interface signals are named P_xxx and connect to
14
--  the usb_packet component.
15
--
16
--  The application interface signals are named T_xxx and operate as
17
--  follows:
18
--
19
--    * At the start of a transaction, either T_IN, T_OUT, T_SETUP or T_PING
20
--      rises to 1, indicating the transaction type.  At the same time,
21
--      T_ENDPT is set to the endpoint number for this transaction.
22
--      These signals are held for the duration of the transaction.
23
--
24
--  OUT and SETUP transactions:
25
--    * Each incoming byte is put on RXDAT and announced by asserting RXRDY.
26
--      These signals are valid for only one clock cycle.
27
--    * OSYNC is set to the transmitter's sync bit and held until the end
28
--      of the transaction.
29
--    * The last two bytes are CRC bytes; these should be ignored.
30
--    * Successfull completion is indicated by asserting T_FIN for one cycle.
31
--    * Receive errors are indicated by deasserting T_OUT/T_SETUP without
32
--      ever asserting T_FIN. In this case, the application must discard any
33
--      data already accepted during this transaction.
34
--    * It is probably safe to assume that the first assertion of T_RXRDY
35
--      does not immediately coincide with the rising T_OUT/T_SETUP signal.
36
--      The implementation of usb_control and usb_serial depend on this
37
--      assumption. The assumption may be false if PHY_RXACTIVE is low for
38
--      only one clock between token and data, and re-assertion of PHY_RXACTIVE
39
--      coincides with assertion of PHY_RXVALID. This is not explicitly
40
--      prohibited in the UTMI spec, but it just seems extremely unlikely.
41
--
42
--  OUT transactions:
43
--    * If the application is not ready to accept data, it should assert
44
--      either NAK or STALL. These signals must be set up as soon as the last
45
--      byte of the packet has been received, and kept stable until the end
46
--      of the transaction.
47
--    * If the application is ready to accept this OUT packet, but not ready
48
--      to accept a subsequent OUT packet, it may assert T_NYET. This signal
49
--      must be set up as soon as the last byte of the packet has been received
50
--      and kept stable until the end of the transaction. NYET is only valid
51
--      in high speed mode; in full speed mode, this entity will ignore the
52
--      NYET signal and send ACK instead.
53
--    * Note: NAK/STALL/NYET must not be used during SETUP transactions;
54
--      the standard specifies that SETUP transactions must always be ACK-ed
55
--      and errors reported during the subsequent data transaction.
56
--
57
--  IN transactions:
58
--    * The application should assert SEND, put the sync bit on ISYNC
59
--      and put the first byte on TXDAT. The component will assert TXRDY
60
--      to acknowledge each byte; in the following cycle, the application
61
--      must either provide the next data byte or release SEND to indicate
62
--      the end of the packet.
63
--      After T_IN rises, the application must respond within 2 clock cycles.
64
--    * The application must not include CRC bytes.
65
--    * If the application is not ready to send data, it should assert
66
--      either NAK or STALL and keep it asserted until the end of the
67
--      transaction.
68
--    * An empty packet can be sent by keeping SEND, NAK and STALL
69
--      deasserted; the component will interpret this as a zero-length SEND.
70
--    * Successfull completion of an IN transaction is indicated by
71
--      asserting FIN for one cycle.
72
--    * Timeout is indicated by deasserting T_IN without ever asserting FIN.
73
--      In this case, the application must assume that the IN transaction
74
--      failed.
75
--
76
--  PING transactions:
77
--    * In high speed mode only, the host may send a PING transaction to which
78
--      the application must respond with either ACK or NAK to indicate whether
79
--      it is willing to receive a full sized OUT transaction.
80
--    * When a PING is received, T_PING is raised and at the same time T_ENDPT
81
--      becomes valid. The application must respond within 2 clock cycles.
82
--    * If the application is not ready to received data, it should assert T_NAK
83
--      and keep it asserted until the end of the transaction. If the application
84
--      does not assert either T_NAK or T_STALL, an ACK response will be sent.
85
--
86
 
87
library ieee;
88
use ieee.std_logic_1164.all, ieee.numeric_std.all;
89
 
90
entity usb_transact is
91
 
92
    generic (
93
 
94
        -- Support high speed mode.
95
        HSSUPPORT : boolean := false );
96
 
97
    port (
98
 
99
        -- 60 MHz UTMI clock.
100
        CLK :           in  std_logic;
101
 
102
        -- Synchronous reset of this entity.
103
        RESET :         in  std_logic;
104
 
105
        -- High during IN transactions.
106
        T_IN :          out std_logic;
107
 
108
        -- High during OUT transactions.
109
        T_OUT :         out std_logic;
110
 
111
        -- High during SETUP transactions.
112
        T_SETUP :       out std_logic;
113
 
114
        -- High during PING transactions.
115
        T_PING :        out std_logic;
116
 
117
        -- Indicates successfull completion of a transaction.
118
        T_FIN :         out std_logic;
119
 
120
        -- Device address.
121
        T_ADDR :        in  std_logic_vector(6 downto 0);
122
 
123
        -- Endpoint number for current transaction.
124
        T_ENDPT :       out std_logic_vector(3 downto 0);
125
 
126
        -- Triggers a NAK response to IN/OUT/PING.
127
        T_NAK :         in  std_logic;
128
 
129
        -- Triggers a STALL response to IN/OUT.
130
        T_STALL :       in  std_logic;
131
 
132
        -- Triggers a NYET response to OUT.
133
        T_NYET :        in  std_logic;
134
 
135
        -- High while application has data to send (in response to OUT).
136
        T_SEND :        in  std_logic;
137
 
138
        -- Sync bit to use for IN transactions.
139
        T_ISYNC :       in  std_logic;
140
 
141
        -- Sync bit used for the current OUT transaction.
142
        T_OSYNC :       out std_logic;
143
 
144
        -- Indicates next byte received.
145
        T_RXRDY :       out std_logic;
146
 
147
        -- Received data; valid when T_RXRDY = '1'.
148
        T_RXDAT :       out std_logic_vector(7 downto 0);
149
 
150
        -- Requests next byte to transmit; application must update T_TXDAT or T_SEND in next cycle.
151
        T_TXRDY :       out std_logic;
152
 
153
        -- Data byte to transmit; must be valid when T_SEND = '1'.
154
        T_TXDAT :       in  std_logic_vector(7 downto 0);
155
 
156
        -- Connect to I_HIGHSPEED from usb_init.
157
        I_HIGHSPEED :   in  std_logic;
158
 
159
        -- Connect to P_RXACT from usb_packet.
160
        P_RXACT :       in  std_logic;
161
 
162
        -- Connect to P_RXRDY from usb_packet.
163
        P_RXRDY :       in  std_logic;
164
 
165
        -- Connect to P_RXFIN from usb_packet.
166
        P_RXFIN :       in  std_logic;
167
 
168
        -- Connect to P_RXDAT from usb_packet.
169
        P_RXDAT :       in  std_logic_vector(7 downto 0);
170
 
171
        -- Connect to P_TXACT towards usb_packet.
172
        P_TXACT :       out std_logic;
173
 
174
        -- Connect to P_TXRDY from usb_packet.
175
        P_TXRDY :       in  std_logic;
176
 
177
        -- Connect to P_TXDAT towards usb_packet.
178
        P_TXDAT :       out std_logic_vector(7 downto 0) );
179
 
180
end entity usb_transact;
181
 
182
architecture usb_transact_arch of usb_transact is
183
 
184
    -- PID constants
185
    constant pid_out :  std_logic_vector(3 downto 0) := "0001";
186
    constant pid_in :   std_logic_vector(3 downto 0) := "1001";
187
    constant pid_setup: std_logic_vector(3 downto 0) := "1101";
188
    constant pid_ack :  std_logic_vector(3 downto 0) := "0010";
189
    constant pid_nak :  std_logic_vector(3 downto 0) := "1010";
190
    constant pid_stall: std_logic_vector(3 downto 0) := "1110";
191
    constant pid_nyet : std_logic_vector(3 downto 0) := "0110";
192
    constant pid_ping : std_logic_vector(3 downto 0) := "0100";
193
    constant pid_data : std_logic_vector(2 downto 0) :=  "011";
194
 
195
    function pid_mirror(v: std_logic_vector) return std_logic_vector
196
    is begin
197
        return (not v) & v;
198
    end function;
199
 
200
    -- State machine
201
    type t_state is (
202
      ST_IDLE, ST_SKIP,
203
      ST_GETTOKEN1, ST_GETTOKEN2, ST_GETTOKEN3, ST_GOTTOKEN,
204
      ST_SENDSHAKE,
205
      ST_GETDATA, ST_GOTDATA,
206
      ST_SENDDATA, ST_SENDING,
207
      ST_WAITACK, ST_WAITSKIP, ST_GETACK );
208
    signal s_state : t_state := ST_IDLE;
209
    signal s_active :   std_logic;
210
 
211
    -- Transaction state
212
    signal s_in :       std_logic := '0';
213
    signal s_out :      std_logic := '0';
214
    signal s_setup :    std_logic := '0';
215
    signal s_ping :     std_logic := '0';
216
    signal s_finished : std_logic := '0';
217
 
218
    -- Previous value of P_RXACT; needed to detect bad packet while waiting for host.
219
    signal s_prevrxact : std_logic;
220
 
221
    -- PID byte to use for outgoing packet (ST_SENDSHAKE or ST_SENDDATA)
222
    signal s_sendpid :  std_logic_vector(3 downto 0);
223
 
224
    -- Registered output signals
225
    signal s_endpt : std_logic_vector(3 downto 0) := "0000";
226
    signal s_osync : std_logic := '0';
227
 
228
    -- In full speed mode, we must time out an expected host response after
229
    -- 16 to 18 bit periods. In high speed mode, we must time out after
230
    -- 736 to 816 bit periods. We can not get accurate timing because we don't
231
    -- know the delay due to CRC, EOP, SYNC and UTMI pipeline. (We should use
232
    -- PHY_LINESTATE for timing, but we don't.) So we just use a much longer
233
    -- timeout; wait_timeout_fs = 511 cycles = 102 bit periods;
234
    -- wait_timeout_hs = 127 cycles = 1020 bit periods.
235
    constant wait_timeout_fs : unsigned(8 downto 0) := "111111111";
236
    constant wait_timeout_hs : unsigned(8 downto 0) := "001111111";
237
 
238
    -- In full speed mode, we must wait at least 2 and at most 6.5 bit periods
239
    -- before responding to the host. We have wait_send_fs = 14 cycles from
240
    -- rising T_IN/OUT/SETUP until valid T_NAK; equals 16 cycles from rising
241
    -- P_RXFIN until rising P_TXACT; equals 18 cycles from falling PHY_RXACTIVE
242
    -- until rising PHY_TXVALID. Including pipeline delay in the UTMI, we end
243
    -- up with 2 to 5 bit periods from SE0-to-J until SYNC.
244
    constant wait_send_fs : unsigned(8 downto 0) := "000001110";
245
 
246
    -- In high speed mode, we must wait at least 8 and at most 192 bit periods
247
    -- before responding to the host. We give the application wait_send_hs = 2
248
    -- cycles to get its act together; i.e. from rising T_IN/OUT/SETUP/PING
249
    -- until valid T_NAK/STALL/NYET/SEND. This corresponds to 4 cycles from
250
    -- P_RXFIN until P_TXACT; equals 6 cycles from falling PHY_RXACTIVE until
251
    -- rising PHY_TXVALID. Including pipeline delay in the UTMI, we end up
252
    -- with 78 to 127 bit periods between packets.
253
    constant wait_send_hs : unsigned(8 downto 0) := "000000010";
254
 
255
    -- Count down timer.
256
    signal wait_count : unsigned(8 downto 0);
257
 
258
begin
259
 
260
    -- Assign control signals
261
    s_active <=
262
        '1' when (s_state = ST_IDLE or s_state = ST_GOTTOKEN or
263
                  s_state = ST_SENDSHAKE or
264
                  s_state = ST_GETDATA or s_state = ST_GOTDATA or
265
                  s_state = ST_SENDDATA or s_state = ST_SENDING or
266
                  s_state = ST_WAITACK or s_state = ST_WAITSKIP or s_state = ST_GETACK)
267
        else '0';
268
    T_IN    <= s_in and s_active;
269
    T_OUT   <= s_out and s_active;
270
    T_SETUP <= s_setup and s_active;
271
    T_PING  <= s_ping and s_active;
272
    T_FIN   <= s_finished;  -- Note: T_FIN only occurs when s_state = ST_IDLE
273
    T_ENDPT <= s_endpt;
274
    T_OSYNC <= s_osync;
275
 
276
    -- Received bytes
277
    T_RXRDY <= P_RXRDY when (s_state = ST_GETDATA) else '0';
278
    T_RXDAT <= P_RXDAT;
279
 
280
    -- Byte to transmit: handshake PID, data PID or data byte
281
    T_TXRDY <= P_TXRDY when (s_state = ST_SENDING) else '0';
282
    P_TXACT <= '1' when (s_state = ST_SENDSHAKE or s_state = ST_SENDDATA or
283
                         (s_state = ST_SENDING and T_SEND = '1'))
284
               else '0';
285
    P_TXDAT <= pid_mirror(s_sendpid) when (s_state = ST_SENDSHAKE or s_state = ST_SENDDATA)
286
               else T_TXDAT;
287
 
288
 
289
    -- On every rising clock edge
290
    process is
291
    begin
292
        wait until rising_edge(CLK);
293
 
294
        s_prevrxact     <= P_RXACT;
295
 
296
        if RESET = '1' then
297
 
298
            -- Reset this component
299
            s_state     <= ST_IDLE;
300
            s_in        <= '0';
301
            s_out       <= '0';
302
            s_setup     <= '0';
303
            s_ping      <= '0';
304
            s_finished  <= '0';
305
 
306
        else
307
 
308
            case s_state is
309
 
310
                when ST_IDLE =>
311
                    -- Idle; wait for incoming packet
312
                    s_in        <= '0';
313
                    s_out       <= '0';
314
                    s_setup     <= '0';
315
                    s_ping      <= '0';
316
                    s_finished  <= '0';
317
                    if P_RXRDY = '1' then
318
                        case P_RXDAT(3 downto 0) is
319
                            when pid_out =>
320
                                -- OUT token
321
                                s_out   <= '1';
322
                                s_state <= ST_GETTOKEN1;
323
                            when pid_in =>
324
                                -- IN token
325
                                s_in    <= '1';
326
                                s_state <= ST_GETTOKEN1;
327
                            when pid_setup =>
328
                                -- SETUP token
329
                                s_setup <= '1';
330
                                s_state <= ST_GETTOKEN1;
331
                            when pid_ping =>
332
                                -- PING token
333
                                if HSSUPPORT then
334
                                    s_ping  <= '1';
335
                                    s_state <= ST_GETTOKEN1;
336
                                else
337
                                    -- no PINGing for full speed devices
338
                                    s_state <= ST_SKIP;
339
                                end if;
340
                            when others =>
341
                                -- unexpected packet
342
                                s_state <= ST_SKIP;
343
                        end case;
344
                    end if;
345
 
346
                when ST_SKIP =>
347
                    -- Skip incoming packet and go back to IDLE
348
                    if P_RXACT = '0' then
349
                        s_state <= ST_IDLE;
350
                    end if;
351
 
352
                when ST_GETTOKEN1 =>
353
                    -- Receive and check 2nd byte of a token packet
354
                    if P_RXACT = '0' then
355
                        -- Bad packet
356
                        s_state <= ST_IDLE;
357
                    elsif P_RXRDY = '1' then
358
                        -- Store endpoint number
359
                        s_endpt(0) <= P_RXDAT(7);
360
                        -- Check address
361
                        if P_RXDAT(6 downto 0) = T_ADDR then
362
                            -- Packet is addressed to us
363
                            s_state <= ST_GETTOKEN2;
364
                        else
365
                            -- Packet not addressed to us
366
                            s_state <= ST_SKIP;
367
                        end if;
368
                    end if;
369
 
370
                when ST_GETTOKEN2 =>
371
                    -- Receive 3rd byte of token packet
372
                    if P_RXACT = '0' then
373
                        -- Bad packet
374
                        s_state <= ST_IDLE;
375
                    elsif P_RXRDY = '1' then
376
                        -- Store endpoint number
377
                        s_endpt(3 downto 1) <= P_RXDAT(2 downto 0);
378
                        s_state <= ST_GETTOKEN3;
379
                    end if;
380
 
381
                when ST_GETTOKEN3 =>
382
                    -- Wait for end of incoming token packet
383
                    if P_RXFIN = '1' then
384
                        -- Token was ok
385
                        s_state <= ST_GOTTOKEN;
386
                    elsif P_RXACT = '0' then
387
                        -- Token was bad
388
                        s_state <= ST_IDLE;
389
                    end if;
390
                    if (s_in = '1') or (HSSUPPORT and (s_ping = '1')) then
391
                        if HSSUPPORT and (I_HIGHSPEED = '1') then
392
                            wait_count <= wait_send_hs;
393
                        else
394
                            wait_count <= wait_send_fs;
395
                        end if;
396
                    else
397
                        if HSSUPPORT and (I_HIGHSPEED = '1') then
398
                            wait_count <= wait_timeout_hs;
399
                        else
400
                            wait_count <= wait_timeout_fs;
401
                        end if;
402
                    end if;
403
 
404
                when ST_GOTTOKEN =>
405
                    -- Wait for data packet or wait for our turn to respond
406
                    if P_RXACT = '1' then
407
                        if P_RXRDY = '1' then
408
                            -- Got PID byte
409
                            if ((s_out = '1') or (s_setup = '1')) and
410
                               (P_RXDAT(2 downto 0) = pid_data) then
411
                                -- This is the DATA packet we were waiting for
412
                                s_osync <= P_RXDAT(3);
413
                                s_state <= ST_GETDATA;
414
                            else
415
                                -- Got unexpected packet
416
                                s_in    <= '0';
417
                                s_out   <= '0';
418
                                s_setup <= '0';
419
                                s_ping  <= '0';
420
                                case P_RXDAT(3 downto 0) is
421
                                    when pid_out =>
422
                                        -- unexpected OUT token
423
                                        s_out <= '1';
424
                                        s_state <= ST_GETTOKEN1;
425
                                    when pid_in =>
426
                                        -- unexpected IN token
427
                                        s_in <= '1';
428
                                        s_state <= ST_GETTOKEN1;
429
                                    when pid_setup =>
430
                                        -- unexpected SETUP token
431
                                        s_setup <= '1';
432
                                        s_state <= ST_GETTOKEN1;
433
                                    when pid_ping =>
434
                                        -- unexpected PING token
435
                                        if HSSUPPORT then
436
                                            s_ping  <= '1';
437
                                            s_state <= ST_GETTOKEN1;
438
                                        else
439
                                            -- no PINGing for full speed devices
440
                                            s_state <= ST_SKIP;
441
                                        end if;
442
                                    when others =>
443
                                        -- unexpected packet
444
                                        s_state <= ST_SKIP;
445
                                end case;
446
                            end if;
447
                        end if;
448
                    elsif s_prevrxact = '1' then
449
                        -- got bad packet
450
                        s_state <= ST_IDLE;
451
                    elsif wait_count = 0 then
452
                        -- timer reached zero
453
                        if s_in = '1' then
454
                            -- IN transaction: send response
455
                            if T_STALL = '1' then
456
                                s_state   <= ST_SENDSHAKE;
457
                                s_sendpid <= pid_stall;
458
                            elsif T_NAK = '1' then
459
                                s_state   <= ST_SENDSHAKE;
460
                                s_sendpid <= pid_nak;
461
                            else
462
                                s_state   <= ST_SENDDATA;
463
                                s_sendpid <= T_ISYNC & pid_data;
464
                            end if;
465
                        elsif HSSUPPORT and (s_ping = '1') then
466
                            -- PING transaction: send handshake
467
                            s_state <= ST_SENDSHAKE;
468
                            if T_STALL = '1' then
469
                                s_sendpid <= pid_stall;
470
                            elsif T_NAK = '1' then
471
                                s_sendpid <= pid_nak;
472
                            else
473
                                s_sendpid <= pid_ack;
474
                            end if;
475
                        else
476
                            -- OUT/SETUP transaction:
477
                            -- timeout while waiting for DATA packet
478
                            s_state <= ST_IDLE;
479
                        end if;
480
                    end if;
481
                    -- count down timer
482
                    wait_count <= wait_count - 1;
483
 
484
                when ST_SENDSHAKE =>
485
                    -- Send handshake packet
486
                    if P_TXRDY = '1' then
487
                        -- Handshake done, transaction completed
488
                        s_finished <= '1';
489
                        s_state <= ST_IDLE;
490
                    end if;
491
 
492
                when ST_GETDATA =>
493
                    -- Wait for end of incoming data packet
494
                    if P_RXFIN = '1' then
495
                        -- Data packet was good, respond with handshake
496
                        s_state <= ST_GOTDATA;
497
                    elsif P_RXACT = '0' then
498
                        -- Data packet was bad, ignore it
499
                        s_state <= ST_IDLE;
500
                    end if;
501
                    if HSSUPPORT and (I_HIGHSPEED = '1') then
502
                        wait_count <= wait_send_hs;
503
                    else
504
                        wait_count <= wait_send_fs;
505
                    end if;
506
 
507
                when ST_GOTDATA =>
508
                    -- Wait for inter-packet delay before responding
509
                    if wait_count = 0 then
510
                        -- Move to response state
511
                        s_state <= ST_SENDSHAKE;
512
                        if T_STALL = '1' then
513
                            s_sendpid <= pid_stall;
514
                        elsif T_NAK = '1' then
515
                            s_sendpid <= pid_nak;
516
                        elsif HSSUPPORT and (I_HIGHSPEED = '1') and (T_NYET = '1') then
517
                            s_sendpid <= pid_nyet;
518
                        else
519
                            s_sendpid <= pid_ack;
520
                        end if;
521
                    end if;
522
                    wait_count <= wait_count - 1;
523
 
524
                when ST_SENDDATA =>
525
                    -- Start sending a data packet
526
                    if P_TXRDY = '1' then
527
                        -- Sent PID byte, need first data byte
528
                        s_state <= ST_SENDING;
529
                    end if;
530
 
531
                when ST_SENDING =>
532
                    -- Send payload of data packet
533
                    if T_SEND = '0' then
534
                        -- End of data packet
535
                        s_state <= ST_WAITACK;
536
                    end if;
537
                    if HSSUPPORT and (I_HIGHSPEED = '1') then
538
                        wait_count <= wait_timeout_hs;
539
                    else
540
                        wait_count <= wait_timeout_fs;
541
                    end if;
542
 
543
                when ST_WAITACK =>
544
                    -- Wait for ACK handshake
545
                    if P_RXACT = '1' then
546
                        if P_RXRDY = '1' then
547
                            -- Got PID byte
548
                            case P_RXDAT(3 downto 0) is
549
                                when pid_ack =>
550
                                    -- ACK handshake
551
                                    s_state <= ST_GETACK;
552
                                when pid_out =>
553
                                    -- unexpected OUT token
554
                                    s_in    <= '0';
555
                                    s_out   <= '1';
556
                                    s_state <= ST_GETTOKEN1;
557
                                when pid_in =>
558
                                    -- unexpected IN token
559
                                    s_in    <= '1';
560
                                    s_state <= ST_GETTOKEN1;
561
                                when pid_setup =>
562
                                    -- unexpected SETUP token
563
                                    s_in    <= '0';
564
                                    s_setup <= '1';
565
                                    s_state <= ST_GETTOKEN1;
566
                                when pid_ping =>
567
                                    -- unexpected PING token
568
                                    if HSSUPPORT then
569
                                        s_in    <= '0';
570
                                        s_ping  <= '1';
571
                                        s_state <= ST_GETTOKEN1;
572
                                    else
573
                                        -- no PINGing for full speed devices
574
                                        s_state <= ST_SKIP;
575
                                    end if;
576
                                when ("0" & pid_data) | ("1" & pid_data) =>
577
                                    -- unexpected DATA packet
578
                                    -- This could be our own transmitted packet
579
                                    -- (if it was very short), so skip this.
580
                                    s_state <= ST_WAITSKIP;
581
                                when others =>
582
                                    -- unexpected packet
583
                                    s_state <= ST_SKIP;
584
                            end case;
585
                        end if;
586
                    elsif s_prevrxact = '1' then
587
                        -- got bad packet
588
                        s_state <= ST_IDLE;
589
                    elsif wait_count = 0 then
590
                        -- timeout while waiting for ACK
591
                        s_state <= ST_IDLE;
592
                    end if;
593
                    -- count down timer
594
                    wait_count <= wait_count - 1;
595
 
596
                when ST_WAITSKIP =>
597
                    -- Skip the echo of our own transmitted packet
598
                    if wait_count = 0 then
599
                        -- timeout
600
                        s_state <= ST_SKIP;
601
                    elsif P_RXFIN = '1' then
602
                        -- end of packet
603
                        s_state <= ST_WAITACK;
604
                    elsif P_RXACT = '0' then
605
                        -- bad packet
606
                        s_state <= ST_IDLE;
607
                    end if;
608
                    -- count down timer
609
                    wait_count <= wait_count - 1;
610
 
611
                when ST_GETACK =>
612
                    -- Wait for end of incoming ACK packet
613
                    if P_RXFIN = '1' then
614
                        -- ACK handshake was good
615
                        s_finished <= '1';
616
                        s_state <= ST_IDLE;
617
                    elsif P_RXACT = '0' then
618
                        -- ACK handshake was bad
619
                        s_state <= ST_IDLE;
620
                    end if;
621
 
622
            end case;
623
 
624
        end if;
625
 
626
    end process;
627
 
628
end architecture usb_transact_arch;

powered by: WebSVN 2.1.0

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