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

Subversion Repositories ht_tunnel

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

powered by: WebSVN 2.1.0

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