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

Subversion Repositories usbhostslave

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 43 sfielding
 
2
// File        : ../RTL/serialInterfaceEngine/processTxByte.v
3
// Generated   : 11/10/06 05:37:23
4
// From        : ../RTL/serialInterfaceEngine/processTxByte.asf
5
// By          : FSM2VHDL ver. 5.0.0.9
6
 
7
//////////////////////////////////////////////////////////////////////
8
////                                                              ////
9
//// processTxByte
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
module processTxByte (JBit, KBit, TxByteCtrlIn, TxByteFullSpeedRateIn, TxByteIn, USBWireCtrl, USBWireData, USBWireFullSpeedRate, USBWireGnt, USBWireRdy, USBWireReq, USBWireWEn, clk, processTxByteRdy, processTxByteWEn, rst);
55
input   [1:0] JBit;
56
input   [1:0] KBit;
57
input   [7:0] TxByteCtrlIn;
58
input   TxByteFullSpeedRateIn;
59
input   [7:0] TxByteIn;
60
input   USBWireGnt;
61
input   USBWireRdy;
62
input   clk;
63
input   processTxByteWEn;
64
input   rst;
65
output  USBWireCtrl;
66
output  [1:0] USBWireData;
67
output  USBWireFullSpeedRate;
68
output  USBWireReq;
69
output  USBWireWEn;
70
output  processTxByteRdy;
71
 
72
wire    [1:0] JBit;
73
wire    [1:0] KBit;
74
wire    [7:0] TxByteCtrlIn;
75
wire    TxByteFullSpeedRateIn;
76
wire    [7:0] TxByteIn;
77
reg     USBWireCtrl, next_USBWireCtrl;
78
reg     [1:0] USBWireData, next_USBWireData;
79
reg     USBWireFullSpeedRate, next_USBWireFullSpeedRate;
80
wire    USBWireGnt;
81
wire    USBWireRdy;
82
reg     USBWireReq, next_USBWireReq;
83
reg     USBWireWEn, next_USBWireWEn;
84
wire    clk;
85
reg     processTxByteRdy, next_processTxByteRdy;
86
wire    processTxByteWEn;
87
wire    rst;
88
 
89
// diagram signals declarations
90
reg  [1:0]TXLineState, next_TXLineState;
91
reg  [3:0]TXOneCount, next_TXOneCount;
92
reg  [7:0]TxByteCtrl, next_TxByteCtrl;
93
reg  TxByteFullSpeedRate, next_TxByteFullSpeedRate;
94
reg  [7:0]TxByte, next_TxByte;
95
reg  [3:0]i, next_i;
96
 
97
// BINARY ENCODED state machine: prcTxB
98
// State codes definitions:
99
`define START_PTBY 5'b00000
100
`define PTBY_WAIT_EN 5'b00001
101
`define SEND_BYTE_UPDATE_BYTE 5'b00010
102
`define SEND_BYTE_WAIT_RDY 5'b00011
103
`define SEND_BYTE_CHK 5'b00100
104
`define SEND_BYTE_BIT_STUFF 5'b00101
105
`define SEND_BYTE_WAIT_RDY2 5'b00110
106
`define SEND_BYTE_CHK_FIN 5'b00111
107
`define PTBY_WAIT_GNT 5'b01000
108
`define STOP_SND_SE0_2 5'b01001
109
`define STOP_SND_SE0_1 5'b01010
110
`define STOP_CHK 5'b01011
111
`define STOP_SND_J 5'b01100
112
`define STOP_SND_IDLE 5'b01101
113
`define STOP_FIN 5'b01110
114
`define WAIT_RDY_WIRE 5'b01111
115
`define WAIT_RDY_PKT 5'b10000
116
`define LS_START_SND_IDLE3 5'b10001
117
`define LS_START_SND_J1 5'b10010
118
`define LS_START_SND_IDLE1 5'b10011
119
`define LS_START_SND_IDLE2 5'b10100
120
`define LS_START_FIN 5'b10101
121
`define LS_START_W_RDY1 5'b10110
122
`define LS_START_W_RDY2 5'b10111
123
`define LS_START_W_RDY3 5'b11000
124
`define STOP_W_RDY1 5'b11001
125
`define STOP_W_RDY2 5'b11010
126
`define STOP_W_RDY3 5'b11011
127
`define STOP_W_RDY4 5'b11100
128
 
129
reg [4:0] CurrState_prcTxB;
130
reg [4:0] NextState_prcTxB;
131
 
132
 
133
//--------------------------------------------------------------------
134
// Machine: prcTxB
135
//--------------------------------------------------------------------
136
//----------------------------------
137
// Next State Logic (combinatorial)
138
//----------------------------------
139
always @ (TxByteIn or TxByteCtrlIn or TxByteFullSpeedRateIn or JBit or i or TxByte or TXOneCount or TXLineState or KBit or processTxByteWEn or USBWireGnt or USBWireRdy or TxByteFullSpeedRate or TxByteCtrl or processTxByteRdy or USBWireData or USBWireCtrl or USBWireReq or USBWireWEn or USBWireFullSpeedRate or CurrState_prcTxB)
140
begin : prcTxB_NextState
141
  NextState_prcTxB <= CurrState_prcTxB;
142
  // Set default values for outputs and signals
143
  next_processTxByteRdy <= processTxByteRdy;
144
  next_USBWireData <= USBWireData;
145
  next_USBWireCtrl <= USBWireCtrl;
146
  next_USBWireReq <= USBWireReq;
147
  next_USBWireWEn <= USBWireWEn;
148
  next_i <= i;
149
  next_TxByte <= TxByte;
150
  next_TxByteCtrl <= TxByteCtrl;
151
  next_TXLineState <= TXLineState;
152
  next_TXOneCount <= TXOneCount;
153
  next_USBWireFullSpeedRate <= USBWireFullSpeedRate;
154
  next_TxByteFullSpeedRate <= TxByteFullSpeedRate;
155
  case (CurrState_prcTxB)
156
    `START_PTBY:
