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

Subversion Repositories usb2uart

[/] [usb2uart/] [trunk/] [rtl/] [usb1_core/] [usb1_pl.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dinesha
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  Protocol Layer                                             ////
4
////  This block is typically referred to as the SEI in USB      ////
5
////  Specification. It encapsulates the Packet Assembler,       ////
6
////  disassembler, protocol engine and internal DMA             ////
7
////                                                             ////
8
////  Author: Rudolf Usselmann                                   ////
9
////          rudi@asics.ws                                      ////
10
////                                                             ////
11
////                                                             ////
12
////  Downloaded from: http://www.opencores.org/cores/usb1_fucnt/////
13
////                                                             ////
14
/////////////////////////////////////////////////////////////////////
15
////                                                             ////
16
//// Copyright (C) 2000-2002 Rudolf Usselmann                    ////
17
////                         www.asics.ws                        ////
18
////                         rudi@asics.ws                       ////
19
////                                                             ////
20
//// This source file may be used and distributed without        ////
21
//// restriction provided that this copyright statement is not   ////
22
//// removed from the file and that any derivative work contains ////
23
//// the original copyright notice and the associated disclaimer.////
24
////                                                             ////
25
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
26
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
27
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
28
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
29
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
30
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
31
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
32
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
33
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
34
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
35
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
36
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
37
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
38
////                                                             ////
39
/////////////////////////////////////////////////////////////////////
40
 
41
//  CVS Log
42
//
43
//  $Id: usb1_pl.v,v 1.2 2002-09-25 06:06:49 rudi Exp $
44
//
45
//  $Date: 2002-09-25 06:06:49 $
46
//  $Revision: 1.2 $
47
//  $Author: rudi $
48
//  $Locker:  $
49
//  $State: Exp $
50
//
51
// Change History:
52
//               $Log: not supported by cvs2svn $
53
//               Revision 1.1.1.1  2002/09/19 12:07:28  rudi
54
//               Initial Checkin
55
//
56
//
57
//
58
//
59
//
60
//
61
//
62
//
63
//
64
 
65
module usb1_pl( clk, rst,
66
 
67
                // UTMI Interface
68
                rx_data, rx_valid, rx_active, rx_err,
69
                tx_data, tx_valid, tx_valid_last, tx_ready,
70
                tx_first, tx_valid_out,
71
 
72
                token_valid,
73
 
74
                // Register File Interface
75
                fa,
76
                ep_sel,
77
                x_busy,
78
                int_crc16_set, int_to_set, int_seqerr_set,
79
 
80
                // Misc
81
                frm_nat,
82
                pid_cs_err, nse_err,
83
                crc5_err,
84
                rx_size, rx_done,
85
                ctrl_setup, ctrl_in, ctrl_out,
86
 
87
                // Block Frames
88
                ep_bf_en, ep_bf_size,
89
                dropped_frame, misaligned_frame,
90
 
91
                // EP Interface
92
                csr,
93
                tx_data_st,
94
                rx_ctrl_data,
95
                rx_ctrl_data_d,
96
                rx_ctrl_dvalid,
97
                rx_ctrl_ddone,
98
                idma_re, idma_we,
99
                ep_empty, ep_full, send_stall
100
 
101
                );
102
 
103
// UTMI Interface
104
input           clk, rst;
105
input   [7:0]    rx_data;
106
input           rx_valid, rx_active, rx_err;
107
output  [7:0]    tx_data;
108
output          tx_valid;
109
output          tx_valid_last;
110
input           tx_ready;
111
output          tx_first;
112
input           tx_valid_out;
113
 
114
output          token_valid;
115
 
116
// Register File interface
117
input   [6:0]    fa;             // Function Address (as set by the controller)
118
output  [3:0]    ep_sel;         // Endpoint Number Input
119
output          x_busy;         // Indicates USB is busy
120
 
121
output          int_crc16_set;  // Set CRC16 error interrupt
122
output          int_to_set;     // Set time out interrupt
123
output          int_seqerr_set; // Set PID sequence error interrupt
124
 
125
// Misc
126
output          pid_cs_err;     // pid checksum error
127
output          crc5_err;       // crc5 error
128
output  [31:0]   frm_nat;
129
output          nse_err;        // no such endpoint error
130
output  [7:0]    rx_size;
131
output          rx_done;
132
output          ctrl_setup;
133
output          ctrl_in;
134
output          ctrl_out;
135
input           ep_bf_en;
136
input   [6:0]    ep_bf_size;
137
output          dropped_frame, misaligned_frame;
138
 
139
// Endpoint Interfaces
140
input   [13:0]   csr;
141
input   [7:0]    tx_data_st;
142
output  [7:0]    rx_ctrl_data;
143
output  [7:0]    rx_ctrl_data_d;
144
output          rx_ctrl_dvalid;
145
output          rx_ctrl_ddone;
146
output          idma_re, idma_we;
147
input           ep_empty;
148
input           ep_full;
149
 
150
input           send_stall;
151
 
152
///////////////////////////////////////////////////////////////////
153
//
154
// Local Wires and Registers
155
//
156
 
157
// Packet Disassembler Interface
158
wire            clk, rst;
159
wire    [7:0]    rx_data;
160
wire            pid_OUT, pid_IN, pid_SOF, pid_SETUP;
161
wire            pid_DATA0, pid_DATA1, pid_DATA2, pid_MDATA;
162
wire            pid_ACK, pid_NACK, pid_STALL, pid_NYET;
163
wire            pid_PRE, pid_ERR, pid_SPLIT, pid_PING;
164
wire    [6:0]    token_fadr;
165
wire            token_valid;
166
wire            crc5_err;
167
wire    [10:0]   frame_no;
168
wire    [7:0]    rx_ctrl_data;
169
reg     [7:0]    rx_ctrl_data_d;
170
wire            rx_ctrl_dvalid;
171
wire            rx_ctrl_ddone;
172
wire            crc16_err;
173
wire            rx_seq_err;
174
 
175
// Packet Assembler Interface
176
wire            send_token;
177
wire    [1:0]    token_pid_sel;
178
wire            send_data;
179
wire    [1:0]    data_pid_sel;
180
wire    [7:0]    tx_data_st;
181
wire    [7:0]    tx_data_st_o;
182
wire            rd_next;
183
 
184
// IDMA Interface
185
wire            rx_dma_en;      // Allows the data to be stored
186
wire            tx_dma_en;      // Allows for data to be retrieved
187
wire            abort;          // Abort Transfer (time_out, crc_err or rx_error)
188
wire            idma_done;      // DMA is done
189
 
190
// Memory Arbiter Interface
191
wire            idma_we;
192
wire            idma_re;
193
 
194
// Local signals
195
wire            pid_bad;
196
 
197
reg             hms_clk;        // 0.5 Micro Second Clock
198
reg     [4:0]    hms_cnt;
199
reg     [10:0]   frame_no_r;     // Current Frame Number register
200
wire            frame_no_we;
201
reg     [11:0]   sof_time;       // Time since last sof
202
reg             clr_sof_time;
203
wire            fsel;           // This Function is selected
204
wire            match_o;
205
 
206
reg             frame_no_we_r;
207
reg             ctrl_setup;
208
reg             ctrl_in;
209
reg             ctrl_out;
210
 
211
wire            idma_we_d;
212
wire            ep_empty_int;
213
wire            rx_busy;
214
wire            tx_busy;
215
 
216
///////////////////////////////////////////////////////////////////
217
//
218
// Misc Logic
219
//
220
 
221
assign x_busy = tx_busy | rx_busy;
222
 
223
// PIDs we should never receive
224
assign pid_bad = pid_ACK | pid_NACK | pid_STALL | pid_NYET | pid_PRE |
225
                        pid_ERR | pid_SPLIT |  pid_PING;
226
 
227
assign match_o = !pid_bad & token_valid & !crc5_err;
228
 
229
// Receiving Setup
230
always @(posedge clk)
231
        ctrl_setup <= #1 token_valid & pid_SETUP & (ep_sel==4'h0);
232
 
233
always @(posedge clk)
234
        ctrl_in <= #1 token_valid & pid_IN & (ep_sel==4'h0);
235
 
236
always @(posedge clk)
237
        ctrl_out <= #1 token_valid & pid_OUT & (ep_sel==4'h0);
238
 
239
// Frame Number (from SOF token)
240
assign frame_no_we = token_valid & !crc5_err & pid_SOF;
241
 
242
always @(posedge clk)
243
        frame_no_we_r <= #1 frame_no_we;
244
 
245
always @(posedge clk or negedge rst)
246
        if(!rst)                frame_no_r <= #1 11'h0;
247
        else
248
        if(frame_no_we_r)       frame_no_r <= #1 frame_no;
249
 
250
//SOF delay counter
251
always @(posedge clk)
252
        clr_sof_time <= #1 frame_no_we;
253
 
254
always @(posedge clk)
255
        if(clr_sof_time)        sof_time <= #1 12'h0;
256
        else
257
        if(hms_clk)             sof_time <= #1 sof_time + 12'h1;
258
 
259
assign frm_nat = {4'h0, 1'b0, frame_no_r, 4'h0, sof_time};
260
 
261
// 0.5 Micro Seconds Clock Generator
262
always @(posedge clk or negedge rst)
263
        if(!rst)                                hms_cnt <= #1 5'h0;
264
        else
265
        if(hms_clk | frame_no_we_r)             hms_cnt <= #1 5'h0;
266
        else                                    hms_cnt <= #1 hms_cnt + 5'h1;
267
 
268
always @(posedge clk)
269
        hms_clk <= #1 (hms_cnt == `USBF_HMS_DEL);
270
 
271
always @(posedge clk)
272
        rx_ctrl_data_d <= rx_ctrl_data;
273
 
274
///////////////////////////////////////////////////////////////////
275
 
276
// This function is addressed
277
assign fsel = (token_fadr == fa);
278
 
279
// Only write when we are addressed !!!
280
assign idma_we = idma_we_d & fsel; // moved full check to idma ...  & !ep_full;
281
 
282
///////////////////////////////////////////////////////////////////
283
//
284
// Module Instantiations
285
//
286
 
287
//Packet Decoder
288
usb1_pd u0(     .clk(           clk             ),
289
                .rst(           rst             ),
290
 
291
                .rx_data(       rx_data         ),
292
                .rx_valid(      rx_valid        ),
293
                .rx_active(     rx_active       ),
294
                .rx_err(        rx_err          ),
295
                .pid_OUT(       pid_OUT         ),
296
                .pid_IN(        pid_IN          ),
297
                .pid_SOF(       pid_SOF         ),
298
                .pid_SETUP(     pid_SETUP       ),
299
                .pid_DATA0(     pid_DATA0       ),
300
                .pid_DATA1(     pid_DATA1       ),
301
                .pid_DATA2(     pid_DATA2       ),
302
                .pid_MDATA(     pid_MDATA       ),
303
                .pid_ACK(       pid_ACK         ),
304
                .pid_NACK(      pid_NACK        ),
305
                .pid_STALL(     pid_STALL       ),
306
                .pid_NYET(      pid_NYET        ),
307
                .pid_PRE(       pid_PRE         ),
308
                .pid_ERR(       pid_ERR         ),
309
                .pid_SPLIT(     pid_SPLIT       ),
310
                .pid_PING(      pid_PING        ),
311
                .pid_cks_err(   pid_cs_err      ),
312
                .token_fadr(    token_fadr      ),
313
                .token_endp(    ep_sel          ),
314
                .token_valid(   token_valid     ),
315
                .crc5_err(      crc5_err        ),
316
                .frame_no(      frame_no        ),
317
                .rx_data_st(    rx_ctrl_data    ),
318
                .rx_data_valid( rx_ctrl_dvalid  ),
319
                .rx_data_done(  rx_ctrl_ddone   ),
320
                .crc16_err(     crc16_err       ),
321
                .seq_err(       rx_seq_err      ),
322
                .rx_busy(       rx_busy         )
323
                );
324
 
325
// Packet Assembler
326
usb1_pa u1(     .clk(           clk             ),
327
                .rst(           rst             ),
328
                .tx_data(       tx_data         ),
329
                .tx_valid(      tx_valid        ),
330
                .tx_valid_last( tx_valid_last   ),
331
                .tx_ready(      tx_ready        ),
332
                .tx_first(      tx_first        ),
333
                .send_token(    send_token      ),
334
                .token_pid_sel( token_pid_sel   ),
335
                .send_data(     send_data       ),
336
                .data_pid_sel(  data_pid_sel    ),
337
                .tx_data_st(    tx_data_st_o    ),
338
                .rd_next(       rd_next         ),
339
                .ep_empty(      ep_empty_int)
340
                );
341
 
342
// Internal DMA / Memory Arbiter Interface
343
usb1_idma
344
        u2(     .clk(           clk             ),
345
                .rst(           rst             ),
346
 
347
                .tx_valid(      tx_valid        ),
348
                .rx_data_valid( rx_ctrl_dvalid  ),
349
                .rx_data_done(  rx_ctrl_ddone   ),
350
                .send_data(     send_data       ),
351
                .rd_next(       rd_next         ),
352
 
353
                .tx_data_st_i(  tx_data_st      ),
354
                .tx_data_st_o(  tx_data_st_o    ),
355
                .ep_sel(        ep_sel          ),
356
 
357
                .ep_bf_en(      ep_bf_en        ),
358
                .ep_bf_size(    ep_bf_size      ),
359
                .dropped_frame(dropped_frame    ),
360
                .misaligned_frame(misaligned_frame),
361
 
362
                .tx_busy(       tx_busy         ),
363
 
364
                .tx_dma_en(     tx_dma_en       ),
365
                .rx_dma_en(     rx_dma_en       ),
366
                .idma_done(     idma_done       ),
367
                .size(          csr[8:0] ),
368
                .rx_cnt(        rx_size         ),
369
                .rx_done(       rx_done         ),
370
                .mwe(           idma_we_d       ),
371
                .mre(           idma_re         ),
372
                .ep_empty(      ep_empty        ),
373
                .ep_empty_int(  ep_empty_int    ),
374
                .ep_full(       ep_full         )
375
                );
376
 
377
// Protocol Engine
378
usb1_pe
379
        u3(     .clk(                   clk                     ),
380
                .rst(                   rst                     ),
381
 
382
                .tx_valid(              tx_valid_out            ),
383
                .rx_active(             rx_active               ),
384
                .pid_OUT(               pid_OUT                 ),
385
                .pid_IN(                pid_IN                  ),
386
                .pid_SOF(               pid_SOF                 ),
387
                .pid_SETUP(             pid_SETUP               ),
388
                .pid_DATA0(             pid_DATA0               ),
389
                .pid_DATA1(             pid_DATA1               ),
390
                .pid_DATA2(             pid_DATA2               ),
391
                .pid_MDATA(             pid_MDATA               ),
392
                .pid_ACK(               pid_ACK                 ),
393
                .pid_PING(              pid_PING                ),
394
                .token_valid(           token_valid             ),
395
                .rx_data_done(          rx_ctrl_ddone           ),
396
                .crc16_err(             crc16_err               ),
397
                .send_token(            send_token              ),
398
                .token_pid_sel(         token_pid_sel           ),
399
                .data_pid_sel(          data_pid_sel            ),
400
                .rx_dma_en(             rx_dma_en               ),
401
                .tx_dma_en(             tx_dma_en               ),
402
                .abort(                 abort                   ),
403
                .idma_done(             idma_done               ),
404
                .fsel(                  fsel                    ),
405
                .ep_sel(                ep_sel                  ),
406
                .ep_full(               ep_full                 ),
407
                .ep_empty(              ep_empty                ),
408
                .match(                 match_o                 ),
409
                .nse_err(               nse_err                 ),
410
                .int_upid_set(          int_upid_set            ),
411
                .int_crc16_set(         int_crc16_set           ),
412
                .int_to_set(            int_to_set              ),
413
                .int_seqerr_set(        int_seqerr_set          ),
414
                .csr(                   csr                     ),
415
                .send_stall(            send_stall              )
416
                );
417
 
418
endmodule

powered by: WebSVN 2.1.0

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