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

Subversion Repositories usbhostslave

[/] [usbhostslave/] [trunk/] [RTL/] [hostController/] [USBHostControlBI.v] - Blame information for rev 18

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

Line No. Rev Author Line
1 2 sfielding
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// USBHostControlBI.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 9 sfielding
`timescale 1ns / 1ps
45 2 sfielding
 
46 9 sfielding
 
47 2 sfielding
`include "usbHostControl_h.v"
48
 
49
module USBHostControlBI (address, dataIn, dataOut, writeEn,
50
  strobe_i,
51 18 sfielding
  busClk,
52
  rstSyncToBusClk,
53
  usbClk,
54
  rstSyncToUsbClk,
55 5 sfielding
  SOFSentIntOut, connEventIntOut, resumeIntOut, transDoneIntOut,
56
  TxTransTypeReg, TxSOFEnableReg,
57
  TxAddrReg, TxEndPReg, frameNumIn,
58
  RxPktStatusIn, RxPIDIn,
59
  connectStateIn,
60
  SOFSentIn, connEventIn, resumeIntIn, transDoneIn,
61 2 sfielding
  hostControlSelect,
62
  clrTransReq,
63
  preambleEn,
64
  SOFSync,
65
  TxLineState,
66
  LineDirectControlEn,
67
  fullSpeedPol,
68
  fullSpeedRate,
69 14 sfielding
  transReq,
70 16 sfielding
  isoEn,
71
  SOFTimer
72 2 sfielding
  );
73
input [3:0] address;
74
input [7:0] dataIn;
75
input writeEn;
76
input strobe_i;
77 18 sfielding
input busClk;
78
input rstSyncToBusClk;
79
input usbClk;
80
input rstSyncToUsbClk;
81 2 sfielding
output [7:0] dataOut;
82
output SOFSentIntOut;
83
output connEventIntOut;
84
output resumeIntOut;
85
output transDoneIntOut;
86
 
87
output [1:0] TxTransTypeReg;
88
output TxSOFEnableReg;
89
output [6:0] TxAddrReg;
90
output [3:0] TxEndPReg;
91
input [10:0] frameNumIn;
92
input [7:0] RxPktStatusIn;
93
input [3:0] RxPIDIn;
94
input [1:0] connectStateIn;
95
input SOFSentIn;
96
input connEventIn;
97
input resumeIntIn;
98
input transDoneIn;
99
input hostControlSelect;
100
input clrTransReq;
101
output preambleEn;
102
output SOFSync;
103
output [1:0] TxLineState;
104
output LineDirectControlEn;
105
output fullSpeedPol;
106
output fullSpeedRate;
107
output transReq;
108 14 sfielding
output isoEn;     //enable isochronous mode
109 16 sfielding
input [15:0] SOFTimer;
110 2 sfielding
 
111
wire [3:0] address;
112
wire [7:0] dataIn;
113
wire writeEn;
114
wire strobe_i;
115 18 sfielding
wire busClk;
116
wire rstSyncToBusClk;
117
wire usbClk;
118
wire rstSyncToUsbClk;
119 2 sfielding
reg [7:0] dataOut;
120
 
121
reg SOFSentIntOut;
122
reg connEventIntOut;
123
reg resumeIntOut;
124
reg transDoneIntOut;
125
 
126
reg [1:0] TxTransTypeReg;
127
reg TxSOFEnableReg;
128
reg [6:0] TxAddrReg;
129
reg [3:0] TxEndPReg;
130
wire [10:0] frameNumIn;
131
wire [7:0] RxPktStatusIn;
132
wire [3:0] RxPIDIn;
133
wire [1:0] connectStateIn;
134
 
135
wire SOFSentIn;
136
wire connEventIn;
137
wire resumeIntIn;
138
wire transDoneIn;
139
wire hostControlSelect;
140
wire clrTransReq;
141
reg preambleEn;
142
reg SOFSync;
143
reg [1:0] TxLineState;
144
reg LineDirectControlEn;
145
reg fullSpeedPol;
146
reg fullSpeedRate;
147
reg transReq;
148 14 sfielding
reg isoEn;
149 16 sfielding
wire [15:0] SOFTimer;
150 2 sfielding
 
