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

Subversion Repositories usbhostslave

[/] [usbhostslave/] [trunk/] [usbDevice/] [RTL/] [EP0.v] - Blame information for rev 43

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

Line No. Rev Author Line
1 37 sfielding
 
2
//////////////////////////////////////////////////////////////////////
3
////                                                              ////
4
//// EP0.v                                                 ////
5
////                                                              ////
6
//// This file is part of the usbHostSlave opencores effort.
7
//// <http://www.opencores.org/cores//>                           ////
8
////                                                              ////
9
//// Module Description:                                          ////
10
//// Implements EP0 control endpoint
11
//// Responds to 8-byte SETUP packets
12
//// of type GET_STATUS, GET_DESCRIPTOR and
13
//// SET_ADDRESS
14
////                                                              ////
15
//// To Do:                                                       ////
16
//// 
17
////                                                              ////
18
//// Author(s):                                                   ////
19
//// - Steve Fielding, sfielding@base2designs.com                 ////
20
////                                                              ////
21
//////////////////////////////////////////////////////////////////////
22
////                                                              ////
23
//// Copyright (C) 2008 Steve Fielding and OPENCORES.ORG          ////
24
////                                                              ////
25
//// This source file may be used and distributed without         ////
26
//// restriction provided that this copyright statement is not    ////
27
//// removed from the file and that any derivative work contains  ////
28
//// the original copyright notice and the associated disclaimer. ////
29
////                                                              ////
30
//// This source file is free software; you can redistribute it   ////
31
//// and/or modify it under the terms of the GNU Lesser General   ////
32
//// Public License as published by the Free Software Foundation; ////
33
//// either version 2.1 of the License, or (at your option) any   ////
34
//// later version.                                               ////
35
////                                                              ////
36
//// This source is distributed in the hope that it will be       ////
37
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
38
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
39
//// PURPOSE. See the GNU Lesser General Public License for more  ////
40
//// details.                                                     ////
41
////                                                              ////
42
//// You should have received a copy of the GNU Lesser General    ////
43
//// Public License along with this source; if not, download it   ////
44
//// from <http://www.opencores.org/lgpl.shtml>                   ////
45
////                                                              ////
46
//////////////////////////////////////////////////////////////////////
47
//
48
`include "timescale.v"
49
`include "usbHostSlaveReg_define.v"
50
`include "usbDevice_define.v"
51
 
52
 
53
module EP0 (clk, initComplete, memAddr, memData, memRdEn, rst, wb_ack, wb_addr, wb_data_i, wb_data_o, wb_stb, wb_we, wbBusGnt, wbBusReq);
54
input   clk;
55
input   [7:0]memData;
56
input   rst;
57
input   wb_ack;
58
input   [7:0]wb_data_i;
59
input   wbBusGnt;
60
output  initComplete;
61
output  [7:0]memAddr;
62
output  memRdEn;
63
output  [7:0]wb_addr;
64
output  [7:0]wb_data_o;
65
output  wb_stb;
66
output  wb_we;
67
output  wbBusReq;
68
 
69
wire    clk;
70
reg     initComplete, next_initComplete;
71
reg     [7:0]memAddr, next_memAddr;
72
wire    [7:0]memData;
73
reg     memRdEn, next_memRdEn;
74
wire    rst;
75
wire    wb_ack;
76
reg     [7:0]wb_addr, next_wb_addr;
77
wire    [7:0]wb_data_i;
78
reg     [7:0]wb_data_o, next_wb_data_o;
79
reg     wb_stb, next_wb_stb;
80
reg     wb_we, next_wb_we;
81
wire    wbBusGnt;
82
reg     wbBusReq, next_wbBusReq;
83
 
84
// diagram signals declarations
85
reg bm_req_dir, next_bm_req_dir;
86
reg  [4:0]bm_req_recp, next_bm_req_recp;
87
reg  [1:0]bm_req_type, next_bm_req_type;
88
reg  [7:0]bRequest, next_bRequest;
89
reg  [7:0]cnt, next_cnt;
90
reg dataSeq, next_dataSeq;
91
reg  [7:0]epStatus, next_epStatus;
92
reg  [7:0]epTransType, next_epTransType;
93
reg localRst, next_localRst;
94
reg  [15:0]rxDataSize, next_rxDataSize;
95
reg transDone, next_transDone;
96
reg  [7:0]txDataIndex, next_txDataIndex;
97
reg  [7:0]txDataSize, next_txDataSize;
98
reg  [7:0]txPacketRemSize, next_txPacketRemSize;
99
reg updateUSBAddress, next_updateUSBAddress;
100
reg  [7:0]USBAddress, next_USBAddress;
101
reg  [15:0]wIndex, next_wIndex;
102
reg  [15:0]wLength, next_wLength;
103
reg  [15:0]wValue, next_wValue;
104
 
105
// BINARY ENCODED state machine: EP0St
106
// State codes definitions:
107
`define INIT_RST 6'b000000
108
`define INIT_WT_GNT 6'b000001
109
`define INIT_WT_RST 6'b000010
110
`define INIT_WT_VBUS 6'b000011
111
`define INIT_FIN 6'b000100
112
`define DO_TRANS_WT_GNT 6'b000101
113
`define DO_TRANS_TX_EMPTY 6'b000110
114
`define DO_TRANS_WR_TX_FIFO 6'b000111
115
`define DO_TRANS_RD_MEM 6'b001000
116
`define DO_TRANS_CHK_TX_DONE 6'b001001
117
`define DO_TRANS_TRANS_GO 6'b001010
118
`define DO_TRANS_WT_TRANS_DONE_WT_GNT 6'b001011
119
`define DO_TRANS_WT_TRANS_DONE_GET_RDY_STS 6'b001100
120
`define DO_TRANS_WT_TRANS_DONE_WT_UNGNT 6'b001101
121
`define DO_TRANS_WT_TRANS_DONE_CHK_DONE 6'b001110
122
`define CHK_TRANS_RD_STAT 6'b001111
123
`define CHK_TRANS_WT_GNT 6'b010000
124
`define CHK_TRANS_RD_RX_SIZE1 6'b010001
125
`define CHK_TRANS_RD_RX_SIZE2 6'b010010
126
`define CHK_TRANS_RD_TRANS_TYPE 6'b010011
127
`define CHK_TRANS_WT_UNGNT 6'b010100
128
`define SETUP_CHK_ERR 6'b010101
129
`define SETUP_GET_DATA_DAT1 6'b010110
130
`define SETUP_GET_DATA_WT_GNT 6'b010111
131
`define SETUP_GET_DATA_DAT2 6'b011000
132
`define SETUP_GET_DATA_DAT3 6'b011001
133
`define SETUP_GET_DATA_DAT4 6'b011010
134
`define SETUP_GET_DATA_DAT6 6'b011011
135
`define SETUP_GET_DATA_DAT5 6'b011100
136
`define SETUP_GET_DATA_DAT8 6'b011101
137
`define SETUP_GET_DATA_DAT7 6'b011110
138
`define SETUP_GET_DATA_WT_UNGNT 6'b011111
139
`define SETUP_GET_STAT 6'b100000
140
`define SETUP_SET_ADDR 6'b100001
141
`define SETUP_GET_DESC_S1 6'b100010
142
`define SETUP_CHK_MAX_LEN 6'b100011
143
`define OUT_CHK_SEQ 6'b100100
144
`define IN_CHK_ACK 6'b100101
145
`define IN_SET_PTR 6'b100110
146
`define IN_SET_ADDR 6'b100111
147
`define IN_WT_GNT 6'b101000
148
`define IN_WT_UNGNT 6'b101001
149
`define DO_TRANS_RX_EMPTY 6'b101010
150
`define DO_TRANS_WT_TRANS_DONE_DEL 6'b101011
151
`define START 6'b101100
152
`define INIT_CONN 6'b101101
153
`define INIT_WT_CONN 6'b101110
154
`define DO_TRANS_DEL 6'b101111
155
`define SETUP_PTR_SET 6'b110000
156
 
