Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / model / verilog / niu / niu_enet_models / xaui.v
CommitLineData
86530b38
AT
1
2module clock_multiplier_10x(refclk, clk);
3input refclk;
4output clk;
5reg clk;
6
7reg clk_;
8
9integer old_time;
10integer count;
11
12always @(clk_)
13 clk = #1 clk_;
14
15integer period, first_half, second_half;
16initial begin
17 period = 10000;
18 first_half = 5000;
19 second_half = 5000;
20end
21
22initial clk_ = 0;
23initial count = 0;
24
25always @(posedge clk_) begin
26 clk_ = #first_half ~clk_;
27end
28
29always @(negedge clk_) begin
30 if(count == 2)
31 clk_ = #second_half ~clk_;
32end
33
34always @(period) begin
35 first_half = period / 2;
36 second_half = period - first_half;
37end
38
39always @(posedge refclk) begin
40 if(count < 2) count = count + 1;
41 if(count == 2) begin
42 period = ($time - old_time) / 10;
43 clk_ = 1;
44 end
45 old_time = $time;
46end
47
48endmodule
49
50
51module xaui_port (
52 XAUI_RX_N,
53 XAUI_RX_P,
54 xaui_clk,
55 mac_clk,
56 reset,
57 XAUI_AMUX,
58 XAUI_TX_N,
59 XAUI_TX_P,
60 esr_mac_rxd0,
61 esr_mac_rxd1,
62 esr_mac_rxd2,
63 esr_mac_rxd3,
64 mac_esr_txd0,
65 mac_esr_txd1,
66 mac_esr_txd2,
67 mac_esr_txd3);
68
69input [3:0] XAUI_RX_N;
70input [3:0] XAUI_RX_P;
71
72input xaui_clk;
73input mac_clk;
74input reset;
75
76output XAUI_AMUX;
77output [3:0] XAUI_TX_N;
78output [3:0] XAUI_TX_P;
79
80output [9:0] esr_mac_rxd0;
81output [9:0] esr_mac_rxd1;
82output [9:0] esr_mac_rxd2;
83output [9:0] esr_mac_rxd3;
84
85input [9:0] mac_esr_txd0;
86input [9:0] mac_esr_txd1;
87input [9:0] mac_esr_txd2;
88input [9:0] mac_esr_txd3;
89
90
91reg XAUI_AMUX;
92reg [3:0] XAUI_TX_N;
93reg [3:0] XAUI_TX_P;
94
95reg [9:0] esr_mac_rxd0;
96reg [9:0] esr_mac_rxd1;
97reg [9:0] esr_mac_rxd2;
98reg [9:0] esr_mac_rxd3;
99
100reg [6:0] xaui_comma0;
101reg [6:0] xaui_comma1;
102reg [6:0] xaui_comma2;
103reg [6:0] xaui_comma3;
104
105reg [3:0] xaui_count0, xaui_count1, xaui_count2, xaui_count3;
106reg [3:0] xaui_serdes_count;
107
108reg [9:0] mac_esr_tx0, mac_esr_tx1, mac_esr_tx2, mac_esr_tx3;
109reg [9:0] esr_mac_rx_l0, esr_mac_rx_l1, esr_mac_rx_l2, esr_mac_rx_l3;
110reg [9:0] esr_mac_rx0, esr_mac_rx1, esr_mac_rx2, esr_mac_rx3;
111reg reset_sync;
112
113wire [3:0] tx;
114
115initial begin
116 xaui_count0 = 0;
117 xaui_count1 = 0;
118 xaui_count2 = 0;
119 xaui_count3 = 0;
120end
121
122always @(posedge mac_clk) begin
123 mac_esr_tx0 <= mac_esr_txd0;
124 mac_esr_tx1 <= mac_esr_txd1;
125 mac_esr_tx2 <= mac_esr_txd2;
126 mac_esr_tx3 <= mac_esr_txd3;
127 reset_sync <= reset;
128end
129
130always @(posedge mac_clk) begin
131 esr_mac_rxd0 <= esr_mac_rx_l0;
132 esr_mac_rxd1 <= esr_mac_rx_l1;
133 esr_mac_rxd2 <= esr_mac_rx_l2;
134 esr_mac_rxd3 <= esr_mac_rx_l3;
135end
136
137assign tx[0] = mac_esr_tx0[9 - xaui_serdes_count];
138assign tx[1] = mac_esr_tx1[9 - xaui_serdes_count];
139assign tx[2] = mac_esr_tx2[9 - xaui_serdes_count];
140assign tx[3] = mac_esr_tx3[9 - xaui_serdes_count];
141
142always @(posedge xaui_clk) begin
143 XAUI_AMUX <= 1'b0;
144 if(reset_sync) begin
145 XAUI_TX_P <= 4'b0000;
146 XAUI_TX_N <= 4'b1111;
147 xaui_serdes_count = 0;
148 end else begin
149 XAUI_TX_P <= tx;
150 XAUI_TX_N <= ~tx;
151 xaui_serdes_count <= (xaui_serdes_count + 1) % 10;
152 end
153end
154
155
156always @(negedge xaui_clk) begin
157 if(reset_sync) begin
158 xaui_comma0 <= 7'b0;
159 xaui_comma1 <= 7'b0;
160 xaui_comma2 <= 7'b0;
161 xaui_comma3 <= 7'b0;
162 xaui_count0 <= 0;
163 xaui_count1 <= 0;
164 xaui_count2 <= 0;
165 xaui_count3 <= 0;
166 end else begin
167
168 xaui_comma0[6:0] <= {xaui_comma0[5:0], XAUI_RX_P[0]};
169 xaui_comma1[6:0] <= {xaui_comma1[5:0], XAUI_RX_P[1]};
170 xaui_comma2[6:0] <= {xaui_comma2[5:0], XAUI_RX_P[2]};
171 xaui_comma3[6:0] <= {xaui_comma3[5:0], XAUI_RX_P[3]};
172
173 esr_mac_rx0[9 - xaui_count0] <= XAUI_RX_P[0];
174 esr_mac_rx1[9 - xaui_count1] <= XAUI_RX_P[1];
175 esr_mac_rx2[9 - xaui_count2] <= XAUI_RX_P[2];
176 esr_mac_rx3[9 - xaui_count3] <= XAUI_RX_P[3];
177
178 if(xaui_count0 == 9) esr_mac_rx_l0 <= {esr_mac_rx0[9:1],XAUI_RX_P[0]};
179 if(xaui_count1 == 9) esr_mac_rx_l1 <= {esr_mac_rx1[9:1],XAUI_RX_P[1]};
180 if(xaui_count2 == 9) esr_mac_rx_l2 <= {esr_mac_rx2[9:1],XAUI_RX_P[2]};
181 if(xaui_count3 == 9) esr_mac_rx_l3 <= {esr_mac_rx3[9:1],XAUI_RX_P[3]};
182
183 if(xaui_comma0 == 7'b0011111) begin
184 xaui_count0 <= 8;
185 end else begin
186 xaui_count0 <= (xaui_count0 + 1) % 10;
187 end
188 if(xaui_comma1 == 7'b0011111) begin
189 xaui_count1 <= 8;
190 end else begin
191 xaui_count1 <= (xaui_count1 + 1) % 10;
192 end
193 if(xaui_comma2 == 7'b0011111) begin
194 xaui_count2 <= 8;
195 end else begin
196 xaui_count2 <= (xaui_count2 + 1) % 10;
197 end
198 if(xaui_comma3 == 7'b0011111) begin
199 xaui_count3 <= 8;
200 end else begin
201 xaui_count3 <= (xaui_count3 + 1) % 10;
202 end
203 end
204end
205
206endmodule
207