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

Subversion Repositories ht_tunnel

[/] [ht_tunnel/] [trunk/] [rtl/] [systemc/] [link_l2/] [link_l2.cpp] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 acastong
//link_l2.cpp
2
/* ***** BEGIN LICENSE BLOCK *****
3
 * Version: MPL 1.1
4
 *
5
 * The contents of this file are subject to the Mozilla Public License Version
6
 * 1.1 (the "License"); you may not use this file except in compliance with
7
 * the License. You may obtain a copy of the License at
8
 * http://www.mozilla.org/MPL/
9
 *
10
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 * for the specific language governing rights and limitations under the
13
 * License.
14
 *
15
 * The Original Code is HyperTransport Tunnel IP Core.
16
 *
17
 * The Initial Developer of the Original Code is
18
 * Ecole Polytechnique de Montreal.
19
 * Portions created by the Initial Developer are Copyright (C) 2005
20
 * the Initial Developer. All Rights Reserved.
21
 *
22
 * Contributor(s):
23
 *   Ami Castonguay <acastong@grm.polymtl.ca>
24
 *
25
 * Alternatively, the contents of this file may be used under the terms
26
 * of the Polytechnique HyperTransport Tunnel IP Core Source Code License
27
 * (the  "PHTICSCL License", see the file PHTICSCL.txt), in which case the
28
 * provisions of PHTICSCL License are applicable instead of those
29
 * above. If you wish to allow use of your version of this file only
30
 * under the terms of the PHTICSCL License and not to allow others to use
31
 * your version of this file under the MPL, indicate your decision by
32
 * deleting the provisions above and replace them with the notice and
33
 * other provisions required by the PHTICSCL License. If you do not delete
34
 * the provisions above, a recipient may use your version of this file
35
 * under either the MPL or the PHTICSCL License."
36
 *
37
 * ***** END LICENSE BLOCK ***** */
38
 
39
#include "link_l2.h"
40
#include "link_frame_rx_l3.h"
41
#include "link_frame_tx_l3.h"
42
 
43
link_l2::link_l2( sc_module_name name) : sc_module(name) {
44
        ////////////////////////////////////////
45
        // Process declaration
46
        ////////////////////////////////////////
47
 
48
        SC_METHOD(rx_crc_state_machine);
49
        sensitive_pos(clk);
50
        sensitive_neg(resetx);
51
 
52
        SC_METHOD(tx_crc_state_machine);
53
        sensitive_pos(clk);
54
        sensitive_neg(resetx);
55
 
56
        SC_METHOD(evaluate_rx_crc_process);
57
        sensitive_pos(clk);
58
        sensitive_neg(resetx);
59
 
60
        SC_METHOD(evaluate_tx_crc_process);
61
        sensitive_pos(clk);
62
        sensitive_neg(resetx);
63 6 acastong
 
64
        SC_METHOD(output_ldtstop_disconnected);
65
        sensitive << ldtstop_disconnect_tx;
66 2 acastong
 
67
        SC_METHOD(select_output);
68
        sensitive << transmit_select << tx_last_crc <<
69
                                fc_dword_lk << fc_lctl_lk << fc_hctl_lk <<
70
                                tx_consume_data;
71
 
72
        SC_METHOD(output_framed_data);
73
        sensitive(framed_data_ready);
74
        sensitive(framed_data_available);
75
 
76
        ////////////////////////////////////////
77
        // RX Framer linking
78
        ////////////////////////////////////////
79
 
80
        frame_rx = new link_frame_rx_l3("link_frame_rx_l3");
81
        frame_rx->clk(clk);
82
        frame_rx->phy_ctl_lk(phy_ctl_lk);
83
 
84
        for(int n = 0; n < CAD_IN_WIDTH; n++){
85
                frame_rx->phy_cad_lk[n](phy_cad_lk[n]);
86
        }
87
        frame_rx->lk_disable_receivers_phy(lk_disable_receivers_phy);
88
        frame_rx->phy_available_lk(phy_available_lk);
89
 
90
#ifndef INTERNAL_SHIFTER_ALIGNMENT
91
        frame_rx->lk_deser_stall_phy(lk_deser_stall_phy);
92
        frame_rx->lk_deser_stall_cycles_phy(lk_deser_stall_cycles_phy);
93
#endif
94
 
95
        frame_rx->framed_cad(lk_dword_cd);
96
        frame_rx->framed_lctl(lk_lctl_cd);
97
        frame_rx->framed_hctl(lk_hctl_cd);
98
        frame_rx->framed_data_available(framed_data_available);
99
 
100
        frame_rx->resetx(resetx);
101
        frame_rx->pwrok(pwrok);
102
        frame_rx->ldtstopx(ldtstopx);
103
 
104
        frame_rx->csr_rx_link_width_lk(csr_rx_link_width_lk);
105
        frame_rx->csr_end_of_chain(csr_end_of_chain);
106
        frame_rx->csr_sync(csr_sync);
107
        frame_rx->csr_extended_ctl_timeout_lk(csr_extended_ctl_timeout_lk);
108
 
109
        frame_rx->lk_update_link_width_csr(lk_update_link_width_csr);
110
        frame_rx->lk_sampled_link_width_csr(lk_sampled_link_width_csr);
111
 
112
 
113
        frame_rx->lk_update_link_failure_property_csr(lk_update_link_failure_property_csr);
114
        frame_rx->lk_link_failure_csr(lk_link_failure_csr);
115
 
116
        frame_rx->ldtstop_disconnect_rx(ldtstop_disconnect_rx);
117
 
118
        frame_rx->lk_protocol_error_csr(lk_protocol_error_csr);
119
 
120
        frame_rx->rx_waiting_for_ctl_tx(rx_waiting_for_ctl_tx);
121
 
122
        frame_rx->lk_rx_connected(lk_rx_connected);
123
 
124
#ifdef RETRY_MODE_ENABLED
125
        frame_rx->csr_retry(csr_retry);
126
        frame_rx->cd_initiate_retry_disconnect(cd_initiate_retry_disconnect);
127
        frame_rx->lk_initiate_retry_disconnect(lk_initiate_retry_disconnect);
128
#endif
129
 
130
        ////////////////////////////////////////
131
        // TX Framer linking
132
        ////////////////////////////////////////
133
 
134
        frame_tx = new link_frame_tx_l3("link_frame_tx_l3");
135
        frame_tx->clk(clk);
136
 
137
        frame_tx->lk_ctl_phy(lk_ctl_phy);
138
 
139
 
140
        for(int n = 0; n < CAD_OUT_WIDTH; n++){
141
                frame_tx->lk_cad_phy[n](lk_cad_phy[n]);
142
        }
143
        frame_tx->phy_consume_lk(phy_consume_lk);
144
 
145
        frame_tx->disable_drivers(lk_disable_drivers_phy);
146
 
147
        frame_tx->cad_to_frame(cad_to_frame);
148
        frame_tx->lctl_to_frame(lctl_to_frame);
149
        frame_tx->hctl_to_frame(hctl_to_frame);
150
        frame_tx->tx_consume_data(tx_consume_data);
151
 
152
        frame_tx->resetx(resetx);
153
        frame_tx->ldtstopx(ldtstopx);
154
 
155
        frame_tx->csr_tx_link_width_lk(csr_tx_link_width_lk);
156
        frame_tx->csr_end_of_chain(csr_end_of_chain);
157
        frame_tx->csr_transmitter_off_lk(csr_transmitter_off_lk);
158
        frame_tx->csr_extented_ctl_lk(csr_extented_ctl_lk);
159
        frame_tx->csr_ldtstop_tristate_enable_lk(csr_ldtstop_tristate_enable_lk);
160
 
161
#ifdef RETRY_MODE_ENABLED
162
        frame_tx->tx_retry_disconnect(tx_retry_disconnect);
163
#endif
164
 
165
        frame_tx->ldtstop_disconnect_tx(ldtstop_disconnect_tx);
166
        frame_tx->rx_waiting_for_ctl_tx(rx_waiting_for_ctl_tx);
167
}
168
 
