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

Subversion Repositories usbhostslave

[/] [usbhostslave/] [tags/] [rel_00_01_alpha/] [RTL/] [serialInterfaceEngine/] [readUSBWireData.v] - Blame information for rev 43

Go to most recent revision | 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
// $Id: readUSBWireData.v,v 1.1.1.1 2004-10-11 04:01:01 sfielding Exp $
45
//
46
// CVS Revision History
47
//
48
// $Log: not supported by cvs2svn $
49
//
50
 
51
`timescale 1ns / 1ps
52
`include "usbSerialInterfaceEngine_h.v"
53
 
54
module readUSBWireData (RxBitsIn, RxDataInTick, RxBitsOut, SIERxRdyIn, SIERxWEn, fullSpeedRate, disableWireRead, clk, rst);
55
input   [1:0] RxBitsIn;
56
output  RxDataInTick;
57
input   SIERxRdyIn;
58
input   clk;
59
input   fullSpeedRate;
60
input   rst;
61
input   disableWireRead;
62
output  [1:0] RxBitsOut;
63
output  SIERxWEn;
64
 
65
wire   [1:0] RxBitsIn;
66
reg    RxDataInTick;
67
wire   SIERxRdyIn;
68
wire   clk;
69
wire   fullSpeedRate;
70
wire   rst;
71
reg    [1:0] RxBitsOut;
72
reg    SIERxWEn;
73
 
74
// local registers
75
reg  [1:0]buffer0;
76
reg  [1:0]buffer1;
77
reg  [1:0]buffer2;
78
reg  [1:0]buffer3;
79
reg  [2:0]bufferCnt;
80
reg  [1:0]bufferInIndex;
81
reg  [1:0]bufferOutIndex;
82
reg decBufferCnt;
83
reg  [4:0]i;
84
reg incBufferCnt;
85
reg  [1:0]oldRxBitsIn;
86
 
87
// buffer output state machine state codes:
88
`define WAIT_BUFFER_NOT_EMPTY 2'b00
89
`define WAIT_SIE_RX_READY 2'b01
90
`define SIE_RX_WRITE 2'b10
91
 
92
reg [1:0] bufferOutStMachCurrState;
93
 
94
 
95
always @(posedge clk) begin
96
  if (rst == 1'b1)
97
  begin
98
    bufferCnt <= 3'b000;
99
        end
100
  else begin
101
    if (incBufferCnt == 1'b1 && decBufferCnt == 1'b0)
102
      bufferCnt <= bufferCnt + 1'b1;
103
    else if (incBufferCnt == 1'b0 && decBufferCnt == 1'b1)
104
      bufferCnt <= bufferCnt - 1'b1;
105
  end
106
end
107
 
108
 
109
 
110
//Perform line rate clock recovery
111
//Recover the wire data, and store data to buffer
112
always @(posedge clk) begin
113
  if (rst == 1'b1)
114
  begin
115
    i <= 5'b00000;
116
                incBufferCnt <= 1'b0;
117
                bufferInIndex <= 2'b00;
118
                buffer0 <= 2'b00;
119
                buffer1 <= 2'b00;
120
                buffer2 <= 2'b00;
121
                buffer3 <= 2'b00;
122
    RxDataInTick <= 1'b0;
123
        end
124
  else begin
125
          incBufferCnt <= 1'b0;         //default value
126
          oldRxBitsIn <= RxBitsIn;
127
          if (oldRxBitsIn != RxBitsIn)  //if edge detected then
128
                  i <= 5'b00000;              //reset the counter
129
          else
130
                  i <= i + 1'b1;
131
    if ( (fullSpeedRate == 1'b1 && i[1:0] == 2'b10) || (fullSpeedRate == 1'b0 && i == 5'b10000) )
132
          begin
133
      RxDataInTick <= !RxDataInTick;
134
      if (disableWireRead != 1'b1)  //do not read wire data when transmitter is active
135
      begin
136
        incBufferCnt <= 1'b1;
137
                    bufferInIndex <= bufferInIndex + 1'b1;
138
                    case (bufferInIndex)
139
                            2'b00 : buffer0 <= RxBitsIn;
140
                            2'b01 : buffer1 <= RxBitsIn;
141
                            2'b10 : buffer2 <= RxBitsIn;
142
                            2'b11 : buffer3 <= RxBitsIn;
143
                    endcase
144
      end
145
          end
146
  end
147
end
148
 
149
 
150
 
151
//read from buffer, and output to SIEReceiver
152
always @(posedge clk) begin
153
  if (rst == 1'b1)
154
  begin
155
                decBufferCnt <= 1'b0;
156
                bufferOutIndex <= 2'b00;
157
                RxBitsOut <= 2'b00;
158
                SIERxWEn <= 1'b0;
159
                bufferOutStMachCurrState <= `WAIT_BUFFER_NOT_EMPTY;
160
        end
161
  else begin
162
          case (bufferOutStMachCurrState)
163
                  `WAIT_BUFFER_NOT_EMPTY:
164
                  begin
165
                          if (bufferCnt != 3'b000)
166
                                  bufferOutStMachCurrState <= `WAIT_SIE_RX_READY;
167
                  end
168
                  `WAIT_SIE_RX_READY:
169
                  begin
170
                          if (SIERxRdyIn == 1'b1)
171
                          begin
172
                                  SIERxWEn <= 1'b1;
173
                                  bufferOutStMachCurrState <= `SIE_RX_WRITE;
174
                                  decBufferCnt <= 1'b1;
175
                                  bufferOutIndex <= bufferOutIndex + 1'b1;
176
                                  case (bufferOutIndex)
177
                            2'b00 :     RxBitsOut <= buffer0;
178
                                          2'b01 : RxBitsOut <= buffer1;
179
                                          2'b10 : RxBitsOut <= buffer2;
180
                                          2'b11 : RxBitsOut <= buffer3;
181
                                  endcase
182
                          end
183
                  end
184
                  `SIE_RX_WRITE:
185
                  begin
186
                          SIERxWEn <= 1'b0;
187
                          decBufferCnt <= 1'b0;
188
                          bufferOutStMachCurrState <= `WAIT_BUFFER_NOT_EMPTY;
189
                  end
190
          endcase
191
  end
192
end
193
 
194
 
195
 
196
 
197
 
198
endmodule

powered by: WebSVN 2.1.0

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