151
//internal wire and regs
152
reg [1:0] TxControlReg;
153
reg [4:0] TxLineControlReg;
154
reg clrSOFReq;
155
reg clrConnEvtReq;
156
reg clrResInReq;
157
reg clrTransDoneReq;
158
reg SOFSentInt;
159
reg connEventInt;
160
reg resumeInt;
161
reg transDoneInt;
162
reg [3:0] interruptMaskReg;
163
reg setTransReq;
164
 
165 18 sfielding
//clock domain crossing sync registers
166
//STB = Sync To Busclk
167
reg [1:0] TxTransTypeRegSTB;
168
reg TxSOFEnableRegSTB;
169
reg [6:0] TxAddrRegSTB;
170
reg [3:0] TxEndPRegSTB;
171
reg preambleEnSTB;
172
reg SOFSyncSTB;
173
reg [1:0] TxLineStateSTB;
174
reg LineDirectControlEnSTB;
175
reg fullSpeedPolSTB;
176
reg fullSpeedRateSTB;
177
reg transReqSTB;
178
reg isoEnSTB;
179
reg [10:0] frameNumInSTB;
180
reg [7:0] RxPktStatusInSTB;
181
reg [3:0] RxPIDInSTB;
182
reg [1:0] connectStateInSTB;
183
reg SOFSentInSTB;
184
reg connEventInSTB;
185
reg resumeIntInSTB;
186
reg transDoneInSTB;
187
reg clrTransReqSTB;
188
reg [15:0] SOFTimerSTB;
189
 
190
 