157
    begin
158
      next_processTxByteRdy <= 1'b0;
159
      next_USBWireData <= 2'b00;
160
      next_USBWireCtrl <= `TRI_STATE;
161
      next_USBWireReq <= 1'b0;
162
      next_USBWireWEn <= 1'b0;
163
      next_i <= 4'h0;
164
      next_TxByte <= 8'h00;
165
      next_TxByteCtrl <= 8'h00;
166
      next_TXLineState <= 2'b0;
167
      next_TXOneCount <= 4'h0;
168
      next_USBWireFullSpeedRate <= 1'b0;
169
      next_TxByteFullSpeedRate <= 1'b0;
170
      NextState_prcTxB <= `PTBY_WAIT_EN;
171
    end
172
    `PTBY_WAIT_EN:
173
    begin
174
      next_processTxByteRdy <= 1'b1;
175
      if ((processTxByteWEn == 1'b1) && (TxByteCtrlIn == `DATA_START))
176
      begin
177
        NextState_prcTxB <= `PTBY_WAIT_GNT;
178
        next_processTxByteRdy <= 1'b0;
179
        next_TxByte <= TxByteIn;
180
        next_TxByteCtrl <= TxByteCtrlIn;
181
        next_TxByteFullSpeedRate <= TxByteFullSpeedRateIn;
182
        next_USBWireFullSpeedRate <= TxByteFullSpeedRateIn;
183
        next_TXOneCount <= 4'h0;
184
        next_TXLineState <= JBit;
185
        next_USBWireReq <= 1'b1;
186
      end
187
      else if (processTxByteWEn == 1'b1)
188
      begin
189
        NextState_prcTxB <= `SEND_BYTE_UPDATE_BYTE;
190
        next_processTxByteRdy <= 1'b0;
191
        next_TxByte <= TxByteIn;
192
        next_TxByteCtrl <= TxByteCtrlIn;
193
        next_TxByteFullSpeedRate <= TxByteFullSpeedRateIn;
194
        next_USBWireFullSpeedRate <= TxByteFullSpeedRateIn;
195
        next_i <= 4'h0;
196
      end
197
    end
198
    `PTBY_WAIT_GNT:
199
      if (USBWireGnt == 1'b1)
200
        NextState_prcTxB <= `WAIT_RDY_WIRE;
201
    `WAIT_RDY_WIRE:
202
      if ((USBWireRdy == 1'b1) && (TxByteFullSpeedRate  == 1'b0))
203
        NextState_prcTxB <= `LS_START_SND_IDLE1;
