Skip to content

Commit ed8205b

Browse files
committed
push 8b10b code to github
1 parent d57e17a commit ed8205b

File tree

5 files changed

+605
-0
lines changed

5 files changed

+605
-0
lines changed

endec8b10b/sim/Sim8b10b.do

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
vlog ../src/mEnc8b10bMem.v
3+
vlog ../src/mDec8b10bMem.v
4+
vlog m8b10bEndecTestbench.v
5+

endec8b10b/sim/Veritil.v

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
/*
3+
Include this file after module
4+
*/
5+
integer ErrorCnt;
6+
integer ErrorCode;
7+
initial begin
8+
ErrorCnt=0;
9+
ErrorCode=0;
10+
end
11+
`define CheckE(Signal,Value,SignalName) if(Signal!==Value) begin \
12+
$display("E@(%d): expect %x, actual %x (%s,%s,%d)",$time,Value,Signal,SignalName,`__FILE__,`__LINE__); \
13+
ErrorCnt=ErrorCnt+1;\
14+
end
15+
`define CheckF(Signal,Value,SignalName) if(Signal!==Value) begin \
16+
$display("F@(%d): expect %x, actual %x (%s,%s,%d)",$time,Value,Signal,SignalName,`__FILE__,`__LINE__); \
17+
$stop(1);\
18+
end
19+
`define CheckW(Signal,Value,SignalName) if(Signal!==Value) begin \
20+
$display("W@(%d): expect %x, actual %x (%s,%s,%d)",$time,Value,Signal,SignalName,`__FILE__,`__LINE__); \
21+
end
22+
23+
`define WaitTil(Signal,Value,Clk,Message) while(Signal!==Value) begin @(posedge Clk);#0.001;end \
24+
$display(Message);
25+
`define WaitTilRise(Signal) @(posedge Signal);#0.001;
26+
`define WaitTilRall(Signal) @(negedge Signal);#0.001;
27+
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
2+
3+
4+
`timescale 1ns/10ps
5+
6+
module m8b10bEndecTestbench;
7+
`include "Veritil.v"
8+
9+
wire w_Clk;
10+
reg [7:0] r8_DataIn;
11+
reg r_Kin;
12+
wire [9:0] w10_DataOut;
13+
reg r_ARst_L;
14+
wire w_Rd;
15+
wire [7:0] w8_DecDataOut;
16+
wire w_Kout;
17+
reg r_ForceParity,r_Disparity;
18+
wire w_Err;
19+
20+
mClkGen u0ClkGen(w_Clk);
21+
22+
mEnc8b10bMem u0Enc8b10bMem(
23+
.i8_Din (r8_DataIn),
24+
.i_Kin (r_Kin),
25+
.i_ForceDisparity (r_ForceParity),
26+
.i_Disparity (r_Disparity), //1 positive, 0 is negative
27+
.o10_Dout (w10_DataOut),
28+
.o_Rd (w_Rd),
29+
.o_KErr (w_KErr),
30+
.i_Clk (w_Clk),
31+
.i_ARst_L (r_ARst_L));
32+
33+
mDec8b10bMem u0Dec8b10bMem(
34+
.o8_Dout (w8_DecDataOut), //HGFEDCBA
35+
.o_Kout (w_Kout),
36+
.o_DErr (w_Err),
37+
.o_KErr (),
38+
.o_DpErr (),
39+
.i_ForceDisparity (1'b0),
40+
.i_Disparity (1'b0), //1 Is negative, 0 is positive
41+
.i10_Din (w10_DataOut), //abcdeifghj
42+
.o_Rd (),
43+
.i_Clk (w_Clk),
44+
.i_ARst_L (r_ARst_L));
45+
46+
initial
47+
begin
48+
r_ARst_L = 1'b0;
49+
r_Kin = 1'b0;
50+
r_ForceParity = 1'b0;
51+
r_Disparity = 1'b0;
52+
#100;
53+
r_ARst_L = 1'b1;
54+
r8_DataIn = 0;
55+
56+
//Normal Test no K
57+
$display("Normal data test, no K");
58+
repeat(256)
59+
begin
60+
@(posedge w_Clk);
61+
r8_DataIn = r8_DataIn +1;
62+
end
63+
#10000;
64+
65+
//Normal Test with K
66+
$display("Normal data test, with valid K");
67+
repeat(100)
68+
repeat(256)
69+
begin
70+
@(posedge w_Clk);
71+
r8_DataIn = r8_DataIn +1;
72+
if(r8_DataIn==8'h1C||r8_DataIn==8'h3C||r8_DataIn==8'h5C||r8_DataIn==8'h7C||
73+
r8_DataIn==8'h9C||r8_DataIn==8'hBC||r8_DataIn==8'hDC||r8_DataIn==8'hFC||
74+
r8_DataIn==8'hF7||r8_DataIn==8'hFB||r8_DataIn==8'hFD||r8_DataIn==8'hFE)
75+
r_Kin=$random; else r_Kin=1'b0;
76+
end
77+
78+
//Force Parity Error
79+
$display("Inject Parity Error");
80+
repeat(256)
81+
begin
82+
@(posedge w_Clk);
83+
r8_DataIn = r8_DataIn +1;
84+
if(r8_DataIn==8'h1C||r8_DataIn==8'h3C||r8_DataIn==8'h5C||r8_DataIn==8'h7C||
85+
r8_DataIn==8'h9C||r8_DataIn==8'hBC||r8_DataIn==8'hDC||r8_DataIn==8'hFC||
86+
r8_DataIn==8'hF7||r8_DataIn==8'hFB||r8_DataIn==8'hFD||r8_DataIn==8'hFE)
87+
r_Kin=$random; else r_Kin=1'b0;
88+
if(($random&32'h3F)==0)
89+
begin
90+
r_Disparity = ~w_Rd;
91+
r_ForceParity = 1'b1;
92+
end
93+
else
94+
r_ForceParity = 1'b0;
95+
end
96+
r_ForceParity = 1'b0;
97+
#10000;
98+
$display("Inject K Error");
99+
repeat(100)
100+
repeat(256)
101+
begin
102+
@(posedge w_Clk);
103+
r8_DataIn = r8_DataIn +1;
104+
if(r8_DataIn==8'h1C||r8_DataIn==8'h3C||r8_DataIn==8'h5C||r8_DataIn==8'h7C||
105+
r8_DataIn==8'h9C||r8_DataIn==8'hBC||r8_DataIn==8'hDC||r8_DataIn==8'hFC||
106+
r8_DataIn==8'hF7||r8_DataIn==8'hFB||r8_DataIn==8'hFD||r8_DataIn==8'hFE||
107+
r8_DataIn==8'h17||r8_DataIn==8'h1B||r8_DataIn==8'h1D||r8_DataIn==8'h1E)//Invalid Ks
108+
r_Kin=$random; else r_Kin=1'b0;
109+
end
110+
111+
#10000;
112+
$display("Totally Random Test");
113+
repeat(25600000)
114+
begin
115+
@(posedge w_Clk);
116+
r8_DataIn = $random&8'hFF;
117+
if(r8_DataIn==8'h1C||r8_DataIn==8'h3C||r8_DataIn==8'h5C||r8_DataIn==8'h7C||
118+
r8_DataIn==8'h9C||r8_DataIn==8'hBC||r8_DataIn==8'hDC||r8_DataIn==8'hFC||
119+
r8_DataIn==8'hF7||r8_DataIn==8'hFB||r8_DataIn==8'hFD||r8_DataIn==8'hFE||
120+
r8_DataIn==8'h17||r8_DataIn==8'h1B||r8_DataIn==8'h1D||r8_DataIn==8'h1E)//Invalid Ks
121+
r_Kin=$random; else r_Kin=1'b0;
122+
if(($random&32'h3F)==0)
123+
begin
124+
r_Disparity = ~w_Rd;
125+
r_ForceParity = 1'b1;
126+
end
127+
else
128+
r_ForceParity = 1'b0;
129+
end
130+
131+
$display("Done");
132+
$stop;
133+
end
134+
135+
//Checker
136+
reg [7:0] r8_D[7:0];
137+
reg [7:0] r_K;
138+
reg [7:0] r_KEncErr;
139+
reg [7:0] r_DecErr;
140+
141+
always@(posedge w_Clk)
142+
if(~w_Err)
143+
begin
144+
r8_D[0] <= r8_DataIn;
145+
r8_D[1] <= r8_D[0];
146+
r_K[0] <= r_Kin;
147+
r_K[1] <= r_K[0];
148+
r_KEncErr[0] <= w_KErr;
149+
`CheckW(w8_DecDataOut,r8_D[1],"Data Out Mismatch")
150+
if(~r_KEncErr[0]) `CheckW(w_Kout,r_K[1],"Data Out Mismatch")
151+
end
152+
153+
endmodule
154+
155+
156+
module mClkGen #(parameter pClkPeriod=10) (output reg o_Clk);
157+
158+
initial
159+
forever
160+
begin
161+
o_Clk = 1'b0;
162+
#pClkPeriod;
163+
o_Clk = 1'b1;
164+
#pClkPeriod;
165+
end
166+
167+
endmodule

endec8b10b/src/mDec8b10bMem.v

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
/*
2+
Copyright © 2012 [email protected]
3+
4+
This file is part of SGMII-IP-Core.
5+
SGMII-IP-Core is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
SGMII-IP-Core is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with SGMII-IP-Core. If not, see <http://www.gnu.org/licenses/>.
17+
18+
File :
19+
Description :
20+
Remarks :
21+
Revision :
22+
Date Author Description
23+
02/09/12 Jefflieu
24+
*/
25+
26+
module mDec8b10bMem(
27+
output reg [7:0] o8_Dout, //HGFEDCBA
28+
output reg o_Kout,
29+
output reg o_DErr,
30+
output reg o_KErr,
31+
output reg o_DpErr,
32+
input i_ForceDisparity,
33+
input i_Disparity, //1 Is negative, 0 is positive
34+
input [9:0] i10_Din, //abcdeifghj
35+
output o_Rd,
36+
input i_Clk,
37+
input i_ARst_L);
38+
39+
parameter pNEG = 2'b01;
40+
parameter pPOS = 2'b10;
41+
parameter pNEU = 2'b00;
42+
parameter pERR = 2'b11;
43+
parameter pD = 2'b01;
44+
parameter pK = 2'b10;
45+
parameter pDK = 2'b11;
46+
47+
48+
reg r_Disp;
49+
reg [8:0] w9_5bDecode;
50+
reg [6:0] w7_3bDecode;
51+
wire w_Disp,w_jDisp,w_iDisp;
52+
wire w_iDpErr,w_jDpErr;
53+
wire w_iDErr,w_jDErr;
54+
wire [7:0] w8_ABCDEFGH;
55+
wire wa,wb,wc,wd,we,wi,wf,wg,wh,wj;
56+
wire w_K28;
57+
reg w_Kx;
58+
wire w_cdeihj;
59+
assign w_Disp = i_ForceDisparity?i_Disparity:r_Disp;
60+
assign {wa,wb,wc,wd,we,wi,wf,wg,wh,wj} = i10_Din;
61+
62+
63+
always@(*)
64+
case(i10_Din[9:4])
65+
6'b011000 : w9_5bDecode <= {5'b00000,pD,pPOS};
66+
6'b100111 : w9_5bDecode <= {5'b00000,pD,pNEG};
67+
6'b100010 : w9_5bDecode <= {5'b10000,pD,pPOS};
68+
6'b011101 : w9_5bDecode <= {5'b10000,pD,pNEG};
69+
6'b010010 : w9_5bDecode <= {5'b01000,pD,pPOS};
70+
6'b101101 : w9_5bDecode <= {5'b01000,pD,pNEG};
71+
6'b110001 : w9_5bDecode <= {5'b11000,pD,pNEU};
72+
6'b001010 : w9_5bDecode <= {5'b00100,pD,pPOS};
73+
6'b110101 : w9_5bDecode <= {5'b00100,pD,pNEG};
74+
6'b101001 : w9_5bDecode <= {5'b10100,pD,pNEU};
75+
6'b011001 : w9_5bDecode <= {5'b01100,pD,pNEU};
76+
6'b111000 : w9_5bDecode <= {5'b11100,pD,pNEG};
77+
6'b000111 : w9_5bDecode <= {5'b11100,pD,pPOS};
78+
6'b000110 : w9_5bDecode <= {5'b00010,pD,pPOS};
79+
6'b111001 : w9_5bDecode <= {5'b00010,pD,pNEG};
80+
6'b100101 : w9_5bDecode <= {5'b10010,pD,pNEU};
81+
6'b010101 : w9_5bDecode <= {5'b01010,pD,pNEU};
82+
6'b110100 : w9_5bDecode <= {5'b11010,pD,pNEU};
83+
6'b001101 : w9_5bDecode <= {5'b00110,pD,pNEU};
84+
6'b101100 : w9_5bDecode <= {5'b10110,pD,pNEU};
85+
6'b011100 : w9_5bDecode <= {5'b01110,pD,pNEU};
86+
6'b101000 : w9_5bDecode <= {5'b11110,pD,pPOS};
87+
6'b010111 : w9_5bDecode <= {5'b11110,pD,pNEG};
88+
6'b011011 : w9_5bDecode <= {5'b00001,pD,pNEG};
89+
6'b100100 : w9_5bDecode <= {5'b00001,pD,pPOS};
90+
6'b100011 : w9_5bDecode <= {5'b10001,pD,pNEU};
91+
6'b010011 : w9_5bDecode <= {5'b01001,pD,pNEU};
92+
6'b110010 : w9_5bDecode <= {5'b11001,pD,pNEU};
93+
6'b001011 : w9_5bDecode <= {5'b00101,pD,pNEU};
94+
6'b101010 : w9_5bDecode <= {5'b10101,pD,pNEU};
95+
6'b011010 : w9_5bDecode <= {5'b01101,pD,pNEU};
96+
6'b111010 : w9_5bDecode <= {5'b11101,pDK,pNEG};
97+
6'b000101 : w9_5bDecode <= {5'b11101,pDK,pPOS};
98+
6'b001100 : w9_5bDecode <= {5'b00011,pD,pPOS};
99+
6'b110011 : w9_5bDecode <= {5'b00011,pD,pNEG};
100+
6'b100110 : w9_5bDecode <= {5'b10011,pD,pNEU};
101+
6'b010110 : w9_5bDecode <= {5'b01011,pD,pNEU};
102+
6'b110110 : w9_5bDecode <= {5'b11011,pDK,pNEG};
103+
6'b001001 : w9_5bDecode <= {5'b11011,pDK,pPOS};
104+
105+
6'b001110 : w9_5bDecode <= {5'b00111,pD,pNEU};
106+
6'b001111 : w9_5bDecode <= {5'b00111,pK,pNEG};
107+
6'b110000 : w9_5bDecode <= {5'b00111,pK,pPOS};
108+
109+
6'b101110 : w9_5bDecode <= {5'b10111,pDK,pNEG};
110+
6'b010001 : w9_5bDecode <= {5'b10111,pDK,pPOS};
111+
6'b011110 : w9_5bDecode <= {5'b01111,pDK,pNEG};
112+
6'b100001 : w9_5bDecode <= {5'b01111,pDK,pPOS};
113+
6'b101011 : w9_5bDecode <= {5'b11111,pDK,pNEG};
114+
6'b010100 : w9_5bDecode <= {5'b11111,pDK,pPOS};
115+
default : w9_5bDecode <= {5'b11111,pERR,pERR};
116+
endcase
117+
118+
119+
120+
assign w_iDpErr = (w9_5bDecode[1:0]==pNEG && w_Disp==1'b1) | (w9_5bDecode[1:0]==pPOS && w_Disp==1'b0);
121+
assign w_iDErr = (w9_5bDecode[1:0]==pERR)?1'b1:1'b0;
122+
assign w_iDisp = (w9_5bDecode[1:0]==pERR||w9_5bDecode[1:0]==pNEU||i10_Din[9:4]==6'b111000||i10_Din[9:4]==6'b000111)?w_Disp:~w9_5bDecode[1];
123+
124+
assign w_jDpErr = (w7_3bDecode[1:0]==pNEG && w_iDisp==1'b1) | (w7_3bDecode[1:0]==pPOS && w_iDisp==1'b0);
125+
assign w_jDisp = (w7_3bDecode[1:0]==pERR||w7_3bDecode[1:0]==pNEU||i10_Din[3:0]==4'b1100||i10_Din[3:0]==4'b0011)?w_iDisp:~w_iDisp;
126+
assign w_jDErr = (w7_3bDecode[1:0]==pERR)?1'b1:1'b0;
127+
assign w_cdeihj = (~(|{wc,wd,we,wi}))&(wh^wj);
128+
always@(*)
129+
case(i10_Din[3:0])
130+
4'b0100 : w7_3bDecode <= {3'b000,pDK,pPOS};
131+
4'b1011 : w7_3bDecode <= {3'b000,pDK,pNEG};
132+
4'b1001 : if(w_cdeihj)
133+
w7_3bDecode <= {3'b011,pK,pNEU};
134+
else
135+
w7_3bDecode <= {3'b100,pDK,pNEU};
136+
4'b0110 : if(w_cdeihj)
137+
w7_3bDecode <= {3'b100,pK,pNEU};
138+
else
139+
w7_3bDecode <= {3'b011,pDK,pNEU};
140+
4'b0101 : if(w_cdeihj)
141+
w7_3bDecode <= {3'b101,pK,pNEU};
142+
else
143+
w7_3bDecode <= {3'b010,pDK,pNEU};
144+
4'b1010 : if(w_cdeihj)
145+
w7_3bDecode <= {3'b010,pK,pNEU};
146+
else
147+
w7_3bDecode <= {3'b101,pDK,pNEU};
148+
4'b1100 : w7_3bDecode <= {3'b110,pDK,pNEG};
149+
4'b0011 : w7_3bDecode <= {3'b110,pDK,pPOS};
150+
4'b0010 : w7_3bDecode <= {3'b001,pDK,pPOS};
151+
4'b1101 : w7_3bDecode <= {3'b001,pDK,pNEG};
152+
//4'b1010 :
153+
//4'b0101 :
154+
//4'b0110 :
155+
//4'b1001 :
156+
4'b1110 : w7_3bDecode <= {3'b111,pD,pNEG};
157+
4'b0001 : w7_3bDecode <= {3'b111,pD,pPOS};
158+
4'b0111 : w7_3bDecode <= {3'b111,pDK,pNEG};
159+
4'b1000 : w7_3bDecode <= {3'b111,pDK,pPOS};
160+
default : w7_3bDecode <= {3'b111,pERR,pERR};
161+
endcase
162+
163+
assign w8_ABCDEFGH = {w9_5bDecode[8:4],w7_3bDecode[6:4]};
164+
165+
integer I;
166+
always@(posedge i_Clk or negedge i_ARst_L)
167+
if(~i_ARst_L)
168+
begin
169+
o_DErr <= 1'b1;
170+
o_DpErr <= 1'b0;
171+
o_KErr <= 1'b0;
172+
o_Kout <= 1'b0;
173+
o8_Dout <= 8'h0;
174+
r_Disp <= 1'b0;
175+
end
176+
else
177+
begin
178+
o_DErr <= w_jDErr|w_iDErr;
179+
o_DpErr <= w_jDpErr|w_iDpErr;
180+
o_KErr <= ~(|(w9_5bDecode[3:2]&w7_3bDecode[3:2]));
181+
o_Kout <= ((w9_5bDecode[3:2]==pK)&(w7_3bDecode[3]))|((w9_5bDecode[3:2]==pDK)&(w7_3bDecode[3])&(w7_3bDecode[6:4]==3'b111));
182+
r_Disp <= w_jDisp;
183+
for(I=0;I<8;I=I+1)
184+
o8_Dout[7-I] <= w8_ABCDEFGH[I];
185+
end
186+
assign o_Rd = r_Disp;
187+
188+
endmodule

0 commit comments

Comments
 (0)