169
void link_l2::rx_crc_state_machine(){
170
        //initial value at reset
171
        if(!resetx.read()){
172
                rx_state = RX_FIRST_CRC_WINDOW_ST;
173
                rx_crc_count = 0;
174
                new_rx_crc_window = false;
175
                ldtstop_disconnect_rx = false;
176
                framed_data_ready = true;
177
        }
178
        //action to take at clock edge
179
        else{
180
                //default values
181
                framed_data_ready = true;
182
                new_rx_crc_window = false;
183
                ldtstop_disconnect_rx = false;
184
 
185
                //RX state machine
186
                switch(rx_state.read()){
187
 
188
                case RX_CRC_WINDOW_BEGIN_ST:
189
                        //incremet rx count when data available only
190
                        if(framed_data_available.read())
191
                                rx_crc_count = rx_crc_count.read()+1;
192
 
193
                        //After 16 dword, it is time to received CRC
194
                        if(rx_crc_count.read() == 15 && framed_data_available.read()){
195
                                //Do not send CRC to the decoder
196
                                framed_data_ready = false;
197
 
198
                                //If starting a ldtstop sequence, we need to go to a second
199
                                //set of state so that we disconnect after the next CRC
200
                                //window is done
201
                                if(cd_initiate_nonretry_disconnect_lk.read()){
202
                                        rx_state = RX_RECEIVE_CRC_LDTSTOP_ST;
203
                                }
204
                                else{
205
                                        rx_state = RX_RECEIVE_CRC_ST;
206
                                }
207
                        }
208
                        else if(cd_initiate_nonretry_disconnect_lk.read()){
209
                                //When we receive a disconnect NOP, it gets decoded immediately
210
                                //, that's why if the rx_crc count
211
                                //is 0, it means we were in the current window
212
                                rx_state = RX_CRC_WINDOW_BEGIN_LDTSTOP_ST;
213
                        }
214
                        break;
215
                case RX_RECEIVE_CRC_ST:
216
                        rx_crc_count = rx_crc_count.read();//Don't modify the CRC count
217
                        //Don't send the CRC received to the decoder by default unless framed data available
218
                        framed_data_ready = false;
219
 
220
                        if(framed_data_available.read()){
221
                                framed_data_ready = true;
222
                                if(cd_initiate_nonretry_disconnect_lk.read()){
223
                                        rx_state = RX_CRC_WINDOW_END_LDTSTOP_ST;
224
                                }
225
                                else{
226
                                        rx_state = RX_CRC_WINDOW_END_ST;
227
                                }
228
                        }
229
                        else if(cd_initiate_nonretry_disconnect_lk.read()){
230
                                rx_state = RX_RECEIVE_CRC_LDTSTOP_ST;
231
                        }
232
                        break;
233
 
234
                case RX_CRC_WINDOW_END_ST:
235
                        if(framed_data_available.read())
236
                                rx_crc_count = rx_crc_count.read()+1;
237
 
238
                        if(rx_crc_count.read() == 127 && framed_data_available.read()){
239
                                new_rx_crc_window = true;
240
                                if(cd_initiate_nonretry_disconnect_lk.read()){
241
                                        rx_state = RX_CRC_WINDOW_LAST_LDTSTOP_ST;
242
                                }
243
                                else{
244
                                        rx_state = RX_CRC_WINDOW_BEGIN_ST;
245
                                }
246
                        }
247
                        else if(cd_initiate_nonretry_disconnect_lk.read()){
248
                                rx_state = RX_CRC_WINDOW_END_LDTSTOP_ST;
249
                        }
250
                        break;
251
 
252
                /**
253
                        The previous group of states it for normal operation (also includes
254
                        the last default state : RX_FIRST_CRC_WINDOW_ST)
255
 
256
                        The next group of states is for when a LDTSTOP sequence is initiated.
257
                        When LDTSTOP is initiated, the current CRC window must be finished,
258
                        the last CRC sent and then disconnect.
259
                */
260
 
261
                case RX_FIRST_CRC_WINDOW_LDTSTOP_ST:
262
                        if(framed_data_available.read())
263
                                rx_crc_count = rx_crc_count.read()+1;
264
 
265
                        if(rx_crc_count.read() == 127 && framed_data_available.read()){
266
                                new_rx_crc_window = true;
267
                                rx_state = RX_RECEIVE_LAST_CRC_LDTSTOP_ST;
268
                        }
269
                        break;
270
 
271
                case RX_CRC_WINDOW_BEGIN_LDTSTOP_ST:
272
                        if(framed_data_available.read())
273
                                rx_crc_count = rx_crc_count.read()+1;
274
 
275
                        if(rx_crc_count.read() == 15 && framed_data_available.read()){
276
                                framed_data_ready = false;
277
                                rx_state = RX_RECEIVE_CRC_LDTSTOP_ST;
278
                        }
279
                        break;
280
 
281
                case RX_RECEIVE_CRC_LDTSTOP_ST:
282
                        if(framed_data_available.read()){
283
                                rx_state = RX_CRC_WINDOW_END_LDTSTOP_ST;
284
                                framed_data_ready = true;
285
                        }
286
                        else{
287
                                framed_data_ready = false;
288
                        }
289
                        break;
290
 
291
                case RX_CRC_WINDOW_END_LDTSTOP_ST:
292
                        if(framed_data_available.read())
293
                                rx_crc_count = rx_crc_count.read()+1;
294
 
295
                        if(rx_crc_count.read() == 127 && framed_data_available.read()){
296
                                new_rx_crc_window = true;
297
                                rx_state = RX_CRC_WINDOW_LAST_LDTSTOP_ST;
298
                        }
299
                        break;
300
                case RX_CRC_WINDOW_LAST_LDTSTOP_ST:
301
                        if(framed_data_available.read())
302
                                rx_crc_count = rx_crc_count.read()+1;
303
 
304
                        if(rx_crc_count.read() == 15 && framed_data_available.read()){
305
                                rx_state = RX_RECEIVE_LAST_CRC_LDTSTOP_ST;
306
                                framed_data_ready = false;
307
                        }
308
                        break;
309
                case RX_RECEIVE_LAST_CRC_LDTSTOP_ST:
310
                        framed_data_ready = false;
311
                        rx_crc_count = rx_crc_count.read();
312
 
313
                        if(framed_data_available.read()){
314
                                rx_state = RX_DISCONNECTED;
315
                        }
316
                        break;
317
 
318
                //Link is disconnected
319
                case RX_DISCONNECTED:
320
                        framed_data_ready = false;//Don't send any data to decoder
321
                        rx_crc_count = 0;//Keep CRC count at 0
322
                        //Make sure the CRC register is ready to start a new windows
323
                        //by resetting it
324
                        new_rx_crc_window = true;
325
 
326
                        ldtstop_disconnect_rx = true;
327
                        if(!ldtstopx.read() || csr_end_of_chain.read() || csr_sync.read()){
328
                                rx_state = RX_DISCONNECTED;
329
                        }
330
                        else{
331
                                rx_state = RX_FIRST_CRC_WINDOW_ST;
332
                        }
333
                        break;
334
                default: //case RX_FIRST_CRC_WINDOW_ST:
335
                        if(framed_data_available.read())
336
                                rx_crc_count = rx_crc_count.read()+1;
337
 
338
                        if(rx_crc_count.read() == 127 && framed_data_available.read()){
339
                                new_rx_crc_window = true;
340
                                if(cd_initiate_nonretry_disconnect_lk.read()){
341
                                        rx_state = RX_CRC_WINDOW_LAST_LDTSTOP_ST;
342
                                }
343
                                else{
344
                                        rx_state = RX_CRC_WINDOW_BEGIN_ST;
345
                                }
346
                        }
347
                        else if(cd_initiate_nonretry_disconnect_lk.read()){
348
                                rx_state = RX_FIRST_CRC_WINDOW_LDTSTOP_ST;
349
                        }
350
                        break;
351
                }
352
 
353
                /**
354
                        If sync of csr_end_of_chain, go to disconnected state (ignore input)
355
 
356
                        Also disconnect if the connect sequence is not complete
357
                        (!lk_rx_connected.read()) when ldtstop sequence is initiated.  In retry mode,
358
                        ldtstop sequence might start in the middle of a retry reconnect sequence.  This
359
                        code will make RX abort reconnect, which might not be the case for the TX : it
360
                        will finish the connect, the flow_control_l2 will make it send a discon nop and
361
                        then it will redisconnect
362
                */
363
                if(csr_sync.read() || csr_end_of_chain.read() ||
364
                        (!lk_rx_connected.read() && !ldtstopx.read()))
365
                {
366
                        framed_data_ready = false;
367
                        rx_state = RX_DISCONNECTED;
368
                }
369
#ifdef RETRY_MODE_ENABLED
370
                /*
371
                In the case of a retry sequence, the RX framer will disconnect so just go directly
372
                to the first CRC window to wait for it to complete the reconnect sequence
373
 
374
                Note: the command decoder is NOT allowed to activate cd_initiate_nonretry_disconnect_lk.
375
                If a ldtstop sequence is started, it's cd_initiate_retry_disconnect_lk that will
376
                be activated
377
                */
378
                else if(lk_initiate_retry_disconnect.read() || cd_initiate_retry_disconnect.read()){
379
                        rx_state = RX_FIRST_CRC_WINDOW_ST;
380
                        rx_crc_count = 0;
381
                }
382
#endif
383
        }
384
}
385
 