157
reg [5:0]CurrState_EP0St, NextState_EP0St;
158
 
159
// Diagram actions (continuous assignments allowed only: assign ...)
160
// diagram ACTION
161
 
162
 
163
// Machine: EP0St
164
 
165
// NextState logic (combinatorial)
166
always @ (wb_ack or wbBusGnt or cnt or wb_data_i or memData or txDataIndex or txDataSize or transDone or epStatus or epTransType or rxDataSize or bRequest or wValue or wLength or dataSeq or updateUSBAddress or txPacketRemSize or USBAddress or wb_addr or wb_data_o or wb_stb or wb_we or wbBusReq or initComplete or memAddr or memRdEn or bm_req_dir or bm_req_type or bm_req_recp or wIndex or CurrState_EP0St)
167
begin
168
  NextState_EP0St <= CurrState_EP0St;
169
  // Set default values for outputs and signals
170
  next_wb_addr <= wb_addr;
171
  next_wb_data_o <= wb_data_o;
172
  next_wb_stb <= wb_stb;
173
  next_wb_we <= wb_we;
174
  next_cnt <= cnt;
175
  next_wbBusReq <= wbBusReq;
176
  next_initComplete <= initComplete;
177
  next_memAddr <= memAddr;
178
  next_memRdEn <= memRdEn;
179
  next_txDataSize <= txDataSize;
180
  next_txDataIndex <= txDataIndex;
181
  next_transDone <= transDone;
