1 |
4 |
dwp |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// File name "decoder_8b_rx_model.v" ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// This file is part of the : ////
|
6 |
|
|
//// ////
|
7 |
|
|
//// "1000BASE-X IEEE 802.3-2008 Clause 36 - PCS project" ////
|
8 |
|
|
//// ////
|
9 |
|
|
//// http://opencores.org/project,1000base-x ////
|
10 |
|
|
//// ////
|
11 |
|
|
//// Author(s): ////
|
12 |
|
|
//// - D.W.Pegler Cambridge Broadband Networks Ltd ////
|
13 |
|
|
//// ////
|
14 |
|
|
//// { peglerd@gmail.com, dwp@cambridgebroadand.com } ////
|
15 |
|
|
//// ////
|
16 |
|
|
//////////////////////////////////////////////////////////////////////
|
17 |
|
|
//// ////
|
18 |
|
|
//// Copyright (C) 2009 AUTHORS. All rights reserved. ////
|
19 |
|
|
//// ////
|
20 |
|
|
//// This source file may be used and distributed without ////
|
21 |
|
|
//// restriction provided that this copyright statement is not ////
|
22 |
|
|
//// removed from the file and that any derivative work contains ////
|
23 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
24 |
|
|
//// ////
|
25 |
|
|
//// This source file is free software; you can redistribute it ////
|
26 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
27 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
28 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
29 |
|
|
//// later version. ////
|
30 |
|
|
//// ////
|
31 |
|
|
//// This source is distributed in the hope that it will be ////
|
32 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
33 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
34 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
35 |
|
|
//// details. ////
|
36 |
|
|
//// ////
|
37 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
38 |
|
|
//// Public License along with this source; if not, download it ////
|
39 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
40 |
|
|
//// ////
|
41 |
|
|
//////////////////////////////////////////////////////////////////////
|
42 |
|
|
//// ////
|
43 |
|
|
//// This module is based on the coding method described in ////
|
44 |
|
|
//// IEEE Std 802.3-2008 Clause 36 "Physical Coding Sublayer(PCS) ////
|
45 |
|
|
//// and Physical Medium Attachment (PMA) sublayer, type ////
|
46 |
|
|
//// 1000BASE-X"; see : ////
|
47 |
|
|
//// ////
|
48 |
|
|
//// http://standards.ieee.org/about/get/802/802.3.html ////
|
49 |
|
|
//// and ////
|
50 |
|
|
//// doc/802.3-2008_section3.pdf, Clause/Section 36. ////
|
51 |
|
|
//// ////
|
52 |
|
|
//////////////////////////////////////////////////////////////////////
|
53 |
|
|
|
54 |
|
|
`include "timescale_tb.v"
|
55 |
|
|
|
56 |
|
|
module decoder_8b_rx_model #(
|
57 |
|
|
parameter DEBUG = 0,
|
58 |
|
|
parameter out_delay = 5,
|
59 |
|
|
parameter in_delay = 2
|
60 |
|
|
)(
|
61 |
|
|
interface check_intf,
|
62 |
|
|
|
63 |
|
|
// --- Clocks
|
64 |
|
|
input SBYTECLK,
|
65 |
|
|
|
66 |
|
|
input reset,
|
67 |
|
|
|
68 |
|
|
input K,
|
69 |
|
|
|
70 |
|
|
input disparity,
|
71 |
|
|
|
72 |
|
|
input coding_err,
|
73 |
|
|
|
74 |
|
|
input disparity_err,
|
75 |
|
|
|
76 |
|
|
// -- Ten but input to decoder
|
77 |
|
|
input [9:0] tbi,
|
78 |
|
|
|
79 |
|
|
// --- Eight but output from decoder
|
80 |
|
|
input [7:0] ebi
|
81 |
|
|
);
|
82 |
|
|
|
83 |
|
|
import encoder_8b10b_threads::split;
|
84 |
|
|
import encoder_8b10b_threads::decode;
|
85 |
|
|
|
86 |
|
|
//----------------------------------------------------------------------------
|
87 |
|
|
// Checker interface functions
|
88 |
|
|
//----------------------------------------------------------------------------
|
89 |
|
|
|
90 |
|
|
function automatic string check_intf.whoami();
|
91 |
|
|
string buffer;
|
92 |
|
|
$sformat(buffer, "%m");
|
93 |
|
|
return buffer.substr(0, buffer.len()-17);
|
94 |
|
|
endfunction
|
95 |
|
|
|
96 |
|
|
//----------------------------------------------------------------------------
|
97 |
|
|
// 10b symbol, disparity and coding checker
|
98 |
|
|
//----------------------------------------------------------------------------
|
99 |
|
|
|
100 |
|
|
int iteration = 0;
|
101 |
|
|
|
102 |
|
|
// Decoder signals
|
103 |
|
|
reg [9:0] decoder_10b_symbol = 10'b0; reg [7:0] decoder_8b_symbol = 8'b0;
|
104 |
|
|
|
105 |
|
|
reg decoder_K, decoder_disparity, decoder_disparity_err, decoder_code_err;
|
106 |
|
|
|
107 |
|
|
reg [4:0] decoder_X; reg [2:0] decoder_Y;
|
108 |
|
|
|
109 |
|
|
// Checker signals
|
110 |
|
|
reg [7:0] checker_8b_symbol;
|
111 |
|
|
|
112 |
|
|
reg checker_K, checker_disparity, checker_disparity_err, checker_code_err;
|
113 |
|
|
|
114 |
|
|
reg [4:0] checker_X; reg [2:0] checker_Y; reg checker_errors;
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
// Signal to indicate that there is a mismatch between the output of the decoder and the checker.
|
118 |
|
|
reg null_rd, decoder_checker_fail = 1'b1;
|
119 |
|
|
|
120 |
|
|
task automatic decoder_8b_checker();
|
121 |
|
|
|
122 |
|
|
// 8b output from decoder
|
123 |
|
|
decoder_8b_symbol = ebi;
|
124 |
|
|
decoder_disparity = disparity;
|
125 |
|
|
decoder_disparity_err = disparity_err;
|
126 |
|
|
decoder_code_err = coding_err;
|
127 |
|
|
decoder_K = K;
|
128 |
|
|
|
129 |
|
|
decoder_10b_symbol = tbi;
|
130 |
|
|
|
131 |
|
|
// Encode the 8b decoder input symbol
|
132 |
|
|
encoder_8b10b_threads::decode(decoder_10b_symbol, checker_disparity, checker_disparity, checker_K,
|
133 |
|
|
checker_8b_symbol, checker_disparity_err, checker_code_err);
|
134 |
|
|
|
135 |
|
|
// Split the checker 8b symbol into 5b/6b and 3b/4b components x and y - Dx.y and Kx.y
|
136 |
|
|
encoder_8b10b_threads::split(checker_8b_symbol, checker_X, checker_Y);
|
137 |
|
|
|
138 |
|
|
// Are there any checker disparity or coding errors
|
139 |
|
|
if (DEBUG | (iteration & (checker_disparity_err | checker_code_err)))
|
140 |
|
|
begin
|
141 |
|
|
|
142 |
|
|
$display("Checker disparity/coding test %08d: [10b_symbol = %010b, RD = %01b, 8b_symbol = %08b, K = %01b, RD_err = %01b, CODE_err = %01b] : %s : %s%02d.%01d",
|
143 |
|
|
iteration, decoder_10b_symbol,
|
144 |
|
|
checker_disparity, checker_8b_symbol, checker_K,
|
145 |
|
|
checker_disparity_err, checker_code_err,
|
146 |
|
|
((checker_disparity_err | checker_code_err) ? "FAIL" : "PASSED"),
|
147 |
|
|
((checker_K) ? "K" : "D"), checker_X, checker_Y);
|
148 |
|
|
|
149 |
|
|
// Halt if disparity or coding errors
|
150 |
|
|
if (!DEBUG) $stop;
|
151 |
|
|
end
|
152 |
|
|
|
153 |
|
|
// Split the checker 8b symbol into 5b/6b and 3b/4b components x and y - Dx.y and Kx.y
|
154 |
|
|
encoder_8b10b_threads::split(decoder_8b_symbol, decoder_X, decoder_Y);
|
155 |
|
|
|
156 |
|
|
// Are there any decoder disparity or coding errors
|
157 |
|
|
if (DEBUG | (iteration & (decoder_disparity_err | decoder_code_err)))
|
158 |
|
|
begin
|
159 |
|
|
$display("Decoder disparity/coding test %08d: [10b_symbol = %010b, RD = %01b, 8b_symbol = %08b, K = %01b, RD_err = %01b, CODE_err = %01b] : %s : %s%02d.%01d",
|
160 |
|
|
iteration, decoder_10b_symbol,
|
161 |
|
|
decoder_disparity, decoder_8b_symbol, decoder_K,
|
162 |
|
|
decoder_disparity_err, decoder_code_err,
|
163 |
|
|
((decoder_disparity_err | decoder_code_err) ? "FAIL" : "PASSED"),
|
164 |
|
|
((decoder_K) ? "K" : "D"), decoder_X, decoder_Y);
|
165 |
|
|
|
166 |
|
|
end
|
167 |
|
|
|
168 |
|
|
// Does the output of the decoder match that of the checker ?
|
169 |
|
|
decoder_checker_fail = ((decoder_8b_symbol != checker_8b_symbol) || (decoder_K != checker_K));
|
170 |
|
|
|
171 |
|
|
// Make sure the resultant symbols are the same
|
172 |
|
|
if (DEBUG | (iteration & decoder_checker_fail))
|
173 |
|
|
begin
|
174 |
|
|
$display("Decoder/Checker 8b test %08d: Decoder [8b_symbol = %010b, K = %01b], Checker [8b_symbol = %010b, K = %01b] : %s : Decoder[%s%02d.%01d] : Checker[%s%02d.%01d]",
|
175 |
|
|
iteration, decoder_8b_symbol, decoder_K, checker_8b_symbol, checker_K,
|
176 |
|
|
(decoder_checker_fail ? "FAIL" : "PASSED"),
|
177 |
|
|
((decoder_K) ? "K" : "D"), decoder_X, decoder_Y,
|
178 |
|
|
((checker_K) ? "K" : "D"), checker_X, checker_Y);
|
179 |
|
|
|
180 |
|
|
if (!DEBUG) $stop;
|
181 |
|
|
|
182 |
|
|
end
|
183 |
|
|
|
184 |
|
|
iteration++;
|
185 |
|
|
endtask // automatic
|
186 |
|
|
|
187 |
|
|
initial
|
188 |
|
|
begin
|
189 |
|
|
// Intlialise disparity and coding errors
|
190 |
|
|
checker_K = 0; checker_disparity_err = 0; checker_code_err = 0;
|
191 |
|
|
|
192 |
|
|
// Initialise checker 8b/10b generation
|
193 |
|
|
encoder_8b10b_threads::init(null_rd, checker_disparity, checker_errors);
|
194 |
|
|
|
195 |
|
|
// Obtain initial sync...
|
196 |
|
|
@(posedge SBYTECLK);
|
197 |
|
|
|
198 |
|
|
while (1)
|
199 |
|
|
begin
|
200 |
|
|
// Handle receive from TBI interface
|
201 |
|
|
if (~reset) decoder_8b_checker();
|
202 |
|
|
@(posedge SBYTECLK);
|
203 |
|
|
end
|
204 |
|
|
end
|
205 |
|
|
endmodule
|
206 |
|
|
|