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

Subversion Repositories usbhostslave

[/] [usbhostslave/] [trunk/] [RTL/] [serialInterfaceEngine/] [SIETransmitter.v] - Blame information for rev 14

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sfielding
 
2
//////////////////////////////////////////////////////////////////////
3
////                                                              ////
4
//// SIETransmitter
5
////                                                              ////
6
//// This file is part of the usbhostslave opencores effort.
7
//// http://www.opencores.org/cores/usbhostslave/                 ////
8
////                                                              ////
9
//// Module Description:                                          ////
10
//// 
11
////                                                              ////
12
//// To Do:                                                       ////
13
//// 
14
////                                                              ////
15
//// Author(s):                                                   ////
16
//// - Steve Fielding, sfielding@base2designs.com                 ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20
//// Copyright (C) 2004 Steve Fielding and OPENCORES.ORG          ////
21
////                                                              ////
22
//// This source file may be used and distributed without         ////
23
//// restriction provided that this copyright statement is not    ////
24
//// removed from the file and that any derivative work contains  ////
25
//// the original copyright notice and the associated disclaimer. ////
26
////                                                              ////
27
//// This source file is free software; you can redistribute it   ////
28
//// and/or modify it under the terms of the GNU Lesser General   ////
29
//// Public License as published by the Free Software Foundation; ////
30
//// either version 2.1 of the License, or (at your option) any   ////
31
//// later version.                                               ////
32
////                                                              ////
33
//// This source is distributed in the hope that it will be       ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
36
//// PURPOSE. See the GNU Lesser General Public License for more  ////
37
//// details.                                                     ////
38
////                                                              ////
39
//// You should have received a copy of the GNU Lesser General    ////
40
//// Public License along with this source; if not, download it   ////
41
//// from http://www.opencores.org/lgpl.shtml                     ////
42
////                                                              ////
43
//////////////////////////////////////////////////////////////////////
44
//
45
`timescale 1ns / 1ps
46
`include "usbSerialInterfaceEngine_h.v"
47
`include "usbConstants_h.v"
48
 
49
 
50 14 sfielding
module SIETransmitter (clk, CRC16En, CRC16Result, CRC16UpdateRdy, CRC5_8Bit, CRC5En, CRC5Result, CRC5UpdateRdy, CRCData, fullSpeedRateIn, JBit, KBit, processTxByteRdy, processTxByteWEn, rst, rstCRC, SIEPortCtrlIn, SIEPortDataIn, SIEPortTxRdy, SIEPortWEn, TxByteOut, TxByteOutCtrl, TxByteOutFullSpeedRate, USBWireCtrl, USBWireData, USBWireFullSpeedRate, USBWireGnt, USBWireRdy, USBWireReq, USBWireWEn);
51 5 sfielding
input   clk;
52
input   [15:0]CRC16Result;
53
input   CRC16UpdateRdy;
54
input   [4:0]CRC5Result;
55
input   CRC5UpdateRdy;
56 14 sfielding
input   fullSpeedRateIn;
57 5 sfielding
input   [1:0]JBit;
58
input   [1:0]KBit;
59
input   processTxByteRdy;
60
input   rst;
61
input   [7:0]SIEPortCtrlIn;
62
input   [7:0]SIEPortDataIn;
63
input   SIEPortWEn;
64
input   USBWireGnt;
65
input   USBWireRdy;
66
output  CRC16En;
67
output  CRC5_8Bit;
68
output  CRC5En;
69
output  [7:0]CRCData;
70
output  processTxByteWEn;
71
output  rstCRC;
72
output  SIEPortTxRdy;
73
output  [7:0]TxByteOut;
74
output  [7:0]TxByteOutCtrl;
75 14 sfielding
output  TxByteOutFullSpeedRate;
76 5 sfielding
output  USBWireCtrl;
77
output  [1:0]USBWireData;
78 14 sfielding
output  USBWireFullSpeedRate;
79 5 sfielding
output  USBWireReq;
80
output  USBWireWEn;
81
 
82
wire    clk;
83
reg     CRC16En, next_CRC16En;
84
wire    [15:0]CRC16Result;
85
wire    CRC16UpdateRdy;
86
reg     CRC5_8Bit, next_CRC5_8Bit;
87
reg     CRC5En, next_CRC5En;
88
wire    [4:0]CRC5Result;
89
wire    CRC5UpdateRdy;
90
reg     [7:0]CRCData, next_CRCData;
91 14 sfielding
wire    fullSpeedRateIn;
92 5 sfielding
wire    [1:0]JBit;
93
wire    [1:0]KBit;
94
wire    processTxByteRdy;
95
reg     processTxByteWEn, next_processTxByteWEn;
96
wire    rst;
97
reg     rstCRC, next_rstCRC;
98
wire    [7:0]SIEPortCtrlIn;
99
wire    [7:0]SIEPortDataIn;
100
reg     SIEPortTxRdy, next_SIEPortTxRdy;
101
wire    SIEPortWEn;
102
reg     [7:0]TxByteOut, next_TxByteOut;
103
reg     [7:0]TxByteOutCtrl, next_TxByteOutCtrl;
104 14 sfielding
reg     TxByteOutFullSpeedRate, next_TxByteOutFullSpeedRate;
105 5 sfielding
reg     USBWireCtrl, next_USBWireCtrl;
106
reg     [1:0]USBWireData, next_USBWireData;
107 14 sfielding
reg     USBWireFullSpeedRate, next_USBWireFullSpeedRate;
108 5 sfielding
wire    USBWireGnt;
109
wire    USBWireRdy;
110
reg     USBWireReq, next_USBWireReq;
111
reg     USBWireWEn, next_USBWireWEn;
112
 
113
// diagram signals declarations
114 14 sfielding
reg  [2:0]i, next_i;
115
reg  [15:0]resumeCnt, next_resumeCnt;
116 5 sfielding
reg  [7:0]SIEPortCtrl, next_SIEPortCtrl;
117
reg  [7:0]SIEPortData, next_SIEPortData;
118
 
119
// BINARY ENCODED state machine: SIETx
120
// State codes definitions:
121 14 sfielding
`define DIR_CTL_CHK_FIN 6'b000000
122
`define RES_ST_CHK_FIN 6'b000001
123 9 sfielding
`define PKT_ST_CHK_PID 6'b000010
124
`define PKT_ST_DATA_DATA_CHK_STOP 6'b000011
125
`define IDLE 6'b000100
126 14 sfielding
`define PKT_ST_DATA_DATA_PKT_SENT 6'b000101
127
`define PKT_ST_DATA_PID_PKT_SENT 6'b000110
128
`define PKT_ST_HS_PKT_SENT 6'b000111
129
`define PKT_ST_TKN_CRC_PKT_SENT 6'b001000
130
`define PKT_ST_TKN_PID_PKT_SENT 6'b001001
131
`define PKT_ST_SPCL_PKT_SENT 6'b001010
132 5 sfielding
`define PKT_ST_DATA_CRC_PKT_SENT1 6'b001011
133
`define PKT_ST_TKN_BYTE1_PKT_SENT1 6'b001100
134
`define PKT_ST_DATA_CRC_PKT_SENT2 6'b001101
135 14 sfielding
`define RES_ST_SND_J_1 6'b001110
136
`define RES_ST_SND_J_2 6'b001111
137
`define RES_ST_SND_SE0_1 6'b010000
138
`define RES_ST_SND_SE0_2 6'b010001
139
`define START_SIETX 6'b010010
140
`define STX_CHK_ST 6'b010011
141
`define STX_WAIT_BYTE 6'b010100
142
`define PKT_ST_TKN_CRC_UPD_CRC 6'b010101
143
`define PKT_ST_TKN_BYTE1_UPD_CRC 6'b010110
144
`define PKT_ST_DATA_DATA_UPD_CRC 6'b010111
145
`define RES_ST_W_RDY1 6'b011000
146
`define PKT_ST_TKN_CRC_WAIT_BYTE 6'b011001
147
`define PKT_ST_TKN_BYTE1_WAIT_BYTE 6'b011010
148
`define PKT_ST_DATA_DATA_WAIT_BYTE 6'b011011
149
`define RES_ST_WAIT_GNT 6'b011100
150
`define DIR_CTL_WAIT_GNT 6'b011101
151
`define PKT_ST_HS_WAIT_RDY 6'b011110
152
`define PKT_ST_SPCL_WAIT_RDY 6'b011111
153
`define PKT_ST_TKN_CRC_WAIT_RDY 6'b100000
154 9 sfielding
`define PKT_ST_TKN_PID_WAIT_RDY 6'b100001
155
`define PKT_ST_DATA_PID_WAIT_RDY 6'b100010
156 14 sfielding
`define RES_ST_WAIT_RDY 6'b100011
157
`define PKT_ST_TKN_BYTE1_WAIT_RDY 6'b100100
158
`define PKT_ST_DATA_DATA_WAIT_RDY 6'b100101
159
`define DIR_CTL_WAIT_RDY 6'b100110
160
`define PKT_ST_DATA_CRC_WAIT_RDY1 6'b100111
161
`define PKT_ST_DATA_CRC_WAIT_RDY2 6'b101000
162
`define PKT_ST_WAIT_RDY_PKT 6'b101001
163
`define PKT_ST_TKN_CRC_WAIT_CRC_RDY 6'b101010
164
`define PKT_ST_DATA_DATA_WAIT_CRC_RDY 6'b101011
165
`define PKT_ST_TKN_BYTE1_WAIT_CRC_RDY 6'b101100
166
`define TX_LS_EOP_WAIT_GNT1 6'b101101
167
`define TX_LS_EOP_SND_SE0_2 6'b101110
168
`define TX_LS_EOP_SND_SE0_1 6'b101111
169
`define TX_LS_EOP_W_RDY1 6'b110000
170
`define TX_LS_EOP_SND_J 6'b110001
171
`define TX_LS_EOP_W_RDY2 6'b110010
172
`define TX_LS_EOP_W_RDY3 6'b110011
173
`define RES_ST_DELAY 6'b110100
174
`define RES_ST_W_RDY2 6'b110101
175
`define RES_ST_W_RDY3 6'b110110
176
`define RES_ST_W_RDY4 6'b110111
177
`define DIR_CTL_DELAY 6'b111000
178 5 sfielding
 
