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

Subversion Repositories usb11

[/] [usb11/] [trunk/] [rtl/] [systemc/] [usb_pd_sie.h] - Blame information for rev 13

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfoltran
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  USB Packet Disassembler                                    ////
4
////                                                             ////
5
////  SystemC Version: usb_pd_sie.h                              ////
6
////  Author: Alfredo Luiz Foltran Fialho                        ////
7
////          alfoltran@ig.com.br                                ////
8
////                                                             ////
9
////                                                             ////
10
/////////////////////////////////////////////////////////////////////
11
////                                                             ////
12
//// Verilog Version: usb1_pd.v                                  ////
13
//// Copyright (C) 2000-2002 Rudolf Usselmann                    ////
14
////                         www.asics.ws                        ////
15
////                         rudi@asics.ws                       ////
16
////                                                             ////
17
//// This source file may be used and distributed without        ////
18
//// restriction provided that this copyright statement is not   ////
19
//// removed from the file and that any derivative work contains ////
20
//// the original copyright notice and the associated disclaimer.////
21
////                                                             ////
22
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
23
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
24
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
25
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
26
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
27
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
28
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
29
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
30
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
31
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
32
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
33
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
34
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
35
////                                                             ////
36
/////////////////////////////////////////////////////////////////////
37
 
38
#ifndef USB_PD_SIE_H
39
#define USB_PD_SIE_H
40
 
41
#include "usb_defines.h"
42
#include "usb_crc5.h"
43
#include "usb_crc16.h"
44
 
45
enum PD_STATE { PD_IDLE = 1,
46
                                PD_ACTIVE = 2,
47
                                PD_TOKEN = 4,
48
                                PD_DATA = 8};
49
 
