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

Subversion Repositories usbhostslave

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

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

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

powered by: WebSVN 2.1.0

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