179
reg [5:0]CurrState_SIETx, NextState_SIETx;
180
 
181
 
182
// Machine: SIETx
183
 
184
// NextState logic (combinatorial)
185 14 sfielding
always @ (i or resumeCnt or SIEPortData or SIEPortCtrl or fullSpeedRateIn or SIEPortWEn or SIEPortDataIn or SIEPortCtrlIn or USBWireRdy or USBWireGnt or processTxByteRdy or CRC5Result or KBit or CRC16Result or CRC5UpdateRdy or CRC16UpdateRdy or JBit or USBWireWEn or USBWireReq or processTxByteWEn or rstCRC or USBWireFullSpeedRate or TxByteOut or TxByteOutCtrl or USBWireData or USBWireCtrl or CRCData or CRC5En or CRC5_8Bit or CRC16En or SIEPortTxRdy or TxByteOutFullSpeedRate or CurrState_SIETx)
186 5 sfielding
begin
187
  NextState_SIETx <= CurrState_SIETx;
188
  // Set default values for outputs and signals
189
  next_USBWireWEn <= USBWireWEn;
190
  next_i <= i;
191
  next_USBWireReq <= USBWireReq;
192
  next_processTxByteWEn <= processTxByteWEn;
193
  next_rstCRC <= rstCRC;