50
SC_MODULE(usb_pd_sie) {
51
 
52
  public:
53
 
54
        sc_in<bool>                     clk;
55
        sc_in<bool>                     rst;
56
 
57
        // RX Interface
58
        sc_in<sc_uint<8> >      rx_data;
59
        sc_in<bool>                     rx_valid, rx_active, rx_err;
60
 
61
        // PID Information
62
        // Decoded PIDs (used when token_valid is asserted)
63
        sc_out<bool>            pid_OUT, pid_IN, pid_SOF, pid_SETUP;
64
        sc_out<bool>            pid_DATA0, pid_DATA1, pid_DATA2, pid_MDATA;
65
        sc_out<bool>            pid_ACK, pid_NACK, pid_STALL, pid_NYET;
66
        sc_out<bool>            pid_PRE, pid_ERR, pid_SPLIT, pid_PING;
67
        sc_out<bool>            pid_cks_err;                                                            // Indicates a PID checksum error
68
 
69
        // Token Information
70
        sc_out<sc_uint<7> >     token_fadr;                                                                     // Function address from token
71
        sc_out<sc_uint<4> >     token_endp;                                                                     // Endpoint number from token
72
        sc_out<bool>            token_valid;                                                            // Token is valid
73
        sc_out<bool>            crc5_err;                                                                       // Token CRC5 error
74
        sc_out<sc_uint<11> >frame_no;                                                                   // Frame number for SOF tokens
75
 
76
        // Receive Data Output
77
        sc_out<sc_uint<8> >     rx_data_st;                                                                     // Data to memory store unit
78
        sc_out<bool>            rx_data_valid;                                                          // Data on rx_data_st is valid
79
        sc_out<bool>            rx_data_done;                                                           // Indicates end of a transfer
80
        sc_out<bool>            crc16_err;                                                                      // Data packet CRC16 error
81
 
82
        // Misc
83
        sc_out<bool>            seq_err;                                                                        // State Machine Sequence Error
84
        sc_out<bool>            rx_busy;                                                                        // Receiving Data Packet
85
 
86
        // Local Signals
87
        sc_signal<sc_uint<4> >  state, next_state;// synopsys state_vector state
88
        sc_signal<sc_uint<8> >  pid;                                                                    // Packet PID
89
        sc_signal<bool>                 pid_le_sm;                                                              // PID load enable from State Machine
90
        sc_signal<bool>                 pid_ld_en;                                                              // Enable loading of PID (all conditions)
91
        sc_signal<bool>                 pid_RES;
92
        sc_signal<bool>                 pid_TOKEN;                                                              // All TOKEN packet that we recognize
93
        sc_signal<bool>                 pid_DATA;                                                               // All DATA packet that we recognize
94
        sc_signal<sc_uint<8> >  token0, token1;                                                 // Token registers
95
        sc_signal<bool>                 token_le_1, token_le_2;                                 // Latch enables for token storage registers
96
        sc_signal<sc_uint<5> >  token_crc5;
97
        sc_signal<sc_uint<8> >  d0, d1, d2;                                                             // Data path delay line (used to filter out crcs)
98
        sc_signal<bool>                 data_valid_d;                                                   // Data valid output from State Machine
99
        sc_signal<bool>                 data_done;                                                              // Data cycle complete output from State Machine
100
        sc_signal<bool>                 data_valid0;                                                    // Data valid delay line
101
        sc_signal<bool>                 rxv1, rxv2;
102
        sc_signal<bool>                 pid_ack;
103
        sc_signal<bool>                 token_valid_r1;
104
        sc_signal<bool>                 token_valid_str1;
105
        sc_signal<bool>                 rx_active_r;
106
        sc_signal<bool>                 rx_busy_d;
107
        sc_signal<sc_uint<5> >  crc5_out, crc5_out2;
108
        sc_signal<sc_uint<5> >  crc5_pol;
109
        sc_signal<sc_uint<11> > crc5_din;
110
        sc_signal<bool>                 crc16_clr;
111
        sc_signal<sc_uint<16> > crc16_sum, crc16_out;
112
        sc_signal<sc_uint<8> >  crc16_din;
113
 
114
        usb_crc5                                *i_crc5;                                                                // CRC5 Calculator
115
        usb_crc16                               *i_crc16;                                                               // CRC16 Calculator
116
 
117
        // Busy Logic Functions
118
        void rx_busy_up1(void);
119
        void rx_busy_up2(void);
120
 
121
        // PID Decoding Logic Functions
122
        void pid_ld_up(void);
123
        void pid_up(void);
124
        void pid_cks_err_up(void);
125
        void pid_decoder(void);
126
        void pid_token_up(void);
127
        void pid_data_up(void);
128
 
129
        // Token Decoding Logic Functions
130
        void token_decoder(void);
131
        void token_valid_up1(void);
132
        void token_valid_up2(void);
133
        void token_valid_up3(void);
134
        void token_up(void);
135
 
136
        // CRC5 Logic Functions
137
        void crc5_din_up(void);
138
        void crc5_err_up(void);
139
        void crc5_out2_up(void);
140
 
141
        // Data Receiving Logic Functions
142
        void rxv1_up(void);
143
        void rxv2_up(void);
144
        void data_valid0_up(void);
145
        void d_up(void);
146
        void rx_data_st_up(void);
147
        void rx_data_valid_up(void);
148
        void rx_data_done_up(void);
149
 
150
        // CRC16 Logic Functions
151
        void rx_active_r_up(void);
152
        void crc16_din_up(void);
153
        void crc16_clr_up(void);
154
        void crc16_sum_up(void);
155
        void crc16_err_up(void);
156
 
157
        // Receive/Decode State Machine Functions
158
        void state_up(void);
159
        void pd_statemachine(void);
160
 
161
        // Destructor
162
//      ~usb_pd_sie(void);
163
 
164
        SC_CTOR(usb_pd_sie) {
165
                crc5_pol.write(31);
166
 
167
                SC_METHOD(rx_busy_up1);
168
                sensitive << clk.pos() << rst.neg();
169
                SC_METHOD(rx_busy_up2);
170
                sensitive << clk.pos();
171
 
172
                SC_METHOD(pid_ld_up);
173
                sensitive << pid_le_sm << rx_active << rx_valid;
174
                SC_METHOD(pid_up);
175
                sensitive << clk.pos() << rst.neg();
176
                SC_METHOD(pid_cks_err_up);
177
                sensitive << pid;
178
                SC_METHOD(pid_decoder);
179
                sensitive << pid;
180
                SC_METHOD(pid_token_up);
181
                sensitive << pid_OUT << pid_IN << pid_SOF << pid_SETUP << pid_PING;
182
                SC_METHOD(pid_data_up);
183
                sensitive << pid_DATA0 << pid_DATA1 << pid_DATA2 << pid_MDATA;
184
 
185
                SC_METHOD(token_decoder);
186
                sensitive << clk.pos();
187
                SC_METHOD(token_valid_up1);
188
                sensitive << clk.pos();
189
                SC_METHOD(token_valid_up2);
190
                sensitive << clk.pos();
191
                SC_METHOD(token_valid_up3);
192
                sensitive << token_valid_str1;
193
                SC_METHOD(token_up);
194
                sensitive << token0 << token1;
195
 
196
                SC_METHOD(crc5_din_up);
197
                sensitive << token_fadr << token_endp;
198
                SC_METHOD(crc5_err_up);
199
                sensitive << token_valid << crc5_out2 << token_crc5;
200
                SC_METHOD(crc5_out2_up);
201
                sensitive << crc5_out;
202
 
203
                SC_METHOD(rxv1_up);
204
                sensitive << clk.pos() << rst.neg();
205
                SC_METHOD(rxv2_up);
206
                sensitive << clk.pos() << rst.neg();
207
                SC_METHOD(data_valid0_up);
208
                sensitive << clk.pos();
209
                SC_METHOD(d_up);
210
                sensitive << clk.pos();
211
                SC_METHOD(rx_data_st_up);
212
                sensitive << d2;
213
                SC_METHOD(rx_data_valid_up);
214
                sensitive << data_valid0;
215
                SC_METHOD(rx_data_done_up);
216
                sensitive << data_done;
217
 
218
                SC_METHOD(rx_active_r_up);
219
                sensitive << clk.pos();
220
                SC_METHOD(crc16_din_up);
221
                sensitive << rx_data;
222
                SC_METHOD(crc16_clr_up);
223
                sensitive << rx_active << rx_active_r;
224
                SC_METHOD(crc16_sum_up);
225
                sensitive << clk.pos();
226
                SC_METHOD(crc16_err_up);
227
                sensitive << data_done << crc16_sum;
228
 
229
                SC_METHOD(state_up);
230
                sensitive << clk.pos() << rst.neg();
231
                SC_METHOD(pd_statemachine);
232
                sensitive << state << rx_valid << rx_active << rx_err << pid_ACK << pid_TOKEN << pid_DATA;
233
 
234
                // CRC5 Calculator Instantiation and Binding
235
                i_crc5 = new usb_crc5("CRC5");
236
                i_crc5->crc_in(crc5_pol);
237
                i_crc5->din(crc5_din);
238
                i_crc5->crc_out(crc5_out);
239
 
240
                // CRC16 Calculator Instantiation and Binding
241
                i_crc16 = new usb_crc16("CRC16");
242
                i_crc16->crc_in(crc16_sum);
243
                i_crc16->din(crc16_din);
244
                i_crc16->crc_out(crc16_out);
245
        }
246
 
247
};
248
 
249
#endif
250
 

powered by: WebSVN 2.1.0

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