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

Subversion Repositories usbhostslave

[/] [usbhostslave/] [tags/] [rel_00_06_alpha/] [RTL/] [serialInterfaceEngine/] [readUSBWireData.v] - Blame information for rev 40

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sfielding
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// readUSBWireData.v                                            ////
4
////                                                              ////
5
//// This file is part of the usbhostslave opencores effort.
6
//// <http://www.opencores.org/cores//>                           ////
7
////                                                              ////
8
//// Module Description:                                          ////
9
//// 
10
////                                                              ////
11
//// To Do:                                                       ////
12
//// 
13
////                                                              ////
14
//// Author(s):                                                   ////
15
//// - Steve Fielding, sfielding@base2designs.com                 ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2004 Steve Fielding and OPENCORES.ORG          ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE. See the GNU Lesser General Public License for more  ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from <http://www.opencores.org/lgpl.shtml>                   ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
//
44
`timescale 1ns / 1ps
45
`include "usbSerialInterfaceEngine_h.v"
46
 
47 9 sfielding
module readUSBWireData (RxBitsIn, RxDataInTick, RxBitsOut, SIERxRdyIn, SIERxWEn, fullSpeedRate, TxWireActiveDrive, clk, rst, noActivityTimeOut);
48 2 sfielding
input   [1:0] RxBitsIn;
49
output  RxDataInTick;
50
input   SIERxRdyIn;
51
input   clk;
52
input   fullSpeedRate;
53
input   rst;
54 9 sfielding
input   TxWireActiveDrive;
55 2 sfielding
output  [1:0] RxBitsOut;
56
output  SIERxWEn;
57 9 sfielding
output noActivityTimeOut;
58 2 sfielding
 
59
wire   [1:0] RxBitsIn;
60
reg    RxDataInTick;
61
wire   SIERxRdyIn;
62
wire   clk;
63
wire   fullSpeedRate;
64
wire   rst;
65
reg    [1:0] RxBitsOut;
66
reg    SIERxWEn;
67 9 sfielding
reg    noActivityTimeOut;
68 2 sfielding
 
69
// local registers
70
reg  [1:0]buffer0;
71
reg  [1:0]buffer1;
72
reg  [1:0]buffer2;
73
reg  [1:0]buffer3;
74
reg  [2:0]bufferCnt;
75
reg  [1:0]bufferInIndex;
76
reg  [1:0]bufferOutIndex;
77
reg decBufferCnt;
78
reg  [4:0]i;
79
reg incBufferCnt;
80
reg  [1:0]oldRxBitsIn;
81 5 sfielding
reg [1:0] RxBitsInReg;
82 9 sfielding
reg [15:0] timeOutCnt;
83
reg RxWireActive;
84 2 sfielding
 
