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

Subversion Repositories usb11

[/] [usb11/] [trunk/] [rtl/] [systemc/] [usb_core.h] - Blame information for rev 13

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfoltran
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  USB 1.1                                                    ////
4
////  Function IP Core                                           ////
5
////                                                             ////
6
////  SystemC Version: usb_core.h                                ////
7
////  Author: Alfredo Luiz Foltran Fialho                        ////
8
////          alfoltran@ig.com.br                                ////
9
////                                                             ////
10
////                                                             ////
11
/////////////////////////////////////////////////////////////////////
12
////                                                             ////
13
//// Verilog Version: usb1_core.v                                ////
14
//// Copyright (C) 2000-2002 Rudolf Usselmann                    ////
15
////                         www.asics.ws                        ////
16
////                         rudi@asics.ws                       ////
17
////                                                             ////
18
//// This source file may be used and distributed without        ////
19
//// restriction provided that this copyright statement is not   ////
20
//// removed from the file and that any derivative work contains ////
21
//// the original copyright notice and the associated disclaimer.////
22
////                                                             ////
23
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
24
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
25
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
26
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
27
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
28
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
29
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
30
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
31
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
32
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
33
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
34
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
35
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
36
////                                                             ////
37
/////////////////////////////////////////////////////////////////////
38
 
39
#ifndef USB_CORE_H
40
#define USB_CORE_H
41
 
42
#include "usb_defines.h"
43
 
44
#include "usb_phy.h"
45
#include "usb_sie.h"
46
#include "usb_ep0.h"
47
#include "usb_rom.h"
48
#include "usb_fifo64x8.h"
49
 
50
/*
51
                USB PHY Interface
52
                tx_dp, tx_dn, tx_oe,
53
                rx_d, rx_dp, rx_dn,
54
These pins are a semi-standard interface to USB 1.1 transceivers.
55
Just match up the signal names with the IOs of the transceiver.
56
 
57
                USB Misc
58
                phy_tx_mode, usb_rst,
59
The PHY supports single ended and differential output to the
60
transceiver. Depending on which device you are using, you have
61
to tie the phy_tx_mode high or low.
62
usb_rst is asserted whenever the host signals reset on the USB
63
bus. The USB core will internally reset itself automatically.
64
This output is provided for external logic that needs to be
65
reset when the USB bus is reset.
66
 
67
                Interrupts
68
                crc16_err,
69
crc16_err, indicates when a crc 16 error was detected on the
70
payload of a USB packet.
71
 
72
                Vendor Features
73
                v_set_int, v_set_feature, wValue,
74
                wIndex, vendor_data,
75
This signals allow to control vendor specific registers and logic
76
that can be manipulated and monitored via the control endpoint
77
through vendor defined commands.
78
 
79
                USB Status
80
                usb_busy, ep_sel,
81
usb_busy is asserted when the USB core is busy transferring
82
data ep_sel indicated the endpoint that is currently busy.
83
This information might be useful if one desires to reset/clear
84
the attached FIFOs and want to do this when the endpoint is idle.
85
 
86
                Endpoint Interface
87
This implementation supports 8 endpoints. Endpoint 0 is the
88
control endpoint and used internally. Endpoints 1-7 are available
89
to the user. replace 'N' with the endpoint number.
90
 
91
                epN_cfg,
92
This is a constant input used to configure the endpoint by ORing
93
these defines together and adding the max packet size for this
94
endpoint:
95
`IN and `OUT select the transfer direction for this endpoint
96
`ISO, `BULK and `INT determine the endpoint type
97
 
98
Example: "`BULK | `IN  | 14'd064" defines a BULK IN endpoint with
99
max packet size of 64 bytes
100
 
101
                epN_din,  epN_we, epN_full,
102
This is the OUT FIFO interface. If this is a IN endpoint, ground
103
all unused inputs and leave outputs unconnected.
104
 
105
                epN_dout, epN_re, epN_empty,
106
this is the IN FIFO interface. If this is a OUT endpoint ground
107
all unused inputs and leave outputs unconnected.
108
 
109
*/
110
 
