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

Subversion Repositories usbhostslave

[/] [usbhostslave/] [tags/] [rel_01_01/] [RTL/] [serialInterfaceEngine/] [processRxBit.v] - Blame information for rev 12

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

Line No. Rev Author Line
1 5 sfielding
 
2
//////////////////////////////////////////////////////////////////////
3
////                                                              ////
4
//// processrxbit
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
 
48
 
49
module processRxBit (clk, JBit, KBit, processRxBitRdy, processRxBitsWEn, processRxByteRdy, processRxByteWEn, resumeDetected, rst, RxBitsIn, RxCtrlOut, RxDataOut);
50
input   clk;
51
input   [1:0]JBit;
52
input   [1:0]KBit;
53
input   processRxBitsWEn;
54
input   processRxByteRdy;
55
input   rst;
56
input   [1:0]RxBitsIn;
57
output  processRxBitRdy;
58
output  processRxByteWEn;
59
output  resumeDetected;
60
output  [7:0]RxCtrlOut;
61
output  [7:0]RxDataOut;
62
 
63
wire    clk;
64
wire    [1:0]JBit;
65
wire    [1:0]KBit;
66
reg     processRxBitRdy, next_processRxBitRdy;
67
wire    processRxBitsWEn;
68
wire    processRxByteRdy;
69
reg     processRxByteWEn, next_processRxByteWEn;
70
reg     resumeDetected, next_resumeDetected;
71
wire    rst;
72
wire    [1:0]RxBitsIn;
73
reg     [7:0]RxCtrlOut, next_RxCtrlOut;
74
reg     [7:0]RxDataOut, next_RxDataOut;
75
 
76
// diagram signals declarations
77
reg bitStuffError, next_bitStuffError;
78
reg  [1:0]oldRXBits, next_oldRXBits;
79
reg  [3:0]resumeWaitCnt, next_resumeWaitCnt;
80
reg  [3:0]RXBitCount, next_RXBitCount;
81
reg  [1:0]RxBits, next_RxBits;
82
reg  [1:0]RXBitStMachCurrState, next_RXBitStMachCurrState;
83
reg  [7:0]RXByte, next_RXByte;
84
reg  [3:0]RXSameBitCount, next_RXSameBitCount;
85
 
86
// BINARY ENCODED state machine: prRxBit
87
// State codes definitions:
88
`define START 4'b0000
89
`define IDLE_FIRST_BIT 4'b0001
90
`define WAIT_BITS 4'b0010
91
`define IDLE_CHK_KBIT 4'b0011
92
`define DATA_RX_LAST_BIT 4'b0100
93
`define DATA_RX_CHK_SE0 4'b0101
94
`define DATA_RX_DATA_DESTUFF 4'b0110
95
`define DATA_RX_BYTE_SEND2 4'b0111
96
`define DATA_RX_BYTE_WAIT_RDY 4'b1000
97
`define RES_RX_CHK 4'b1001
98
`define DATA_RX_ERROR_CHK_RES 4'b1010
99
`define RES_END_CHK1 4'b1011
100
`define IDLE_WAIT_PRB_RDY 4'b1100
101
`define DATA_RX_WAIT_PRB_RDY 4'b1101
102
`define DATA_RX_ERROR_WAIT_RDY 4'b1110
103
 
104
reg [3:0]CurrState_prRxBit, NextState_prRxBit;
105
 
106
 
107
// Machine: prRxBit
108
 
109
// NextState logic (combinatorial)
110
always @ (RxBits or processRxBitsWEn or JBit or RxBitsIn or KBit or RXSameBitCount or RXBitCount or RXByte or processRxByteRdy or resumeWaitCnt or processRxByteWEn or RxCtrlOut or RxDataOut or resumeDetected or RXBitStMachCurrState or oldRXBits or bitStuffError or processRxBitRdy or CurrState_prRxBit)
111
begin
112
  NextState_prRxBit <= CurrState_prRxBit;
113
  // Set default values for outputs and signals
114
  next_processRxByteWEn <= processRxByteWEn;
115
  next_RxCtrlOut <= RxCtrlOut;
116
  next_RxDataOut <= RxDataOut;
117
  next_resumeDetected <= resumeDetected;
118
  next_RXBitStMachCurrState <= RXBitStMachCurrState;
119
  next_RxBits <= RxBits;
120
  next_RXSameBitCount <= RXSameBitCount;
121
  next_RXBitCount <= RXBitCount;
122
  next_oldRXBits <= oldRXBits;
123
  next_RXByte <= RXByte;
124
  next_bitStuffError <= bitStuffError;
125
  next_resumeWaitCnt <= resumeWaitCnt;
126
  next_processRxBitRdy <= processRxBitRdy;
127
  case (CurrState_prRxBit)  // synopsys parallel_case full_case
128
    `START:
