1 |
4 |
dwp |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// File name "encoder_10b_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 encoder_10b_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 |
|
|
// --- Ten bit input bus
|
69 |
|
|
input [9:0] tbi_rx
|
70 |
|
|
);
|
71 |
|
|
|
72 |
|
|
//----------------------------------------------------------------------------
|
73 |
|
|
// Checker interface functions
|
74 |
|
|
//----------------------------------------------------------------------------
|
75 |
|
|
|
76 |
|
|
function automatic string check_intf.whoami();
|
77 |
|
|
string buffer;
|
78 |
|
|
$sformat(buffer, "%m");
|
79 |
|
|
return buffer.substr(0, buffer.len()-17);
|
80 |
|
|
endfunction
|
81 |
|
|
|
82 |
|
|
//----------------------------------------------------------------------------
|
83 |
|
|
// 10B symbol, disparity and coding checker
|
84 |
|
|
//----------------------------------------------------------------------------
|
85 |
|
|
|
86 |
|
|
integer iteration = 0;
|
87 |
|
|
|
88 |
|
|
reg [9:0] checker_10b_symbol = 10'b0; reg [7:0] checker_8B_symbol = 8'b0;
|
89 |
|
|
|
90 |
|
|
reg null_rd, checker_rd, checker_k, checker_rd_err, checker_code_err;
|
91 |
|
|
|
92 |
|
|
integer checker_x, checker_y, checker_errors;
|
93 |
|
|
|
94 |
|
|
task automatic encoder_10b_checker();
|
95 |
|
|
|
96 |
|
|
// Pull the next byte
|
97 |
|
|
checker_10b_symbol = tbi_rx;
|
98 |
|
|
|
99 |
|
|
// Decode the 10b symbol from the checker model
|
100 |
|
|
encoder_8b10b_threads::decode(checker_10b_symbol, checker_rd, checker_rd, checker_k,
|
101 |
|
|
checker_8B_symbol, checker_rd_err, checker_code_err);
|
102 |
|
|
|
103 |
|
|
// Split the 8b symbol into 5b/6b and 3b/4b components x and y - Dx.y and Kx.y
|
104 |
|
|
encoder_8b10b_threads::split(checker_8B_symbol, checker_x, checker_y);
|
105 |
|
|
|
106 |
|
|
// Only check for errors after the first symbol
|
107 |
|
|
//if (DEBUG | (iteration & (checker_rd_err | checker_code_err)))
|
108 |
|
|
if (DEBUG)
|
109 |
|
|
begin
|
110 |
|
|
$display("Checker 10b %08d: [10b_symbol = %010b, RD = %01b, 8B_symbol = %08b, K = %01b, RD_err = %01b, CODE_err = %01b] : %s : %s%02d.%01d",
|
111 |
|
|
iteration, checker_10b_symbol,
|
112 |
|
|
checker_rd, checker_8B_symbol, checker_k,
|
113 |
|
|
checker_rd_err, checker_code_err,
|
114 |
|
|
((checker_rd_err | checker_code_err) ? "FAIL" : "PASSED"),
|
115 |
|
|
((checker_k) ? "K" : "D"), checker_x, checker_y);
|
116 |
|
|
|
117 |
|
|
// Halt if disparity or coding errors
|
118 |
|
|
if (!DEBUG) $stop;
|
119 |
|
|
end
|
120 |
|
|
|
121 |
|
|
iteration++;
|
122 |
|
|
endtask // automatic
|
123 |
|
|
|
124 |
|
|
initial
|
125 |
|
|
begin
|
126 |
|
|
// Intlialise disparity and coding errors
|
127 |
|
|
checker_k = 0; checker_rd_err = 0; checker_code_err = 0;
|
128 |
|
|
|
129 |
|
|
// Initialise checker 8B/10b generation
|
130 |
|
|
encoder_8b10b_threads::init(null_rd, checker_rd, checker_errors);
|
131 |
|
|
|
132 |
|
|
// On startup, the receiver (decoder) should assume +ve or -ve disparity
|
133 |
|
|
// See IEEE 802.3-2005 Clause 35 - 36.2.4.4
|
134 |
|
|
// I'm overiding the statup disparity set in encoder_8b10b_threads::init
|
135 |
|
|
// so that it starts as -ve.
|
136 |
|
|
checker_rd = 0;
|
137 |
|
|
|
138 |
|
|
// Obtain initial sync...
|
139 |
|
|
@(posedge SBYTECLK);
|
140 |
|
|
|
141 |
|
|
while (~reset)
|
142 |
|
|
begin
|
143 |
|
|
// Handle receive from TBI interface
|
144 |
|
|
encoder_10b_checker();
|
145 |
|
|
@(posedge SBYTECLK);
|
146 |
|
|
end
|
147 |
|
|
end
|
148 |
|
|
endmodule
|
149 |
|
|
|