191 2 sfielding
//sync write demux
192 18 sfielding
always @(posedge busClk)
193 2 sfielding
begin
194 18 sfielding
  if (rstSyncToBusClk == 1'b1) begin
195
    isoEnSTB <= 1'b0;
196
    preambleEnSTB <= 1'b0;
197
    SOFSyncSTB <= 1'b0;
198
    TxTransTypeRegSTB <= 2'b00;
199 14 sfielding
    TxLineControlReg <= 5'h00;
200 18 sfielding
    TxSOFEnableRegSTB <= 1'b0;
201
    TxAddrRegSTB <= 7'h00;
202
    TxEndPRegSTB <= 4'h0;
203 14 sfielding
    interruptMaskReg <= 4'h0;
204 5 sfielding
  end
205 14 sfielding
  else begin
206
    clrSOFReq <= 1'b0;
207
    clrConnEvtReq <= 1'b0;
208
    clrResInReq <= 1'b0;
209
    clrTransDoneReq <= 1'b0;
210
    setTransReq <= 1'b0;
211
    if (writeEn == 1'b1 && strobe_i == 1'b1 && hostControlSelect == 1'b1)
212
    begin
213
      case (address)
214
        `TX_CONTROL_REG : begin
215 18 sfielding
          isoEnSTB <= dataIn[`ISO_ENABLE_BIT];
216
          preambleEnSTB <= dataIn[`PREAMBLE_ENABLE_BIT];
217
          SOFSyncSTB <= dataIn[`SOF_SYNC_BIT];
218 14 sfielding
          setTransReq <= dataIn[`TRANS_REQ_BIT];
219
        end
220 18 sfielding
        `TX_TRANS_TYPE_REG : TxTransTypeRegSTB <= dataIn[1:0];
221 14 sfielding
        `TX_LINE_CONTROL_REG : TxLineControlReg <= dataIn[4:0];
222 18 sfielding
        `TX_SOF_ENABLE_REG : TxSOFEnableRegSTB <= dataIn[`SOF_EN_BIT];
223
        `TX_ADDR_REG : TxAddrRegSTB <= dataIn[6:0];
224
        `TX_ENDP_REG : TxEndPRegSTB <= dataIn[3:0];
225 14 sfielding
        `INTERRUPT_STATUS_REG :  begin
226
          clrSOFReq <= dataIn[`SOF_SENT_BIT];
227
          clrConnEvtReq <= dataIn[`CONNECTION_EVENT_BIT];
228
          clrResInReq <= dataIn[`RESUME_INT_BIT];
229
          clrTransDoneReq <= dataIn[`TRANS_DONE_BIT];
230
        end
231
        `INTERRUPT_MASK_REG  : interruptMaskReg <= dataIn[3:0];
232
      endcase
233
    end
234
  end
235 2 sfielding
end
236
 
237
//interrupt control
238 18 sfielding
always @(posedge busClk)
239 2 sfielding
begin
240 18 sfielding
  if (rstSyncToBusClk == 1'b1) begin
241 5 sfielding
    SOFSentInt <= 1'b0;
242
    connEventInt <= 1'b0;
243 14 sfielding
    resumeInt <= 1'b0;
244
    transDoneInt <= 1'b0;
245
  end
246
  else begin
247 18 sfielding
    if (SOFSentInSTB == 1'b1)
248 14 sfielding
      SOFSentInt <= 1'b1;
249
    else if (clrSOFReq == 1'b1)
250
      SOFSentInt <= 1'b0;
251 5 sfielding
 
252 18 sfielding
    if (connEventInSTB == 1'b1)
253 14 sfielding
      connEventInt <= 1'b1;
254
    else if (clrConnEvtReq == 1'b1)
255
      connEventInt <= 1'b0;
256
 
257 18 sfielding
    if (resumeIntInSTB == 1'b1)
258 14 sfielding
      resumeInt <= 1'b1;
259
    else if (clrResInReq == 1'b1)
260
      resumeInt <= 1'b0;
261 2 sfielding
 
262 18 sfielding
    if (transDoneInSTB == 1'b1)
263 14 sfielding
      transDoneInt <= 1'b1;
264
    else if (clrTransDoneReq == 1'b1)
265
      transDoneInt <= 1'b0;
266
  end
267 2 sfielding
end
268
 
269
//mask interrupts
270
always @(interruptMaskReg or transDoneInt or resumeInt or connEventInt or SOFSentInt) begin
271
  transDoneIntOut <= transDoneInt & interruptMaskReg[`TRANS_DONE_BIT];
272
  resumeIntOut <= resumeInt & interruptMaskReg[`RESUME_INT_BIT];
273
  connEventIntOut <= connEventInt & interruptMaskReg[`CONNECTION_EVENT_BIT];
274
  SOFSentIntOut <= SOFSentInt & interruptMaskReg[`SOF_SENT_BIT];
275
end
276
 
277
//transaction request set/clear
278 18 sfielding
//Since 'busClk' can be a higher freq than 'usbClk',
279
//'setTransReq' must be delayed with respect to other control signals, thus
280
//ensuring that control signals have been clocked through to 'usbClk' clock
281
//domain before the transaction request is asserted.
282
//Not sure this is required because there is at least two 'usbClk' ticks between
283
//detection of 'transReq' and sampling of related control signals.always @(posedge busClk)
284
always @(posedge busClk)
285 2 sfielding
begin
286 18 sfielding
  if (rstSyncToBusClk == 1'b1) begin
287
    transReqSTB <= 1'b0;
288 14 sfielding
  end
289
  else begin
290
    if (setTransReq == 1'b1)
291 18 sfielding
      transReqSTB <= 1'b1;
292
    else if (clrTransReqSTB == 1'b1)
293
      transReqSTB <= 1'b0;
294 14 sfielding
  end
295 2 sfielding
end
296
 
297
//break out control signals
298
always @(TxControlReg or TxLineControlReg) begin
299 18 sfielding
  TxLineStateSTB <= TxLineControlReg[`TX_LINE_STATE_MSBIT:`TX_LINE_STATE_LSBIT];
300
  LineDirectControlEnSTB <= TxLineControlReg[`DIRECT_CONTROL_BIT];
301
  fullSpeedPolSTB <= TxLineControlReg[`FULL_SPEED_LINE_POLARITY_BIT];
302
  fullSpeedRateSTB <= TxLineControlReg[`FULL_SPEED_LINE_RATE_BIT];
303 2 sfielding
end
304
 
305
// async read mux
306
always @(address or
307 18 sfielding
  TxControlReg or TxTransTypeRegSTB or TxLineControlReg or TxSOFEnableRegSTB or
308
  TxAddrRegSTB or TxEndPRegSTB or frameNumInSTB or
309 5 sfielding
  SOFSentInt or connEventInt or resumeInt or transDoneInt or
310 18 sfielding
  interruptMaskReg or RxPktStatusInSTB or RxPIDInSTB or connectStateInSTB or
311
  preambleEnSTB or SOFSyncSTB or transReqSTB or isoEnSTB or SOFTimer)
312 2 sfielding
begin
313 5 sfielding
  case (address)
314 18 sfielding
      `TX_CONTROL_REG : dataOut <= {4'b0000, isoEnSTB, preambleEnSTB, SOFSyncSTB, transReqSTB} ;
315
      `TX_TRANS_TYPE_REG : dataOut <= {6'b000000, TxTransTypeRegSTB};
316 5 sfielding
      `TX_LINE_CONTROL_REG : dataOut <= {3'b000, TxLineControlReg};
317 18 sfielding
      `TX_SOF_ENABLE_REG : dataOut <= {7'b0000000, TxSOFEnableRegSTB};
318
      `TX_ADDR_REG : dataOut <= {1'b0, TxAddrRegSTB};
319
      `TX_ENDP_REG : dataOut <= {4'h0, TxEndPRegSTB};
320
      `FRAME_NUM_MSB_REG : dataOut <= {5'b00000, frameNumInSTB[10:8]};
321
      `FRAME_NUM_LSB_REG : dataOut <= frameNumInSTB[7:0];
322 5 sfielding
      `INTERRUPT_STATUS_REG :  dataOut <= {4'h0, SOFSentInt, connEventInt, resumeInt, transDoneInt};
323
      `INTERRUPT_MASK_REG  : dataOut <= {4'h0, interruptMaskReg};
324 18 sfielding
      `RX_STATUS_REG  : dataOut <= RxPktStatusInSTB;
325
      `RX_PID_REG  : dataOut <= {4'b0000, RxPIDInSTB};
326
      `RX_CONNECT_STATE_REG : dataOut <= {6'b000000, connectStateInSTB};
327 16 sfielding
      `HOST_SOF_TIMER_MSB_REG : dataOut <= SOFTimer[15:8];
328 2 sfielding
      default: dataOut <= 8'h00;
329 5 sfielding
  endcase
330 2 sfielding
end
331
 
332 18 sfielding
//re-sync from busClk to usbClk. 
333
always @(posedge usbClk) begin
334
  if (rstSyncToUsbClk == 1'b1) begin
335
    isoEn <= 1'b0;
336
    preambleEn <= 1'b0;
337
    SOFSync <= 1'b0;
338
    TxTransTypeReg <= 2'b00;
339
    TxSOFEnableReg <= 1'b0;
340
    TxAddrReg <= 7'h00;
341
    TxEndPReg <= 4'h0;
342
    TxLineState <= 2'b00;
343
    LineDirectControlEn <= 1'b0;
344
    fullSpeedPol <= 1'b0;
345
    fullSpeedRate <= 1'b0;
346
    transReq <= 1'b0;
347
  end
348
  else begin
349
    isoEn <= isoEnSTB;
350
    preambleEn <= preambleEnSTB;
351
    SOFSync <= SOFSyncSTB;
352
    TxTransTypeReg <= TxTransTypeRegSTB;
353
    TxSOFEnableReg <= TxSOFEnableRegSTB;
354
    TxAddrReg <= TxAddrRegSTB;
355
    TxEndPReg <= TxEndPRegSTB;
356
    TxLineState <= TxLineStateSTB;
357
    LineDirectControlEn <= LineDirectControlEnSTB;
358
    fullSpeedPol <= fullSpeedPolSTB;
359
    fullSpeedRate <= fullSpeedRateSTB;
360
    transReq <= transReqSTB;
361
  end
362
end
363 2 sfielding
 
364 18 sfielding
//re-sync from usbClk to busClk. Since 'clrTransReq', 'transDoneIn' etc are only asserted 
365
//for one 'usbClk' tick, busClk freq must be greater than or equal to usbClk freq
366
always @(posedge busClk) begin
367
  frameNumInSTB <= frameNumIn;
368
  RxPktStatusInSTB <= RxPktStatusIn;
369
  RxPIDInSTB <= RxPIDIn;
370
  connectStateInSTB <= connectStateIn;
371
  SOFSentInSTB <= SOFSentIn;
372
  connEventInSTB <= connEventIn;
373
  resumeIntInSTB <= resumeIntIn;
374
  transDoneInSTB <= transDoneIn;
375
  clrTransReqSTB <= clrTransReq;
376
  SOFTimerSTB <= SOFTimer;
377
end
378
 
379
 
380
endmodule

powered by: WebSVN 2.1.0

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