129
    begin
130
      next_processRxByteWEn <= 1'b0;
131
      next_RxCtrlOut <= 8'h00;
132
      next_RxDataOut <= 8'h00;
133
      next_resumeDetected <= 1'b0;
134
      next_RXBitStMachCurrState <= `IDLE_BIT_ST;
135
      next_RxBits <= 2'b00;
136
      next_RXSameBitCount <= 4'h0;
137
      next_RXBitCount <= 4'h0;
138
      next_oldRXBits <= 2'b00;
139
      next_RXByte <= 8'h00;
140
      next_bitStuffError <= 1'b0;
141
      next_resumeWaitCnt <= 4'h0;
142
      next_processRxBitRdy <= 1'b1;
143
      NextState_prRxBit <= `WAIT_BITS;
144
    end
145
    `WAIT_BITS:
146
    begin
147 12 sfielding
      if ((processRxBitsWEn == 1'b1) && (RXBitStMachCurrState == `DATA_RECEIVE_BIT_ST))
148 5 sfielding
      begin
149 12 sfielding
        NextState_prRxBit <= `DATA_RX_CHK_SE0;
150 5 sfielding
        next_RxBits <= RxBitsIn;
151
        next_processRxBitRdy <= 1'b0;
152
      end
153 12 sfielding
      else if ((processRxBitsWEn == 1'b1) && (RXBitStMachCurrState == `WAIT_RESUME_ST))
154 5 sfielding
      begin
155 12 sfielding
        NextState_prRxBit <= `RES_RX_CHK;
156 5 sfielding
        next_RxBits <= RxBitsIn;
157
        next_processRxBitRdy <= 1'b0;
158
      end
159 12 sfielding
      else if ((processRxBitsWEn == 1'b1) && (RXBitStMachCurrState == `RESUME_END_WAIT_ST))
160 5 sfielding
      begin
161 12 sfielding
        NextState_prRxBit <= `RES_END_CHK1;
162 5 sfielding
        next_RxBits <= RxBitsIn;
163
        next_processRxBitRdy <= 1'b0;
164
      end
165 12 sfielding
      else if ((processRxBitsWEn == 1'b1) && (RXBitStMachCurrState == `IDLE_BIT_ST))
166 5 sfielding
      begin
167 12 sfielding
        NextState_prRxBit <= `IDLE_CHK_KBIT;
168 5 sfielding
        next_RxBits <= RxBitsIn;
169
        next_processRxBitRdy <= 1'b0;
170
      end
171
    end
172
    `IDLE_FIRST_BIT:
173
    begin
174
      next_processRxByteWEn <= 1'b0;
175
      next_RXBitStMachCurrState <= `DATA_RECEIVE_BIT_ST;
176 12 sfielding
      next_RXSameBitCount <= 4'h0;
177 5 sfielding
      next_RXBitCount <= 4'h1;
178
      next_oldRXBits <= RxBits;
179
      //zero is always the first RZ data bit of a new packet
180
      next_RXByte <= 8'h00;
181
      NextState_prRxBit <= `WAIT_BITS;
182
      next_processRxBitRdy <= 1'b1;
183
    end
184
    `IDLE_CHK_KBIT:
185
    begin
186
      if (RxBits == KBit)
187
      begin
188
        NextState_prRxBit <= `IDLE_WAIT_PRB_RDY;
189
      end
190
      else
191
      begin
192
        NextState_prRxBit <= `WAIT_BITS;
193
        next_processRxBitRdy <= 1'b1;
194
      end
195
    end
196
    `IDLE_WAIT_PRB_RDY:
197
    begin