194 14 sfielding
  next_USBWireFullSpeedRate <= USBWireFullSpeedRate;
195
  next_TxByteOut <= TxByteOut;
196
  next_TxByteOutCtrl <= TxByteOutCtrl;
197 5 sfielding
  next_USBWireData <= USBWireData;
198
  next_USBWireCtrl <= USBWireCtrl;
199
  next_CRCData <= CRCData;
200
  next_CRC5En <= CRC5En;
201
  next_CRC5_8Bit <= CRC5_8Bit;
202
  next_CRC16En <= CRC16En;
203
  next_SIEPortTxRdy <= SIEPortTxRdy;
204
  next_SIEPortData <= SIEPortData;
205
  next_SIEPortCtrl <= SIEPortCtrl;
206 14 sfielding
  next_resumeCnt <= resumeCnt;
207
  next_TxByteOutFullSpeedRate <= TxByteOutFullSpeedRate;
208 5 sfielding
  case (CurrState_SIETx)  // synopsys parallel_case full_case
209 9 sfielding
    `IDLE:
210
    begin
211
      NextState_SIETx <= `STX_WAIT_BYTE;
212
    end
213 5 sfielding
    `START_SIETX:
214
    begin
215
      next_processTxByteWEn <= 1'b0;
216
      next_TxByteOut <= 8'h00;
217
      next_TxByteOutCtrl <= 8'h00;
218
      next_USBWireData <= 2'b00;
219
      next_USBWireCtrl <= `TRI_STATE;
220
      next_USBWireReq <= 1'b0;
221
      next_USBWireWEn <= 1'b0;
222
      next_rstCRC <= 1'b0;
223
      next_CRCData <= 8'h00;
224
      next_CRC5En <= 1'b0;
225
      next_CRC5_8Bit <= 1'b0;
226
      next_CRC16En <= 1'b0;
227
      next_SIEPortTxRdy <= 1'b0;
228
      next_SIEPortData <= 8'h00;
229
      next_SIEPortCtrl <= 8'h00;
230 14 sfielding
      next_i <= 3'h0;
231
      next_resumeCnt <= 16'h0000;
232
      next_TxByteOutFullSpeedRate <= 1'b0;
233
      next_USBWireFullSpeedRate <= 1'b0;
234 5 sfielding
      NextState_SIETx <= `STX_WAIT_BYTE;
235
    end
236
    `STX_CHK_ST:
237
    begin
