Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: running_disparity.h | |
5 | * Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved | |
6 | * 4150 Network Circle, Santa Clara, California 95054, U.S.A. | |
7 | * | |
8 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; version 2 of the License. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
22 | * | |
23 | * For the avoidance of doubt, and except that if any non-GPL license | |
24 | * choice is available it will apply instead, Sun elects to use only | |
25 | * the General Public License version 2 (GPLv2) at this time for any | |
26 | * software where a choice of GPL license versions is made | |
27 | * available with the language indicating that GPLv2 or any later version | |
28 | * may be used, or where a choice of which version of the GPL is applied is | |
29 | * otherwise unspecified. | |
30 | * | |
31 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
32 | * CA 95054 USA or visit www.sun.com if you need additional information or | |
33 | * have any questions. | |
34 | * | |
35 | * | |
36 | * ========== Copyright Header End ============================================ | |
37 | */ | |
38 | // ========== Copyright Header Begin ========================================== | |
39 | // | |
40 | // OpenSPARC T2 Processor File: running_disparity.h | |
41 | // Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved | |
42 | // 4150 Network Circle, Santa Clara, California 95054, U.S.A. | |
43 | // | |
44 | // * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
45 | // | |
46 | // This program is free software; you can redistribute it and/or modify | |
47 | // it under the terms of the GNU General Public License as published by | |
48 | // the Free Software Foundation; version 2 of the License. | |
49 | // | |
50 | // This program is distributed in the hope that it will be useful, | |
51 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
52 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
53 | // GNU General Public License for more details. | |
54 | // | |
55 | // You should have received a copy of the GNU General Public License | |
56 | // along with this program; if not, write to the Free Software | |
57 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
58 | // | |
59 | // For the avoidance of doubt, and except that if any non-GPL license | |
60 | // choice is available it will apply instead, Sun elects to use only | |
61 | // the General Public License version 2 (GPLv2) at this time for any | |
62 | // software where a choice of GPL license versions is made | |
63 | // available with the language indicating that GPLv2 or any later version | |
64 | // may be used, or where a choice of which version of the GPL is applied is | |
65 | // otherwise unspecified. | |
66 | // | |
67 | // Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
68 | // CA 95054 USA or visit www.sun.com if you need additional information or | |
69 | // have any questions. | |
70 | // | |
71 | // ========== Copyright Header End ============================================ | |
72 | #ifndef INC_running_disparity_h__ | |
73 | #define INC_running_disparity_h__ | |
74 | ||
75 | #ifndef __EDG__ | |
76 | ||
77 | #include "systemc.h" | |
78 | #define LOG_SERVICE | |
79 | ||
80 | #ifdef LINK_1 | |
81 | #define LINK_WIDTH 1 | |
82 | #else | |
83 | #ifdef LINK_2 | |
84 | #define LINK_WIDTH 2 | |
85 | #else | |
86 | #ifdef LINK_4 | |
87 | #define LINK_WIDTH 4 | |
88 | #else | |
89 | #define LINK_WIDTH 8 | |
90 | #endif | |
91 | #endif | |
92 | #endif | |
93 | ||
94 | ||
95 | #include "pcie_common/logger.hpp" | |
96 | ||
97 | using namespace Logger; | |
98 | ||
99 | /// Static class for calculating the CRD of each lane | |
100 | class running_disparity | |
101 | { | |
102 | public : | |
103 | ||
104 | static running_disparity *current_disparity() | |
105 | { | |
106 | if(disparity == NULL) | |
107 | disparity = new running_disparity(); | |
108 | return disparity; | |
109 | } | |
110 | ||
111 | static running_disparity *current_rx_disparity() | |
112 | { | |
113 | if(rx_disparity == NULL) | |
114 | rx_disparity = new running_disparity(); | |
115 | return rx_disparity; | |
116 | } | |
117 | ||
118 | protected : | |
119 | running_disparity() | |
120 | { | |
121 | for(int i=0;i<LINK_WIDTH;i++) | |
122 | { | |
123 | CRD[i] = 1; | |
124 | RX_CRD[i] = 1; | |
125 | } | |
126 | } | |
127 | ||
128 | public : | |
129 | int calculate_disparity(sc_lv<10> vect,int start_point) | |
130 | { | |
131 | int i; | |
132 | int sum = 0; | |
133 | for(i=start_point;i<start_point+10;i++) | |
134 | { | |
135 | if(vect[i] == 0x1) | |
136 | sum++; | |
137 | } | |
138 | if(sum > 5) | |
139 | { | |
140 | return 1; | |
141 | } | |
142 | if(sum < 5) | |
143 | { | |
144 | return 0; | |
145 | } | |
146 | if(sum == 5) | |
147 | { | |
148 | return 2; | |
149 | } | |
150 | } | |
151 | ||
152 | sc_logic get_CRD(int i) | |
153 | { | |
154 | return CRD[i]; | |
155 | } | |
156 | ||
157 | void set_CRD(int i, sc_logic val) | |
158 | { | |
159 | CRD[i] = val; | |
160 | } | |
161 | ||
162 | sc_logic get_rx_CRD(int i) | |
163 | { | |
164 | return RX_CRD[i]; | |
165 | } | |
166 | ||
167 | void set_rx_CRD(int i, sc_logic val) | |
168 | { | |
169 | RX_CRD[i] = val; | |
170 | } | |
171 | ||
172 | private : | |
173 | static running_disparity *disparity; | |
174 | static running_disparity *rx_disparity; | |
175 | sc_logic CRD[LINK_WIDTH]; | |
176 | sc_logic RX_CRD[LINK_WIDTH]; | |
177 | }; | |
178 | #endif // EDG | |
179 | ||
180 | #endif // INC_running_disparity_h__ | |
181 |