204
      else if (USBWireRdy == 1'b1)
205
      begin
206
        NextState_prcTxB <= `WAIT_RDY_PKT;
207
        //actively drive the first J bit
208
        next_USBWireData <= JBit;
209
        next_USBWireCtrl <= `DRIVE;
210
        next_USBWireWEn <= 1'b1;
211
      end
212
    `WAIT_RDY_PKT:
213
    begin
214
      next_USBWireWEn <= 1'b0;
215
      NextState_prcTxB <= `SEND_BYTE_UPDATE_BYTE;
216
      next_i <= 4'h0;
217
    end
218
    `SEND_BYTE_UPDATE_BYTE:
219
    begin
220
      next_i <= i + 1'b1;
221
      next_TxByte <= {1'b0, TxByte[7:1] };
222
      if (TxByte[0] == 1'b1)                      //If this bit is 1, then
223
        next_TXOneCount <= TXOneCount + 1'b1;
224
          //increment 'TXOneCount'
225
      else                                        //else this is a zero bit
226
      begin
227
        next_TXOneCount <= 4'h0;
228
          //reset 'TXOneCount'
229
          if (TXLineState == JBit)
230
          next_TXLineState <= KBit;
231
              //toggle the line state
232
          else
233
          next_TXLineState <= JBit;
234
      end
235
      NextState_prcTxB <= `SEND_BYTE_WAIT_RDY;
236
    end
237
    `SEND_BYTE_WAIT_RDY:
238
      if (USBWireRdy == 1'b1)
239
      begin
240
        NextState_prcTxB <= `SEND_BYTE_CHK;
241
        next_USBWireWEn <= 1'b1;
242
        next_USBWireData <= TXLineState;
243
        next_USBWireCtrl <= `DRIVE;
244
      end
245
    `SEND_BYTE_CHK:
246
    begin
247
      next_USBWireWEn <= 1'b0;
248
      if (TXOneCount == `MAX_CONSEC_SAME_BITS)
249
        NextState_prcTxB <= `SEND_BYTE_BIT_STUFF;
250
      else if (i != 4'h8)
251
        NextState_prcTxB <= `SEND_BYTE_UPDATE_BYTE;
252
      else
253
        NextState_prcTxB <= `STOP_CHK;
254
    end
255
    `SEND_BYTE_BIT_STUFF:
256
    begin
257
      next_TXOneCount <= 4'h0;
258
      //reset 'TXOneCount'
259
      if (TXLineState == JBit)
260
        next_TXLineState <= KBit;
261
          //toggle the line state
262
      else
263
        next_TXLineState <= JBit;
264
      NextState_prcTxB <= `SEND_BYTE_WAIT_RDY2;
265
    end
266
    `SEND_BYTE_WAIT_RDY2:
267
      if (USBWireRdy == 1'b1)
268
      begin
269
        NextState_prcTxB <= `SEND_BYTE_CHK_FIN;
270
        next_USBWireWEn <= 1'b1;
271
        next_USBWireData <= TXLineState;
272
        next_USBWireCtrl <= `DRIVE;
273
      end
274
    `SEND_BYTE_CHK_FIN:
275
    begin
276
      next_USBWireWEn <= 1'b0;
277
      if (i == 4'h8)
278
        NextState_prcTxB <= `STOP_CHK;
279
      else
280
        NextState_prcTxB <= `SEND_BYTE_UPDATE_BYTE;
281
    end
282
    `STOP_SND_SE0_2:
283
    begin
284
      next_USBWireWEn <= 1'b0;
285
      NextState_prcTxB <= `STOP_W_RDY2;
286
    end
287
    `STOP_SND_SE0_1:
288
      NextState_prcTxB <= `STOP_W_RDY1;
289
    `STOP_CHK:
290
      if (TxByteCtrl == `DATA_STOP)
291
        NextState_prcTxB <= `STOP_SND_SE0_1;
292
      else if (TxByteCtrl == `DATA_STOP_PRE)
293
        NextState_prcTxB <= `STOP_SND_J;
294
      else
295
        NextState_prcTxB <= `PTBY_WAIT_EN;
296
    `STOP_SND_J:
297
    begin
298
      next_USBWireWEn <= 1'b0;
299
      NextState_prcTxB <= `STOP_W_RDY3;
300
    end
301
    `STOP_SND_IDLE:
302
    begin
303
      next_USBWireWEn <= 1'b0;
304
      NextState_prcTxB <= `STOP_W_RDY4;
305
    end
306
    `STOP_FIN:
307
    begin
308
      next_USBWireWEn <= 1'b0;
309
      next_USBWireReq <= 1'b0;
310
      //release the wire
311
      NextState_prcTxB <= `PTBY_WAIT_EN;
312
    end
313
    `STOP_W_RDY1:
314
      if (USBWireRdy == 1'b1)
315
      begin
316
        NextState_prcTxB <= `STOP_SND_SE0_2;
317
        next_USBWireWEn <= 1'b1;
318
        next_USBWireData <= `SE0;
319
        next_USBWireCtrl <= `DRIVE;
320
      end
321
    `STOP_W_RDY2:
322
      if (USBWireRdy == 1'b1)
323
      begin
324
        NextState_prcTxB <= `STOP_SND_J;
325
        next_USBWireWEn <= 1'b1;
326
        next_USBWireData <= `SE0;
327
        next_USBWireCtrl <= `DRIVE;
328
      end
329
    `STOP_W_RDY3:
330
      if (USBWireRdy == 1'b1)
331
      begin
332
        NextState_prcTxB <= `STOP_SND_IDLE;
333
        next_USBWireWEn <= 1'b1;
334
        next_USBWireData <= JBit;
335
        next_USBWireCtrl <= `DRIVE;
336
      end
337
    `STOP_W_RDY4:
338
      if (USBWireRdy == 1'b1)
339
      begin
340
        NextState_prcTxB <= `STOP_FIN;
341
        next_USBWireWEn <= 1'b1;
342
        next_USBWireData <= JBit;
343
        next_USBWireCtrl <= `TRI_STATE;
344
      end
345
    `LS_START_SND_IDLE3:
346
    begin
347
      next_USBWireWEn <= 1'b0;
348
      NextState_prcTxB <= `LS_START_W_RDY2;
349
    end
350
    `LS_START_SND_J1:
351
    begin
352
      next_USBWireWEn <= 1'b0;
353
      NextState_prcTxB <= `LS_START_W_RDY3;
354
    end
355
    `LS_START_SND_IDLE1:
356
      if (USBWireRdy == 1'b1)
357
      begin
358
        NextState_prcTxB <= `LS_START_SND_IDLE2;
359
        next_USBWireWEn <= 1'b1;
360
        next_USBWireData <= JBit;
361
        next_USBWireCtrl <= `TRI_STATE;
362
      end
363
    `LS_START_SND_IDLE2:
364
    begin
365
      next_USBWireWEn <= 1'b0;
366
      NextState_prcTxB <= `LS_START_W_RDY1;
367
    end
368
    `LS_START_FIN:
369
    begin
370
      next_USBWireWEn <= 1'b0;
371
      NextState_prcTxB <= `SEND_BYTE_UPDATE_BYTE;
372
      next_i <= 4'h0;
373
    end
374
    `LS_START_W_RDY1:
375
      if (USBWireRdy == 1'b1)
376
      begin
377
        NextState_prcTxB <= `LS_START_SND_IDLE3;
378
        next_USBWireWEn <= 1'b1;
379
        next_USBWireData <= JBit;
380
        next_USBWireCtrl <= `TRI_STATE;
381
      end
382
    `LS_START_W_RDY2:
383
      if (USBWireRdy == 1'b1)
384
      begin
385
        NextState_prcTxB <= `LS_START_SND_J1;
386
        next_USBWireWEn <= 1'b1;
387
        next_USBWireData <= JBit;
388
        next_USBWireCtrl <= `TRI_STATE;
389
      end
390
    `LS_START_W_RDY3:
391
      if (USBWireRdy == 1'b1)
392
      begin
393
        NextState_prcTxB <= `LS_START_FIN;
394
        //Drive the first JBit
395
        next_USBWireWEn <= 1'b1;
396
        next_USBWireData <= JBit;
397
        next_USBWireCtrl <= `DRIVE;
398
      end
399
  endcase
400
end
401
 
402
//----------------------------------
403
// Current State Logic (sequential)
404
//----------------------------------
405
always @ (posedge clk)
406
begin : prcTxB_CurrentState
407
  if (rst)
408
    CurrState_prcTxB <= `START_PTBY;
409
  else
410
    CurrState_prcTxB <= NextState_prcTxB;
411
end
412
 
413
//----------------------------------
414
// Registered outputs logic
415
//----------------------------------
416
always @ (posedge clk)
417
begin : prcTxB_RegOutput
418
  if (rst)
419
  begin
420
    i <= 4'h0;
421
    TxByte <= 8'h00;
422
    TxByteCtrl <= 8'h00;
423
    TXLineState <= 2'b0;
424
    TXOneCount <= 4'h0;
425
    TxByteFullSpeedRate <= 1'b0;
426
    processTxByteRdy <= 1'b0;
427
    USBWireData <= 2'b00;
428
    USBWireCtrl <= `TRI_STATE;
429
    USBWireReq <= 1'b0;
430
    USBWireWEn <= 1'b0;
431
    USBWireFullSpeedRate <= 1'b0;
432
  end
433
  else
434
  begin
435
    i <= next_i;
436
    TxByte <= next_TxByte;
437
    TxByteCtrl <= next_TxByteCtrl;
438
    TXLineState <= next_TXLineState;
439
    TXOneCount <= next_TXOneCount;
440
    TxByteFullSpeedRate <= next_TxByteFullSpeedRate;
441
    processTxByteRdy <= next_processTxByteRdy;
442
    USBWireData <= next_USBWireData;
443
    USBWireCtrl <= next_USBWireCtrl;
444
    USBWireReq <= next_USBWireReq;
445
    USBWireWEn <= next_USBWireWEn;
446
    USBWireFullSpeedRate <= next_USBWireFullSpeedRate;
447
  end
448
end
449
 
450
endmodule

powered by: WebSVN 2.1.0

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