論序
8b/10b編碼/解碼是高速串行通信,如PCle SATA(串行ATA),以及Fiber Channel中常用的編解碼方式。在發(fā)送端,編碼電路將串行輸入的8比特一組的數(shù)據(jù)轉(zhuǎn)變成10比特一組的數(shù)據(jù)并輸出;在接收端,解碼器將10比特一組的輸入數(shù)據(jù)轉(zhuǎn)換成8比特一組的輸出數(shù)據(jù)。編碼和解碼采用相同算法,整個過程就是8b/10b編碼/解碼過程。
這種編碼方式的0-1、1-0跳變豐富,0和1分布均勻,不會出現(xiàn)長連0和長連1。例如,8b/10b編碼比特流中連續(xù)出現(xiàn)的0或1的最大數(shù)量是5。這有助于為數(shù)據(jù)流提供DC平衡,可以為接收端時鐘恢復提供足夠的比特翻轉(zhuǎn)(1-0,0-1)。在1983年,這種編碼方式首次由IBM工程師奧爾?韋迪莫和皮特?弗蘭斯科發(fā)明,之后IBM申請了發(fā)明專利。
8b/10b編碼方式
進行8b/10b編碼時,輸入的每8比特數(shù)據(jù)轉(zhuǎn)化為10比特數(shù)據(jù),這10比特數(shù)據(jù)稱為一個編碼符號或編碼字符,如圖6.20所示。
編碼時,將8比特數(shù)據(jù)分成兩個子組,即低5位子組和高3位子組。低5位編碼后為一個6比特值,高3位編碼后為一個4比特值,此后將二者拼接,可以得到一個10比特字符。對于8比特輸人,會有256種可能的組合,然而對于10比特,就會有1024(1K)種組合,除了有過多連0和連1的編碼組合被丟棄不用外,還要選擇部分10比特組合作為控制字符,或者稱為K字符。
這些特殊的控制符具有不同用途,例如,作為包的開始標識、包的結(jié)束標識,以及特殊COMMA符號。還有一些編碼字符既不屬于控制字符也不屬于和256種8比特輸入數(shù)據(jù)對應的編碼字符,它們都是非法字符,正常工作時不會出現(xiàn)在編碼比特字符流中。在數(shù)據(jù)傳輸出錯時可能會出現(xiàn)非法字符。圖6.20詳細介紹了低5比特和高3比特轉(zhuǎn)換成10比特編碼字符的具體方式。
多字節(jié)8b/10b編碼
在一些應用中,每個時鐘周期需要對多字節(jié)進行編碼。圖6.21是對16比特數(shù)據(jù)進行8b/10b編碼的一種實現(xiàn)方案,它可以在每個時鐘周期進行兩字節(jié)數(shù)據(jù)的8b/10b編碼。
編碼器1輸岀的disparity信號被當成編碼器2的disparity輸入。兩個編碼器的編碼和disparity計算在相同的時鐘周期內(nèi)進行。最終的disparity(編碼器2的輸出)經(jīng)過一個寄存器后作為16比特數(shù)據(jù)的disparity,也就是當前運行的disparity,同時它還作為編碼器1下一個時鐘周期的disparity輸入。
disparity選擇8b/10b編碼方案
當進行8b/10b編碼的并行數(shù)據(jù)字節(jié)數(shù)增加時(例如,4字節(jié)),編碼延遲會增大,從而使編碼器不能滿足高速工作時的定時要求。對于四級級聯(lián)譯碼器來說,最后一級的disparity和10b編碼結(jié)果的計算延遲最大。計算disparity的邏輯處于關(guān)鍵延遲路徑上,只有等前面各級計算結(jié)束后才能計算組后一級的disparity值。改進定時特性,提高編碼速度的一種重要方法是采用disparity選擇機制。
圖6.22給出了disparity選擇編碼電路的結(jié)構(gòu)。對除第一級之外的每一級編碼器,單獨計算每一級的disparity值,包括一個正disparity值和一個負disparity值,最終的disparity值需要根據(jù)前一級的輸出進行選擇,由于選擇器的延遲小于disparity計算邏輯,因此這種方法可以提高電路的工作速度。這種方案由于增加了disparity十算電路的數(shù)量,因此會消耗更多的邏輯電路資源。
代碼舉例
端口說明
##Encoder###Ports
*`clk`-inputClock
*`rst`-inputReset(Active-HIGH)
*`en`-inputEnable(Active-HIGH)
*`kin`-K-orD-symbolselection(`1-K`,`0-D`)
*`din`-8-bitdatainput
*`dout`-10-bitdataoutput
*`disp`-Disparityflagoutput
*`kin_err`-K-symbolerroroutput
##Decoder###Ports
*`clk`-inputClock
*`rst`-inputReset(Active-HIGH)
*`en`-inputEnable(Active-HIGH)
*`din`-10-bitdatainput
*`dout`-8-bitdataoutput
*`kout`-K-orD-symbolflag(`1-K`,`0-D`)
*`code_err`-Codeerrorflagoutput
*`disp`-Disparityoutput
*`disp_err`-Disparityerrorflagoutput
decoder_8b10b.v
`timescale1ns/1ps
//////////////////////////////////////////////////////////////////////////////////
//Company:
//Engineer:DmitryMatyunin(https://github.com/mcjtag)
//
//CreateDate:06.04.20212330
//DesignName:
//ModuleName:decoder_8b10b
//ProjectName:v8b10b
//TargetDevices:
//ToolVersions:
//Description:
//
//Dependencies:
//
//Revision:
//Revision0.01-FileCreated
//AdditionalComments:
//
//////////////////////////////////////////////////////////////////////////////////
moduledecoder_8b10b(
inputwireclk,
inputwirerst,
inputwireen,
inputwire[9:0]din,
outputwire[7:0]dout,
outputwirekout,
outputwirecode_err,
outputwiredisp,
outputwiredisp_err
);
reg[7:0]do;
regk;
regce;
reg[2:0]e;
regp;
reg[3:0]pe;
wire[9:0]d;
assignd=din;
assigndisp_err=pe?1'b1:1'b0;
assigndout=do;
assignkout=k;
assigncode_err=ce;
assigndisp=p;
always@(posedgeclk)begin
if(rst)begin
k<=?0;
??do<=?8'b0;
endelsebegin
if(en==1'b1)begin
k<=?(((d[7]&d[6]&d[5]&d[4])|(!d[7]&!d[6]&!d[5]&!d[4]))|(((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&(!d[5]&d[4]&d[2]&d[1]&d[0]))|(((!((d[9]&d[8])|(!d[9]&!d[8]))&d[7]&d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&d[9]&d[8]))&(d[5]&!d[4]&!d[2]&!d[1]&!d[0])));
???do[7]<=?((d[0]^d[1])&!((!d[3]&d[2]&!d[1]&d[0]&!(!(d[7]|d[6]|d[5]|d[4])))|(!d[3]&d[2]&d[1]&!d[0]&(!(d[7]|d[6]|d[5]|d[4])))|(d[3]&!d[2]&!d[1]&d[0]&!(!(d[7]|d[6]|d[5]|d[4])))|(d[3]&!d[2]&d[1]&!d[0]&(!(d[7]|d[6]|d[5]|d[4])))))|(!d[3]&d[2]&d[1]&d[0])|(d[3]&!d[2]&!d[1]&!d[0]);
???do[6]<=?(d[0]&!d[3]&(d[1]|!d[2]|!(!(d[7]|d[6]|d[5]|d[4]))))|(d[3]&!d[0]&(!d[1]|d[2]|(!(d[7]|d[6]|d[5]|d[4]))))|(!(!(d[7]|d[6]|d[5]|d[4]))&d[2]&d[1])|((!(d[7]|d[6]|d[5]|d[4]))&!d[2]&!d[1]);
???do[5]<=?(d[0]&!d[3]&(d[1]|!d[2]|(!(d[7]|d[6]|d[5]|d[4]))))|(d[3]&!d[0]&(!d[1]|d[2]|!(!(d[7]|d[6]|d[5]|d[4]))))|((!(d[7]|d[6]|d[5]|d[4]))&d[2]&d[1])|(!(!(d[7]|d[6]|d[5]|d[4]))&!d[2]&!d[1]);
???do[4]<=?d[5]^(((((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&!d[5])|(!d[7]&!d[6]&!d[5]&!d[4])|(!d[9]&!d[8]&!d[5]&!d[4]))|((((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&!d[9]&!d[7]&(!(d[5]^d[4])))|(((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))?&?!d[9]?&?!d[8]))&!d[4]))|((((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&d[6]&d[5]&d[4])|(((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&!d[8]&!d[7]&(!(d[5]^d[4])))));
???do[3]<=?d[6]^(((d[9]&d[8]&d[5]&d[4])|(!d[7]&!d[6]&!d[5]&!d[4])|(((!((d[9]&d[8])|(!d[9]&!d[8]))&d[7]&d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&d[9]&d[8]))&d[4]))|((((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&d[9]&d[7]&(!(d[5]^d[4])))|(((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&!d[5]))|((((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&d[6]&d[5]&d[4])|(((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&!d[8]&!d[7]&(!(d[5]^d[4])))));
???do[2]<=?d[7]^(((((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&!d[9]&!d[7]&(!(d[5]^d[4])))|(((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&!d[5]))|((((!((d[9]&d[8])|(!d[9]&!d[8]))&d[7]&d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&d[9]&d[8]))&d[4])|(((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&d[8]&d[7]&(!(d[5]^d[4])))|(((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&d[6]&d[5]&d[4]))|((((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&!d[5])|(!d[7]&!d[6]&!d[5]&!d[4])|(!d[9]&!d[8]&!d[5]&!d[4])));
???do[1]<=?d[8]^(((d[9]&d[8]&d[5]&d[4])|(!d[7]&!d[6]&!d[5]&!d[4])|(((!((d[9]&d[8])|(!d[9]&!d[8]))&d[7]&d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&d[9]&d[8]))&d[4]))|((((!((d[9]&d[8])|(!d[9]&!d[8]))&d[7]&d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&d[9]&d[8]))&d[4])|(((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&d[8]&d[7]&(!(d[5]^d[4])))|(((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&d[6]&d[5]&d[4]))|((((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&d[9]&d[7]&(!(d[5]^d[4])))|(((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&!d[5])));
???do[0]<=?d[9]^(((((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&d[6]&d[5]&d[4])|(((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&!d[8]&!d[7]&(!(d[5]^d[4]))))|((((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&!d[9]&!d[7]&(!(d[5]^d[4])))|(((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&!d[5]))|((d[9]&d[8]&d[5]&d[4])|(!d[7]&!d[6]&!d[5]&!d[4])|(((!((d[9]&d[8])|(!d[9]&!d[8]))&d[7]&d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&d[9]&d[8]))&d[4])));
??end
?end
end
???
always?@(posedge?clk)?begin
?if(rst)begin
p<=?1'b0;
pe<=?4'hF;
ce<=?1'b1;
e=3'b000;
endelsebegin
if(en==1'b1)begin
p<=?(((!((d[3]&d[2])|(!d[3]&!d[2])))&d[1]&d[0])|(!((d[1]&d[0])|(!d[1]&!d[0]))&d[3]&d[2]))|(((d[5]&d[4]&!(((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&!p))|((((!((d[9]&d[8])|(!d[9]&!d[8]))&d[7]&d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&d[9]&d[8]))|(((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&p))&(d[5]|d[4]))|(((!((d[9]&d[8])|(!d[9]&!d[8]))&d[7]&d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&d[9]&d[8]))&p))&((d[3]&d[2]&!d[1]&!d[0])|(!d[3]&!d[2]&d[1]&d[0])|(!((d[3]&d[2])|(!d[3]&!d[2]))&!((d[1]&d[0])|(!d[1]&!d[0])))))?;
???pe[0]?<=?((p&((((!((d[9]&d[8])|(!d[9]&!d[8]))&d[7]&d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&d[9]&d[8]))&(d[5]|d[4]))|(((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&d[5]&d[4])))|(((((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&!(d[5]&d[4]))|(((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&!d[5]&!d[4]))&!p))|((p&!((((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&!(d[5]&d[4]))|(((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&!d[5]&!d[4]))&d[3]&d[2]));
???pe[1]?<=?((p&d[9]&d[8]&d[7]))|((p&!((((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&!(d[5]&d[4]))|(((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&!d[5]&!d[4]))&(((!((d[3]&d[2])|(!d[3]&!d[2])))&d[1]&d[0])|(!((d[1]&d[0])|(!d[1]&!d[0]))&d[3]&d[2]))));
???pe[2]?<=?((!p&!((((!((d[9]&d[8])|(!d[9]&!d[8]))&d[7]&d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&d[9]&d[8]))&(d[5]|d[4]))|(((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&d[5]&d[4]))&!d[3]&!d[2]))|((!p&!d[9]&!d[8]&!d[7]));
???pe[3]?<=?((!p&!((((!((d[9]&d[8])|(!d[9]&!d[8]))&d[7]&d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&d[9]&d[8]))&(d[5]|d[4]))|(((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&d[5]&d[4]))&((!((d[3]&d[2])|(!d[3]&!d[2]))&!d[1]&!d[0])|(!((d[1]&d[0])|(!d[1]&!d[0]))&!d[3]&!d[2]))))|((((((!((d[9]&d[8])|(!d[9]&!d[8]))&d[7]&d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&d[9]&d[8]))&(d[5]|d[4]))|(((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&d[5]&d[4]))&(((!((d[3]&d[2])|(!d[3]&!d[2])))&d[1]&d[0])|(!((d[1]&d[0])|(!d[1]&!d[0]))&d[3]&d[2])))|(((((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&!(d[5]&d[4]))|(((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&!d[5]&!d[4]))&((!((d[3]&d[2])|(!d[3]&!d[2]))&!d[1]&!d[0])|(!((d[1]&d[0])|(!d[1]&!d[0]))&!d[3]&!d[2]))));
???e[0]?<=?((d[9]&d[8]&d[7]&d[6])|(!d[9]&!d[8]&!d[7]&!d[6]))|((((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&!d[5]&!d[4]))|((((!((d[9]&d[8])|(!d[9]&!d[8]))&d[7]&d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&d[9]&d[8]))&d[5]&d[4]))|((d[3]&d[2]&d[1]&d[0])|(!d[3]&!d[2]&!d[1]&!d[0]))|((d[5]&d[4]&d[3]&d[2]&d[1])|(!d[5]&!d[4]&!d[3]&!d[2]&!d[1]))|((d[5]&!d[4]&d[2]&d[1]&d[0])|(!d[5]&d[4]&!d[2]&!d[1]&!d[0]))|((((d[5]&d[4]&!d[2]&!d[1]&!d[0])|(!d[5]&!d[4]&d[2]&d[1]&d[0]))&!((d[7]&d[6]&d[5])|(!d[7]&!d[6]&!d[5]))))|((!((!((d[9]&d[8])|(!d[9]&!d[8]))&d[7]&d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&d[9]&d[8]))&d[5]&!d[4]&!d[2]&!d[1]&!d[0]))|((!((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&!d[5]&d[4]&d[2]&d[1]&d[0]));
???e[1]?<=?((((((!((d[9]&d[8])|(!d[9]&!d[8]))&d[7]&d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&d[9]&d[8]))&(d[5]|d[4]))|(((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&d[5]&d[4]))&(((!((d[3]&d[2])|(!d[3]&!d[2])))&d[1]&d[0])|(!((d[1]&d[0])|(!d[1]&!d[0]))&d[3]&d[2])))|(((((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&!(d[5]&d[4]))|(((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&!d[5]&!d[4]))&((!((d[3]&d[2])|(!d[3]&!d[2]))&!d[1]&!d[0])|(!((d[1]&d[0])|(!d[1]&!d[0]))&!d[3]&!d[2]))))|((d[3]&d[2]&!d[1]&!d[0]&((((!((d[9]&d[8])|(!d[9]&!d[8]))&d[7]&d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&d[9]&d[8]))&(d[5]|d[4]))|(((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&d[5]&d[4]))))|((!d[3]&!d[2]&d[1]&d[0]&((((!((d[9]&d[8])|(!d[9]&!d[8]))&!d[7]&!d[6])|(!((d[7]&d[6])|(!d[7]&!d[6]))&!d[9]&!d[8]))&!(d[5]&d[4]))|(((d[9]&d[8]&!d[7]&!d[6])|(d[7]&d[6]&!d[9]&!d[8])|(!((d[9]&d[8])|(!d[9]&!d[8]))&!((d[7]&d[6])|(!d[7]&!d[6]))))&!d[5]&!d[4]))));
???e[2]?<=?((d[9]&d[8]&d[7]&!d[5]&!d[4]&((!d[3]&!d[2])|((!((d[3]&d[2])|(!d[3]&!d[2]))&!d[1]&!d[0])|(!((d[1]&d[0])|(!d[1]&!d[0]))&!d[3]&!d[2])))))|((!d[9]&!d[8]&!d[7]&d[5]&d[4]&((d[3]&d[2])|(((!((d[3]&d[2])|(!d[3]&!d[2])))&d[1]&d[0])|(!((d[1]&d[0])|(!d[1]&!d[0]))&d[3]&d[2])))))|((d[7]&d[6]&d[5]&d[4]&!d[3]&!d[2]&!d[1]))|((!d[7]&!d[6]&!d[5]&!d[4]&d[3]&d[2]&d[1]));
???ce?<=?e???1'b1:1'b0;
end
end
end
endmodule
encoder_8b10.v
`timescale1ns/1ps
//////////////////////////////////////////////////////////////////////////////////
//Company:
//Engineer:DmitryMatyunin(https://github.com/mcjtag)
//
//CreateDate:06.04.20212328
//DesignName:
//ModuleName:encoder_8b10
//ProjectName:v8b10b
//TargetDevices:
//ToolVersions:
//Description:
//
//Dependencies:
//
//Revision:
//Revision0.01-FileCreated
//AdditionalComments:
//
//////////////////////////////////////////////////////////////////////////////////
moduleencoder_8b10
(
inputwireclk,
inputwirerst,
inputwireen,
inputwirekin,
inputwire[7:0]din,
outputwire[9:0]dout,
outputwiredisp,
outputwirekin_err
);
regp;
regke;
reg[18:0]t;
reg[9:0]do;
wire[7:0]d;
wirek;
assignd=din;
assignk=kin;
assigndout=do;
assigndisp=p;
assignkin_err=ke;
always@(posedgeclk)begin
if(rst)begin
p<=?1'b0;
ke<=?1'b0;
do<=?10'b0;
endelsebegin
if(en==1'b1)begin
p<=?((d[5]&d[6]&d[7])|(!d[5]&!d[6]))^(p^(((d[4]&d[3]&!d[2]&!d[1]&!d[0])|(!d[4]&!((d[0]&d[1]&!d[2]&!d[3])|(d[2]&d[3]&!d[0]&!d[1])|(!((d[0]&d[1])|(!d[0]&!d[1]))&!((d[2]&d[3])|(!d[2]&!d[3]))))&!((!((d[0]&d[1])|(!d[0]&!d[1]))&d[2]&d[3])|(!((d[2]&d[3])|(!d[2]&!d[3]))&d[0]&d[1]))))|(k|(d[4]&!((d[0]&d[1]&!d[2]&!d[3])|(d[2]&d[3]&!d[0]&!d[1])|(!((d[0]&d[1])|(!d[0]&!d[1]))&!((d[2]&d[3])|(!d[2]&!d[3]))))&!((!((d[0]&d[1])|(!d[0]&!d[1]))&!d[2]&!d[3])|(!((d[2]&d[3])|(!d[2]&!d[3]))&!d[0]&!d[1]))))));
???ke?<=?(k&(d[0]|d[1]|!d[2]|!d[3]|!d[4])&(!d[5]|!d[6]|!d[7]|!d[4]|!((!((d[0]&d[1])|(!d[0]&!d[1]))&d[2]&d[3])|(!((d[2]&d[3])|(!d[2]&!d[3]))&d[0]&d[1]))));?
???do[9]<=?t[12]^t[0];
???do[8]<=?t[12]^(t[1]|t[2]);
???do[7]<=?t[12]^(t[3]|t[4]);
???do[6]<=?t[12]^t[5];
???do[5]<=?t[12]^(t[6]&t[7]);
???do[4]<=?t[12]^(t[8]|t[9]|t[10]|t[11]);
???do[3]<=?t[13]^(t[15]&!t[14]);
???do[2]<=?t[13]^t[16];
???do[1]<=?t[13]^t[17];
???do[0]<=?t[13]^(t[18]|t[14]);
??end
?end
end
??
always?@(posedge?clk)?begin
?if(rst)begin
t<=?0;
?end?elsebegin
if(en==1'b1)begin
t[0]<=?d[0];
???t[1]?<=?d[1]&!(d[0]&d[1]&d[2]&d[3]);
???t[2]?<=?(!d[0]&!d[1]&!d[2]&!d[3]);
???t[3]?<=?(!d[0]&!d[1]&!d[2]&!d[3])|d[2];
???t[4]?<=?d[4]&d[3]&!d[2]&!d[1]&!d[0];
???t[5]?<=?d[3]&!(d[0]&d[1]&d[2]);
???t[6]?<=?d[4]|((!((d[0]&d[1])|(!d[0]&!d[1]))&!d[2]&!d[3])|(!((d[2]&d[3])|(!d[2]&!d[3]))&!d[0]&!d[1]));
???t[7]?<=?!(d[4]&d[3]&!d[2]&!d[1]&!d[0]);
???t[8]?<=?(((d[0]&d[1]&!d[2]&!d[3])|(d[2]&d[3]&!d[0]&!d[1])|(!((d[0]&d[1])|(!d[0]&!d[1]))&!((d[2]&d[3])|(!d[2]&!d[3]))))&!d[4])|(d[4]&(d[0]&d[1]&d[2]&d[3]));
???t[9]?<=?d[4]&!d[3]&!d[2]&!(d[0]&d[1]);
???t[10]?<=?k&d[4]&d[3]&d[2]&!d[1]&!d[0];
???t[11]?<=?d[4]&!d[3]&d[2]&!d[1]&!d[0];
???t[12]?<=?(((d[4]&d[3]&!d[2]&!d[1]&!d[0])|(!d[4]&!((d[0]&d[1]&!d[2]&!d[3])|(d[2]&d[3]&!d[0]&!d[1])|(!((d[0]&d[1])|(!d[0]&!d[1]))&!((d[2]&d[3])|(!d[2]&!d[3]))))&!((!((d[0]&d[1])|(!d[0]&!d[1]))&d[2]&d[3])|(!((d[2]&d[3])|(!d[2]&!d[3]))&d[0]&d[1]))))&!p)|((k|(d[4]&!((d[0]&d[1]&!d[2]&!d[3])|(d[2]&d[3]&!d[0]&!d[1])|(!((d[0]&d[1])|(!d[0]&!d[1]))&!((d[2]&d[3])|(!d[2]&!d[3]))))&!((!((d[0]&d[1])|(!d[0]&!d[1]))&!d[2]&!d[3])|(!((d[2]&d[3])|(!d[2]&!d[3]))&!d[0]&!d[1])))|(!d[4]&!d[3]&d[2]&d[1]&d[0]))&p);
???t[13]?<=?(((!d[5]&!d[6])|(k&((d[5]&!d[6])|(!d[5]&d[6]))))&!(p^(((d[4]&d[3]&!d[2]&!d[1]&!d[0])|(!d[4]&!((d[0]&d[1]&!d[2]&!d[3])|(d[2]&d[3]&!d[0]&!d[1])|(!((d[0]&d[1])|(!d[0]&!d[1]))&!((d[2]&d[3])|(!d[2]&!d[3]))))&!((!((d[0]&d[1])|(!d[0]&!d[1]))&d[2]&d[3])|(!((d[2]&d[3])|(!d[2]&!d[3]))&d[0]&d[1]))))|(k|(d[4]&!((d[0]&d[1]&!d[2]&!d[3])|(d[2]&d[3]&!d[0]&!d[1])|(!((d[0]&d[1])|(!d[0]&!d[1]))&!((d[2]&d[3])|(!d[2]&!d[3]))))&!((!((d[0]&d[1])|(!d[0]&!d[1]))&!d[2]&!d[3])|(!((d[2]&d[3])|(!d[2]&!d[3]))&!d[0]&!d[1])))))))|((d[5]&d[6])&(p^(((d[4]&d[3]&!d[2]&!d[1]&!d[0])|(!d[4]&!((d[0]&d[1]&!d[2]&!d[3])|(d[2]&d[3]&!d[0]&!d[1])|(!((d[0]&d[1])|(!d[0]&!d[1]))&!((d[2]&d[3])|(!d[2]&!d[3]))))&!((!((d[0]&d[1])|(!d[0]&!d[1]))&d[2]&d[3])|(!((d[2]&d[3])|(!d[2]&!d[3]))&d[0]&d[1]))))|(k|(d[4]&!((d[0]&d[1]&!d[2]&!d[3])|(d[2]&d[3]&!d[0]&!d[1])|(!((d[0]&d[1])|(!d[0]&!d[1]))&!((d[2]&d[3])|(!d[2]&!d[3]))))&!((!((d[0]&d[1])|(!d[0]&!d[1]))&!d[2]&!d[3])|(!((d[2]&d[3])|(!d[2]&!d[3]))&!d[0]&!d[1])))))));
???t[14]?<=?d[5]&d[6]&d[7]&(k|(p?(!d[4]&d[3]&((!((d[0]&d[1])|(!d[0]&!d[1]))&d[2]&d[3])|(!((d[2]&d[3])|(!d[2]&!d[3]))&d[0]&d[1]))):(d[4]&!d[3]&((!((d[0]&d[1])|(!d[0]&!d[1]))&!d[2]&!d[3])|(!((d[2]&d[3])|(!d[2]&!d[3]))&!d[0]&!d[1])))));
???t[15]?<=?d[5];
???t[16]?<=?d[6]|(!d[5]&!d[6]&!d[7]);
???t[17]?<=?d[7];
???t[18]?<=?!d[7]&(d[6]^d[5]);
??end
?end
end
endmodule
VHDL文件詳見:
https://github.com/suisuisi/8b10b_encdec
其他常用編碼方式
8b/10b編碼為時鐘恢復提供了足夠的0與1翻轉(zhuǎn),但編碼效率較低,每傳輸10比特數(shù)據(jù),只有8比特為有效數(shù)據(jù),編碼效率只有80%,有20%為輔助比特。64b/66b編碼中的0、1分布不如8b/10b均勻,但編碼效率高,輔助比特少,每66比特中只有2比特是輔助比特,所占比例僅為3%。64b/66b被用于10Gbit以太網(wǎng)中。本部分將詳細介紹64b/66b編碼。
64b/66b編碼機制
66比特的編碼塊由2比特的前導碼和64比特數(shù)據(jù)組成。
- 當前導碼為“01”時,后面的64比特為數(shù)據(jù);
- 當前導碼為“10”時,其后的8比特為類型字段,后56比特為數(shù)據(jù);
- 其他兩個值“11”和“00”未被使用。
前導碼(10和01)可以保證每66比特中至少有一次比特翻轉(zhuǎn),可用于時鐘恢復。與64b/66b編碼電路相連的還有一個擾碼電路。
128b/130b編碼機制
128b/130b編碼用于PCIe Gen3以取代8b/l0b編碼/解碼。8b/10b編碼中除了數(shù)據(jù)編碼字符外還有很多控制字符,用于表示包的開始始、包的結(jié)束等。然而,該編碼方式編碼效率較低,輔助比特占了20%。128b/130b編碼中輔助比特很少(約為1.5%)。
128比特的數(shù)據(jù)塊加上2比特的同步頭就可以構(gòu)成一個130比特的編碼塊。同步頭編碼為2‘b01時表示后面跟隨的是訓練順序組(training ordered set),2b'10表示后面的是數(shù)據(jù)(TLP、DLLP及空閑數(shù)據(jù)),2’bl1和2’b00被保留。由于128b/130b編碼體制中沒有額外的控制字符,因此需要使用其他機制來指出包的開始和結(jié)束。
-
編碼器
+關(guān)注
關(guān)注
45文章
3573瀏覽量
133980 -
寄存器
+關(guān)注
關(guān)注
31文章
5294瀏覽量
119814 -
數(shù)據(jù)
+關(guān)注
關(guān)注
8文章
6808瀏覽量
88743
原文標題:高速串行通信常用的編碼方式-8b/10b編碼/解碼
文章出處:【微信號:Open_FPGA,微信公眾號:OpenFPGA】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
相關(guān)推薦
評論