182
  next_epStatus <= epStatus;
183
  next_rxDataSize <= rxDataSize;
184
  next_epTransType <= epTransType;
185
  next_bm_req_dir <= bm_req_dir;
186
  next_bm_req_type <= bm_req_type;
187
  next_bm_req_recp <= bm_req_recp;
188
  next_bRequest <= bRequest;
189
  next_wValue <= wValue;
190
  next_wIndex <= wIndex;
191
  next_wLength <= wLength;
192
  next_txPacketRemSize <= txPacketRemSize;
193
  next_USBAddress <= USBAddress;
194
  next_updateUSBAddress <= updateUSBAddress;
195
  next_dataSeq <= dataSeq;
196
  case (CurrState_EP0St)  // synopsys parallel_case full_case
197
    `START:
198
    begin
199
      next_initComplete <= 1'b0;
200
      next_wbBusReq <= 1'b0;
201
      next_wb_addr <= 8'h00;
202
      next_wb_data_o <= 8'h00;
203
      next_wb_stb <= 1'b0;
204
      next_wb_we <= 1'b0;
205
      next_txPacketRemSize <= 8'h00;
206
      next_txDataSize <= 8'h00;
207
      next_txDataIndex <= 8'h00;
208
      next_epTransType <= 8'h00;
209
      next_epStatus <= 8'h00;
210
      next_rxDataSize <= 16'h0000;
211
      next_cnt <= 8'h00;
212
      next_memRdEn <= 1'b0;
213
      next_memAddr <= 8'h00;
214
      next_updateUSBAddress <= 1'b0;
215
      next_transDone <= 1'b0;
216
      next_bm_req_type <= 2'b00;
217
      next_bm_req_dir <= 1'b0;
218
      next_bm_req_recp <= 5'b00000;
219
      next_bRequest <= 8'h00;
220
      next_wLength <= 16'h0000;
221
      next_wIndex <= 16'h0000;
222
      next_wValue <= 16'h0000;
223
      next_dataSeq <= 1'b0;
224
      next_USBAddress <= 8'h00;
225
      NextState_EP0St <= `INIT_WT_GNT;
226
    end
227
    `CHK_TRANS_RD_STAT:
228
    begin
229
      next_wb_addr <= `RA_EP0_STATUS_REG;
230
      next_wb_stb <= 1'b1;
231
      next_wb_we <= 1'b0;