386
 
387
void link_l2::evaluate_rx_crc_process(){
388
        //Init values during reset
389
        if(!resetx.read()){
390
                rx_crc = 0xFFFFFFFF;
391
                rx_last_crc = 0;
392
 
393
                lk_crc_error_csr = false;
394
                crc_error = false;
395
                crc_error_delay = 0;
396
        }
397
 
398
        //Action to take during clock event
399
        else{
400
                //By default, no error is detected
401
                lk_crc_error_csr = false;
402
                bool crc_error_detected = false;
403
 
404
                //Check if we are in a state to check the received CRC
405
                bool crc_comparison_state =
406
                        rx_state.read() == RX_RECEIVE_CRC_ST ||
407
                        rx_state.read() == RX_RECEIVE_CRC_LDTSTOP_ST ||
408
                        rx_state.read() == RX_RECEIVE_LAST_CRC_LDTSTOP_ST;
409
 
410
 
411
                //If starting a new CRC, calculate from 0, otherwise take the old CRC
412
                sc_uint<32>  crc_in;
413
                sc_uint<32>  crc;
414
                if(new_rx_crc_window.read())
415
                        crc_in = 0xFFFFFFFF;
416
                else
417
                        crc_in = rx_crc.read();
418
 
419
 
420
                //Setup the data to send in the CRC :
421
                ////HCTL,data[31,24],HCTL,data[23,16],LCTL,data[15,8],LCTL,data[7,0]
422
                //See chapter 10 of HT spec
423
                sc_bv<36> d;
424
                d.range(7,0) = lk_dword_cd.read().range(7,0);
425
                d[8] = lk_lctl_cd.read();
426
                d.range(16,9) = lk_dword_cd.read().range(15,8);
427
                d[17] = lk_lctl_cd.read();
428
                d.range(25,18) = lk_dword_cd.read().range(23,16);
429
                d[26] = lk_hctl_cd.read();
430
                d.range(34,27) = lk_dword_cd.read().range(31,24);
431
                d[35] = lk_hctl_cd.read();
432
 
433
                /*//Calculate the CRC
434
                for (int i=0; i<36; ++i) {
435
                        bool tmp = crc[31];  // store highest bit
436
 
437
                        // subtract poly if greater:
438
                        crc[31] = crc[30];
439
                        crc[30] = crc[29];
440
                        crc[29] = crc[28];
441
                        crc[28] = crc[27];
442
                        crc[27] = crc[26];
443
                        crc[26] = crc[25]^tmp;
444
                        crc[25] = crc[24];
445
                        crc[24] = crc[23];
446
                        crc[23] = crc[22]^tmp;
447
                        crc[22] = crc[21]^tmp;
448
                        crc[21] = crc[20];
449
                        crc[20] = crc[19];
450
                        crc[19] = crc[18];
451
                        crc[18] = crc[17];
452
                        crc[17] = crc[16];
453
                        crc[16] = crc[15]^tmp;
454
                        crc[15] = crc[14];
455
                        crc[14] = crc[13];
456
                        crc[13] = crc[12];
457
                        crc[12] = crc[11]^tmp;
458
                        crc[11] = crc[10]^tmp;
459
                        crc[10] = crc[9]^tmp;
460
                        crc[9] = crc[8];
461
                        crc[8] = crc[7]^tmp;
462
                        crc[7] = crc[6]^tmp;
463
                        crc[6] = crc[5];
464
                        crc[5] = crc[4]^tmp;
465
                        crc[4] = crc[3]^tmp;
466
                        crc[3] = crc[2];
467
                        crc[2] = crc[1]^tmp;
468
                        crc[1] = crc[0]^tmp;
469
                        crc[0] = ((sc_bit)crc_data[i]) ^ tmp;
470
                }*/
471
                //Obtained with a slightly modified Xilinx Xapp209
472
                crc[0] = (sc_bit)(crc_in[2] ^ crc_in[20] ^ crc_in[12] ^ crc_in[21] ^ crc_in[5] ^ crc_in[30] ^ crc_in[22] ^ crc_in[6] ^ d[35] ^ crc_in[24] ^ crc_in[8] ^ d[3] ^ crc_in[25] ^ crc_in[26] ^ crc_in[27] ^ crc_in[28]);
473
                crc[1] = (sc_bit)(crc_in[2] ^ crc_in[3] ^ crc_in[20] ^ crc_in[12] ^ crc_in[5] ^ crc_in[13] ^ crc_in[30] ^ crc_in[31] ^ d[34] ^ crc_in[23] ^ crc_in[7] ^ d[2] ^ crc_in[24] ^ crc_in[8] ^ d[3] ^ crc_in[9] ^ crc_in[29]);
474
                crc[2] = (sc_bit)(crc_in[3] ^ crc_in[20] ^ crc_in[5] ^ crc_in[13] ^ d[33] ^ crc_in[22] ^ crc_in[31] ^ d[2] ^ crc_in[9] ^ crc_in[26] ^ crc_in[28] ^ crc_in[2] ^ crc_in[10] ^ crc_in[4] ^ crc_in[12] ^ d[1] ^ crc_in[14] ^ d[3] ^ crc_in[27]);
475
                crc[3] = (sc_bit)(crc_in[3] ^ crc_in[11] ^ crc_in[13] ^ crc_in[5] ^ d[0] ^ d[2] ^ crc_in[15] ^ crc_in[28] ^ crc_in[10] ^ crc_in[4] ^ d[32] ^ crc_in[21] ^ crc_in[6] ^ d[1] ^ crc_in[14] ^ crc_in[23] ^ crc_in[27] ^ crc_in[29]);
476
                crc[4] = (sc_bit)(crc_in[11] ^ d[31] ^ crc_in[20] ^ d[0] ^ crc_in[7] ^ crc_in[15] ^ crc_in[26] ^ crc_in[0] ^ crc_in[2] ^ crc_in[4] ^ crc_in[21] ^ d[1] ^ crc_in[14] ^ d[3] ^ crc_in[8] ^ crc_in[16] ^ crc_in[25] ^ crc_in[27] ^ crc_in[29]);
477
                crc[5] = (sc_bit)(crc_in[3] ^ crc_in[20] ^ d[0] ^ d[2] ^ crc_in[15] ^ crc_in[24] ^ crc_in[9] ^ crc_in[17] ^ crc_in[0] ^ crc_in[2] ^ d[30] ^ crc_in[6] ^ d[3] ^ crc_in[16] ^ crc_in[25] ^ crc_in[1]);
478
                crc[6] = (sc_bit)(crc_in[3] ^ d[2] ^ crc_in[7] ^ crc_in[17] ^ crc_in[26] ^ crc_in[0] ^ crc_in[2] ^ crc_in[10] ^ crc_in[4] ^ crc_in[21] ^ d[1] ^ crc_in[16] ^ crc_in[25] ^ d[29] ^ crc_in[18] ^ crc_in[1]);
479
                crc[7] = (sc_bit)(crc_in[11] ^ crc_in[3] ^ crc_in[20] ^ d[0] ^ crc_in[24] ^ d[28] ^ crc_in[17] ^ crc_in[19] ^ crc_in[28] ^ crc_in[4] ^ crc_in[12] ^ crc_in[21] ^ crc_in[30] ^ crc_in[6] ^ d[1] ^ d[3] ^ crc_in[25] ^ crc_in[18] ^ crc_in[1]);
480
                crc[8] = (sc_bit)(d[0] ^ crc_in[13] ^ crc_in[31] ^ crc_in[7] ^ d[2] ^ crc_in[24] ^ crc_in[19] ^ crc_in[28] ^ crc_in[0] ^ crc_in[4] ^ crc_in[30] ^ crc_in[6] ^ d[27] ^ d[3] ^ crc_in[8] ^ crc_in[18] ^ crc_in[27] ^ crc_in[29]);
481
                crc[9] = (sc_bit)(crc_in[20] ^ crc_in[5] ^ crc_in[31] ^ d[26] ^ d[2] ^ crc_in[7] ^ crc_in[9] ^ crc_in[19] ^ crc_in[28] ^ crc_in[0] ^ crc_in[30] ^ d[1] ^ crc_in[14] ^ crc_in[8] ^ crc_in[25] ^ crc_in[29] ^ crc_in[1]);
482
                crc[10] = (sc_bit)(d[0] ^ crc_in[5] ^ crc_in[22] ^ crc_in[31] ^ crc_in[15] ^ crc_in[24] ^ crc_in[9] ^ crc_in[28] ^ crc_in[10] ^ crc_in[12] ^ d[25] ^ d[1] ^ d[3] ^ crc_in[25] ^ crc_in[27] ^ crc_in[29] ^ crc_in[1]);
483
                crc[11] = (sc_bit)(crc_in[11] ^ crc_in[20] ^ d[24] ^ d[0] ^ crc_in[5] ^ crc_in[13] ^ crc_in[22] ^ d[2] ^ crc_in[24] ^ crc_in[0] ^ crc_in[10] ^ crc_in[12] ^ crc_in[21] ^ crc_in[23] ^ d[3] ^ crc_in[8] ^ crc_in[16] ^ crc_in[27] ^ crc_in[29]);
484
                crc[12] = (sc_bit)(crc_in[11] ^ crc_in[20] ^ crc_in[5] ^ crc_in[13] ^ d[2] ^ crc_in[9] ^ crc_in[17] ^ crc_in[26] ^ crc_in[0] ^ crc_in[2] ^ d[23] ^ d[1] ^ crc_in[14] ^ crc_in[23] ^ d[3] ^ crc_in[8] ^ crc_in[27] ^ crc_in[1]);
485
                crc[13] = (sc_bit)(d[22] ^ crc_in[3] ^ d[0] ^ d[2] ^ crc_in[15] ^ crc_in[24] ^ crc_in[9] ^ crc_in[28] ^ crc_in[2] ^ crc_in[10] ^ crc_in[12] ^ crc_in[21] ^ crc_in[6] ^ d[1] ^ crc_in[14] ^ crc_in[18] ^ crc_in[27] ^ crc_in[1]);
486
                crc[14] = (sc_bit)(crc_in[3] ^ crc_in[11] ^ d[0] ^ crc_in[13] ^ crc_in[22] ^ crc_in[7] ^ crc_in[15] ^ crc_in[19] ^ crc_in[28] ^ crc_in[0] ^ d[21] ^ crc_in[2] ^ crc_in[10] ^ crc_in[4] ^ d[1] ^ crc_in[16] ^ crc_in[25] ^ crc_in[29]);
487
                crc[15] = (sc_bit)(crc_in[3] ^ crc_in[11] ^ crc_in[20] ^ crc_in[5] ^ d[0] ^ crc_in[17] ^ crc_in[26] ^ crc_in[0] ^ crc_in[4] ^ crc_in[12] ^ crc_in[30] ^ crc_in[14] ^ crc_in[23] ^ crc_in[8] ^ crc_in[16] ^ crc_in[29] ^ d[20] ^ crc_in[1]);
488
                crc[16] = (sc_bit)(crc_in[20] ^ crc_in[13] ^ crc_in[22] ^ crc_in[31] ^ crc_in[15] ^ d[19] ^ crc_in[9] ^ crc_in[17] ^ crc_in[26] ^ crc_in[28] ^ crc_in[0] ^ crc_in[4] ^ d[3] ^ crc_in[8] ^ crc_in[25] ^ crc_in[18] ^ crc_in[1]);
489
                crc[17] = (sc_bit)(crc_in[5] ^ d[2] ^ crc_in[9] ^ crc_in[26] ^ crc_in[19] ^ crc_in[2] ^ crc_in[10] ^ crc_in[21] ^ crc_in[14] ^ crc_in[23] ^ d[18] ^ crc_in[16] ^ crc_in[18] ^ crc_in[27] ^ crc_in[29] ^ crc_in[1]);
490
                crc[18] = (sc_bit)(crc_in[11] ^ crc_in[3] ^ crc_in[20] ^ crc_in[22] ^ d[17] ^ crc_in[15] ^ crc_in[24] ^ crc_in[17] ^ crc_in[19] ^ crc_in[28] ^ crc_in[2] ^ crc_in[10] ^ crc_in[30] ^ d[1] ^ crc_in[6] ^ crc_in[27]);
491
                crc[19] = (sc_bit)(crc_in[3] ^ crc_in[11] ^ crc_in[20] ^ d[0] ^ crc_in[31] ^ crc_in[7] ^ crc_in[28] ^ crc_in[12] ^ crc_in[4] ^ crc_in[21] ^ d[16] ^ crc_in[23] ^ crc_in[16] ^ crc_in[25] ^ crc_in[18] ^ crc_in[29]);
492
                crc[20] = (sc_bit)(d[15] ^ crc_in[13] ^ crc_in[5] ^ crc_in[22] ^ crc_in[24] ^ crc_in[17] ^ crc_in[26] ^ crc_in[19] ^ crc_in[0] ^ crc_in[4] ^ crc_in[12] ^ crc_in[21] ^ crc_in[30] ^ crc_in[8] ^ crc_in[29]);
493
                crc[21] = (sc_bit)(crc_in[20] ^ crc_in[5] ^ crc_in[13] ^ crc_in[22] ^ crc_in[31] ^ crc_in[9] ^ d[14] ^ crc_in[30] ^ crc_in[14] ^ crc_in[6] ^ crc_in[23] ^ crc_in[25] ^ crc_in[18] ^ crc_in[27] ^ crc_in[1]);
494
                crc[22] = (sc_bit)(d[13] ^ crc_in[20] ^ crc_in[5] ^ crc_in[22] ^ crc_in[31] ^ crc_in[15] ^ crc_in[7] ^ crc_in[19] ^ crc_in[10] ^ crc_in[12] ^ crc_in[30] ^ crc_in[14] ^ crc_in[23] ^ d[3] ^ crc_in[8] ^ crc_in[25] ^ crc_in[27]);
495
                crc[23] = (sc_bit)(crc_in[11] ^ crc_in[5] ^ crc_in[13] ^ crc_in[22] ^ crc_in[31] ^ d[2] ^ crc_in[15] ^ crc_in[9] ^ d[12] ^ crc_in[2] ^ crc_in[12] ^ crc_in[30] ^ crc_in[23] ^ d[3] ^ crc_in[16] ^ crc_in[25] ^ crc_in[27]);
496
                crc[24] = (sc_bit)(crc_in[3] ^ crc_in[13] ^ crc_in[31] ^ d[2] ^ crc_in[24] ^ crc_in[17] ^ crc_in[26] ^ crc_in[28] ^ crc_in[10] ^ crc_in[12] ^ crc_in[6] ^ d[1] ^ crc_in[14] ^ crc_in[23] ^ crc_in[16] ^ d[11]);
497
                crc[25] = (sc_bit)(crc_in[11] ^ d[0] ^ crc_in[13] ^ crc_in[7] ^ crc_in[15] ^ crc_in[24] ^ crc_in[17] ^ d[10] ^ crc_in[4] ^ d[1] ^ crc_in[14] ^ crc_in[25] ^ crc_in[18] ^ crc_in[27] ^ crc_in[29]);
498
                crc[26] = (sc_bit)(crc_in[20] ^ d[0] ^ crc_in[22] ^ crc_in[15] ^ crc_in[24] ^ crc_in[19] ^ crc_in[0] ^ crc_in[2] ^ crc_in[21] ^ crc_in[6] ^ crc_in[14] ^ d[3] ^ crc_in[16] ^ crc_in[18] ^ crc_in[27] ^ d[9]);
499
                crc[27] = (sc_bit)(crc_in[3] ^ crc_in[20] ^ crc_in[22] ^ d[2] ^ crc_in[7] ^ crc_in[15] ^ crc_in[17] ^ crc_in[19] ^ crc_in[28] ^ d[8] ^ crc_in[0] ^ crc_in[21] ^ crc_in[23] ^ crc_in[16] ^ crc_in[25] ^ crc_in[1]);
500
                crc[28] = (sc_bit)(crc_in[20] ^ crc_in[22] ^ crc_in[24] ^ crc_in[17] ^ crc_in[26] ^ crc_in[2] ^ crc_in[4] ^ crc_in[21] ^ d[1] ^ crc_in[23] ^ crc_in[8] ^ crc_in[16] ^ crc_in[18] ^ d[7] ^ crc_in[29] ^ crc_in[1]);
501
                crc[29] = (sc_bit)(crc_in[3] ^ crc_in[5] ^ d[0] ^ crc_in[22] ^ crc_in[24] ^ crc_in[9] ^ crc_in[17] ^ crc_in[19] ^ d[6] ^ crc_in[2] ^ crc_in[21] ^ crc_in[30] ^ crc_in[23] ^ crc_in[25] ^ crc_in[18] ^ crc_in[27]);
502
                crc[30] = (sc_bit)(crc_in[3] ^ crc_in[20] ^ crc_in[22] ^ crc_in[31] ^ crc_in[24] ^ crc_in[26] ^ crc_in[19] ^ crc_in[28] ^ crc_in[0] ^ crc_in[10] ^ crc_in[4] ^ crc_in[6] ^ crc_in[23] ^ crc_in[25] ^ crc_in[18] ^ d[5]);
503
                crc[31] = (sc_bit)(crc_in[11] ^ crc_in[20] ^ crc_in[5] ^ crc_in[7] ^ crc_in[24] ^ d[4] ^ crc_in[26] ^ crc_in[19] ^ crc_in[4] ^ crc_in[21] ^ crc_in[23] ^ crc_in[25] ^ crc_in[27] ^ crc_in[29] ^ crc_in[1]);
504
 
505
                //CRC is sent inverted on the link
506
                sc_uint<32> inverted_lk_dword_cd = ~(sc_uint<32>(lk_dword_cd.read()));
507
 
508
                //If in comparison state, check if received CRC is correct
509
                if(framed_data_available.read() && crc_comparison_state){
510
                        crc_error_detected = rx_last_crc.read() != inverted_lk_dword_cd;
511
                }
512
 
513
                if(framed_data_available.read() && !crc_comparison_state){
514
                        rx_crc = crc;
515
                }
516
                else if(new_rx_crc_window.read()){
517
                        rx_crc = 0xFFFFFFFF;
518
                }
519
 
520
                //When starting a new windows, store the last value since the CRC of 
521
                //window is sent with a delay
522
                if(new_rx_crc_window.read()){
523
                        rx_last_crc = rx_crc;
524
                }
525
 
526
                //Only log error after 15 cycles to exlude sync and reset errors
527
                if(crc_error_delay.read() == 15){
528
                        lk_crc_error_csr = true;
529
                }
530
 
531
                //Don't log errors in sync, end of chain, of retry mode.  Reset crc_error
532
                //if crc_error_delay reached 15 and the error is logged
533
                if(csr_sync.read() || csr_end_of_chain.read() || crc_error_delay.read() == 15
534
#ifdef RETRY_MODE_ENABLED
535
                        || csr_retry.read()
536
#endif
537
                        ){
538
                        crc_error = false;
539
                }
540
                else if(crc_error_detected){
541
                        crc_error = true;
542
                }
543
 
544
                //Increment CRC error while the error is detected
545
                if(crc_error.read() && !csr_sync.read()){
546
                        crc_error_delay = crc_error_delay.read() + 1;
547
                }
548
                else{
549
                        crc_error_delay = 0;
550
                }
551
 
552
        }
553
 
554
}
555
 