198
      if (processRxByteRdy == 1'b1)
199
      begin
200
        NextState_prRxBit <= `IDLE_FIRST_BIT;
201
        next_RxDataOut <= 8'h00;
202
        //redundant data
203
        next_RxCtrlOut <= `DATA_START;
204
        //start of packet
205
        next_processRxByteWEn <= 1'b1;
206
      end
207
    end
208
    `DATA_RX_LAST_BIT:
209
    begin
210
      next_processRxByteWEn <= 1'b0;
211
      next_RXBitStMachCurrState <= `IDLE_BIT_ST;
212
      NextState_prRxBit <= `WAIT_BITS;
213
      next_processRxBitRdy <= 1'b1;
214
    end
215
    `DATA_RX_CHK_SE0:
216
    begin
217
      next_bitStuffError <= 1'b0;
218
      if (RxBits == `SE0)
219
      begin
220
        NextState_prRxBit <= `DATA_RX_WAIT_PRB_RDY;
221
      end
222
      else
223
      begin
224
        NextState_prRxBit <= `DATA_RX_DATA_DESTUFF;
225
        if (RxBits == oldRXBits)                 //if the current 'RxBits' are the same as the old 'RxBits', then
226
        begin
227
        next_RXSameBitCount <= RXSameBitCount + 1'b1;
228
        //inc 'RXSameBitCount'
229 12 sfielding
        if (RXSameBitCount == `MAX_CONSEC_SAME_BITS) //if 'RXSameBitCount' == 6 there has been a bit stuff error
230 5 sfielding
        next_bitStuffError <= 1'b1;
231
        //flag 'bitStuffError'
232
        else                                          //else no bit stuffing error
233
        begin
234
        next_RXBitCount <= RXBitCount + 1'b1;
235 12 sfielding
        if (RXBitCount != `MAX_CONSEC_SAME_BITS_PLUS1) begin
236 5 sfielding
        next_processRxBitRdy <= 1'b1;
237
        //early indication of ready
238
        end
239
        next_RXByte <= { 1'b1, RXByte[7:1]};
240
        //RZ bit <= 1 (ie no change in 'RxBits')
241
        end
242
        end
243
        else                                            //else current 'RxBits' are different from old 'RxBits'
244
        begin
245
        if (RXSameBitCount != `MAX_CONSEC_SAME_BITS)  //if this is not the RZ 0 bit after 6 consecutive RZ 1s, then
246
        begin
247
        next_RXBitCount <= RXBitCount + 1'b1;
248
        if (RXBitCount != 4'h7) begin
249
        next_processRxBitRdy <= 1'b1;
250
        //early indication of ready
251
        end
252
        next_RXByte <= {1'b0, RXByte[7:1]};
253
        //RZ bit <= 0 (ie current'RxBits' is different than old 'RxBits')
254
        end
255 12 sfielding
        next_RXSameBitCount <= 4'h0;
256 5 sfielding
        //reset 'RXSameBitCount'
257
        end
258
        next_oldRXBits <= RxBits;
259
      end
260
    end
261
    `DATA_RX_WAIT_PRB_RDY:
262
    begin
263
      if (processRxByteRdy == 1'b1)
264
      begin
265
        NextState_prRxBit <= `DATA_RX_LAST_BIT;
266
        next_RxDataOut <= 8'h00;
267
        //redundant data
268
        next_RxCtrlOut <= `DATA_STOP;
269
        //end of packet
270
        next_processRxByteWEn <= 1'b1;
271
      end
272
    end
273
    `DATA_RX_DATA_DESTUFF:
274
    begin
275
      if (RXBitCount == 4'h8 & bitStuffError == 1'b0)
276
      begin
277
        NextState_prRxBit <= `DATA_RX_BYTE_WAIT_RDY;
278
      end
279
      else if (bitStuffError == 1'b1)
280
      begin
281
        NextState_prRxBit <= `DATA_RX_ERROR_WAIT_RDY;
282
      end
283
      else
284
      begin
285
        NextState_prRxBit <= `WAIT_BITS;
286
        next_processRxBitRdy <= 1'b1;
287
      end
288
    end
289
    `DATA_RX_BYTE_SEND2:
290
    begin
291
      next_processRxByteWEn <= 1'b0;
292
      NextState_prRxBit <= `WAIT_BITS;
293
      next_processRxBitRdy <= 1'b1;
294
    end
295
    `DATA_RX_BYTE_WAIT_RDY:
296
    begin
297
      if (processRxByteRdy == 1'b1)
298
      begin
299
        NextState_prRxBit <= `DATA_RX_BYTE_SEND2;
300
        next_RXBitCount <= 4'h0;
301
        next_RxDataOut <= RXByte;
302
        next_RxCtrlOut <= `DATA_STREAM;
303
        next_processRxByteWEn <= 1'b1;
304
      end
305
    end
306
    `DATA_RX_ERROR_CHK_RES:
307
    begin
308
      next_processRxByteWEn <= 1'b0;
309
      if (RxBits == JBit)                           //if current bit is a JBit, then
310
      next_RXBitStMachCurrState <= `IDLE_BIT_ST;
311
      //next state is idle
312
      else                                          //else
313
      begin
314
      next_RXBitStMachCurrState <= `WAIT_RESUME_ST;
315
      //check for resume
316
      next_resumeWaitCnt <= 0;
317
      end
318
      NextState_prRxBit <= `WAIT_BITS;
319
      next_processRxBitRdy <= 1'b1;
320
    end
321
    `DATA_RX_ERROR_WAIT_RDY:
322
    begin
323
      if (processRxByteRdy == 1'b1)
324
      begin
325
        NextState_prRxBit <= `DATA_RX_ERROR_CHK_RES;
326
        next_RxDataOut <= 8'h00;
327
        //redundant data
328
        next_RxCtrlOut <= `DATA_BIT_STUFF_ERROR;
329
        next_processRxByteWEn <= 1'b1;
330
      end
331
    end
332
    `RES_RX_CHK:
333
    begin
334
      if (RxBits != KBit)  //can only be a resume if line remains in Kbit state
335
      next_RXBitStMachCurrState <= `IDLE_BIT_ST;
336
      else
337
      begin
338
      next_resumeWaitCnt <= resumeWaitCnt + 1'b1;
339
      //if we've waited long enough, then
340
      if (resumeWaitCnt == `RESUME_WAIT_TIME_MINUS1)
341
      begin
342
      next_RXBitStMachCurrState <= `RESUME_END_WAIT_ST;
343
      next_resumeDetected <= 1'b1;
344
      //report resume detected
345
      end
346
      end
347
      NextState_prRxBit <= `WAIT_BITS;
348
      next_processRxBitRdy <= 1'b1;
349
    end
350
    `RES_END_CHK1:
351
    begin
352
      if (RxBits != KBit)  //line must leave KBit state for the end of resume
353
      begin
354
      next_RXBitStMachCurrState <= `IDLE_BIT_ST;
355
      next_resumeDetected <= 1'b0;
356
      //clear resume detected flag
357
      end
358
      NextState_prRxBit <= `WAIT_BITS;
359
      next_processRxBitRdy <= 1'b1;
360
    end
361
  endcase
362
end
363
 
364
// Current State Logic (sequential)
365
always @ (posedge clk)
366
begin
367
  if (rst)
368
    CurrState_prRxBit <= `START;
369
  else
370
    CurrState_prRxBit <= NextState_prRxBit;
371
end
372
 
373
// Registered outputs logic
374
always @ (posedge clk)
375
begin
376
  if (rst)
377
  begin
378
    processRxByteWEn <= 1'b0;
379
    RxCtrlOut <= 8'h00;
380
    RxDataOut <= 8'h00;
381
    resumeDetected <= 1'b0;
382
    processRxBitRdy <= 1'b1;
383
    RXBitStMachCurrState <= `IDLE_BIT_ST;
384
    RxBits <= 2'b00;
385
    RXSameBitCount <= 4'h0;
386
    RXBitCount <= 4'h0;
387
    oldRXBits <= 2'b00;
388
    RXByte <= 8'h00;
389
    bitStuffError <= 1'b0;
390
    resumeWaitCnt <= 4'h0;
391
  end
392
  else
393
  begin
394
    processRxByteWEn <= next_processRxByteWEn;
395
    RxCtrlOut <= next_RxCtrlOut;
396
    RxDataOut <= next_RxDataOut;
397
    resumeDetected <= next_resumeDetected;
398
    processRxBitRdy <= next_processRxBitRdy;
399
    RXBitStMachCurrState <= next_RXBitStMachCurrState;
400
    RxBits <= next_RxBits;
401
    RXSameBitCount <= next_RXSameBitCount;
402
    RXBitCount <= next_RXBitCount;
403
    oldRXBits <= next_oldRXBits;
404
    RXByte <= next_RXByte;
405
    bitStuffError <= next_bitStuffError;
406
    resumeWaitCnt <= next_resumeWaitCnt;
407
  end
408
end
409
 
410 2 sfielding
endmodule

powered by: WebSVN 2.1.0

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