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

Subversion Repositories usb11

[/] [usb11/] [trunk/] [rtl/] [systemc/] [usb_pe_sie.h] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 alfoltran
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  USB Protocol Engine                                        ////
4
////  Performs automatic protocol functions                      ////
5
////                                                             ////
6
////  SystemC Version: usb_pe_sie.h                              ////
7
////  Author: Alfredo Luiz Foltran Fialho                        ////
8
////          alfoltran@ig.com.br                                ////
9
////                                                             ////
10
////                                                             ////
11
/////////////////////////////////////////////////////////////////////
12
////                                                             ////
13
//// Verilog Version: usb1_pe.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_PE_SIE_H
40
#define USB_PE_SIE_H
41
 
42
#include "usb_defines.h"
43
 
44
// TX Token Decoding
45
enum PE_TX_TOKEN {PE_ACK, PE_NACK, PE_STALL, PE_NYET};
46
 
47
// State Decoding
48
enum PE_STATE { PE_IDLE = 1,
49
                                PE_TOKEN = 2,
50
                                PE_IN = 4,
51
                                PE_IN2 = 8,
52
                                PE_OUT = 16,
53
                                PE_OUT2A = 32,
54
                                PE_OUT2B = 64,
55
                                PE_UPDATEW = 128,
56
                                PE_UPDATE = 256,
57
                                PE_UPDATE2 = 512};
58
 
59
SC_MODULE(usb_pe_sie) {
60
 
61
  public:
62
 
63
        sc_in<bool>                     clk;
64
        sc_in<bool>                     rst;
65
 
66
        // PL Interface
67
        sc_in<bool>                     tx_valid;
68
        sc_in<bool>                     rx_active;
69
 
70
        // PD Interface
71
        // Decoded PIDs (used when token_valid is asserted)
72
        sc_in<bool>                     pid_OUT, pid_IN, pid_SOF, pid_SETUP;
73
        sc_in<bool>                     pid_DATA0, pid_DATA1, pid_DATA2, pid_MDATA;
74
        sc_in<bool>                     pid_ACK, pid_PING;
75
        sc_in<bool>                     token_valid;                            // Token is valid
76
        sc_in<bool>                     rx_data_done;                           // Indicates end of a transfer
77
        sc_in<bool>                     crc16_err;                                      // Data packet CRC16 error
78
 
79
        // PA Interface
80
        sc_out<bool>            send_token;
81
        sc_out<sc_uint<2> >     token_pid_sel;
82
        sc_out<sc_uint<2> >     data_pid_sel;
83
 
84
        // IDMA Interface
85
        sc_out<bool>            rx_dma_en;                                      // Allows the data to be stored
86
        sc_out<bool>            tx_dma_en;                                      // Allows for data to be retrieved
87
        sc_out<bool>            abort;                                          // Abort transfer (time out, CRC error or RX error)
88
        sc_in<bool>                     idma_done;                                      // DMA is done indicator
89
        sc_in<bool>                     ep_full;                                        // Indicates the endpoints FIFOs is full
90
        sc_in<bool>                     ep_empty;                                       // Indicates the endpoints FIFOs is empty
91
 
92
        // Register File Interface
93
        sc_in<bool>                     fsel;                                           // This function is selected
94
        sc_in<sc_uint<4> >      ep_sel;                                         // Endpoint Number Input
95
        sc_in<bool>                     match;                                          // Endpoint Matched
96
        sc_out<bool>            nse_err;                                        // No such endpoint error
97
        sc_out<bool>            int_upid_set;                           // Set unsupported PID interrupt
98
        sc_out<bool>            int_crc16_set;                          // Set CRC16 error interrupt
99
        sc_out<bool>            int_to_set;                                     // Set time out interrupt
100
        sc_out<bool>            int_seqerr_set;                         // Set PID sequence error interrupt
101
        sc_in<sc_uint<14> >     csr;                                            // Internal CSR Output
102
        sc_in<bool>                     send_stall;                                     // Force sending a STALL during setup
103
 
104
        // Local Signals
105
        sc_signal<sc_uint<2> >  token_pid_sel_d;
106
        sc_signal<bool>                 send_token_d;
107
        sc_signal<bool>                 int_seqerr_set_d;
108
        sc_signal<bool>                 match_r;
109
 
110
        // Endpoint Decoding
111
        sc_signal<bool>                 IN_ep, OUT_ep, CTRL_ep;                 // Endpoint Types
112
        sc_signal<bool>                 txfr_iso, txfr_bulk, txfr_int;  // Transfer Types
113
 
114
        sc_signal<sc_uint<2> >  uc_dpd;
115
 
116
        // Buffer checks
117
        sc_signal<sc_uint<10> > state, next_state;// synopsys state_vector state
118
 
119
        // PID next and current decoders
120
        sc_signal<sc_uint<2> >  next_dpid;
121
        sc_signal<sc_uint<2> >  this_dpid;
122
        sc_signal<bool>                 pid_seq_err;
123
        sc_signal<sc_uint<2> >  tr_fr_d;
124
 
125
        sc_signal<sc_uint<14> > size_next;
126
        sc_signal<bool>                 buf_smaller;
127
 
128
        // After sending data in response to an IN token from host, the
129
        // host must reply with an ack. The host has XXXnS to reply.
130
        // "rx_ack_to" indicates when this time has expired.
131
        // rx_ack_to_clr, clears the timer
132
        sc_signal<bool>                 rx_ack_to_clr;
133
        sc_signal<bool>                 rx_ack_to_clr_d;
134
        sc_signal<bool>                 rx_ack_to;
135
        sc_signal<sc_uint<8> >  rx_ack_to_cnt;
136
 
137
        // After sending a OUT token the host must send a data packet,
138
        // the host has XXXnS to send the packet. "tx_data_to" indicates
139
        // when this time has expired.
140
        // tx_data_to_clr, clears the timer
141
        sc_signal<bool>                 tx_data_to_clr;
142
        sc_signal<bool>                 tx_data_to;
143
        sc_signal<sc_uint<8> >  tx_data_to_cnt;
144
 
145
        sc_signal<sc_uint<8> >  rx_ack_to_val, tx_data_to_val;
146
        sc_signal<sc_uint<2> >  next_bsel;
147
        sc_signal<bool>                 uc_stat_set_d;
148
        sc_signal<bool>                 uc_dpd_set;
149
        sc_signal<bool>                 in_token;
150
        sc_signal<bool>                 out_token;
151
        sc_signal<bool>                 setup_token;
152
        sc_signal<bool>                 in_op, out_op;                          // Indicate a IN or OUT operation
153
        sc_signal<sc_uint<2> >  allow_pid;
154
        sc_signal<sc_uint<2> >  ep_type, txfr_type;
155
 
156
        sc_signal<sc_uint<2> >  ep0_dpid, ep1_dpid, ep2_dpid, ep3_dpid;
157
        sc_signal<sc_uint<2> >  ep4_dpid, ep5_dpid, ep6_dpid, ep7_dpid;
158
        sc_signal<bool>                 pid_OUT_r, pid_IN_r, pid_PING_r, pid_SETUP_r;
159
        sc_signal<bool>                 send_stall_r;
160
 
161
        // Misc Functions
162
        void csr_decoder(void);
163
        void match_up(void);
164
        void nse_err_up(void);
165
        void send_token_up(void);
166
        void token_pid_sel_up(void);
167
 
168
        // Data PID Storage Functions
169
        void ep0_dpid_up(void);
170
        void ep1_dpid_up(void);
171
        void ep2_dpid_up(void);
172
        void ep3_dpid_up(void);
173
        void ep4_dpid_up(void);
174
        void ep5_dpid_up(void);
175
        void ep6_dpid_up(void);
176
        void ep7_dpid_up(void);
177
        void uc_dpd_up(void);
178
 
179
        // Data PID Sequencer Function
180
        void sq_statemachine(void);
181
 
182
        // Current PID Decoder Functions
183
        void allow_pid_up(void);
184
        void this_dpid_up(void);
185
        void data_pid_sel_up(void);
186
        void pid_seq_err_up(void);
187
 
188
        // IDMA Setup and Buffer Select Functions
189
        void in_token_up(void);
190
        void out_token_up(void);
191
        void setup_token_up(void);
192
        void in_op_up(void);
193
        void out_op_up(void);
194
 
195
        // Register File Update Logic Functions
196
        void uc_dpd_set_up(void);
197
        void abort_up(void);
198
 
199
        // Time Out Functions
200
        void rx_ack_up1(void);
201
        void rx_ack_up2(void);
202
        void rx_ack_up3(void);
203
 
204
        void tx_data_up1(void);
205
        void tx_data_up2(void);
206
        void tx_data_up3(void);
207
 
208
        // Interrupts Functions
209
        void pid_OUT_up(void);
210
        void pid_IN_up(void);
211
        void pid_PING_up(void);
212
        void pid_SETUP_up(void);
213
        void int_upid_up(void);
214
        void int_to_up(void);
215
        void int_crc16_up(void);
216
        void int_seqerr_up(void);
217
 
218
        void send_stall_up(void);
219
 
220
        // Main Protocol State Machine Functions
221
        void state_up(void);
222
        void pe_statemachine(void);
223
 
224
        SC_CTOR(usb_pe_sie) {
225
                tr_fr_d.write(0);
226
                rx_ack_to_val.write(USBF_RX_ACK_TO_VAL_FS);
227
                tx_data_to_val.write(USBF_TX_DATA_TO_VAL_FS);
228
 
229
                SC_METHOD(csr_decoder);
230
                sensitive << csr;
231
                SC_METHOD(match_up);
232
                sensitive << clk.pos();
233
                SC_METHOD(nse_err_up);
234
                sensitive << clk.pos();
235
                SC_METHOD(send_token_up);
236
                sensitive << clk.pos();
237
                SC_METHOD(token_pid_sel_up);
238
                sensitive << clk.pos();
239
 
240
                SC_METHOD(ep0_dpid_up);
241
                sensitive << clk.pos() << rst.neg();
242
                SC_METHOD(ep1_dpid_up);
243
                sensitive << clk.pos() << rst.neg();
244
                SC_METHOD(ep2_dpid_up);
245
                sensitive << clk.pos() << rst.neg();
246
                SC_METHOD(ep3_dpid_up);
247
                sensitive << clk.pos() << rst.neg();
248
                SC_METHOD(ep4_dpid_up);
249
                sensitive << clk.pos() << rst.neg();
250
                SC_METHOD(ep5_dpid_up);
251
                sensitive << clk.pos() << rst.neg();
252
                SC_METHOD(ep6_dpid_up);
253
                sensitive << clk.pos() << rst.neg();
254
                SC_METHOD(ep7_dpid_up);
255
                sensitive << clk.pos() << rst.neg();
256
                SC_METHOD(uc_dpd_up);
257
                sensitive << clk.pos();
258
 
259
                SC_METHOD(sq_statemachine);
260
                sensitive << clk.pos();
261
 
262
                SC_METHOD(allow_pid_up);
263
                sensitive << pid_DATA0 << pid_DATA1 << pid_DATA2 << pid_MDATA;
264
                SC_METHOD(this_dpid_up);
265
                sensitive << clk.pos();
266
                SC_METHOD(data_pid_sel_up);
267
                sensitive << this_dpid;
268
                SC_METHOD(pid_seq_err_up);
269
                sensitive << clk.pos();
270
 
271
                SC_METHOD(in_token_up);
272
                sensitive << clk.pos() << rst.neg();
273
                SC_METHOD(out_token_up);
274
                sensitive << clk.pos() << rst.neg();
275
                SC_METHOD(setup_token_up);
276
                sensitive << clk.pos() << rst.neg();
277
                SC_METHOD(in_op_up);
278
                sensitive << IN_ep << CTRL_ep << in_token;
279
                SC_METHOD(out_op_up);
280
                sensitive << OUT_ep << CTRL_ep << out_token;
281
 
282
                SC_METHOD(uc_dpd_set_up);
283
                sensitive << clk.pos();
284
                SC_METHOD(abort_up);
285
                sensitive << clk.pos();
286
 
287
                SC_METHOD(rx_ack_up1);
288
                sensitive << clk.pos();
289
                SC_METHOD(rx_ack_up2);
290
                sensitive << clk.pos();
291
                SC_METHOD(rx_ack_up3);
292
                sensitive << clk.pos();
293
 
294
                SC_METHOD(tx_data_up1);
295
                sensitive << rx_active;
296
                SC_METHOD(tx_data_up2);
297
                sensitive << clk.pos();
298
                SC_METHOD(tx_data_up3);
299
                sensitive << clk.pos();
300
 
301
                SC_METHOD(pid_OUT_up);
302
                sensitive << clk.pos();
303
                SC_METHOD(pid_IN_up);
304
                sensitive << clk.pos();
305
                SC_METHOD(pid_PING_up);
306
                sensitive << clk.pos();
307
                SC_METHOD(pid_SETUP_up);
308
                sensitive << clk.pos();
309
                SC_METHOD(int_upid_up);
310
                sensitive << clk.pos();
311
                SC_METHOD(int_to_up);
312
                sensitive << state << rx_ack_to << tx_data_to;
313
                SC_METHOD(int_crc16_up);
314
                sensitive << rx_data_done << crc16_err;
315
                SC_METHOD(int_seqerr_up);
316
                sensitive << clk.pos();
317
 
318
                SC_METHOD(send_stall_up);
319
                sensitive << clk.pos() << rst.neg();
320
 
321
                SC_METHOD(state_up);
322
                sensitive << clk.pos() << rst.neg();
323
                SC_METHOD(pe_statemachine);
324
                sensitive << state << pid_seq_err << idma_done << ep_full << ep_empty;
325
                sensitive << token_valid << pid_ACK << rx_data_done << tx_data_to << crc16_err;
326
                sensitive << rx_ack_to << pid_PING << txfr_iso << txfr_int << CTRL_ep;
327
                sensitive << pid_IN << pid_OUT << IN_ep << OUT_ep << pid_SETUP << pid_SOF;
328
                sensitive << match_r << abort << send_stall_r << send_stall;
329
        }
330
 
331
};
332
 
333
#endif
334
 

powered by: WebSVN 2.1.0

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