556
 
557
void link_l2::tx_crc_state_machine(){
558
        //Value registers take at reset
559
        if(!resetx.read()){
560
                tx_state = TX_FIRST_CRC_WINDOW_ST;
561
                tx_crc_count = 0;
562
                new_tx_crc_window = false;
563
                ldtstop_disconnect_tx = false;
564
                transmit_select = TX_SELECT_DATA;
565
        }
566
        else{
567
                //Default values
568
                new_tx_crc_window = false;
569
                ldtstop_disconnect_tx = false;
570
                if(tx_consume_data.read())
571
                        transmit_select = TX_SELECT_DATA;
572
                //else stay the same
573
 
574
                /**
575
                        Note on ldtstop sequence.
576
 
577
                        Ldtstop sequence normally started when the CD detects a discon nop
578
                        and activates cd_initiate_nonretry_disconnect_lk.
579
 
580
                        In the retry mode, it is possible that a retry sequence is started
581
                        while reconnecting the link, in which case the RX might not complete connection
582
                        that a discon nop might never be received.  In that case, the flow_control
583
                        should still activate fc_disconnect_lk to activate the disconnect, which
584
                        should not cause any problem.
585
 
586
                        This *should* not happen in non retry mode, but we check for it anyway
587
                        just to make sure.  If ldtstop is asserted while RX is not connected,
588
                        start an ldtstop sequence just like if the CD had decoded it.
589
                */
590
                bool initiate_ldtstop_sequence = cd_initiate_nonretry_disconnect_lk.read() ||
591
                        !ldtstopx.read() && !lk_rx_connected.read();
592
 
593
                switch(tx_state.read()){
594
                case TX_CRC_WINDOW_BEGIN_ST:
595
                        //Increment the tx CRC count when a dword is sent
596
                        if(tx_consume_data.read())
597
                                tx_crc_count = tx_crc_count.read()+1;
598
 
599
                        //When the window is finished
600
                        if(tx_crc_count.read() == 15 && tx_consume_data.read()){
601
                                if(initiate_ldtstop_sequence)
602
                                        tx_state = TX_SEND_CRC_LDTSTOP_ST;
603
                                else
604
                                        tx_state = TX_SEND_CRC_ST;
605
                                transmit_select = TX_SELECT_CRC;
606
                        }
607
                        else if(initiate_ldtstop_sequence){
608
                                tx_state = TX_CRC_WINDOW_BEGIN_LDTSTOP_ST;
609
                        }
610
                        break;
611
                case TX_SEND_CRC_ST:
612
                        tx_crc_count = tx_crc_count.read();
613
 
614
                        if(tx_consume_data.read()){
615
                                if(initiate_ldtstop_sequence)
616
                                        tx_state = TX_CRC_WINDOW_END_LDTSTOP_ST;
617
                                else
618
                                        tx_state = TX_CRC_WINDOW_END_ST;
619
                        }
620
                        else if(initiate_ldtstop_sequence){
621
                                tx_state = TX_SEND_CRC_LDTSTOP_ST;
622
                        }
623
 
624
                        if(!tx_consume_data.read())
625
                                transmit_select = TX_SELECT_CRC;
626
 
627
                        break;
628
                case TX_CRC_WINDOW_END_ST:
629
                        if(tx_consume_data.read())
630
                                tx_crc_count = tx_crc_count.read()+1;
631
 
632
                        if(tx_crc_count.read() == 127 && tx_consume_data.read()){
633
                                new_tx_crc_window = true;
634
                                if(initiate_ldtstop_sequence)
635
                                        tx_state = TX_CRC_WINDOW_BEGIN_LDTSTOP_ST;
636
                                else
637
                                        tx_state = TX_CRC_WINDOW_BEGIN_ST;
638
                        }
639
                        else if(initiate_ldtstop_sequence){
640
                                tx_state = TX_FIRST_CRC_WINDOW_LDTSTOP_ST;
641
                        }
642
                        break;
643
 
644
 
645
                case TX_FIRST_CRC_WINDOW_LDTSTOP_ST:
646
                        if(tx_consume_data.read())
647
                                tx_crc_count = tx_crc_count.read()+1;
648
 
649
                        if(tx_crc_count.read() == 127 && tx_consume_data.read()){
650
                                new_tx_crc_window = true;
651
                                tx_state = TX_CRC_WINDOW_LAST_LDTSTOP_ST;
652
                        }
653
                        break;
654
                case TX_CRC_WINDOW_BEGIN_LDTSTOP_ST:
655
                        if(tx_consume_data.read())
656
                                tx_crc_count = tx_crc_count.read()+1;
657
 
658
                        if(tx_crc_count.read() == 15 && tx_consume_data.read()){
659
                                tx_state = TX_SEND_CRC_LDTSTOP_ST;
660
                                transmit_select = TX_SELECT_CRC;
661
                        }
662
                        break;
663
                case TX_SEND_CRC_LDTSTOP_ST:
664
                        tx_crc_count = rx_crc_count.read();
665
 
666
                        if(tx_consume_data.read()){
667
                                tx_state = TX_CRC_WINDOW_END_LDTSTOP_ST;
668
                        }
669
 
670
                        if(!tx_consume_data.read())
671
                                transmit_select = TX_SELECT_CRC;
672
 
673
                        break;
674
                case TX_CRC_WINDOW_END_LDTSTOP_ST:
675
                        if(tx_consume_data.read())
676
                                tx_crc_count = tx_crc_count.read()+1;
677
 
678
                        if(tx_crc_count.read() == 127 && tx_consume_data.read()){
679
                                new_tx_crc_window = true;
680
                                tx_state = TX_CRC_WINDOW_LAST_LDTSTOP_ST;
681
                        }
682
                        break;
683
                case TX_CRC_WINDOW_LAST_LDTSTOP_ST:
684
                        if(tx_consume_data.read())
685
                                tx_crc_count = tx_crc_count.read()+1;
686
 
687
                        if(tx_crc_count.read() == 15 && tx_consume_data.read()){
688
                                tx_state = TX_SEND_LAST_CRC_LDTSTOP_ST;
689
                                transmit_select = TX_SELECT_CRC;
690
                        }
691
                        break;
692
                case TX_SEND_LAST_CRC_LDTSTOP_ST:
693
                        tx_crc_count = 0;
694
 
695
                        if(tx_consume_data.read()){
696
                                tx_state = TX_LDTSTOP_M64;
697
                                transmit_select = TX_SELECT_DISCON;
698
                        }
699
                        else
700
                                transmit_select = TX_SELECT_CRC;
701
 
702
                        break;
703
 
704
                case TX_LDTSTOP_M64:
705
                        transmit_select = TX_SELECT_DISCON;
706
 
707
                        if(tx_consume_data.read())
708
                                tx_crc_count = tx_crc_count.read()+1;
709
 
710
                        if(tx_crc_count.read() == 63 && tx_consume_data.read()){
711
                                tx_state = TX_LDTSTOP;
712
                        }
713
                        break;
714
 
715
                case TX_LDTSTOP:
716
                        tx_crc_count = 0;
717
                        new_tx_crc_window = true;
718
                        //Must wait for RX to disconnect
719
                        ldtstop_disconnect_tx = ldtstop_disconnect_rx;
720
                        if(!ldtstopx.read()){
721
                                tx_state = TX_LDTSTOP;
722
                                transmit_select = TX_SELECT_DISCON;
723
                        }
724
                        else{
725
                                tx_state = TX_FIRST_CRC_WINDOW_ST;
726
                                transmit_select = TX_SELECT_DATA;
727
                        }
728
                        break;
729
 
730
                case TX_SYNC_ST:
731
                        tx_crc_count = 0;
732
                        tx_state = TX_SYNC_ST;
733
                        transmit_select = TX_SELECT_SYNC;
734
                        break;
735
 
736
                default: //case TX_FIRST_CRC_WINDOW_ST:
737
                        if(tx_consume_data.read())
738
                                tx_crc_count = tx_crc_count.read()+1;
739
 
740
                        if(tx_crc_count.read() == 127 && tx_consume_data.read()){
741
                                new_tx_crc_window = true;
742
                                if(initiate_ldtstop_sequence)
743
                                        tx_state = TX_CRC_WINDOW_BEGIN_LDTSTOP_ST;
744
                                else
745
                                        tx_state = TX_CRC_WINDOW_BEGIN_ST;
746
                        }
747
                        else if(initiate_ldtstop_sequence)
748
                        {
749
                                tx_state = TX_FIRST_CRC_WINDOW_LDTSTOP_ST;
750
                        }
751
                        break;
752
                }
753
 
754
                if(csr_sync.read()){
755
                        tx_state = TX_SYNC_ST;
756
                        transmit_select = TX_SELECT_SYNC;
757
                }
758
#ifdef RETRY_MODE_ENABLED
759
                //When the flow_control assert retry disconnect, just wait for the tx_framer to reconnect
760
                else if(fc_disconnect_lk.read()){
761
                        tx_state = TX_FIRST_CRC_WINDOW_ST;
762
                        tx_crc_count = 0;
763
                        new_tx_crc_window = true;
764
                }
765
#endif
766
        }
767
}
768
 