111
SC_MODULE(usb_core) {
112
 
113
  public:
114
 
115
        sc_in<bool>                     clk_i;
116
        sc_in<bool>                     rst_i;
117
 
118
        // PHY Interface
119
        sc_out<bool>            tx_dp, tx_dn, tx_oe;
120
        sc_in<bool>                     rx_dp, rx_dn, rx_d;
121
        sc_in<bool>                     phy_tx_mode;
122
 
123
        // Misc
124
        sc_out<bool>            usb_rst;
125
 
126
        // Interrupts
127
        sc_out<bool>            crc16_err;
128
 
129
        // Vendor Features
130
        sc_out<bool>            v_set_int;
131
        sc_out<bool>            v_set_feature;
132
        sc_out<sc_uint<16> >wValue;
133
        sc_out<sc_uint<16> >wIndex;
134
        sc_in<sc_uint<16> >     vendor_data;
135
 
136
        // USB Status
137
        sc_out<bool>            usb_busy;
138
        sc_out<sc_uint<4> >     ep_sel;
139
 
140
        // Endpoint Interface
141
        // EP1
142
        sc_in<sc_uint<14> >     ep1_cfg;
143
        sc_in<sc_uint<8> >      ep1_din;
144
        sc_out<sc_uint<8> >     ep1_dout;
145
        sc_out<bool>            ep1_we, ep1_re;
146
        sc_in<bool>                     ep1_empty, ep1_full;
147
 
148
        // EP2
149
        sc_in<sc_uint<14> >     ep2_cfg;
150
        sc_in<sc_uint<8> >      ep2_din;
151
        sc_out<sc_uint<8> >     ep2_dout;
152
        sc_out<bool>            ep2_we, ep2_re;
153
        sc_in<bool>                     ep2_empty, ep2_full;
154
 
155
        // EP3
156
        sc_in<sc_uint<14> >     ep3_cfg;
157
        sc_in<sc_uint<8> >      ep3_din;
158
        sc_out<sc_uint<8> >     ep3_dout;
159
        sc_out<bool>            ep3_we, ep3_re;
160
        sc_in<bool>                     ep3_empty, ep3_full;
161
 
162
        // EP4
163
        sc_in<sc_uint<14> >     ep4_cfg;
164
        sc_in<sc_uint<8> >      ep4_din;
165
        sc_out<sc_uint<8> >     ep4_dout;
166
        sc_out<bool>            ep4_we, ep4_re;
167
        sc_in<bool>                     ep4_empty, ep4_full;
168
 
169
        // EP5
170
        sc_in<sc_uint<14> >     ep5_cfg;
171
        sc_in<sc_uint<8> >      ep5_din;
172
        sc_out<sc_uint<8> >     ep5_dout;
173
        sc_out<bool>            ep5_we, ep5_re;
174
        sc_in<bool>                     ep5_empty, ep5_full;
175
 
176
        // EP6
177
        sc_in<sc_uint<14> >     ep6_cfg;
178
        sc_in<sc_uint<8> >      ep6_din;
179
        sc_out<sc_uint<8> >     ep6_dout;
180
        sc_out<bool>            ep6_we, ep6_re;
181
        sc_in<bool>                     ep6_empty, ep6_full;
182
 
183
        // EP7
184
        sc_in<sc_uint<14> >     ep7_cfg;
185
        sc_in<sc_uint<8> >      ep7_din;
186
        sc_out<sc_uint<8> >     ep7_dout;
187
        sc_out<bool>            ep7_we, ep7_re;
188
        sc_in<bool>                     ep7_empty, ep7_full;
189
 
190
        // Local Signals
191
 
192
        // SIE Interface
193
        sc_signal<sc_uint<8> >  DataOut;
194
        sc_signal<bool>                 TxValid;
195
        sc_signal<bool>                 TxReady;
196
        sc_signal<sc_uint<8> >  DataIn;
197
        sc_signal<bool>                 RxValid;
198
        sc_signal<bool>                 RxActive;
199
        sc_signal<bool>                 RxError;
200
        sc_signal<sc_uint<2> >  LineState;
201
 
202
        // Internal Register File Interface
203
        sc_signal<sc_uint<7> >  funct_adr;                      // This function address (set by Controller)
204
        sc_signal<bool>                 int_to_set;                     // Set time out interrupt
205
        sc_signal<bool>                 int_seqerr_set;         // Set PID sequence error interrupt
206
        sc_signal<sc_uint<32> > frm_nat;                        // Frame number and time register
207
        sc_signal<bool>                 nse_err;                        // No such endpoint error
208
        sc_signal<bool>                 pid_cs_err;                     // PID CS error
209
        sc_signal<bool>                 crc5_err;                       // CRC5 error
210
 
211
        // Status Signals
212
        sc_signal<sc_uint<11> > frame_no;
213
        sc_signal<bool>                 addressed;
214
        sc_signal<bool>                 configured;
215
        sc_signal<bool>                 halt;
216
 
217
        // Data and Control Signals
218
        sc_signal<sc_uint<8> >  tx_data_st;
219
        sc_signal<sc_uint<8> >  rx_data_st;
220
        sc_signal<sc_uint<14> > cfg;
221
        sc_signal<bool>                 ep_empty;
222
        sc_signal<bool>                 ep_full;
223
        sc_signal<sc_uint<8> >  rx_size;
224
        sc_signal<bool>                 rx_done;
225
 
226
        // EP0 Signals
227
        sc_signal<sc_uint<8> >  ep0_din;
228
        sc_signal<sc_uint<8> >  ep0_dout;
229
        sc_signal<bool>                 ep0_re, ep0_we;
230
        sc_signal<sc_uint<8> >  ep0_size;
231
        sc_signal<sc_uint<8> >  ep0_ctrl_dout, ep0_ctrl_din;
232
        sc_signal<bool>                 ep0_ctrl_re, ep0_ctrl_we;
233
        sc_signal<sc_uint<4> >  ep0_ctrl_stat;
234
 
235
        // Control Pipe Interface
236
        sc_signal<bool>                 ctrl_setup, ctrl_in, ctrl_out;
237
        sc_signal<bool>                 send_stall;
238
        sc_signal<bool>                 token_valid;
239
        sc_signal<bool>                 rst_local;                      // Internal reset
240
 
241
        // ROM Signals
242
        sc_signal<sc_uint<8> >  rom_adr;
243
        sc_signal<sc_uint<8> >  rom_data;
244
 
245
        // FIFO Signals
246
        sc_signal<bool>                 idma_re, idma_we;
247
        sc_signal<bool>                 ep0_empty, ep0_full;
248
 
249
        sc_signal<bool>                 stat1, stat2;
250
 
251
        usb_phy                                 *i_phy;                         // PHY
252
        usb_sie                                 *i_sie;                         // SIE
253
        usb_ep0                                 *i_ep0;                         // EP0
254
        usb_rom                                 *i_rom;                         // ROM
255
        usb_fifo64x8                    *i_ff_in;                       // FIFO_IN
256
        usb_fifo64x8                    *i_ff_out;                      // FIFO_OUT
257
 
258
        // Internal Reset Function
259
        void rst_local_up(void);
260
 
261
        // Misc Functions
262
        void stat_up(void);
263
        void frame_no_up(void);
264
 
265
        // Muxes Functions
266
        void cfg_mux(void);
267
        void tx_data_mux(void);
268
        void ep_empty_mux(void);
269
        void ep_full_mux(void);
270
 
271
        // Decos Functions
272
        void ep_dout_deco(void);
273
        void ep_re_deco(void);
274
        void ep_we_deco(void);
275
 
276
        // Destructor
277
//      ~usb_core(void);
278
 
279
        SC_CTOR(usb_core) {
280
                SC_METHOD(rst_local_up);
281
                sensitive << clk_i.pos();
282
 
283
                SC_METHOD(stat_up);
284
                sensitive << stat1 << stat2;
285
                SC_METHOD(frame_no_up);
286
                sensitive << frm_nat;
287
 
288
                SC_METHOD(cfg_mux);
289
                sensitive << ep_sel << ep0_size << ep1_cfg << ep2_cfg << ep3_cfg;
290
                sensitive << ep4_cfg << ep5_cfg << ep6_cfg << ep7_cfg;
291
                SC_METHOD(tx_data_mux);
292
                sensitive << clk_i.pos();
293
                SC_METHOD(ep_empty_mux);
294
                sensitive << clk_i.pos();
295
                SC_METHOD(ep_full_mux);
296
                sensitive << ep_sel << ep0_full << ep1_full << ep2_full << ep3_full;
297
                sensitive << ep4_full << ep5_full << ep6_full << ep7_full;
298
 
299
                SC_METHOD(ep_dout_deco);
300
                sensitive << rx_data_st;
301
                SC_METHOD(ep_re_deco);
302
                sensitive << idma_re << ep_sel << ep1_empty << ep2_empty << ep3_empty;
303
                sensitive << ep4_empty << ep5_empty << ep6_empty << ep7_empty;
304
                SC_METHOD(ep_we_deco);
305
                sensitive << idma_we << ep_sel << ep1_full << ep2_full << ep3_full;
306
                sensitive << ep4_full << ep5_full << ep6_full << ep7_full;
307
 
308
                // PHY Instantiation and Binding
309
                i_phy = new usb_phy("PHY");
310
                i_phy->clk(clk_i);
311
                i_phy->rst(rst_i);                              // ONLY external reset
312
                i_phy->phy_tx_mode(phy_tx_mode);
313
                i_phy->usb_rst(usb_rst);
314
                i_phy->txdp(tx_dp);
315
                i_phy->txdn(tx_dn);
316
                i_phy->txoe(tx_oe);
317
                i_phy->rxd(rx_d);
318
                i_phy->rxdp(rx_dp);
319
                i_phy->rxdn(rx_dn);
320
                i_phy->DataOut_i(DataOut);
321
                i_phy->TxValid_i(TxValid);
322
                i_phy->TxReady_o(TxReady);
323
                i_phy->DataIn_o(DataIn);
324
                i_phy->RxValid_o(RxValid);
325
                i_phy->RxActive_o(RxActive);
326
                i_phy->RxError_o(RxError);
327
                i_phy->LineState_o(LineState);
328
 
329
                // SIE Instantiation and Binding
330
                i_sie = new usb_sie("SIE");
331
                i_sie->clk(clk_i);
332
                i_sie->rst(rst_local);
333
                i_sie->DataOut(DataOut);
334
                i_sie->TxValid(TxValid);
335
                i_sie->TxReady(TxReady);
336
                i_sie->DataIn(DataIn);
337
                i_sie->RxValid(RxValid);
338
                i_sie->RxActive(RxActive);
339
                i_sie->RxError(RxError);
340
                i_sie->token_valid(token_valid);
341
                i_sie->fa(funct_adr);
342
                i_sie->ep_sel(ep_sel);
343
                i_sie->x_busy(usb_busy);
344
                i_sie->int_crc16_set(crc16_err);
345
                i_sie->int_to_set(int_to_set);
346
                i_sie->int_seqerr_set(int_seqerr_set);
347
                i_sie->pid_cs_err(pid_cs_err);
348
                i_sie->crc5_err(crc5_err);
349
                i_sie->frm_nat(frm_nat);
350
                i_sie->nse_err(nse_err);
351
                i_sie->rx_size(rx_size);
352
                i_sie->rx_done(rx_done);
353
                i_sie->ctrl_setup(ctrl_setup);
354
                i_sie->ctrl_in(ctrl_in);
355
                i_sie->ctrl_out(ctrl_out);
356
                i_sie->csr(cfg);
357
                i_sie->tx_data_st(tx_data_st);
358
                i_sie->rx_data_st(rx_data_st);
359
                i_sie->idma_re(idma_re);
360
                i_sie->idma_we(idma_we);
361
                i_sie->ep_empty(ep_empty);
362
                i_sie->ep_full(ep_full);
363
                i_sie->send_stall(send_stall);
364
 
365
                // EP0 Instantiation and Binding
366
                i_ep0 = new usb_ep0("EP0");
367
                i_ep0->clk(clk_i);
368
                i_ep0->rst(rst_local);
369
                i_ep0->rom_adr(rom_adr);
370
                i_ep0->rom_data(rom_data);
371
                i_ep0->ctrl_setup(ctrl_setup);
372
                i_ep0->ctrl_in(ctrl_in);
373
                i_ep0->ctrl_out(ctrl_out);
374
                i_ep0->frame_no(frame_no);
375
                i_ep0->send_stall(send_stall);
376
                i_ep0->funct_adr(funct_adr);
377
                i_ep0->addressed(addressed);
378
                i_ep0->configured(configured);
379
                i_ep0->halt(halt);
380
                i_ep0->ep0_din(ep0_ctrl_dout);
381
                i_ep0->ep0_dout(ep0_ctrl_din);
382
                i_ep0->ep0_re(ep0_ctrl_re);
383
                i_ep0->ep0_we(ep0_ctrl_we);
384
                i_ep0->ep0_stat(ep0_ctrl_stat);
385
                i_ep0->ep0_size(ep0_size);
386
                i_ep0->v_set_int(v_set_int);
387
                i_ep0->v_set_feature(v_set_feature);
388
                i_ep0->wValue(wValue);
389
                i_ep0->wIndex(wIndex);
390
                i_ep0->vendor_data(vendor_data);
391
 
392
                // ROM Instantiation and Binding
393
                i_rom = new usb_rom("ROM");
394
                i_rom->clk(clk_i);
395
                i_rom->adr(rom_adr);
396
                i_rom->dout(rom_data);
397
 
398
                // FIFO_IN Instantiation and Binding
399
                i_ff_in = new usb_fifo64x8("FIFO_IN");
400
                i_ff_in->clk(clk_i);
401
                i_ff_in->rst(rst_i);
402
                i_ff_in->clr(usb_rst);
403
                i_ff_in->we(ep0_ctrl_we);
404
                i_ff_in->din(ep0_ctrl_din);
405
                i_ff_in->re(ep0_re);
406
                i_ff_in->dout(ep0_dout);
407
                i_ff_in->empty(ep0_empty);
408
                i_ff_in->full(stat2);
409
 
410
                // FIFO_OUT Instantiation and Binding
411
                i_ff_out = new usb_fifo64x8("FIFO_OUT");
412
                i_ff_out->clk(clk_i);
413
                i_ff_out->rst(rst_i);
414
                i_ff_out->clr(usb_rst);
415
                i_ff_out->we(ep0_we);
416
                i_ff_out->din(rx_data_st);
417
                i_ff_out->re(ep0_ctrl_re);
418
                i_ff_out->dout(ep0_ctrl_dout);
419
                i_ff_out->empty(stat1);
420
                i_ff_out->full(ep0_full);
421
        }
422
 
423
};
424
 
425
#endif
426
 

powered by: WebSVN 2.1.0

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