Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / model / pcie / dll / calculate_dllp_crc.cpp
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: calculate_dllp_crc.cpp
4// Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
5// 4150 Network Circle, Santa Clara, California 95054, U.S.A.
6//
7// * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8//
9// This program is free software; you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation; version 2 of the License.
12//
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21//
22// For the avoidance of doubt, and except that if any non-GPL license
23// choice is available it will apply instead, Sun elects to use only
24// the General Public License version 2 (GPLv2) at this time for any
25// software where a choice of GPL license versions is made
26// available with the language indicating that GPLv2 or any later version
27// may be used, or where a choice of which version of the GPL is applied is
28// otherwise unspecified.
29//
30// Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
31// CA 95054 USA or visit www.sun.com if you need additional information or
32// have any questions.
33//
34// ========== Copyright Header End ============================================
35#include "dll_top.hpp"
36
37namespace pcie {
38
39 /**
40 This function calculates the crc in the DLL packet
41 **/
42 sc_uint<16> dll_top::calculate_dllp_crc(RefPciePacket received_packet,int pkt_begin, int pkt_end)
43 {
44 int index, byte_index;
45 sc_uint<8> byte;
46 sc_uint<16> tmp_dllp_crc;
47 sc_uint<16> dllp_crc_mapped;
48
49 /// Reset initial dllp crc value
50 dllp_crc = 0xffff;
51
52 for(byte_index=pkt_begin; byte_index < pkt_end; byte_index++)
53 {
54 byte = received_packet->get_byte(byte_index);
55 for (index=0; index < 8; index++)
56 {
57 tmp_dllp_crc = dllp_crc;
58 dllp_crc[0] = byte[index] ^ tmp_dllp_crc[15];
59 dllp_crc[1] = tmp_dllp_crc[0] ^ tmp_dllp_crc[15] ^ byte[index];
60 dllp_crc[2] = tmp_dllp_crc[1];
61 dllp_crc[3] = tmp_dllp_crc[2] ^ tmp_dllp_crc[15] ^ byte[index];;
62 dllp_crc[4] = tmp_dllp_crc[3] ;
63 dllp_crc[5] = tmp_dllp_crc[4];
64 dllp_crc[6] = tmp_dllp_crc[5];
65 dllp_crc[7] = tmp_dllp_crc[6];
66 dllp_crc[8] = tmp_dllp_crc[7];
67 dllp_crc[9] = tmp_dllp_crc[8];
68 dllp_crc[10] = tmp_dllp_crc[9];
69 dllp_crc[11] = tmp_dllp_crc[10];
70 dllp_crc[12] = tmp_dllp_crc[11] ^ tmp_dllp_crc[15] ^ byte[index];
71 dllp_crc[13] = tmp_dllp_crc[12];
72 dllp_crc[14] = tmp_dllp_crc[13];
73 dllp_crc[15] = tmp_dllp_crc[14];
74
75 dllp_crc_mapped[0] = ~dllp_crc[7];
76 dllp_crc_mapped[1] = ~dllp_crc[6];
77 dllp_crc_mapped[2] = ~dllp_crc[5];
78 dllp_crc_mapped[3] = ~dllp_crc[4];
79 dllp_crc_mapped[4] = ~dllp_crc[3];
80 dllp_crc_mapped[5] = ~dllp_crc[2];
81 dllp_crc_mapped[6] = ~dllp_crc[1];
82 dllp_crc_mapped[7] = ~dllp_crc[0];
83
84 dllp_crc_mapped[8] = ~dllp_crc[15];
85 dllp_crc_mapped[9] = ~dllp_crc[14];
86 dllp_crc_mapped[10] = ~dllp_crc[13];
87 dllp_crc_mapped[11] = ~dllp_crc[12];
88 dllp_crc_mapped[12] = ~dllp_crc[11];
89 dllp_crc_mapped[13] = ~dllp_crc[10];
90 dllp_crc_mapped[14] = ~dllp_crc[9];
91 dllp_crc_mapped[15] = ~dllp_crc[8];
92
93
94 }
95 }
96
97 return dllp_crc_mapped;
98 }
99
100}
101