769
void link_l2::evaluate_tx_crc_process(){
770
        if(!resetx.read()){
771
                tx_crc = 0xFFFFFFFF;
772
                tx_last_crc = 0;
773
        }
774
        else{
775
                //If we are in a state where we have to evaluate CRC when consuming data
776
                bool evaluate_tx_crc = lk_consume_fc.read();
777
 
778
                sc_bv<32> mod_cad_data;
779
 
780
                //Change the data when forcing bad CRC
781
                if(csr_crc_force_error_lk.read())
782
                        mod_cad_data = 0x55555555;
783
                else
784
                        mod_cad_data = 0;
785
 
786
                sc_bv<32> cad_to_crc = cad_to_frame.read() ^ mod_cad_data;
787
 
788
                sc_bv<36> d;
789
                d.range(7,0) = cad_to_crc.range(7,0);
790
                d[8] = lctl_to_frame.read();
791
                d.range(16,9) = cad_to_crc.range(15,8);
792
                d[17] = lctl_to_frame.read();
793
                d.range(25,18) = cad_to_crc.range(23,16);
794
                d[26] = hctl_to_frame.read();
795
                d.range(34,27) = cad_to_crc.range(31,24);
796
                d[35] = hctl_to_frame.read();
797
 
798
                sc_uint<32> crc_in;
799
                sc_uint<32> crc;
800
                if(new_tx_crc_window)
801
                        crc_in = 0xFFFFFFFF;
802
                else
803
                        crc_in = tx_crc.read();
804
 
805
 
806
                /*for (unsigned i=0; i<36; ++i) {
807
                        bool tmp = crc[31];  // store highest bit
808
 
809
                        // subtract poly if greater:
810
                        crc[31] = crc[30];
811
                        crc[30] = crc[29];
812
                        crc[29] = crc[28];
813
                        crc[28] = crc[27];
814
                        crc[27] = crc[26];
815
                        crc[26] = crc[25]^tmp;
816
                        crc[25] = crc[24];
817
                        crc[24] = crc[23];
818
                        crc[23] = crc[22]^tmp;
819
                        crc[22] = crc[21]^tmp;
820
                        crc[21] = crc[20];
821
                        crc[20] = crc[19];
822
                        crc[19] = crc[18];
823
                        crc[18] = crc[17];
824
                        crc[17] = crc[16];
825
                        crc[16] = crc[15]^tmp;
826
                        crc[15] = crc[14];
827
                        crc[14] = crc[13];
828
                        crc[13] = crc[12];
829
                        crc[12] = crc[11]^tmp;
830
                        crc[11] = crc[10]^tmp;
831
                        crc[10] = crc[9]^tmp;
832
                        crc[9] = crc[8];
833
                        crc[8] = crc[7]^tmp;
834
                        crc[7] = crc[6]^tmp;
835
                        crc[6] = crc[5];
836
                        crc[5] = crc[4]^tmp;
837
                        crc[4] = crc[3]^tmp;
838
                        crc[3] = crc[2];
839
                        crc[2] = crc[1]^tmp;
840
                        crc[1] = crc[0]^tmp;
841
                        crc[0] = ((sc_bit)crc_data[i]) ^ tmp;
842
                }*/
843
                //Obtained with a slightly modified Xilinx Xapp209
844
                crc[0] = (sc_bit)(crc_in[2] ^ crc_in[20] ^ crc_in[12] ^ crc_in[21] ^ crc_in[5] ^ crc_in[30] ^ crc_in[22] ^ crc_in[6] ^ d[35] ^ crc_in[24] ^ crc_in[8] ^ d[3] ^ crc_in[25] ^ crc_in[26] ^ crc_in[27] ^ crc_in[28]);
845
                crc[1] = (sc_bit)(crc_in[2] ^ crc_in[3] ^ crc_in[20] ^ crc_in[12] ^ crc_in[5] ^ crc_in[13] ^ crc_in[30] ^ crc_in[31] ^ d[34] ^ crc_in[23] ^ crc_in[7] ^ d[2] ^ crc_in[24] ^ crc_in[8] ^ d[3] ^ crc_in[9] ^ crc_in[29]);
846
                crc[2] = (sc_bit)(crc_in[3] ^ crc_in[20] ^ crc_in[5] ^ crc_in[13] ^ d[33] ^ crc_in[22] ^ crc_in[31] ^ d[2] ^ crc_in[9] ^ crc_in[26] ^ crc_in[28] ^ crc_in[2] ^ crc_in[10] ^ crc_in[4] ^ crc_in[12] ^ d[1] ^ crc_in[14] ^ d[3] ^ crc_in[27]);
847
                crc[3] = (sc_bit)(crc_in[3] ^ crc_in[11] ^ crc_in[13] ^ crc_in[5] ^ d[0] ^ d[2] ^ crc_in[15] ^ crc_in[28] ^ crc_in[10] ^ crc_in[4] ^ d[32] ^ crc_in[21] ^ crc_in[6] ^ d[1] ^ crc_in[14] ^ crc_in[23] ^ crc_in[27] ^ crc_in[29]);
848
                crc[4] = (sc_bit)(crc_in[11] ^ d[31] ^ crc_in[20] ^ d[0] ^ crc_in[7] ^ crc_in[15] ^ crc_in[26] ^ crc_in[0] ^ crc_in[2] ^ crc_in[4] ^ crc_in[21] ^ d[1] ^ crc_in[14] ^ d[3] ^ crc_in[8] ^ crc_in[16] ^ crc_in[25] ^ crc_in[27] ^ crc_in[29]);
849
                crc[5] = (sc_bit)(crc_in[3] ^ crc_in[20] ^ d[0] ^ d[2] ^ crc_in[15] ^ crc_in[24] ^ crc_in[9] ^ crc_in[17] ^ crc_in[0] ^ crc_in[2] ^ d[30] ^ crc_in[6] ^ d[3] ^ crc_in[16] ^ crc_in[25] ^ crc_in[1]);
850
                crc[6] = (sc_bit)(crc_in[3] ^ d[2] ^ crc_in[7] ^ crc_in[17] ^ crc_in[26] ^ crc_in[0] ^ crc_in[2] ^ crc_in[10] ^ crc_in[4] ^ crc_in[21] ^ d[1] ^ crc_in[16] ^ crc_in[25] ^ d[29] ^ crc_in[18] ^ crc_in[1]);
851
                crc[7] = (sc_bit)(crc_in[11] ^ crc_in[3] ^ crc_in[20] ^ d[0] ^ crc_in[24] ^ d[28] ^ crc_in[17] ^ crc_in[19] ^ crc_in[28] ^ crc_in[4] ^ crc_in[12] ^ crc_in[21] ^ crc_in[30] ^ crc_in[6] ^ d[1] ^ d[3] ^ crc_in[25] ^ crc_in[18] ^ crc_in[1]);
852
                crc[8] = (sc_bit)(d[0] ^ crc_in[13] ^ crc_in[31] ^ crc_in[7] ^ d[2] ^ crc_in[24] ^ crc_in[19] ^ crc_in[28] ^ crc_in[0] ^ crc_in[4] ^ crc_in[30] ^ crc_in[6] ^ d[27] ^ d[3] ^ crc_in[8] ^ crc_in[18] ^ crc_in[27] ^ crc_in[29]);
853
                crc[9] = (sc_bit)(crc_in[20] ^ crc_in[5] ^ crc_in[31] ^ d[26] ^ d[2] ^ crc_in[7] ^ crc_in[9] ^ crc_in[19] ^ crc_in[28] ^ crc_in[0] ^ crc_in[30] ^ d[1] ^ crc_in[14] ^ crc_in[8] ^ crc_in[25] ^ crc_in[29] ^ crc_in[1]);
854
                crc[10] = (sc_bit)(d[0] ^ crc_in[5] ^ crc_in[22] ^ crc_in[31] ^ crc_in[15] ^ crc_in[24] ^ crc_in[9] ^ crc_in[28] ^ crc_in[10] ^ crc_in[12] ^ d[25] ^ d[1] ^ d[3] ^ crc_in[25] ^ crc_in[27] ^ crc_in[29] ^ crc_in[1]);
855
                crc[11] = (sc_bit)(crc_in[11] ^ crc_in[20] ^ d[24] ^ d[0] ^ crc_in[5] ^ crc_in[13] ^ crc_in[22] ^ d[2] ^ crc_in[24] ^ crc_in[0] ^ crc_in[10] ^ crc_in[12] ^ crc_in[21] ^ crc_in[23] ^ d[3] ^ crc_in[8] ^ crc_in[16] ^ crc_in[27] ^ crc_in[29]);
856
                crc[12] = (sc_bit)(crc_in[11] ^ crc_in[20] ^ crc_in[5] ^ crc_in[13] ^ d[2] ^ crc_in[9] ^ crc_in[17] ^ crc_in[26] ^ crc_in[0] ^ crc_in[2] ^ d[23] ^ d[1] ^ crc_in[14] ^ crc_in[23] ^ d[3] ^ crc_in[8] ^ crc_in[27] ^ crc_in[1]);
857
                crc[13] = (sc_bit)(d[22] ^ crc_in[3] ^ d[0] ^ d[2] ^ crc_in[15] ^ crc_in[24] ^ crc_in[9] ^ crc_in[28] ^ crc_in[2] ^ crc_in[10] ^ crc_in[12] ^ crc_in[21] ^ crc_in[6] ^ d[1] ^ crc_in[14] ^ crc_in[18] ^ crc_in[27] ^ crc_in[1]);
858
                crc[14] = (sc_bit)(crc_in[3] ^ crc_in[11] ^ d[0] ^ crc_in[13] ^ crc_in[22] ^ crc_in[7] ^ crc_in[15] ^ crc_in[19] ^ crc_in[28] ^ crc_in[0] ^ d[21] ^ crc_in[2] ^ crc_in[10] ^ crc_in[4] ^ d[1] ^ crc_in[16] ^ crc_in[25] ^ crc_in[29]);
859
                crc[15] = (sc_bit)(crc_in[3] ^ crc_in[11] ^ crc_in[20] ^ crc_in[5] ^ d[0] ^ crc_in[17] ^ crc_in[26] ^ crc_in[0] ^ crc_in[4] ^ crc_in[12] ^ crc_in[30] ^ crc_in[14] ^ crc_in[23] ^ crc_in[8] ^ crc_in[16] ^ crc_in[29] ^ d[20] ^ crc_in[1]);
860
                crc[16] = (sc_bit)(crc_in[20] ^ crc_in[13] ^ crc_in[22] ^ crc_in[31] ^ crc_in[15] ^ d[19] ^ crc_in[9] ^ crc_in[17] ^ crc_in[26] ^ crc_in[28] ^ crc_in[0] ^ crc_in[4] ^ d[3] ^ crc_in[8] ^ crc_in[25] ^ crc_in[18] ^ crc_in[1]);
861
                crc[17] = (sc_bit)(crc_in[5] ^ d[2] ^ crc_in[9] ^ crc_in[26] ^ crc_in[19] ^ crc_in[2] ^ crc_in[10] ^ crc_in[21] ^ crc_in[14] ^ crc_in[23] ^ d[18] ^ crc_in[16] ^ crc_in[18] ^ crc_in[27] ^ crc_in[29] ^ crc_in[1]);
862
                crc[18] = (sc_bit)(crc_in[11] ^ crc_in[3] ^ crc_in[20] ^ crc_in[22] ^ d[17] ^ crc_in[15] ^ crc_in[24] ^ crc_in[17] ^ crc_in[19] ^ crc_in[28] ^ crc_in[2] ^ crc_in[10] ^ crc_in[30] ^ d[1] ^ crc_in[6] ^ crc_in[27]);
863
                crc[19] = (sc_bit)(crc_in[3] ^ crc_in[11] ^ crc_in[20] ^ d[0] ^ crc_in[31] ^ crc_in[7] ^ crc_in[28] ^ crc_in[12] ^ crc_in[4] ^ crc_in[21] ^ d[16] ^ crc_in[23] ^ crc_in[16] ^ crc_in[25] ^ crc_in[18] ^ crc_in[29]);
864
                crc[20] = (sc_bit)(d[15] ^ crc_in[13] ^ crc_in[5] ^ crc_in[22] ^ crc_in[24] ^ crc_in[17] ^ crc_in[26] ^ crc_in[19] ^ crc_in[0] ^ crc_in[4] ^ crc_in[12] ^ crc_in[21] ^ crc_in[30] ^ crc_in[8] ^ crc_in[29]);
865
                crc[21] = (sc_bit)(crc_in[20] ^ crc_in[5] ^ crc_in[13] ^ crc_in[22] ^ crc_in[31] ^ crc_in[9] ^ d[14] ^ crc_in[30] ^ crc_in[14] ^ crc_in[6] ^ crc_in[23] ^ crc_in[25] ^ crc_in[18] ^ crc_in[27] ^ crc_in[1]);
866
                crc[22] = (sc_bit)(d[13] ^ crc_in[20] ^ crc_in[5] ^ crc_in[22] ^ crc_in[31] ^ crc_in[15] ^ crc_in[7] ^ crc_in[19] ^ crc_in[10] ^ crc_in[12] ^ crc_in[30] ^ crc_in[14] ^ crc_in[23] ^ d[3] ^ crc_in[8] ^ crc_in[25] ^ crc_in[27]);
867
                crc[23] = (sc_bit)(crc_in[11] ^ crc_in[5] ^ crc_in[13] ^ crc_in[22] ^ crc_in[31] ^ d[2] ^ crc_in[15] ^ crc_in[9] ^ d[12] ^ crc_in[2] ^ crc_in[12] ^ crc_in[30] ^ crc_in[23] ^ d[3] ^ crc_in[16] ^ crc_in[25] ^ crc_in[27]);
868
                crc[24] = (sc_bit)(crc_in[3] ^ crc_in[13] ^ crc_in[31] ^ d[2] ^ crc_in[24] ^ crc_in[17] ^ crc_in[26] ^ crc_in[28] ^ crc_in[10] ^ crc_in[12] ^ crc_in[6] ^ d[1] ^ crc_in[14] ^ crc_in[23] ^ crc_in[16] ^ d[11]);
869
                crc[25] = (sc_bit)(crc_in[11] ^ d[0] ^ crc_in[13] ^ crc_in[7] ^ crc_in[15] ^ crc_in[24] ^ crc_in[17] ^ d[10] ^ crc_in[4] ^ d[1] ^ crc_in[14] ^ crc_in[25] ^ crc_in[18] ^ crc_in[27] ^ crc_in[29]);
870
                crc[26] = (sc_bit)(crc_in[20] ^ d[0] ^ crc_in[22] ^ crc_in[15] ^ crc_in[24] ^ crc_in[19] ^ crc_in[0] ^ crc_in[2] ^ crc_in[21] ^ crc_in[6] ^ crc_in[14] ^ d[3] ^ crc_in[16] ^ crc_in[18] ^ crc_in[27] ^ d[9]);
871
                crc[27] = (sc_bit)(crc_in[3] ^ crc_in[20] ^ crc_in[22] ^ d[2] ^ crc_in[7] ^ crc_in[15] ^ crc_in[17] ^ crc_in[19] ^ crc_in[28] ^ d[8] ^ crc_in[0] ^ crc_in[21] ^ crc_in[23] ^ crc_in[16] ^ crc_in[25] ^ crc_in[1]);
872
                crc[28] = (sc_bit)(crc_in[20] ^ crc_in[22] ^ crc_in[24] ^ crc_in[17] ^ crc_in[26] ^ crc_in[2] ^ crc_in[4] ^ crc_in[21] ^ d[1] ^ crc_in[23] ^ crc_in[8] ^ crc_in[16] ^ crc_in[18] ^ d[7] ^ crc_in[29] ^ crc_in[1]);
873
                crc[29] = (sc_bit)(crc_in[3] ^ crc_in[5] ^ d[0] ^ crc_in[22] ^ crc_in[24] ^ crc_in[9] ^ crc_in[17] ^ crc_in[19] ^ d[6] ^ crc_in[2] ^ crc_in[21] ^ crc_in[30] ^ crc_in[23] ^ crc_in[25] ^ crc_in[18] ^ crc_in[27]);
874
                crc[30] = (sc_bit)(crc_in[3] ^ crc_in[20] ^ crc_in[22] ^ crc_in[31] ^ crc_in[24] ^ crc_in[26] ^ crc_in[19] ^ crc_in[28] ^ crc_in[0] ^ crc_in[10] ^ crc_in[4] ^ crc_in[6] ^ crc_in[23] ^ crc_in[25] ^ crc_in[18] ^ d[5]);
875
                crc[31] = (sc_bit)(crc_in[11] ^ crc_in[20] ^ crc_in[5] ^ crc_in[7] ^ crc_in[24] ^ d[4] ^ crc_in[26] ^ crc_in[19] ^ crc_in[4] ^ crc_in[21] ^ crc_in[23] ^ crc_in[25] ^ crc_in[27] ^ crc_in[29] ^ crc_in[1]);
876
 
877
                if(evaluate_tx_crc)
878
                        tx_crc = crc;
879
                else if(new_tx_crc_window)
880
                        tx_crc = 0xFFFFFFFF;
881
 
882
                if(new_tx_crc_window)
883
                        tx_last_crc = tx_crc;
884
        }
885
}
886
 
