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

Subversion Repositories usb1_funct

[/] [usb1_funct/] [trunk/] [rtl/] [verilog/] [usb1_pl.v] - Blame information for rev 5

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

Line No. Rev Author Line
1 2 rudi
/////////////////////////////////////////////////////////////////////
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 5 rudi
//  $Id: usb1_pl.v,v 1.2 2002-09-25 06:06:49 rudi Exp $
44 2 rudi
//
45 5 rudi
//  $Date: 2002-09-25 06:06:49 $
46
//  $Revision: 1.2 $
47 2 rudi
//  $Author: rudi $
48
//  $Locker:  $
49
//  $State: Exp $
50
//
51
// Change History:
52
//               $Log: not supported by cvs2svn $
53 5 rudi
//               Revision 1.1.1.1  2002/09/19 12:07:28  rudi
54
//               Initial Checkin
55 2 rudi
//
56
//
57
//
58
//
59
//
60
//
61
//
62
//
63 5 rudi
//
64 2 rudi
 
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 5 rudi
                x_busy,
78 2 rudi
                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 5 rudi
 
87
                // Block Frames
88
                ep_bf_en, ep_bf_size,
89 2 rudi
                dropped_frame, misaligned_frame,
90
 
91
                // EP Interface
92
                csr,
93
                tx_data_st, rx_data_st, idma_re, idma_we,
94
                ep_empty, ep_full, send_stall
95
 
96
                );
97
 
98
// UTMI Interface
99
input           clk, rst;
100
input   [7:0]    rx_data;
101
input           rx_valid, rx_active, rx_err;
102
output  [7:0]    tx_data;
103
output          tx_valid;
104
output          tx_valid_last;
105
input           tx_ready;
106
output          tx_first;
107
input           tx_valid_out;
108
 
109
output          token_valid;
110
 
111
// Register File interface
112
input   [6:0]    fa;             // Function Address (as set by the controller)
113
output  [3:0]    ep_sel;         // Endpoint Number Input
114 5 rudi
output          x_busy;         // Indicates USB is busy
115 2 rudi
 
116
output          int_crc16_set;  // Set CRC16 error interrupt
117
output          int_to_set;     // Set time out interrupt
118
output          int_seqerr_set; // Set PID sequence error interrupt
119
 
120
// Misc
121
output          pid_cs_err;     // pid checksum error
122
output          crc5_err;       // crc5 error
123
output  [31:0]   frm_nat;
124
output          nse_err;        // no such endpoint error
125
output  [7:0]    rx_size;
126
output          rx_done;
127
output          ctrl_setup;
128
output          ctrl_in;
129
output          ctrl_out;
130 5 rudi
input           ep_bf_en;
131
input   [6:0]    ep_bf_size;
132 2 rudi
output          dropped_frame, misaligned_frame;
133
 
134
// Endpoint Interfaces
135
input   [13:0]   csr;
136
input   [7:0]    tx_data_st;
137
output  [7:0]    rx_data_st;
138
output          idma_re, idma_we;
139
input           ep_empty;
140
input           ep_full;
141
 
142
input           send_stall;
143
 
144
///////////////////////////////////////////////////////////////////
145
//
146
// Local Wires and Registers
147
//
148
 
149
// Packet Disassembler Interface
150
wire            clk, rst;
151
wire    [7:0]    rx_data;
152
wire            pid_OUT, pid_IN, pid_SOF, pid_SETUP;
153
wire            pid_DATA0, pid_DATA1, pid_DATA2, pid_MDATA;
154
wire            pid_ACK, pid_NACK, pid_STALL, pid_NYET;
155
wire            pid_PRE, pid_ERR, pid_SPLIT, pid_PING;
156
wire    [6:0]    token_fadr;
157
wire            token_valid;
158
wire            crc5_err;
159
wire    [10:0]   frame_no;
160
reg     [7:0]    rx_data_st;
161
wire    [7:0]    rx_data_st_d;
162
wire            rx_data_valid;
163
wire            rx_data_done;
164
wire            crc16_err;
165
wire            rx_seq_err;
166
 
167
// Packet Assembler Interface
168
wire            send_token;
169
wire    [1:0]    token_pid_sel;
170
wire            send_data;
171
wire    [1:0]    data_pid_sel;
172
wire    [7:0]    tx_data_st;
173
wire    [7:0]    tx_data_st_o;
174
wire            rd_next;
175
 
176
// IDMA Interface
177
wire            rx_dma_en;      // Allows the data to be stored
178
wire            tx_dma_en;      // Allows for data to be retrieved
179
wire            abort;          // Abort Transfer (time_out, crc_err or rx_error)
180
wire            idma_done;      // DMA is done
181
 
182
// Memory Arbiter Interface
183
wire            idma_we;
184
wire            idma_re;
185
 
186
// Local signals
187
wire            pid_bad;
188
 
