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

Subversion Repositories usb_device_core

[/] [usb_device_core/] [trunk/] [src_v/] [usbf_sie_ep.v] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 ultra_embe
//-----------------------------------------------------------------
2
//                       USB Device Core
3
//                           V1.0
4
//                     Ultra-Embedded.com
5
//                     Copyright 2014-2019
6
//
7
//                 Email: admin@ultra-embedded.com
8
//
9
//                         License: GPL
10
// If you would like a version with a more permissive license for
11
// use in closed source commercial applications please contact me
12
// for details.
13
//-----------------------------------------------------------------
14
//
15
// This file is open source HDL; you can redistribute it and/or 
16
// modify it under the terms of the GNU General Public License as 
17
// published by the Free Software Foundation; either version 2 of 
18
// the License, or (at your option) any later version.
19
//
20
// This file is distributed in the hope that it will be useful,
21
// but WITHOUT ANY WARRANTY; without even the implied warranty of
22
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
// GNU General Public License for more details.
24
//
25
// You should have received a copy of the GNU General Public 
26
// License along with this file; if not, write to the Free Software
27
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28
// USA
29
//-----------------------------------------------------------------
30
 
31
//-----------------------------------------------------------------
32
//                          Generated File
33
//-----------------------------------------------------------------
34
 
35
module usbf_sie_ep
36
(
37
    // Inputs
38
     input           clk_i
39
    ,input           rst_i
40
    ,input           rx_setup_i
41
    ,input           rx_valid_i
42
    ,input           rx_strb_i
43
    ,input  [  7:0]  rx_data_i
44
    ,input           rx_last_i
45
    ,input           rx_crc_err_i
46
    ,input           rx_full_i
47
    ,input           rx_ack_i
48
    ,input  [  7:0]  tx_data_i
49
    ,input           tx_empty_i
50
    ,input           tx_flush_i
51
    ,input  [ 10:0]  tx_length_i
52
    ,input           tx_start_i
53
    ,input           tx_data_accept_i
54
 
55
    // Outputs
56
    ,output          rx_space_o
57
    ,output          rx_push_o
58
    ,output [  7:0]  rx_data_o
59
    ,output [ 10:0]  rx_length_o
60
    ,output          rx_ready_o
61
    ,output          rx_err_o
62
    ,output          rx_setup_o
63
    ,output          tx_pop_o
64
    ,output          tx_busy_o
65
    ,output          tx_err_o
66
    ,output          tx_ready_o
67
    ,output          tx_data_valid_o
68
    ,output          tx_data_strb_o
69
    ,output [  7:0]  tx_data_o
70
    ,output          tx_data_last_o
71
);
72
 
73
 
74
 
75
//-----------------------------------------------------------------
76
// Rx
77
//-----------------------------------------------------------------
78
reg        rx_ready_q;
79
reg        rx_err_q;
80
reg [10:0] rx_len_q;
81
reg        rx_setup_q;
82
 
83
always @ (posedge clk_i or posedge rst_i)
84
if (rst_i)
85
    rx_ready_q <= 1'b0;
86
else if (rx_ack_i)
87
    rx_ready_q <= 1'b0;
88
else if (rx_valid_i && rx_last_i)
89
    rx_ready_q <= 1'b1;
90
 
91
assign rx_space_o = !rx_ready_q;
92
 
93
always @ (posedge clk_i or posedge rst_i)
94
if (rst_i)
95
    rx_len_q <= 11'b0;
96
else if (rx_ack_i)
97
    rx_len_q <= 11'b0;
98
else if (rx_valid_i && rx_strb_i)
99
    rx_len_q <= rx_len_q + 11'd1;
100
 
101
always @ (posedge clk_i or posedge rst_i)
102
if (rst_i)
103
    rx_err_q <= 1'b0;
104
else if (rx_ack_i)
105
    rx_err_q <= 1'b0;
106
else if (rx_valid_i && rx_last_i && rx_crc_err_i)
107
    rx_err_q <= 1'b1;
108
else if (rx_full_i && rx_push_o)
109
    rx_err_q <= 1'b1;
110
 
111
always @ (posedge clk_i or posedge rst_i)
112
if (rst_i)
113
    rx_setup_q <= 1'b0;
114
else if (rx_ack_i)
115
    rx_setup_q <= 1'b0;
116
else if (rx_setup_i)
117
    rx_setup_q <= 1'b1;
118
 
119
assign rx_length_o = rx_len_q;
120
assign rx_ready_o  = rx_ready_q;
121
assign rx_err_o    = rx_err_q;
122
assign rx_setup_o  = rx_setup_q;
123
 
124
assign rx_push_o   = rx_valid_i & rx_strb_i;
125
assign rx_data_o   = rx_data_i;
126
 
127
//-----------------------------------------------------------------
128
// Tx
129
//-----------------------------------------------------------------
130
reg        tx_active_q;
131
reg        tx_err_q;
132
reg        tx_zlp_q;
133
reg [10:0] tx_len_q;
134
 
135
// Tx active
136
always @ (posedge clk_i or posedge rst_i)
137
if (rst_i)
138
    tx_active_q <= 1'b0;
139
else if (tx_flush_i)
140
    tx_active_q <= 1'b0;
141
else if (tx_start_i)
142
    tx_active_q <= 1'b1;
143
else if (tx_data_valid_o && tx_data_last_o && tx_data_accept_i)
144
    tx_active_q <= 1'b0;
145
 
146
assign tx_ready_o = tx_active_q;
147
 
148
// Tx zero length packet
149
always @ (posedge clk_i or posedge rst_i)
150
if (rst_i)
151
    tx_zlp_q <= 1'b0;
152
else if (tx_flush_i)
153
    tx_zlp_q <= 1'b0;
154
else if (tx_start_i)
155
    tx_zlp_q <= (tx_length_i == 11'b0);
156
 
157
// Tx length
158
always @ (posedge clk_i or posedge rst_i)
159
if (rst_i)
160
    tx_len_q <= 11'b0;
161
else if (tx_flush_i)
162
    tx_len_q <= 11'b0;
163
else if (tx_start_i)
164
    tx_len_q <= tx_length_i;
165
else if (tx_data_valid_o && tx_data_accept_i && !tx_zlp_q)
166
    tx_len_q <= tx_len_q - 11'd1;
167
 
168
// Tx SIE Interface
169
assign tx_data_valid_o = tx_active_q;
170
assign tx_data_strb_o  = !tx_zlp_q;
171
assign tx_data_last_o  = tx_zlp_q || (tx_len_q == 11'd1);
172
assign tx_data_o       = tx_data_i;
173
 
174
// Error: Buffer underrun
175
always @ (posedge clk_i or posedge rst_i)
176
if (rst_i)
177
    tx_err_q <= 1'b0;
178
else if (tx_flush_i)
179
    tx_err_q <= 1'b0;
180
else if (tx_start_i)
181
    tx_err_q <= 1'b0;
182
else if (!tx_zlp_q && tx_empty_i && tx_data_valid_o)
183
    tx_err_q <= 1'b1;
184
 
185
// Tx Register Interface
186
assign tx_err_o      = tx_err_q;
187
assign tx_busy_o     = tx_active_q;
188
 
189
// Tx FIFO Interface
190
assign tx_pop_o      = tx_data_accept_i & tx_active_q;
191
 
192
 
193
endmodule

powered by: WebSVN 2.1.0

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