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

Subversion Repositories usbhostslave

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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