189
reg             hms_clk;        // 0.5 Micro Second Clock
190
reg     [4:0]    hms_cnt;
191
reg     [10:0]   frame_no_r;     // Current Frame Number register
192
wire            frame_no_we;
193
reg     [11:0]   sof_time;       // Time since last sof
194
reg             clr_sof_time;
195
wire            fsel;           // This Function is selected
196
wire            match_o;
197
 
198
reg             frame_no_we_r;
199
reg             ctrl_setup;
200
reg             ctrl_in;
201
reg             ctrl_out;
202
 
203
wire            idma_we_d;
204 5 rudi
wire            ep_empty_int;
205
wire            rx_busy;
206
wire            tx_busy;
207 2 rudi
 
208
///////////////////////////////////////////////////////////////////
209
//
210
// Misc Logic
211
//
212
 
213 5 rudi
assign x_busy = tx_busy | rx_busy;
214
 
215 2 rudi
// PIDs we should never receive
216
assign pid_bad = pid_ACK | pid_NACK | pid_STALL | pid_NYET | pid_PRE |
217
                        pid_ERR | pid_SPLIT |  pid_PING;
218
 
219
assign match_o = !pid_bad & token_valid & !crc5_err;
220
 
221 5 rudi
// Receiving Setup
222 2 rudi
always @(posedge clk)
223
        ctrl_setup <= #1 token_valid & pid_SETUP & (ep_sel==4'h0);
224
 
225
always @(posedge clk)
226
        ctrl_in <= #1 token_valid & pid_IN & (ep_sel==4'h0);
227
 
228
always @(posedge clk)
229
        ctrl_out <= #1 token_valid & pid_OUT & (ep_sel==4'h0);
230
 
231
// Frame Number (from SOF token)
232
assign frame_no_we = token_valid & !crc5_err & pid_SOF;
233
 
234
always @(posedge clk)
235
        frame_no_we_r <= #1 frame_no_we;
236
 
237
always @(posedge clk or negedge rst)
238
        if(!rst)                frame_no_r <= #1 11'h0;
239
        else
240
        if(frame_no_we_r)       frame_no_r <= #1 frame_no;
241
 
242
//SOF delay counter
243
always @(posedge clk)
244
        clr_sof_time <= #1 frame_no_we;
245
 
246
always @(posedge clk)
247
        if(clr_sof_time)        sof_time <= #1 12'h0;
248
        else
249
        if(hms_clk)             sof_time <= #1 sof_time + 12'h1;
250
 