232
      if (wb_ack == 1'b1)
233
      begin
234
        NextState_EP0St <= `CHK_TRANS_RD_RX_SIZE1;
235
        next_wb_stb <= 1'b0;
236
        next_epStatus <= wb_data_i;
237
      end
238
    end
239
    `CHK_TRANS_WT_GNT:
240
    begin
241
      if (wbBusGnt == 1'b1)
242
      begin
243
        NextState_EP0St <= `CHK_TRANS_RD_STAT;
244
      end
245
    end
246
    `CHK_TRANS_RD_RX_SIZE1:
247
    begin
248
      next_wb_addr <= `RA_EP0_RX_FIFO_DATA_COUNT_MSB;
249
      next_wb_stb <= 1'b1;
250
      next_wb_we <= 1'b0;
251
      if (wb_ack == 1'b1)
252
      begin
253
        NextState_EP0St <= `CHK_TRANS_RD_RX_SIZE2;
254
        next_wb_stb <= 1'b0;
255
        next_rxDataSize[15:8] <= wb_data_i;
256
      end
257
    end
258
    `CHK_TRANS_RD_RX_SIZE2:
259
    begin
260
      next_wb_addr <= `RA_EP0_RX_FIFO_DATA_COUNT_LSB;
261
      next_wb_stb <= 1'b1;
262
      next_wb_we <= 1'b0;
263
      if (wb_ack == 1'b1)
264
      begin
265
        NextState_EP0St <= `CHK_TRANS_RD_TRANS_TYPE;
266
        next_wb_stb <= 1'b0;
267
        next_rxDataSize[7:0] <= wb_data_i;
268
      end
269
    end
270
    `CHK_TRANS_RD_TRANS_TYPE:
271
    begin
272
      next_wb_addr <= `RA_EP0_TRANSTYPE_STATUS_REG;
273
      next_wb_stb <= 1'b1;
274
      next_wb_we <= 1'b0;
275
      if (wb_ack == 1'b1)
276
      begin
277
        NextState_EP0St <= `CHK_TRANS_WT_UNGNT;
278
        next_wb_stb <= 1'b0;
279
        next_epTransType <= wb_data_i;
280
      end
281
    end
282
    `CHK_TRANS_WT_UNGNT:
283
    begin
284
      next_wbBusReq <= 1'b0;
285
      if ((wbBusGnt == 1'b0) && ((epStatus & 8'h0f) != 8'h00))
286
      begin
287
        NextState_EP0St <= `DO_TRANS_WT_GNT;
288
      end
289
      else if ((wbBusGnt == 1'b0) && (epTransType == `SC_SETUP_TRANS))
290
      begin
291
        NextState_EP0St <= `SETUP_CHK_ERR;
292
      end
293
      else if ((wbBusGnt == 1'b0) && (epTransType == `SC_IN_TRANS))
294
      begin
295
        NextState_EP0St <= `IN_CHK_ACK;
296
      end
297
      else if ((wbBusGnt == 1'b0) && (epTransType == `SC_OUTDATA_TRANS))
298
      begin
299
        NextState_EP0St <= `OUT_CHK_SEQ;
300
      end
301
      else if (wbBusGnt == 1'b0)
302
      begin
303
        NextState_EP0St <= `DO_TRANS_WT_GNT;
304
      end
305
    end
306
    `DO_TRANS_WT_GNT:
307
    begin
308
      next_wbBusReq <= 1'b1;
309
      if (wbBusGnt == 1'b1)
310
      begin
311
        NextState_EP0St <= `DO_TRANS_TX_EMPTY;
312
      end
313
    end
314
    `DO_TRANS_TX_EMPTY:
315
    begin
316
      next_wb_addr <= `RA_EP0_TX_FIFO_CONTROL_REG;
317
      next_wb_data_o <= 8'h01;
318
      //force tx fifo empty
319
      next_wb_stb <= 1'b1;
320
      next_wb_we <= 1'b1;
321
      if (wb_ack == 1'b1)
322
      begin
323
        NextState_EP0St <= `DO_TRANS_RX_EMPTY;
324
        next_wb_stb <= 1'b0;
325
      end
326
    end
327
    `DO_TRANS_WR_TX_FIFO:
328
    begin
329
      next_wb_data_o <= memData;
330
      next_wb_addr <= `RA_EP0_TX_FIFO_DATA_REG;
331
      next_wb_stb <= 1'b1;
332
      next_wb_we <= 1'b1;
333
      if (wb_ack == 1'b1)
334
      begin
335
        NextState_EP0St <= `DO_TRANS_CHK_TX_DONE;
336
        next_wb_stb <= 1'b0;
337
      end
338
    end
339
    `DO_TRANS_RD_MEM:
340
    begin
341
      next_memAddr <= txDataIndex;
342
      next_memRdEn <= 1'b1;
343
      next_txDataSize <= txDataSize - 1'b1;
344
      next_txDataIndex <= txDataIndex + 1'b1;
345
      NextState_EP0St <= `DO_TRANS_DEL;
346
    end
347
    `DO_TRANS_CHK_TX_DONE:
348
    begin
349
      if (txDataSize == 8'h00)
350
      begin
351
        NextState_EP0St <= `DO_TRANS_TRANS_GO;
352
      end
353
      else
354
      begin
355
        NextState_EP0St <= `DO_TRANS_RD_MEM;
356
      end
357
    end
358
    `DO_TRANS_TRANS_GO:
359
    begin
360
      next_wb_addr <= `RA_EP0_CONTROL_REG;
361
      if (dataSeq == 1'b1)
362
      next_wb_data_o <= 8'h07;
363
      else
364
      next_wb_data_o <= 8'h03;
365
      next_wb_stb <= 1'b1;
366
      next_wb_we <= 1'b1;
367
      if (wb_ack == 1'b1)
368
      begin
369
        NextState_EP0St <= `DO_TRANS_WT_TRANS_DONE_WT_GNT;
370
        next_wb_stb <= 1'b0;
371
        next_transDone <= 1'b0;
372
      end
373
    end
374
    `DO_TRANS_RX_EMPTY:
375
    begin
376
      next_wb_addr <= `RA_EP0_RX_FIFO_CONTROL_REG;
377
      next_wb_data_o <= 8'h01;
378
      //force rx fifo empty
379
      next_wb_stb <= 1'b1;
380
      next_wb_we <= 1'b1;
381
      if ((wb_ack == 1'b1) && (txDataSize != 8'h00))
382
      begin
383
        NextState_EP0St <= `DO_TRANS_RD_MEM;
384
        next_wb_stb <= 1'b0;
385
      end
386
      else if (wb_ack == 1'b1)
387
      begin
388
        NextState_EP0St <= `DO_TRANS_TRANS_GO;
389
        next_wb_stb <= 1'b0;
390
      end
391
    end
392
    `DO_TRANS_DEL:
393
    begin
394
      next_memRdEn <= 1'b0;
395
      NextState_EP0St <= `DO_TRANS_WR_TX_FIFO;
396
    end
397
    `DO_TRANS_WT_TRANS_DONE_WT_GNT:
398
    begin
399
      next_wbBusReq <= 1'b1;
400
      if (wbBusGnt == 1'b1)
401
      begin
402
        NextState_EP0St <= `DO_TRANS_WT_TRANS_DONE_GET_RDY_STS;
403
      end
404
    end
405
    `DO_TRANS_WT_TRANS_DONE_GET_RDY_STS:
406
    begin
407
      next_wb_addr <= `RA_EP0_CONTROL_REG;
408
      next_wb_stb <= 1'b1;
409
      next_wb_we <= 1'b0;
410
      if (wb_ack == 1'b1)
411
      begin
412
        NextState_EP0St <= `DO_TRANS_WT_TRANS_DONE_WT_UNGNT;
413
        next_wb_stb <= 1'b0;
414
        next_transDone <= ~wb_data_i[`ENDPOINT_READY_BIT];
415
      end
416
    end
417
    `DO_TRANS_WT_TRANS_DONE_WT_UNGNT:
418
    begin
419
      next_wbBusReq <= 1'b0;
420
      if (wbBusGnt == 1'b0)
421
      begin
422
        NextState_EP0St <= `DO_TRANS_WT_TRANS_DONE_CHK_DONE;
423
      end
424
    end
425
    `DO_TRANS_WT_TRANS_DONE_CHK_DONE:
426
    begin
427
      if (transDone == 1'b1)
428
      begin
429
        NextState_EP0St <= `CHK_TRANS_WT_GNT;
430
        next_wbBusReq <= 1'b1;
431
      end
432
      else
433
      begin
434
        NextState_EP0St <= `DO_TRANS_WT_TRANS_DONE_DEL;
435
        next_cnt <= 8'h00;
436
      end
437
    end
438
    `DO_TRANS_WT_TRANS_DONE_DEL:
439
    begin
440
      next_cnt <= cnt + 1'b1;
441
      if (cnt == `ONE_USEC_DEL)
442
      begin
443
        NextState_EP0St <= `DO_TRANS_WT_TRANS_DONE_WT_GNT;
444
      end
445
    end
446
    `SETUP_CHK_ERR:
447
    begin
448
      if (rxDataSize != 16'h0008)
449
      begin
450
        NextState_EP0St <= `DO_TRANS_WT_GNT;
451
      end
452
      else
453
      begin
454
        NextState_EP0St <= `SETUP_GET_DATA_WT_GNT;
455
        next_wbBusReq <= 1'b1;
456
        next_txDataSize <= 8'h00;
457
        next_txPacketRemSize <= 8'h00;
458
        //default tx packet size
459
        next_dataSeq <= 1'b1;
460
        next_wb_addr <= `RA_EP0_RX_FIFO_DATA_REG;
461
        next_wb_we <= 1'b0;
462
      end
463
    end
464
    `SETUP_GET_STAT:
465
    begin
466
      if (bm_req_type == 2'b00)  begin
467
      next_txPacketRemSize <= 8'h02;
468
      if (bm_req_recp == 5'b00000)
469
      next_txDataIndex <= `ONE_ZERO_STAT_INDEX;
470
      else
471
      next_txDataIndex <= `ZERO_ZERO_STAT_INDEX;
472
      end
473
      else if (bm_req_type == 2'b10) begin
474
      next_txDataIndex <= `VENDOR_DATA_STAT_INDEX;
475
      next_txPacketRemSize <= 8'h02;
476
      end
477
      NextState_EP0St <= `SETUP_CHK_MAX_LEN;
478
    end
479
    `SETUP_SET_ADDR:
480
    begin
481
      if ( (wValue[15:7] == {9{1'b0}}) && (wIndex == 16'h0000) && (wLength == 16'h0000) ) begin
482
      next_USBAddress <= wValue[7:0];
483
      next_updateUSBAddress <= 1'b1;
484
      end
485
      NextState_EP0St <= `SETUP_CHK_MAX_LEN;
486
    end
487
    `SETUP_CHK_MAX_LEN:
488
    begin
489
      if (txPacketRemSize > wLength)
490
      next_txPacketRemSize <= wLength;
491
      NextState_EP0St <= `SETUP_PTR_SET;
492
    end
493
    `SETUP_PTR_SET:
494
    begin
495
      if (txPacketRemSize > `MAX_RESP_SIZE) begin
496
      next_txDataSize <= `MAX_RESP_SIZE;
497
      next_txPacketRemSize <= txPacketRemSize - `MAX_RESP_SIZE;
498
      end
499
      else begin
500
      next_txDataSize <= txPacketRemSize;
501
      next_txPacketRemSize <= 8'h00;
502
      end
503
      NextState_EP0St <= `DO_TRANS_WT_GNT;
504
    end
505
    `SETUP_GET_DATA_DAT1:
506
    begin
507
      next_wb_stb <= 1'b1;
508
      if (wb_ack == 1'b1)
509
      begin
510
        NextState_EP0St <= `SETUP_GET_DATA_DAT2;
511
        next_wb_stb <= 1'b0;
512
        next_bm_req_dir <= wb_data_i[7];
513
        next_bm_req_type <= wb_data_i[6:5];
514
        next_bm_req_recp <= wb_data_i[4:0];
515
      end
516
    end
517
    `SETUP_GET_DATA_WT_GNT:
518
    begin
519
      if (wbBusGnt == 1'b1)
520
      begin
521
        NextState_EP0St <= `SETUP_GET_DATA_DAT1;
522
      end
523
    end
524
    `SETUP_GET_DATA_DAT2:
525
    begin
526
      next_wb_stb <= 1'b1;
527
      if (wb_ack == 1'b1)
528
      begin
529
        NextState_EP0St <= `SETUP_GET_DATA_DAT3;
530
        next_wb_stb <= 1'b0;
531
        next_bRequest <= wb_data_i;
532
      end
533
    end
534
    `SETUP_GET_DATA_DAT3:
535
    begin
536
      next_wb_stb <= 1'b1;
537
      if (wb_ack == 1'b1)
538
      begin
539
        NextState_EP0St <= `SETUP_GET_DATA_DAT4;
540
        next_wb_stb <= 1'b0;
541
        next_wValue[7:0] <= wb_data_i;
542
      end
543
    end
544
    `SETUP_GET_DATA_DAT4:
545
    begin
546
      next_wb_stb <= 1'b1;
547
      if (wb_ack == 1'b1)
548
      begin
549
        NextState_EP0St <= `SETUP_GET_DATA_DAT5;
550
        next_wb_stb <= 1'b0;
551
        next_wValue[15:8] <= wb_data_i;
552
      end
553
    end
554
    `SETUP_GET_DATA_DAT6:
555
    begin
556
      next_wb_stb <= 1'b1;
557
      if (wb_ack == 1'b1)
558
      begin
559
        NextState_EP0St <= `SETUP_GET_DATA_DAT7;
560
        next_wb_stb <= 1'b0;
561
        next_wIndex[15:8] <= wb_data_i;
562
      end
563
    end
564
    `SETUP_GET_DATA_DAT5:
565
    begin
566
      next_wb_stb <= 1'b1;
567
      if (wb_ack == 1'b1)
568
      begin
569
        NextState_EP0St <= `SETUP_GET_DATA_DAT6;
570
        next_wb_stb <= 1'b0;
571
        next_wIndex[7:0] <= wb_data_i;
572
      end
573
    end
574
    `SETUP_GET_DATA_DAT8:
575
    begin
576
      next_wb_stb <= 1'b1;
577
      if (wb_ack == 1'b1)
578
      begin
579
        NextState_EP0St <= `SETUP_GET_DATA_WT_UNGNT;
580
        next_wb_stb <= 1'b0;
581
        next_wLength[15:8] <= wb_data_i;
582
        next_wbBusReq <= 1'b0;
583
      end
584
    end
585
    `SETUP_GET_DATA_DAT7:
586
    begin
587
      next_wb_stb <= 1'b1;
588
      if (wb_ack == 1'b1)
589
      begin
590
        NextState_EP0St <= `SETUP_GET_DATA_DAT8;
591
        next_wb_stb <= 1'b0;
592
        next_wLength[7:0] <= wb_data_i;
593
      end
594
    end
595
    `SETUP_GET_DATA_WT_UNGNT:
596
    begin
597
      if ((wbBusGnt == 1'b0) && (bRequest == `GET_STATUS))
598
      begin
599
        NextState_EP0St <= `SETUP_GET_STAT;
600
      end
601
      else if ((wbBusGnt == 1'b0) && (bRequest == `GET_DESCRIPTOR))
602
      begin
603
        NextState_EP0St <= `SETUP_GET_DESC_S1;
604
      end
605
      else if ((wbBusGnt == 1'b0) && (bRequest == `SET_ADDRESS))
606
      begin
607
        NextState_EP0St <= `SETUP_SET_ADDR;
608
      end
609
      else if (wbBusGnt == 1'b0)
610
      begin
611
        NextState_EP0St <= `DO_TRANS_WT_GNT;
612
      end
613
    end
614
    `SETUP_GET_DESC_S1:
615
    begin
616
      case (wValue[15:8])
617
      `DEV_DESC: begin
618
      next_txPacketRemSize <= `DEV_DESC_SIZE;
619
      next_txDataIndex <= `DEV_DESC_INDEX;
620
      end
621
      `CFG_DESC: begin
622
      next_txPacketRemSize <= `CFG_DESC_SIZE;
623
      next_txDataIndex <= `CFG_DESC_INDEX;
624
      end
625
      `REP_DESC: begin
626
      next_txPacketRemSize <= `REP_DESC_SIZE;
627
      next_txDataIndex <= `REP_DESC_INDEX;
628
      end
629
      `STRING_DESC: begin
630
      case (wValue[3:0])
631
      4'h0: begin
632
      next_txPacketRemSize <= `LANGID_DESC_SIZE;
633
      next_txDataIndex <= `LANGID_DESC_INDEX;
634
      end
635
      4'h1: begin
636
      next_txPacketRemSize <= `STRING1_DESC_SIZE;
637
      next_txDataIndex <= `STRING1_DESC_INDEX;
638
      end
639
      4'h2: begin
640
      next_txPacketRemSize <= `STRING2_DESC_SIZE;
641
      next_txDataIndex <= `STRING2_DESC_INDEX;
642
      end
643
      4'h3: begin
644
      next_txPacketRemSize <= `STRING3_DESC_SIZE;
645
      next_txDataIndex <= `STRING3_DESC_INDEX;
646
      end
647
      endcase
648
      end
649
      endcase
650
      NextState_EP0St <= `SETUP_CHK_MAX_LEN;
651
    end
652
    `IN_CHK_ACK:
653
    begin
654
      if (epStatus[`SC_ACK_RXED_BIT] != 1'b1)
655
      begin
656
        NextState_EP0St <= `DO_TRANS_WT_GNT;
657
      end
658
      else if (updateUSBAddress == 1'b1)
659
      begin
660
        NextState_EP0St <= `IN_WT_GNT;
661
      end
662
      else
663
      begin
664
        NextState_EP0St <= `IN_SET_PTR;
665
      end
666
    end
667
    `IN_SET_PTR:
668
    begin
669
      if (txPacketRemSize > `MAX_RESP_SIZE) begin
670
      next_txDataSize <= `MAX_RESP_SIZE;
671
      next_txPacketRemSize <= txPacketRemSize - `MAX_RESP_SIZE;
672
      end
673
      else begin
674
      next_txDataSize <= txPacketRemSize;
675
      next_txPacketRemSize <= 8'h00;
676
      end
677
      NextState_EP0St <= `DO_TRANS_WT_GNT;
678
    end
679
    `IN_SET_ADDR:
680
    begin
681
      next_wb_addr <= `RA_SC_ADDRESS;
682
      next_wb_data_o <= USBAddress;
683
      next_wb_stb <= 1'b1;
684
      next_wb_we <= 1'b1;
685
      if (wb_ack == 1'b1)
686
      begin
687
        NextState_EP0St <= `IN_WT_UNGNT;
688
        next_wb_stb <= 1'b0;
689
        next_wbBusReq <= 1'b0;
690
      end
691
    end
692
    `IN_WT_GNT:
693
    begin
694
      next_wbBusReq <= 1'b1;
695
      next_updateUSBAddress <= 1'b0;
696
      if (wbBusGnt == 1'b1)
697
      begin
698
        NextState_EP0St <= `IN_SET_ADDR;
699
      end
700
    end
701
    `IN_WT_UNGNT:
702
    begin
703
      if (wbBusGnt == 1'b0)
704
      begin
705
        NextState_EP0St <= `IN_SET_PTR;
706
      end
707
    end
708
    `OUT_CHK_SEQ:
709
    begin
710
      if (epStatus[`SC_DATA_SEQUENCE_BIT] != dataSeq)
711
      begin
712
        NextState_EP0St <= `DO_TRANS_WT_GNT;
713
      end
714
      else
715
      begin
716
        NextState_EP0St <= `DO_TRANS_WT_GNT;
717
        next_dataSeq <= ~dataSeq;
718
      end
719
    end
720
    `INIT_RST:
721
    begin
722
      next_wb_addr <= `RA_HOST_SLAVE_MODE;
723
      next_wb_data_o <= 8'h2;
724
      //reset usbHostSlave
725
      next_wb_stb <= 1'b1;
726
      next_wb_we <= 1'b1;
727
      if (wb_ack == 1'b1)
728
      begin
729
        NextState_EP0St <= `INIT_WT_RST;
730
        next_wb_stb <= 1'b0;
731
        next_cnt <= 8'h00;
732
      end
733
    end
734
    `INIT_WT_GNT:
735
    begin
736
      next_wbBusReq <= 1'b1;
737
      if (wbBusGnt == 1'b1)
738
      begin
739
        NextState_EP0St <= `INIT_RST;
740
      end
741
    end
742
    `INIT_WT_RST:
743
    begin
744
      next_cnt <= cnt + 1'b1;
745
      if (cnt == 8'hff)
746
      begin
747
        NextState_EP0St <= `INIT_WT_VBUS;
748
      end
749
    end
750
    `INIT_WT_VBUS:
751
    begin
752
      next_wb_addr <= `RA_SC_LINE_STATUS_REG;
753
      next_wb_stb <= 1'b1;
754
      next_wb_we <= 1'b0;
755
      if ((wb_ack == 1'b1)  && (wb_data_i[`VBUS_PRES_BIT] == 1'b1))
756
      begin
757
        NextState_EP0St <= `INIT_CONN;
758
        next_wb_stb <= 1'b0;
759
      end
760
    end
761
    `INIT_FIN:
762
    begin
763
      next_wbBusReq <= 1'b0;
764
      next_initComplete <= 1'b1;
765
      if (wbBusGnt == 1'b0)
766
      begin
767
        NextState_EP0St <= `DO_TRANS_WT_GNT;
768
      end
769
    end
770
    `INIT_CONN:
771
    begin
772
      next_wb_addr <= `RA_SC_CONTROL_REG;
773
      next_wb_data_o <= 8'h71;
774
      //connect to host, full speed
775
      next_wb_stb <= 1'b1;
776
      next_wb_we <= 1'b1;
777
      if (wb_ack == 1'b1)
778
      begin
779
        NextState_EP0St <= `INIT_WT_CONN;
780
        next_wb_stb <= 1'b0;
781
      end
782
    end
783
    `INIT_WT_CONN:
784
    begin
785
      next_wb_addr <= `RA_SC_LINE_STATUS_REG;
786
      next_wb_stb <= 1'b1;
787
      next_wb_we <= 1'b0;
788
      if ((wb_ack == 1'b1) && (wb_data_i[1:0] == `FULL_SPEED_CONNECT))
789
      begin
790
        NextState_EP0St <= `INIT_FIN;
791
        next_wb_stb <= 1'b0;
792
      end
793
    end
794
  endcase
795
end
796
 
797
// Current State Logic (sequential)
798
always @ (posedge clk)
799
begin
800
  if (rst == 1'b1)
801
    CurrState_EP0St <= `START;
802
  else
803
    CurrState_EP0St <= NextState_EP0St;
804
end
805
 
806
// Registered outputs logic
807
always @ (posedge clk)
808
begin
809
  if (rst == 1'b1)
810
  begin
811
    wb_addr <= 8'h00;
812
    wb_data_o <= 8'h00;
813
    wb_stb <= 1'b0;
814
    wb_we <= 1'b0;
815
    wbBusReq <= 1'b0;
816
    initComplete <= 1'b0;
817
    memAddr <= 8'h00;
818
    memRdEn <= 1'b0;
819
    cnt <= 8'h00;
820
    txDataSize <= 8'h00;
821
    txDataIndex <= 8'h00;
822
    transDone <= 1'b0;
823
    epStatus <= 8'h00;
824
    rxDataSize <= 16'h0000;
825
    epTransType <= 8'h00;
826
    bm_req_dir <= 1'b0;
827
    bm_req_type <= 2'b00;
828
    bm_req_recp <= 5'b00000;
829
    bRequest <= 8'h00;
830
    wValue <= 16'h0000;
831
    wIndex <= 16'h0000;
832
    wLength <= 16'h0000;
833
    txPacketRemSize <= 8'h00;
834
    USBAddress <= 8'h00;
835
    updateUSBAddress <= 1'b0;
836
    dataSeq <= 1'b0;
837
  end
838
  else
839
  begin
840
    wb_addr <= next_wb_addr;
841
    wb_data_o <= next_wb_data_o;
842
    wb_stb <= next_wb_stb;
843
    wb_we <= next_wb_we;
844
    wbBusReq <= next_wbBusReq;
845
    initComplete <= next_initComplete;
846
    memAddr <= next_memAddr;
847
    memRdEn <= next_memRdEn;
848
    cnt <= next_cnt;
849
    txDataSize <= next_txDataSize;
850
    txDataIndex <= next_txDataIndex;
851
    transDone <= next_transDone;
852
    epStatus <= next_epStatus;
853
    rxDataSize <= next_rxDataSize;
854
    epTransType <= next_epTransType;
855
    bm_req_dir <= next_bm_req_dir;
856
    bm_req_type <= next_bm_req_type;
857
    bm_req_recp <= next_bm_req_recp;
858
    bRequest <= next_bRequest;
859
    wValue <= next_wValue;
860
    wIndex <= next_wIndex;
861
    wLength <= next_wLength;
862
    txPacketRemSize <= next_txPacketRemSize;
863
    USBAddress <= next_USBAddress;
864
    updateUSBAddress <= next_updateUSBAddress;
865
    dataSeq <= next_dataSeq;
866
  end
867
end
868
 
869
endmodule

powered by: WebSVN 2.1.0

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