85
// buffer output state machine state codes:
86
`define WAIT_BUFFER_NOT_EMPTY 2'b00
87
`define WAIT_SIE_RX_READY 2'b01
88
`define SIE_RX_WRITE 2'b10
89
 
90
reg [1:0] bufferOutStMachCurrState;
91
 
92
 
93
always @(posedge clk) begin
94
  if (rst == 1'b1)
95
  begin
96
    bufferCnt <= 3'b000;
97 5 sfielding
  end
98 2 sfielding
  else begin
99
    if (incBufferCnt == 1'b1 && decBufferCnt == 1'b0)
100
      bufferCnt <= bufferCnt + 1'b1;
101
    else if (incBufferCnt == 1'b0 && decBufferCnt == 1'b1)
102
      bufferCnt <= bufferCnt - 1'b1;
103
  end
104
end
105
 
106
 
107
 
108
//Perform line rate clock recovery
109
//Recover the wire data, and store data to buffer
110
always @(posedge clk) begin
111
  if (rst == 1'b1)
112
  begin
113
    i <= 5'b00000;
114 5 sfielding
    incBufferCnt <= 1'b0;
115
    bufferInIndex <= 2'b00;
116
    buffer0 <= 2'b00;
117
    buffer1 <= 2'b00;
118
    buffer2 <= 2'b00;
119
    buffer3 <= 2'b00;
120 2 sfielding
    RxDataInTick <= 1'b0;
121 9 sfielding
    RxWireActive <= 1'b0;
122 5 sfielding
  end
123 2 sfielding
  else begin
124 5 sfielding
    RxBitsInReg <= RxBitsIn;      //sync to local clock to avoid metastability issues
125
    incBufferCnt <= 1'b0;         //default value
126
    oldRxBitsIn <= RxBitsInReg;
127 9 sfielding
    if (oldRxBitsIn != RxBitsInReg) begin  //if edge detected then
128 5 sfielding
      i <= 5'b00000;              //reset the counter
129 9 sfielding
      RxWireActive <= 1'b1;       // flag receive activity
130
    end
131
    else begin
132 5 sfielding
      i <= i + 1'b1;
133 9 sfielding
      RxWireActive <= 1'b0;
134
    end
135 5 sfielding
    if ( (fullSpeedRate == 1'b1 && i[1:0] == 2'b01) || (fullSpeedRate == 1'b0 && i == 5'b10000) )
136
    begin
137 2 sfielding
      RxDataInTick <= !RxDataInTick;
138 9 sfielding
      if (TxWireActiveDrive != 1'b1)  //do not read wire data when transmitter is active
139 2 sfielding
      begin
140
        incBufferCnt <= 1'b1;
141 5 sfielding
        bufferInIndex <= bufferInIndex + 1'b1;
142
        case (bufferInIndex)
143
          2'b00 : buffer0 <= RxBitsInReg;
144
          2'b01 : buffer1 <= RxBitsInReg;
145
          2'b10 : buffer2 <= RxBitsInReg;
146
          2'b11 : buffer3 <= RxBitsInReg;
147
        endcase
148 2 sfielding
      end
149 5 sfielding
    end
150 2 sfielding
  end
151
end
152
 
153 5 sfielding
 
154 2 sfielding
 
155
//read from buffer, and output to SIEReceiver
156
always @(posedge clk) begin
157
  if (rst == 1'b1)
158
  begin
159 5 sfielding
    decBufferCnt <= 1'b0;
160
    bufferOutIndex <= 2'b00;
161
    RxBitsOut <= 2'b00;
162
    SIERxWEn <= 1'b0;
163
    bufferOutStMachCurrState <= `WAIT_BUFFER_NOT_EMPTY;
164
  end
165 2 sfielding
  else begin
166 5 sfielding
    case (bufferOutStMachCurrState)
167
      `WAIT_BUFFER_NOT_EMPTY:
168
      begin
169
        if (bufferCnt != 3'b000)
170
          bufferOutStMachCurrState <= `WAIT_SIE_RX_READY;
171
      end
172
      `WAIT_SIE_RX_READY:
173
      begin
174
        if (SIERxRdyIn == 1'b1)
175
        begin
176
          SIERxWEn <= 1'b1;
177
          bufferOutStMachCurrState <= `SIE_RX_WRITE;
178
          decBufferCnt <= 1'b1;
179
          bufferOutIndex <= bufferOutIndex + 1'b1;
180
          case (bufferOutIndex)
181
            2'b00 :  RxBitsOut <= buffer0;
182
            2'b01 : RxBitsOut <= buffer1;
183
            2'b10 : RxBitsOut <= buffer2;
184
            2'b11 : RxBitsOut <= buffer3;
185
          endcase
186
        end
187
      end
188
      `SIE_RX_WRITE:
189
      begin
190
        SIERxWEn <= 1'b0;
191
        decBufferCnt <= 1'b0;
192
        bufferOutStMachCurrState <= `WAIT_BUFFER_NOT_EMPTY;
193
      end
194
    endcase
195 2 sfielding
  end
196
end
197
 
198 9 sfielding
//generate time out flag if no tx or rx activity
199
always @(posedge clk) begin
200
  if (rst) begin
201
    timeOutCnt <= 16'h0000;
202
    noActivityTimeOut <= 1'b0;
203
  end
204
  else begin
205
    if (TxWireActiveDrive == 1'b1 || RxWireActive == 1'b1)
206
      timeOutCnt <= 16'h0000;
207
    else
208
      timeOutCnt <= timeOutCnt + 1'b1;
209
    //if (timeOutCnt == `RX_PACKET_TOUT * `OVER_SAMPLE_RATE)
210
    if ( (fullSpeedRate == 1'b1 && timeOutCnt == `RX_PACKET_TOUT * `FS_OVER_SAMPLE_RATE)
211
          || (fullSpeedRate == 1'b0 && timeOutCnt == `RX_PACKET_TOUT * `LS_OVER_SAMPLE_RATE) )
212
    //if (timeOutCnt == 16'h200)  //temporary hack
213
      noActivityTimeOut <= 1'b1;
214
    else
215
      noActivityTimeOut <= 1'b0;
216
  end
217
end
218 5 sfielding
 
219 2 sfielding
 
220
 
221
 
222
endmodule

powered by: WebSVN 2.1.0

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