251
assign frm_nat = {4'h0, 1'b0, frame_no_r, 4'h0, sof_time};
252
 
253
// 0.5 Micro Seconds Clock Generator
254
always @(posedge clk or negedge rst)
255
        if(!rst)                                hms_cnt <= #1 5'h0;
256
        else
257
        if(hms_clk | frame_no_we_r)             hms_cnt <= #1 5'h0;
258
        else                                    hms_cnt <= #1 hms_cnt + 5'h1;
259
 
260
always @(posedge clk)
261
        hms_clk <= #1 (hms_cnt == `USBF_HMS_DEL);
262
 
263
always @(posedge clk)
264
        rx_data_st <= rx_data_st_d;
265
 
266
///////////////////////////////////////////////////////////////////
267
 
268
// This function is addressed
269
assign fsel = (token_fadr == fa);
270
 
271
// Only write when we are addressed !!!
272
assign idma_we = idma_we_d & fsel; // moved full check to idma ...  & !ep_full;
273
 
274
///////////////////////////////////////////////////////////////////
275
//
276
// Module Instantiations
277
//
278
 
279
//Packet Decoder
280
usb1_pd u0(     .clk(           clk             ),
281
                .rst(           rst             ),
282
 
283
                .rx_data(       rx_data         ),
284
                .rx_valid(      rx_valid        ),
285
                .rx_active(     rx_active       ),
286
                .rx_err(        rx_err          ),
287
                .pid_OUT(       pid_OUT         ),
288
                .pid_IN(        pid_IN          ),
289
                .pid_SOF(       pid_SOF         ),
290
                .pid_SETUP(     pid_SETUP       ),
291
                .pid_DATA0(     pid_DATA0       ),
292
                .pid_DATA1(     pid_DATA1       ),
293
                .pid_DATA2(     pid_DATA2       ),
294
                .pid_MDATA(     pid_MDATA       ),
295
                .pid_ACK(       pid_ACK         ),
296
                .pid_NACK(      pid_NACK        ),
297
                .pid_STALL(     pid_STALL       ),
298
                .pid_NYET(      pid_NYET        ),
299
                .pid_PRE(       pid_PRE         ),
300
                .pid_ERR(       pid_ERR         ),
301
                .pid_SPLIT(     pid_SPLIT       ),
302
                .pid_PING(      pid_PING        ),
303
                .pid_cks_err(   pid_cs_err      ),
304
                .token_fadr(    token_fadr      ),
305
                .token_endp(    ep_sel          ),
306
                .token_valid(   token_valid     ),
307
                .crc5_err(      crc5_err        ),
308
                .frame_no(      frame_no        ),
309
                .rx_data_st(    rx_data_st_d    ),
310
                .rx_data_valid( rx_data_valid   ),
311
                .rx_data_done(  rx_data_done    ),
312
                .crc16_err(     crc16_err       ),
313 5 rudi
                .seq_err(       rx_seq_err      ),
314
                .rx_busy(       rx_busy         )
315 2 rudi
                );
316
 
317
// Packet Assembler
318
usb1_pa u1(     .clk(           clk             ),
319
                .rst(           rst             ),
320
                .tx_data(       tx_data         ),
321
                .tx_valid(      tx_valid        ),
322
                .tx_valid_last( tx_valid_last   ),
323
                .tx_ready(      tx_ready        ),
324
                .tx_first(      tx_first        ),
325
                .send_token(    send_token      ),
326
                .token_pid_sel( token_pid_sel   ),
327
                .send_data(     send_data       ),
328
                .data_pid_sel(  data_pid_sel    ),
329
                .tx_data_st(    tx_data_st_o    ),
330
                .rd_next(       rd_next         ),
331 5 rudi
                .ep_empty(      ep_empty_int)
332 2 rudi
                );
333
 
334
// Internal DMA / Memory Arbiter Interface
335
usb1_idma
336
        u2(     .clk(           clk             ),
337
                .rst(           rst             ),
338
 
339
                .tx_valid(      tx_valid        ),
340
                .rx_data_valid( rx_data_valid   ),
341
                .rx_data_done(  rx_data_done    ),
342
                .send_data(     send_data       ),
343
                .rd_next(       rd_next         ),
344
 
345
                .tx_data_st_i(  tx_data_st      ),
346
                .tx_data_st_o(  tx_data_st_o    ),
347
                .ep_sel(        ep_sel          ),
348
 
349 5 rudi
                .ep_bf_en(      ep_bf_en        ),
350
                .ep_bf_size(    ep_bf_size      ),
351 2 rudi
                .dropped_frame(dropped_frame    ),
352
                .misaligned_frame(misaligned_frame),
353
 
354 5 rudi
                .tx_busy(       tx_busy         ),
355
 
356 2 rudi
                .tx_dma_en(     tx_dma_en       ),
357
                .rx_dma_en(     rx_dma_en       ),
358
                .idma_done(     idma_done       ),
359
                .size(          csr[8:0] ),
360
                .rx_cnt(        rx_size         ),
361
                .rx_done(       rx_done         ),
362
                .mwe(           idma_we_d       ),
363
                .mre(           idma_re         ),
364
                .ep_empty(      ep_empty        ),
365 5 rudi
                .ep_empty_int(  ep_empty_int    ),
366 2 rudi
                .ep_full(       ep_full         )
367
                );
368
 
369
// Protocol Engine
370
usb1_pe
371
        u3(     .clk(                   clk                     ),
372
                .rst(                   rst                     ),
373
 
374
                .tx_valid(              tx_valid_out            ),
375
                .rx_active(             rx_active               ),
376
                .pid_OUT(               pid_OUT                 ),
377
                .pid_IN(                pid_IN                  ),
378
                .pid_SOF(               pid_SOF                 ),
379
                .pid_SETUP(             pid_SETUP               ),
380
                .pid_DATA0(             pid_DATA0               ),
381
                .pid_DATA1(             pid_DATA1               ),
382
                .pid_DATA2(             pid_DATA2               ),
383
                .pid_MDATA(             pid_MDATA               ),
384
                .pid_ACK(               pid_ACK                 ),
385
                .pid_PING(              pid_PING                ),
386
                .token_valid(           token_valid             ),
387
                .rx_data_done(          rx_data_done            ),
388
                .crc16_err(             crc16_err               ),
389
                .send_token(            send_token              ),
390
                .token_pid_sel(         token_pid_sel           ),
391
                .data_pid_sel(          data_pid_sel            ),
392
                .rx_dma_en(             rx_dma_en               ),
393
                .tx_dma_en(             tx_dma_en               ),
394
                .abort(                 abort                   ),
395
                .idma_done(             idma_done               ),
396
                .fsel(                  fsel                    ),
397
                .ep_sel(                ep_sel                  ),
398
                .ep_full(               ep_full                 ),
399
                .ep_empty(              ep_empty                ),
400
                .match(                 match_o                 ),
401
                .nse_err(               nse_err                 ),
402
                .int_upid_set(          int_upid_set            ),
403
                .int_crc16_set(         int_crc16_set           ),
404
                .int_to_set(            int_to_set              ),
405
                .int_seqerr_set(        int_seqerr_set          ),
406
                .csr(                   csr                     ),
407
                .send_stall(            send_stall              )
408
                );
409
 
410
endmodule

powered by: WebSVN 2.1.0

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