238 14 sfielding
      if ((SIEPortCtrl == `TX_PACKET_START) && (SIEPortData[3:0] == `SOF || SIEPortData[3:0] == `PREAMBLE))
239 5 sfielding
      begin
240 9 sfielding
        NextState_SIETx <= `PKT_ST_WAIT_RDY_PKT;
241 14 sfielding
        next_TxByteOutFullSpeedRate <= 1'b1;
242
        //SOF and PRE always at full speed
243 5 sfielding
      end
244 14 sfielding
      else if (SIEPortCtrl == `TX_PACKET_START)
245
      begin
246
        NextState_SIETx <= `PKT_ST_WAIT_RDY_PKT;
247
      end
248
      else if (SIEPortCtrl == `TX_LS_KEEP_ALIVE)
249
      begin
250
        NextState_SIETx <= `TX_LS_EOP_WAIT_GNT1;
251
        next_USBWireReq <= 1'b1;
252
      end
253 7 sfielding
      else if (SIEPortCtrl == `TX_DIRECT_CONTROL)
254 5 sfielding
      begin
255 7 sfielding
        NextState_SIETx <= `DIR_CTL_WAIT_GNT;
256 5 sfielding
        next_USBWireReq <= 1'b1;
257
      end
258 9 sfielding
      else if (SIEPortCtrl == `TX_IDLE)
259
      begin
260
        NextState_SIETx <= `IDLE;
261
      end
262 5 sfielding
      else if (SIEPortCtrl == `TX_RESUME_START)
263
      begin
264
        NextState_SIETx <= `RES_ST_WAIT_GNT;
265
        next_USBWireReq <= 1'b1;
266 14 sfielding
        next_resumeCnt <= 16'h0000;
267
        next_USBWireFullSpeedRate <= 1'b0;
268
        //resume always uses low speed timing
269 5 sfielding
      end
270
    end
271
    `STX_WAIT_BYTE:
272
    begin
273
      next_SIEPortTxRdy <= 1'b1;
274
      if (SIEPortWEn == 1'b1)
275
      begin
276
        NextState_SIETx <= `STX_CHK_ST;
277
        next_SIEPortData <= SIEPortDataIn;
278
        next_SIEPortCtrl <= SIEPortCtrlIn;
279
        next_SIEPortTxRdy <= 1'b0;
280 14 sfielding
        next_TxByteOutFullSpeedRate <= fullSpeedRateIn;
281
        next_USBWireFullSpeedRate <= fullSpeedRateIn;
282 5 sfielding
      end
283
    end
284
    `DIR_CTL_CHK_FIN:
285
    begin
286
      next_USBWireWEn <= 1'b0;
287
      next_i <= i + 1'b1;
288 14 sfielding
      if (i == 3'h7)
289 5 sfielding
      begin
290
        NextState_SIETx <= `STX_WAIT_BYTE;
291
        next_USBWireReq <= 1'b0;
292
      end
293
      else
294
      begin
295 14 sfielding
        NextState_SIETx <= `DIR_CTL_DELAY;
296 5 sfielding
      end
297
    end
298
    `DIR_CTL_WAIT_GNT:
299
    begin
300 14 sfielding
      next_i <= 3'h0;
301 5 sfielding
      if (USBWireGnt == 1'b1)
302
      begin
303
        NextState_SIETx <= `DIR_CTL_WAIT_RDY;
304
      end
305
    end
306
    `DIR_CTL_WAIT_RDY:
307
    begin
308
      if (USBWireRdy == 1'b1)
309
      begin
310
        NextState_SIETx <= `DIR_CTL_CHK_FIN;
311
        next_USBWireData <= SIEPortData[1:0];
312
        next_USBWireCtrl <= `DRIVE;
313
        next_USBWireWEn <= 1'b1;
314
      end
315
    end
316 14 sfielding
    `DIR_CTL_DELAY:
317
    begin
318
      NextState_SIETx <= `DIR_CTL_WAIT_RDY;
319
    end
320 9 sfielding
    `PKT_ST_CHK_PID:
321 5 sfielding
    begin
322 9 sfielding
      next_processTxByteWEn <= 1'b0;
323
      if (SIEPortData[1:0] == `TOKEN)
324 5 sfielding
      begin
325 9 sfielding
        NextState_SIETx <= `PKT_ST_TKN_PID_WAIT_RDY;
326 5 sfielding
      end
327 9 sfielding
      else if (SIEPortData[1:0] == `HANDSHAKE)
328 5 sfielding
      begin
329 7 sfielding
        NextState_SIETx <= `PKT_ST_HS_WAIT_RDY;
330
      end
331 9 sfielding
      else if (SIEPortData[1:0] == `DATA)
332 7 sfielding
      begin
333 9 sfielding
        NextState_SIETx <= `PKT_ST_DATA_PID_WAIT_RDY;
334 5 sfielding
      end
335 7 sfielding
      else if (SIEPortData[1:0] == `SPECIAL)
336 5 sfielding
      begin
337 7 sfielding
        NextState_SIETx <= `PKT_ST_SPCL_WAIT_RDY;
338 5 sfielding
      end
339
    end
340
    `PKT_ST_WAIT_RDY_PKT:
341
    begin
342
      if (processTxByteRdy == 1'b1)
343
      begin
344
        NextState_SIETx <= `PKT_ST_CHK_PID;
345
        next_processTxByteWEn <= 1'b1;
346
        next_TxByteOut <= `SYNC_BYTE;
347
        next_TxByteOutCtrl <= `DATA_START;
348
      end
349
    end
350
    `PKT_ST_DATA_CRC_PKT_SENT1:
351
    begin
352
      next_processTxByteWEn <= 1'b0;
353
      NextState_SIETx <= `PKT_ST_DATA_CRC_WAIT_RDY2;
354
    end
355
    `PKT_ST_DATA_CRC_PKT_SENT2:
356
    begin
357
      next_processTxByteWEn <= 1'b0;
358
      NextState_SIETx <= `STX_WAIT_BYTE;
359
    end
360
    `PKT_ST_DATA_CRC_WAIT_RDY1:
361
    begin
362
      if (processTxByteRdy == 1'b1)
363
      begin
364
        NextState_SIETx <= `PKT_ST_DATA_CRC_PKT_SENT1;
365
        next_processTxByteWEn <= 1'b1;
366
        next_TxByteOut <= ~CRC16Result[7:0];
367
        next_TxByteOutCtrl <= `DATA_STREAM;
368
      end
369
    end
370
    `PKT_ST_DATA_CRC_WAIT_RDY2:
371
    begin
372
      if (processTxByteRdy == 1'b1)
373
      begin
374
        NextState_SIETx <= `PKT_ST_DATA_CRC_PKT_SENT2;
375
        next_processTxByteWEn <= 1'b1;
376
        next_TxByteOut <= ~CRC16Result[15:8];
377
        next_TxByteOutCtrl <= `DATA_STOP;
378
      end
379
    end
380
    `PKT_ST_DATA_DATA_CHK_STOP:
381
    begin
382
      if (SIEPortCtrl == `TX_PACKET_STOP)
383
      begin
384
        NextState_SIETx <= `PKT_ST_DATA_CRC_WAIT_RDY1;
385
      end
386
      else
387
      begin
388
        NextState_SIETx <= `PKT_ST_DATA_DATA_WAIT_CRC_RDY;
389
      end
390
    end
391
    `PKT_ST_DATA_DATA_PKT_SENT:
392
    begin
393
      next_processTxByteWEn <= 1'b0;
394
      NextState_SIETx <= `PKT_ST_DATA_DATA_WAIT_BYTE;
395
    end
396
    `PKT_ST_DATA_DATA_UPD_CRC:
397
    begin
398
      next_CRCData <= SIEPortData;
399
      next_CRC16En <= 1'b1;
400
      NextState_SIETx <= `PKT_ST_DATA_DATA_WAIT_RDY;
401
    end
402
    `PKT_ST_DATA_DATA_WAIT_BYTE:
403
    begin
404
      next_SIEPortTxRdy <= 1'b1;
405
      if (SIEPortWEn == 1'b1)
406
      begin
407
        NextState_SIETx <= `PKT_ST_DATA_DATA_CHK_STOP;
408
        next_SIEPortData <= SIEPortDataIn;
409
        next_SIEPortCtrl <= SIEPortCtrlIn;
410
        next_SIEPortTxRdy <= 1'b0;
411
      end
412
    end
413
    `PKT_ST_DATA_DATA_WAIT_RDY:
414
    begin
415
      next_CRC16En <= 1'b0;
416
      if (processTxByteRdy == 1'b1)
417
      begin
418
        NextState_SIETx <= `PKT_ST_DATA_DATA_PKT_SENT;
419
        next_processTxByteWEn <= 1'b1;
420
        next_TxByteOut <= SIEPortData;
421
        next_TxByteOutCtrl <= `DATA_STREAM;
422
      end
423
    end
424
    `PKT_ST_DATA_DATA_WAIT_CRC_RDY:
425
    begin
426
      if (CRC16UpdateRdy == 1'b1)
427
      begin
428
        NextState_SIETx <= `PKT_ST_DATA_DATA_UPD_CRC;
429
      end
430
    end
431
    `PKT_ST_DATA_PID_PKT_SENT:
432
    begin
433
      next_processTxByteWEn <= 1'b0;
434
      next_rstCRC <= 1'b0;
435
      NextState_SIETx <= `PKT_ST_DATA_DATA_WAIT_BYTE;
436
    end
437
    `PKT_ST_DATA_PID_WAIT_RDY:
438
    begin
439
      if (processTxByteRdy == 1'b1)
440
      begin
441
        NextState_SIETx <= `PKT_ST_DATA_PID_PKT_SENT;
442
        next_processTxByteWEn <= 1'b1;
443
        next_TxByteOut <= SIEPortData;
444
        next_TxByteOutCtrl <= `DATA_STREAM;
445
        next_rstCRC <= 1'b1;
446
      end
447
    end
448
    `PKT_ST_HS_PKT_SENT:
449
    begin
450
      next_processTxByteWEn <= 1'b0;
451
      NextState_SIETx <= `STX_WAIT_BYTE;
452
    end
453
    `PKT_ST_HS_WAIT_RDY:
454
    begin
455
      if (processTxByteRdy == 1'b1)
456
      begin
457
        NextState_SIETx <= `PKT_ST_HS_PKT_SENT;
458
        next_processTxByteWEn <= 1'b1;
459
        next_TxByteOut <= SIEPortData;
460
        next_TxByteOutCtrl <= `DATA_STOP;
461
      end
462
    end
463
    `PKT_ST_SPCL_PKT_SENT:
464
    begin
465
      next_processTxByteWEn <= 1'b0;
466
      NextState_SIETx <= `STX_WAIT_BYTE;
467
    end
468
    `PKT_ST_SPCL_WAIT_RDY:
469
    begin
470
      if (processTxByteRdy == 1'b1)
471
      begin
472
        NextState_SIETx <= `PKT_ST_SPCL_PKT_SENT;
473
        next_processTxByteWEn <= 1'b1;
474
        next_TxByteOut <= SIEPortData;
475
        next_TxByteOutCtrl <= `DATA_STOP;
476
      end
477
    end
478
    `PKT_ST_TKN_BYTE1_PKT_SENT1:
479
    begin
480
      next_processTxByteWEn <= 1'b0;
481
      NextState_SIETx <= `PKT_ST_TKN_CRC_WAIT_BYTE;
482
    end
483
    `PKT_ST_TKN_BYTE1_UPD_CRC:
484
    begin
485
      next_CRCData <= SIEPortData;
486
      next_CRC5_8Bit <= 1'b1;
487
      next_CRC5En <= 1'b1;
488
      NextState_SIETx <= `PKT_ST_TKN_BYTE1_WAIT_RDY;
489
    end
490
    `PKT_ST_TKN_BYTE1_WAIT_BYTE:
491
    begin
492
      next_SIEPortTxRdy <= 1'b1;
493
      if (SIEPortWEn == 1'b1)
494
      begin
495
        NextState_SIETx <= `PKT_ST_TKN_BYTE1_WAIT_CRC_RDY;
496
        next_SIEPortData <= SIEPortDataIn;
497
        next_SIEPortCtrl <= SIEPortCtrlIn;
498
        next_SIEPortTxRdy <= 1'b0;
499
      end
500
    end
501
    `PKT_ST_TKN_BYTE1_WAIT_RDY:
502
    begin
503
      next_CRC5En <= 1'b0;
504
      if (processTxByteRdy == 1'b1)
505
      begin
506
        NextState_SIETx <= `PKT_ST_TKN_BYTE1_PKT_SENT1;
507
        next_processTxByteWEn <= 1'b1;
508
        next_TxByteOut <= SIEPortData;
509
        next_TxByteOutCtrl <= `DATA_STREAM;
510
      end
511
    end
512
    `PKT_ST_TKN_BYTE1_WAIT_CRC_RDY:
513
    begin
514
      if (CRC5UpdateRdy == 1'b1)
515
      begin
516
        NextState_SIETx <= `PKT_ST_TKN_BYTE1_UPD_CRC;
517
      end
518
    end
519
    `PKT_ST_TKN_CRC_PKT_SENT:
520
    begin
521
      next_processTxByteWEn <= 1'b0;
522
      NextState_SIETx <= `STX_WAIT_BYTE;
523
    end
524
    `PKT_ST_TKN_CRC_UPD_CRC:
525
    begin
526
      next_CRCData <= SIEPortData;
527
      next_CRC5_8Bit <= 1'b0;
528
      next_CRC5En <= 1'b1;
529
      NextState_SIETx <= `PKT_ST_TKN_CRC_WAIT_RDY;
530
    end
531
    `PKT_ST_TKN_CRC_WAIT_BYTE:
532
    begin
533
      next_SIEPortTxRdy <= 1'b1;
534
      if (SIEPortWEn == 1'b1)
535
      begin
536
        NextState_SIETx <= `PKT_ST_TKN_CRC_WAIT_CRC_RDY;
537
        next_SIEPortData <= SIEPortDataIn;
538
        next_SIEPortCtrl <= SIEPortCtrlIn;
539
        next_SIEPortTxRdy <= 1'b0;
540
      end
541
    end
542
    `PKT_ST_TKN_CRC_WAIT_RDY:
543
    begin
544
      next_CRC5En <= 1'b0;
545
      if (processTxByteRdy == 1'b1)
546
      begin
547
        NextState_SIETx <= `PKT_ST_TKN_CRC_PKT_SENT;
548
        next_processTxByteWEn <= 1'b1;
549
        next_TxByteOut <= {~CRC5Result, SIEPortData[2:0] };
550
        next_TxByteOutCtrl <= `DATA_STOP;
551
      end
552
    end
553
    `PKT_ST_TKN_CRC_WAIT_CRC_RDY:
554
    begin
555
      if (CRC5UpdateRdy == 1'b1)
556
      begin
557
        NextState_SIETx <= `PKT_ST_TKN_CRC_UPD_CRC;
558
      end
559
    end
560
    `PKT_ST_TKN_PID_PKT_SENT:
561
    begin
562
      next_processTxByteWEn <= 1'b0;
563
      next_rstCRC <= 1'b0;
564
      NextState_SIETx <= `PKT_ST_TKN_BYTE1_WAIT_BYTE;
565
    end
566
    `PKT_ST_TKN_PID_WAIT_RDY:
567
    begin
568
      if (processTxByteRdy == 1'b1)
569
      begin
570
        NextState_SIETx <= `PKT_ST_TKN_PID_PKT_SENT;
571
        next_processTxByteWEn <= 1'b1;
572
        next_TxByteOut <= SIEPortData;
573
        next_TxByteOutCtrl <= `DATA_STREAM;
574
        next_rstCRC <= 1'b1;
575
      end
576
    end
577
    `RES_ST_CHK_FIN:
578
    begin
579
      next_USBWireWEn <= 1'b0;
580 14 sfielding
      if (resumeCnt == `HOST_TX_RESUME_TIME)
581 5 sfielding
      begin
582 14 sfielding
        NextState_SIETx <= `RES_ST_W_RDY1;
583 5 sfielding
      end
584
      else
585
      begin
586 14 sfielding
        NextState_SIETx <= `RES_ST_DELAY;
587 5 sfielding
      end
588
    end
589 14 sfielding
    `RES_ST_SND_J_1:
590 5 sfielding
    begin
591 14 sfielding
      next_USBWireWEn <= 1'b0;
592
      NextState_SIETx <= `RES_ST_W_RDY4;
593
    end
594
    `RES_ST_SND_J_2:
595
    begin
596
      next_USBWireWEn <= 1'b0;
597
      next_USBWireReq <= 1'b0;
598
      NextState_SIETx <= `STX_WAIT_BYTE;
599
      next_USBWireFullSpeedRate <= fullSpeedRateIn;
600
    end
601
    `RES_ST_SND_SE0_1:
602
    begin
603
      next_USBWireWEn <= 1'b0;
604
      NextState_SIETx <= `RES_ST_W_RDY2;
605
    end
606
    `RES_ST_SND_SE0_2:
607
    begin
608
      next_USBWireWEn <= 1'b0;
609
      NextState_SIETx <= `RES_ST_W_RDY3;
610
    end
611
    `RES_ST_W_RDY1:
612
    begin
613 5 sfielding
      if (USBWireRdy == 1'b1)
614
      begin
615 14 sfielding
        NextState_SIETx <= `RES_ST_SND_SE0_1;
616 5 sfielding
        next_USBWireData <= `SE0;
617
        next_USBWireCtrl <= `DRIVE;
618
        next_USBWireWEn <= 1'b1;
619
      end
620
    end
621 14 sfielding
    `RES_ST_WAIT_GNT:
622 5 sfielding
    begin
623 14 sfielding
      if (USBWireGnt == 1'b1)
624
      begin
625
        NextState_SIETx <= `RES_ST_WAIT_RDY;
626
      end
627
    end
628
    `RES_ST_WAIT_RDY:
629
    begin
630 5 sfielding
      if (USBWireRdy == 1'b1)
631
      begin
632 14 sfielding
        NextState_SIETx <= `RES_ST_CHK_FIN;
633
        next_USBWireData <= KBit;
634
        next_USBWireCtrl <= `DRIVE;
635
        next_USBWireWEn <= 1'b1;
636
        next_resumeCnt <= resumeCnt  + 1'b1;
637
      end
638
    end
639
    `RES_ST_DELAY:
640
    begin
641
      NextState_SIETx <= `RES_ST_WAIT_RDY;
642
    end
643
    `RES_ST_W_RDY2:
644
    begin
645
      if (USBWireRdy == 1'b1)
646
      begin
647
        NextState_SIETx <= `RES_ST_SND_SE0_2;
648 5 sfielding
        next_USBWireData <= `SE0;
649
        next_USBWireCtrl <= `DRIVE;
650
        next_USBWireWEn <= 1'b1;
651
      end
652
    end
653 14 sfielding
    `RES_ST_W_RDY3:
654 5 sfielding
    begin
655
      if (USBWireRdy == 1'b1)
656
      begin
657 14 sfielding
        NextState_SIETx <= `RES_ST_SND_J_1;
658 5 sfielding
        next_USBWireData <= JBit;
659
        next_USBWireCtrl <= `DRIVE;
660
        next_USBWireWEn <= 1'b1;
661
      end
662
    end
663 14 sfielding
    `RES_ST_W_RDY4:
664 5 sfielding
    begin
665
      if (USBWireRdy == 1'b1)
666
      begin
667 14 sfielding
        NextState_SIETx <= `RES_ST_SND_J_2;
668 5 sfielding
        next_USBWireData <= JBit;
669
        next_USBWireCtrl <= `TRI_STATE;
670
        next_USBWireWEn <= 1'b1;
671
      end
672
    end
673 14 sfielding
    `TX_LS_EOP_WAIT_GNT1:
674 5 sfielding
    begin
675 14 sfielding
      if (USBWireGnt == 1'b1)
676
      begin
677
        NextState_SIETx <= `TX_LS_EOP_W_RDY1;
678
      end
679
    end
680
    `TX_LS_EOP_SND_SE0_2:
681
    begin
682 5 sfielding
      next_USBWireWEn <= 1'b0;
683 14 sfielding
      NextState_SIETx <= `TX_LS_EOP_W_RDY3;
684
    end
685
    `TX_LS_EOP_SND_SE0_1:
686
    begin
687
      next_USBWireWEn <= 1'b0;
688
      NextState_SIETx <= `TX_LS_EOP_W_RDY2;
689
    end
690
    `TX_LS_EOP_W_RDY1:
691
    begin
692
      if (USBWireRdy == 1'b1)
693
      begin
694
        NextState_SIETx <= `TX_LS_EOP_SND_SE0_1;
695
        next_USBWireData <= `SE0;
696
        next_USBWireCtrl <= `DRIVE;
697
        next_USBWireWEn <= 1'b1;
698
      end
699
    end
700
    `TX_LS_EOP_SND_J:
701
    begin
702
      next_USBWireWEn <= 1'b0;
703 5 sfielding
      next_USBWireReq <= 1'b0;
704
      NextState_SIETx <= `STX_WAIT_BYTE;
705
    end
706 14 sfielding
    `TX_LS_EOP_W_RDY2:
707 5 sfielding
    begin
708 14 sfielding
      if (USBWireRdy == 1'b1)
709 5 sfielding
      begin
710 14 sfielding
        NextState_SIETx <= `TX_LS_EOP_SND_SE0_2;
711
        next_USBWireData <= `SE0;
712
        next_USBWireCtrl <= `DRIVE;
713
        next_USBWireWEn <= 1'b1;
714 5 sfielding
      end
715
    end
716 14 sfielding
    `TX_LS_EOP_W_RDY3:
717 5 sfielding
    begin
718
      if (USBWireRdy == 1'b1)
719
      begin
720 14 sfielding
        NextState_SIETx <= `TX_LS_EOP_SND_J;
721
        next_USBWireData <= JBit;
722 5 sfielding
        next_USBWireCtrl <= `DRIVE;
723
        next_USBWireWEn <= 1'b1;
724
      end
725
    end
726
  endcase
727
end
728
 
729
// Current State Logic (sequential)
730
always @ (posedge clk)
731
begin
732
  if (rst)
733
    CurrState_SIETx <= `START_SIETX;
734
  else
735
    CurrState_SIETx <= NextState_SIETx;
736
end
737
 
738
// Registered outputs logic
739
always @ (posedge clk)
740
begin
741
  if (rst)
742
  begin
743
    USBWireWEn <= 1'b0;
744
    USBWireReq <= 1'b0;
745
    processTxByteWEn <= 1'b0;
746
    rstCRC <= 1'b0;
747 14 sfielding
    USBWireFullSpeedRate <= 1'b0;
748
    TxByteOut <= 8'h00;
749
    TxByteOutCtrl <= 8'h00;
750 5 sfielding
    USBWireData <= 2'b00;
751
    USBWireCtrl <= `TRI_STATE;
752
    CRCData <= 8'h00;
753
    CRC5En <= 1'b0;
754
    CRC5_8Bit <= 1'b0;
755
    CRC16En <= 1'b0;
756
    SIEPortTxRdy <= 1'b0;
757 14 sfielding
    TxByteOutFullSpeedRate <= 1'b0;
758
    i <= 3'h0;
759 5 sfielding
    SIEPortData <= 8'h00;
760
    SIEPortCtrl <= 8'h00;
761 14 sfielding
    resumeCnt <= 16'h0000;
762 5 sfielding
  end
763
  else
764
  begin
765
    USBWireWEn <= next_USBWireWEn;
766
    USBWireReq <= next_USBWireReq;
767
    processTxByteWEn <= next_processTxByteWEn;
768
    rstCRC <= next_rstCRC;
769 14 sfielding
    USBWireFullSpeedRate <= next_USBWireFullSpeedRate;
770
    TxByteOut <= next_TxByteOut;
771
    TxByteOutCtrl <= next_TxByteOutCtrl;
772 5 sfielding
    USBWireData <= next_USBWireData;
773
    USBWireCtrl <= next_USBWireCtrl;
774
    CRCData <= next_CRCData;
775
    CRC5En <= next_CRC5En;
776
    CRC5_8Bit <= next_CRC5_8Bit;
777
    CRC16En <= next_CRC16En;
778
    SIEPortTxRdy <= next_SIEPortTxRdy;
779 14 sfielding
    TxByteOutFullSpeedRate <= next_TxByteOutFullSpeedRate;
780 5 sfielding
    i <= next_i;
781
    SIEPortData <= next_SIEPortData;
782
    SIEPortCtrl <= next_SIEPortCtrl;
783 14 sfielding
    resumeCnt <= next_resumeCnt;
784 5 sfielding
  end
785
end
786
 
787 2 sfielding
endmodule

powered by: WebSVN 2.1.0

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