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 |
|
|
// $Id: USBHostControlBI.v,v 1.1.1.1 2004-10-11 04:00:56 sfielding Exp $
|
45 |
|
|
//
|
46 |
|
|
// CVS Revision History
|
47 |
|
|
//
|
48 |
|
|
// $Log: not supported by cvs2svn $
|
49 |
|
|
//
|
50 |
|
|
|
51 |
|
|
`include "usbHostControl_h.v"
|
52 |
|
|
|
53 |
|
|
module USBHostControlBI (address, dataIn, dataOut, writeEn,
|
54 |
|
|
strobe_i,
|
55 |
|
|
clk, rst,
|
56 |
|
|
SOFSentIntOut, connEventIntOut, resumeIntOut, transDoneIntOut,
|
57 |
|
|
TxTransTypeReg, TxSOFEnableReg,
|
58 |
|
|
TxAddrReg, TxEndPReg, frameNumIn,
|
59 |
|
|
RxPktStatusIn, RxPIDIn,
|
60 |
|
|
connectStateIn,
|
61 |
|
|
SOFSentIn, connEventIn, resumeIntIn, transDoneIn,
|
62 |
|
|
hostControlSelect,
|
63 |
|
|
clrTransReq,
|
64 |
|
|
preambleEn,
|
65 |
|
|
SOFSync,
|
66 |
|
|
TxLineState,
|
67 |
|
|
LineDirectControlEn,
|
68 |
|
|
fullSpeedPol,
|
69 |
|
|
fullSpeedRate,
|
70 |
|
|
transReq
|
71 |
|
|
);
|
72 |
|
|
input [3:0] address;
|
73 |
|
|
input [7:0] dataIn;
|
74 |
|
|
input writeEn;
|
75 |
|
|
input strobe_i;
|
76 |
|
|
input clk;
|
77 |
|
|
input rst;
|
78 |
|
|
output [7:0] dataOut;
|
79 |
|
|
output SOFSentIntOut;
|
80 |
|
|
output connEventIntOut;
|
81 |
|
|
output resumeIntOut;
|
82 |
|
|
output transDoneIntOut;
|
83 |
|
|
|
84 |
|
|
output [1:0] TxTransTypeReg;
|
85 |
|
|
output TxSOFEnableReg;
|
86 |
|
|
output [6:0] TxAddrReg;
|
87 |
|
|
output [3:0] TxEndPReg;
|
88 |
|
|
input [10:0] frameNumIn;
|
89 |
|
|
input [7:0] RxPktStatusIn;
|
90 |
|
|
input [3:0] RxPIDIn;
|
91 |
|
|
input [1:0] connectStateIn;
|
92 |
|
|
input SOFSentIn;
|
93 |
|
|
input connEventIn;
|
94 |
|
|
input resumeIntIn;
|
95 |
|
|
input transDoneIn;
|
96 |
|
|
input hostControlSelect;
|
97 |
|
|
input clrTransReq;
|
98 |
|
|
output preambleEn;
|
99 |
|
|
output SOFSync;
|
100 |
|
|
output [1:0] TxLineState;
|
101 |
|
|
output LineDirectControlEn;
|
102 |
|
|
output fullSpeedPol;
|
103 |
|
|
output fullSpeedRate;
|
104 |
|
|
output transReq;
|
105 |
|
|
|
106 |
|
|
wire [3:0] address;
|
107 |
|
|
wire [7:0] dataIn;
|
108 |
|
|
wire writeEn;
|
109 |
|
|
wire strobe_i;
|
110 |
|
|
wire clk;
|
111 |
|
|
wire rst;
|
112 |
|
|
reg [7:0] dataOut;
|
113 |
|
|
|
114 |
|
|
reg SOFSentIntOut;
|
115 |
|
|
reg connEventIntOut;
|
116 |
|
|
reg resumeIntOut;
|
117 |
|
|
reg transDoneIntOut;
|
118 |
|
|
|
119 |
|
|
reg [1:0] TxTransTypeReg;
|
120 |
|
|
reg TxSOFEnableReg;
|
121 |
|
|
reg [6:0] TxAddrReg;
|
122 |
|
|
reg [3:0] TxEndPReg;
|
123 |
|
|
wire [10:0] frameNumIn;
|
124 |
|
|
wire [7:0] RxPktStatusIn;
|
125 |
|
|
wire [3:0] RxPIDIn;
|
126 |
|
|
wire [1:0] connectStateIn;
|
127 |
|
|
|
128 |
|
|
wire SOFSentIn;
|
129 |
|
|
wire connEventIn;
|
130 |
|
|
wire resumeIntIn;
|
131 |
|
|
wire transDoneIn;
|
132 |
|
|
wire hostControlSelect;
|
133 |
|
|
wire clrTransReq;
|
134 |
|
|
reg preambleEn;
|
135 |
|
|
reg SOFSync;
|
136 |
|
|
reg [1:0] TxLineState;
|
137 |
|
|
reg LineDirectControlEn;
|
138 |
|
|
reg fullSpeedPol;
|
139 |
|
|
reg fullSpeedRate;
|
140 |
|
|
reg transReq;
|
141 |
|
|
|
142 |
|
|
//internal wire and regs
|
143 |
|
|
reg [1:0] TxControlReg;
|
144 |
|
|
reg [4:0] TxLineControlReg;
|
145 |
|
|
reg clrSOFReq;
|
146 |
|
|
reg clrConnEvtReq;
|
147 |
|
|
reg clrResInReq;
|
148 |
|
|
reg clrTransDoneReq;
|
149 |
|
|
reg SOFSentInt;
|
150 |
|
|
reg connEventInt;
|
151 |
|
|
reg resumeInt;
|
152 |
|
|
reg transDoneInt;
|
153 |
|
|
reg [3:0] interruptMaskReg;
|
154 |
|
|
reg setTransReq;
|
155 |
|
|
|
156 |
|
|
//sync write demux
|
157 |
|
|
always @(posedge clk)
|
158 |
|
|
begin
|
159 |
|
|
clrSOFReq <= 1'b0;
|
160 |
|
|
clrConnEvtReq <= 1'b0;
|
161 |
|
|
clrResInReq <= 1'b0;
|
162 |
|
|
clrTransDoneReq <= 1'b0;
|
163 |
|
|
setTransReq <= 1'b0;
|
164 |
|
|
if (writeEn == 1'b1 && strobe_i == 1'b1 && hostControlSelect == 1'b1)
|
165 |
|
|
begin
|
166 |
|
|
case (address)
|
167 |
|
|
`TX_CONTROL_REG : begin
|
168 |
|
|
preambleEn <= dataIn[2];
|
169 |
|
|
SOFSync <= dataIn[1];
|
170 |
|
|
setTransReq <= dataIn[0];
|
171 |
|
|
end
|
172 |
|
|
`TX_TRANS_TYPE_REG : TxTransTypeReg <= dataIn[1:0];
|
173 |
|
|
`TX_LINE_CONTROL_REG : TxLineControlReg <= dataIn[4:0];
|
174 |
|
|
`TX_SOF_ENABLE_REG : TxSOFEnableReg <= dataIn[0];
|
175 |
|
|
`TX_ADDR_REG : TxAddrReg <= dataIn[6:0];
|
176 |
|
|
`TX_ENDP_REG : TxEndPReg <= dataIn[3:0];
|
177 |
|
|
`INTERRUPT_STATUS_REG : begin
|
178 |
|
|
clrSOFReq <= dataIn[3];
|
179 |
|
|
clrConnEvtReq <= dataIn[2];
|
180 |
|
|
clrResInReq <= dataIn[1];
|
181 |
|
|
clrTransDoneReq <= dataIn[0];
|
182 |
|
|
end
|
183 |
|
|
`INTERRUPT_MASK_REG : interruptMaskReg <= dataIn[3:0];
|
184 |
|
|
endcase
|
185 |
|
|
end
|
186 |
|
|
end
|
187 |
|
|
|
188 |
|
|
//interrupt control
|
189 |
|
|
always @(posedge clk)
|
190 |
|
|
begin
|
191 |
|
|
if (SOFSentIn == 1'b1)
|
192 |
|
|
SOFSentInt <= 1'b1;
|
193 |
|
|
else if (clrSOFReq == 1'b1)
|
194 |
|
|
SOFSentInt <= 1'b0;
|
195 |
|
|
|
196 |
|
|
if (connEventIn == 1'b1)
|
197 |
|
|
connEventInt <= 1'b1;
|
198 |
|
|
else if (clrConnEvtReq == 1'b1)
|
199 |
|
|
connEventInt <= 1'b0;
|
200 |
|
|
|
201 |
|
|
if (resumeIntIn == 1'b1)
|
202 |
|
|
resumeInt <= 1'b1;
|
203 |
|
|
else if (clrResInReq == 1'b1)
|
204 |
|
|
resumeInt <= 1'b0;
|
205 |
|
|
|
206 |
|
|
if (transDoneIn == 1'b1)
|
207 |
|
|
transDoneInt <= 1'b1;
|
208 |
|
|
else if (clrTransDoneReq == 1'b1)
|
209 |
|
|
transDoneInt <= 1'b0;
|
210 |
|
|
end
|
211 |
|
|
|
212 |
|
|
//mask interrupts
|
213 |
|
|
always @(interruptMaskReg or transDoneInt or resumeInt or connEventInt or SOFSentInt) begin
|
214 |
|
|
transDoneIntOut <= transDoneInt & interruptMaskReg[`TRANS_DONE_BIT];
|
215 |
|
|
resumeIntOut <= resumeInt & interruptMaskReg[`RESUME_INT_BIT];
|
216 |
|
|
connEventIntOut <= connEventInt & interruptMaskReg[`CONNECTION_EVENT_BIT];
|
217 |
|
|
SOFSentIntOut <= SOFSentInt & interruptMaskReg[`SOF_SENT_BIT];
|
218 |
|
|
end
|
219 |
|
|
|
220 |
|
|
//transaction request set/clear
|
221 |
|
|
always @(posedge clk)
|
222 |
|
|
begin
|
223 |
|
|
if (setTransReq == 1'b1)
|
224 |
|
|
transReq <= 1'b1;
|
225 |
|
|
else if (clrTransReq == 1'b1)
|
226 |
|
|
transReq <= 1'b0;
|
227 |
|
|
end
|
228 |
|
|
|
229 |
|
|
//break out control signals
|
230 |
|
|
always @(TxControlReg or TxLineControlReg) begin
|
231 |
|
|
TxLineState <= TxLineControlReg[`TX_LINE_STATE_MSBIT:`TX_LINE_STATE_LSBIT];
|
232 |
|
|
LineDirectControlEn <= TxLineControlReg[`DIRECT_CONTROL_BIT];
|
233 |
|
|
fullSpeedPol <= TxLineControlReg[`FULL_SPEED_LINE_POLARITY_BIT];
|
234 |
|
|
fullSpeedRate <= TxLineControlReg[`FULL_SPEED_LINE_RATE_BIT];
|
235 |
|
|
end
|
236 |
|
|
|
237 |
|
|
// async read mux
|
238 |
|
|
always @(address or
|
239 |
|
|
TxControlReg or TxTransTypeReg or TxLineControlReg or TxSOFEnableReg or
|
240 |
|
|
TxAddrReg or TxEndPReg or frameNumIn or
|
241 |
|
|
SOFSentInt or connEventInt or resumeInt or transDoneInt or
|
242 |
|
|
interruptMaskReg or RxPktStatusIn or RxPIDIn or connectStateIn or
|
243 |
|
|
preambleEn or SOFSync or transReq)
|
244 |
|
|
begin
|
245 |
|
|
case (address)
|
246 |
|
|
`TX_CONTROL_REG : dataOut <= {5'b00000, preambleEn, SOFSync, transReq} ;
|
247 |
|
|
`TX_TRANS_TYPE_REG : dataOut <= {6'b000000, TxTransTypeReg};
|
248 |
|
|
`TX_LINE_CONTROL_REG : dataOut <= {3'b000, TxLineControlReg};
|
249 |
|
|
`TX_SOF_ENABLE_REG : dataOut <= {7'b0000000, TxSOFEnableReg};
|
250 |
|
|
`TX_ADDR_REG : dataOut <= {1'b0, TxAddrReg};
|
251 |
|
|
`TX_ENDP_REG : dataOut <= {4'h0, TxEndPReg};
|
252 |
|
|
`FRAME_NUM_MSB_REG : dataOut <= frameNumIn[10:3];
|
253 |
|
|
`FRAME_NUM_LSB_REG : dataOut <= {5'b00000, frameNumIn[2:0]};
|
254 |
|
|
`INTERRUPT_STATUS_REG : dataOut <= {4'h0, SOFSentInt, connEventInt, resumeInt, transDoneInt};
|
255 |
|
|
`INTERRUPT_MASK_REG : dataOut <= {4'h0, interruptMaskReg};
|
256 |
|
|
`RX_STATUS_REG : dataOut <= RxPktStatusIn;
|
257 |
|
|
`RX_PID_REG : dataOut <= {4'b0000, RxPIDIn};
|
258 |
|
|
`RX_CONNECT_STATE_REG : dataOut <= {6'b000000, connectStateIn};
|
259 |
|
|
default: dataOut <= 8'h00;
|
260 |
|
|
endcase
|
261 |
|
|
end
|
262 |
|
|
|
263 |
|
|
|
264 |
|
|
endmodule
|