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 2

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

powered by: WebSVN 2.1.0

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