887
void link_l2::select_output(){
888
 
889
        sc_uint<32> discon_nop = 0x0000020;
890
        sc_uint<32> sync_pkt = 0xFFFFFFFF;
891
 
892
        switch(transmit_select.read()){
893
        case TX_SELECT_CRC:
894
                cad_to_frame = ~tx_last_crc.read();
895
                lctl_to_frame = true;
896
                hctl_to_frame = true;
897
                lk_consume_fc = false;
898
#ifdef RETRY_MODE_ENABLED
899
                tx_retry_disconnect = false;
900
#endif
901
                break;
902
        case TX_SELECT_DISCON:
903
                cad_to_frame = discon_nop;
904
                lctl_to_frame = true;
905
                hctl_to_frame = true;
906
                lk_consume_fc = false;
907
#ifdef RETRY_MODE_ENABLED
908
                tx_retry_disconnect = false;
909
#endif
910
                break;
911
        case TX_SELECT_SYNC:
912
                cad_to_frame = sync_pkt;
913
                lctl_to_frame = true;
914
                hctl_to_frame = true;
915
                lk_consume_fc = false;
916
#ifdef RETRY_MODE_ENABLED
917
                tx_retry_disconnect = false;
918
#endif
919
                break;
920
        default: //case TX_SELECT_DATA:
921
                cad_to_frame = fc_dword_lk.read();
922
                lctl_to_frame = fc_lctl_lk.read();
923
                hctl_to_frame = fc_hctl_lk.read();
924
                lk_consume_fc = tx_consume_data.read();
925
#ifdef RETRY_MODE_ENABLED
926
                tx_retry_disconnect = fc_disconnect_lk;
927
#endif
928
        }
929
}
930
 
931
void link_l2::output_framed_data(){
932
        lk_available_cd = framed_data_available.read() && framed_data_ready.read();
933
}
934
 
935 6 acastong
void link_l2::output_ldtstop_disconnected(){
936
        lk_ldtstop_disconnected = ldtstop_disconnect_tx;
937
}
938 2 acastong
 

powered by: WebSVN 2.1.0

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