📄 decoder_8b10b.vhd
字号:
-- (C) COPYRIGHT PLD APPLICATIONS 1998-2000, ALL RIGHTS RESERVED
-- BUILD G8B10B_0100
library ieee;
use ieee.std_logic_1164.all;
entity decoder_8b10b is
port
(
clk : in std_logic;
rstn : in std_logic;
frame_enc : in std_logic;
data_enc : in std_logic_vector (9 downto 0);
frame_out : out std_logic;
data_out : out std_logic_vector (7 downto 0);
kchar_out : out std_logic_vector (3 downto 0);
error_out : out std_logic
);
end decoder_8b10b;
architecture structural of decoder_8b10b is
signal data_r : std_logic_vector (9 downto 0);
signal frame_in_r,frame_r : std_logic;
signal ain,bin,cin,din,ein,iin,fin,gin,hin,jin : std_logic;
signal err_n,err_r,kn,kr : std_logic_vector (4 downto 1);
signal an,ar,bn,br,cn,cr,dn,dr,en,er,hn,hr : std_logic_vector (3 downto 1);
signal fn,fr,gn,gr : std_logic_vector (2 downto 1);
signal data_n : std_logic_vector (7 downto 0);
signal error,kchar : std_logic;
begin
process (clk,rstn)
begin
if rstn='0' then
frame_in_r <='0';
data_r <=(others=>'0');
elsif rising_edge (clk) then
frame_in_r <=frame_enc;
data_r <=data_enc;
end if;
end process;
ain <=data_r(0);
bin <=data_r(1);
cin <=data_r(2);
din <=data_r(3);
ein <=data_r(4);
iin <=data_r(5);
fin <=data_r(6);
gin <=data_r(7);
hin <=data_r(8);
jin <=data_r(9);
err_n(1) <= ((ain and bin and cin and din) or (((ain and bin and iin) or (cin and din) or fin or
((ain or bin) and (cin or din))) and (not(not(gin) or not(jin) or not(hin) or ein))));
err_n(2) <= ((not(cin or din) or not(fin) or
not((ain or bin or iin) and ((ain and bin) or (cin and din)))) and
(not(not(ein) or gin or hin or jin)));
err_n(3) <= ((((not(cin and din) and not(ain or bin)) or
(not(ain or bin or cin or din)) or
(not(fin or gin or hin))) and not(iin) and not(ein)) OR
(gin and hin and jin and not(iin) and ein) OR
((not(gin or hin or jin)) and iin and not(ein)) OR
(((fin and gin and hin) or
(cin and din and (ain or bin)) or
(ain and bin and (cin or din))) and iin and ein));
err_n(4) <=(not(ain or bin) and not(cin or din));
error <= err_r(4) or err_r(1) or err_r(2) or err_r(3);
kn(1) <=ein and (not (gin or hin or jin or (not(((ain xor bin) and cin and din) or
(ain and bin and not(iin or not(din xor cin))))))) ;
kn(2) <=not (ein) and (gin and hin and jin and
((not(ain or bin) and (iin and (din xor cin))) or
((ain xor bin) and not(cin or din))));
kn(3) <=ein and (cin and din and iin);
kn(4) <=not (ein) and (not(cin or din or iin));
kchar <=kr(1) or kr(2) or kr(3) or kr(4);
an(1) <=((ein or not(iin) or (not(cin xor bin) or din)) and
(ein or not(bin and din and
(not(iin or cin) or (not(ain) and iin and cin)))));
an(2) <=ain and not ((not(ein) or ((din or bin) and (iin or cin))) and
(iin or (not(cin) or (din and bin))));
an(3) <= (not(cin) and din and iin and not(((ain and ein) or (bin and not(ein)))));
data_n(0) <= ar(2) or not(ar(1)) or ar(3);
bn(1) <= ((not(bin) and (din xor ein) and iin) or not(iin or din or ein)) and ain and cin;
bn(2) <= (bin and not(iin) and not(((ain and cin) or not(din or ein)) and (not(ein) or din)));
bn(3) <= (not((not((bin and ein) or (bin and din) or (iin and din)) or ain or cin) and
(din or ein or not(iin) or not(ain xor cin))));
data_n(1) <=br(1) or br(2) or br(3);
cn(1) <= ((not(ain) and din and iin and (not(bin) or (not(cin) and ein))));
cn(2) <=ein or (not((ain and bin and not(cin) and din and iin) or
(not(iin or not(bin) or not(ain xor din))) or
(not(din) and ((not(ain) and bin and iin) or (ain and not(bin) and iin)))));
cn(3) <= (cin and not(((not(ain) and not(ein)) or (ain and bin) or iin) and
((iin and bin) or din or not(ein))));
data_n(2) <= not(cr(2) and not(cr(1)) and not(cr(3)));
dn(1) <= ((not(ain) and (din or (iin and not(ein))) and (cin xor bin)) or
(ain and (cin xor bin) and ((not(din) and ein and iin) or (not(ein) and not(iin)))));
dn(2) <= (not(ein or not(iin) or (not(ain and not(bin) and not(cin)) and
(not(ain) or not(bin) or not(cin) or din))));
dn(3) <= ((not(bin) and ein) or (bin and not(ain and cin))) and din and not (iin);
data_n(3) <=dr(3) or dr(1) or dr(2);
en(1) <= ((not(iin) and bin and ((ain and not(cin) and not(din)) or
(ein and (ain xor cin)))) or
(not(bin or not(din) or ((not(ain) or not(ein) or iin) and
((ain or cin or ein or not(iin)))))));
en(2) <= ein and ((cin and not((ain or (bin and din) or (not(bin) and not(iin))) and
((iin and bin) or not(ain) or din))) or
not(cin or din or not(bin) or not(iin)));
en(3) <=(din xor iin) and not ((cin or ain or not(bin)) and (bin or not(ain xor cin)));
data_n(4) <=er(2) or er(3) or er(1);
fn(1) <=not jin and
((fin and (not(hin and not(iin or ein or din or cin))))
or (gin and (hin and not(iin or ein or din or cin))));
fn(2) <=jin and
((not fin and (hin or not(iin or ein or din or cin)))
or (not gin and not (hin or not(iin or ein or din or cin))));
data_n(5) <=fr(1) or fr(2);
gn(1) <=not jin and (((not(not(fin) or (hin and (iin or ein or din or cin)))) or
fin or (hin and (iin or ein or din or cin))) and
((not(not(fin) or (hin and (iin or ein or din or cin)))) or gin));
gn(2) <=jin and (not((fin or not(iin or ein or hin or din or cin)) and
((gin or hin or iin or ein or din or cin) and (gin or fin))));
data_n(6) <=gr(1) or gr(2);
hn(1) <= hin or (not((jin and not(iin or ein or din or cin)) or (fin and not(jin or gin))));
hn(2) <= ((hin and not(jin) and (iin or ein or din or cin)) or ((hin xor jin) and not(gin xor fin)));
hn(3) <=not(not(fin) and gin and hin and jin);
data_n(7) <= not(hr(1) and not(hr(2)) and hr(3));
process (clk,rstn)
begin
if rstn='0' then
frame_r <='0';
err_r <="0000"; kr <="0000";
ar <="000"; br <="000"; cr <="000";
dr <="000"; er <="000"; fr <="00";
gr <="00"; hr <="000";
elsif rising_edge (clk) then
frame_r <=frame_in_r;
err_r <=err_n; kr <=kn;
ar <=an; br <=bn; cr <=cn;
dr <=dn; er <=en; fr <=fn;
gr <=gn; hr <=hn;
end if;
end process;
process (clk,rstn)
begin
if rstn='0' then
frame_out <='0';
error_out <='0';
data_out <=(others=>'0');
kchar_out <=(others=>'0');
elsif rising_edge (clk) then
frame_out <=frame_r;
data_out <=data_n;
if frame_r='1' then error_out <=error;
else error_out <='0';
end if;
if frame_r='1' and kchar='1' then
if data_n(1 downto 0)="00" then kchar_out <='1' & data_n(7 downto 5);
elsif data_n(3)='0' then kchar_out <="0100";
elsif data_n(2)='0' then kchar_out <="0101";
elsif data_n(1)='0' then kchar_out <="0110";
else kchar_out <="0111";
end if;
else kchar_out <="0000";
end if;
end if;
end process;
end structural;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -