Books | Codec_Books | Fig_11
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.my_package.all;
entity Funcmi is
port (
bit0 : in std_logic;
clk : in std_logic;
codcomplete : out std_logic;
decodcomplete : out std_logic;
dma : in std_logic;
ext_adr : in std_logic_vector(15 downto 0);
ext_in : out std_logic_vector(7 downto 0);
ext_out : in std_logic_vector(7 downto 0);
ext_rdwr : in std_logic;
idle : out std_logic;
m : in std_logic;
nelem : in std_logic_vector(15 downto 0);
rst : in std_logic;
rwrite2m2 : out std_logic_vector(15 downto 0);
rwrite2m3 : out std_logic_vector(15 downto 0);
s : in std_logic
);
end Funcmi;
architecture ARC_Funcmi of Funcmi is
type FSMStates is (
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15,
a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29, a30,
a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, a41, a42, a43, a44, a45,
a46, a47, a48, a49, a50, a51, a52, a53, a54, a55, a56, a57, a58, a59, a60,
a61, a62, a63, a64, a65, a66, a67, a68, a69, a70, a71, a72, a73, a74, a75,
a76, a77
);
type m1_type is array (integer range 0 to 65535) of std_logic_vector(7 downto 0);
type m2_type is array (integer range 0 to 65535) of std_logic_vector(7 downto 0);
type m3_type is array (integer range 0 to 65535) of std_logic_vector(7 downto 0);
signal bitcnt : std_logic_vector(3 downto 0);
signal br : std_logic_vector(7 downto 0);
signal cnt : std_logic_vector(7 downto 0);
signal cnt_elem : std_logic_vector(15 downto 0);
signal cnt_m1_m3 : std_logic_vector(15 downto 0);
signal cnt_m2 : std_logic_vector(15 downto 0);
signal currentState : FSMStates;
signal m1 : m1_type;
signal m2 : m2_type;
signal m3 : m3_type;
signal mac1 : std_logic_vector(15 downto 0);
signal mac2 : std_logic_vector(15 downto 0);
signal rbyte : std_logic_vector(7 downto 0);
signal rd : std_logic_vector(7 downto 0);
signal relem : std_logic_vector(15 downto 0);
signal rfilelength : std_logic_vector(15 downto 0);
signal rlengthd : std_logic_vector(7 downto 0);
signal rmask : std_logic_vector(7 downto 0);
signal rmax : std_logic_vector(7 downto 0);
signal rmin : std_logic_vector(7 downto 0);
signal rt1 : std_logic_vector(7 downto 0);
signal rt2 : std_logic_vector(7 downto 0);
signal rtemp1 : std_logic_vector(15 downto 0);
signal shcnt : std_logic_vector(7 downto 0);
begin
process (clk , rst)
variable m1_address : std_logic_vector(15 downto 0);
variable m2_address : std_logic_vector(15 downto 0);
variable m3_address : std_logic_vector(15 downto 0);
procedure proc_Funcmi is
begin
case currentState is
when a1 =>
if (s and dma and ext_rdwr) = '1' then
m1_address := ext_adr;
m1(to_integer(unsigned(m1_address))) <= ext_out;
currentState <= a7;
elsif (s and dma and not ext_rdwr and m) = '1' then
m3_address := ext_adr;
currentState <= a6;
elsif (s and dma and not ext_rdwr and not m) = '1' then
m2_address := ext_adr;
currentState <= a8;
elsif (s and not dma and bit0) = '1' then
decodcomplete <= '0';
currentState <= a4;
elsif (s and not dma and not bit0) = '1' then
relem <= nelem;
codcomplete <= '0';
currentState <= a3;
else
currentState <= a1;
idle <= '1';
end if;
when a2 =>
m2_address := mac2;
m2(to_integer(unsigned(m2_address))) <= br;
cnt_m2 <= std_logic_vector(unsigned(cnt_m2) + 1);
currentState <= a13;
when a3 =>
mac2 <= (others => '0');
br <= x"ff";
cnt <= (others => '0');
cnt_m2 <= (others => '0');
currentState <= a2;
when a4 =>
mac2 <= (others => '0');
decodcomplete <= '0';
currentState <= a5;
when a5 =>
m2_address := mac2;
currentState <= a21;
when a6 =>
m3_address := ext_adr;
ext_in <= m3(to_integer(unsigned(m3_address)));
currentState <= a1;
idle <= '1';
when a7 =>
cnt_m1_m3 <= std_logic_vector(unsigned(cnt_m1_m3) + 1);
currentState <= a1;
idle <= '1';
when a8 =>
m2_address := ext_adr;
ext_in <= m2(to_integer(unsigned(m2_address)));
currentState <= a1;
idle <= '1';
when a9 =>
cnt_elem <= (others => '0');
rtemp1 <= mac1;
currentState <= a10;
when a10 =>
m1_address := mac1;
currentState <= a36;
when a11 =>
br <= m2(to_integer(unsigned(m2_address)));
mac2 <= std_logic_vector(unsigned(mac2) + 1);
currentState <= a57;
when a12 =>
m2_address := mac2;
currentState <= a11;
when a13 =>
mac2 <= std_logic_vector(unsigned(mac2) + 1);
currentState <= a29;
when a14 =>
if (cnt_m1_m3 = x"0000") then
codcomplete <= '1';
rwrite2m2 <= cnt_m2;
currentState <= a1;
idle <= '1';
else
cnt_elem <= (others => '0');
rtemp1 <= mac1;
currentState <= a10;
end if;
when a15 =>
if (shcnt = std_logic_vector(unsigned(rlengthd) - x"01")) then
m1_address := mac1;
currentState <= a17;
else
rmask <= std_logic_vector(unsigned(rmask) sll 1);
shcnt <= std_logic_vector(unsigned(shcnt) + 1);
currentState <= a15;
end if;
when a16 =>
m1_address := mac1;
currentState <= a17;
when a17 =>
br <= m1(to_integer(unsigned(m1_address)));
mac1 <= std_logic_vector(unsigned(mac1) + 1);
currentState <= a64;
when a18 =>
br <= m2(to_integer(unsigned(m2_address)));
mac2 <= std_logic_vector(unsigned(mac2) + 1);
currentState <= a40;
when a19 =>
br <= m2(to_integer(unsigned(m2_address)));
mac2 <= std_logic_vector(unsigned(mac2) + 1);
currentState <= a41;
when a20 =>
br <= m2(to_integer(unsigned(m2_address)));
mac2 <= std_logic_vector(unsigned(mac2) + 1);
currentState <= a42;
when a21 =>
br <= m2(to_integer(unsigned(m2_address)));
mac2 <= std_logic_vector(unsigned(mac2) + 1);
currentState <= a43;
when a22 =>
bitcnt <= (others => '0');
currentState <= a25;
when a23 =>
if (rlengthd = x"00") then
br <= rmin;
currentState <= a26;
else
m2_address := mac2;
currentState <= a28;
end if;
when a24 =>
if (cnt_elem = relem and cnt_m1_m3 = rfilelength) then
decodcomplete <= '1';
rwrite2m3 <= cnt_m1_m3;
currentState <= a1;
idle <= '1';
elsif (cnt_elem = relem and not (cnt_m1_m3 = rfilelength)) then
m2_address := mac2;
currentState <= a11;
else
br <= rmin;
currentState <= a26;
end if;
when a25 =>
rt1 <= std_logic_vector(unsigned(rmask) and unsigned(rt2));
currentState <= a51;
when a26 =>
m3_address := mac1;
m3(to_integer(unsigned(m3_address))) <= br;
cnt_m1_m3 <= std_logic_vector(unsigned(cnt_m1_m3) + 1);
currentState <= a27;
when a27 =>
mac1 <= std_logic_vector(unsigned(mac1) + 1);
currentState <= a56;
when a28 =>
br <= m2(to_integer(unsigned(m2_address)));
mac2 <= std_logic_vector(unsigned(mac2) + 1);
currentState <= a44;
when a29 =>
if (cnt = x"03") then
rfilelength <= cnt_m1_m3;
currentState <= a9;
else
cnt <= std_logic_vector(unsigned(cnt) + 1);
currentState <= a2;
end if;
when a30 =>
m2_address := mac2;
m2(to_integer(unsigned(m2_address))) <= br;
cnt_m2 <= std_logic_vector(unsigned(cnt_m2) + 1);
currentState <= a60;
when a31 =>
if (rd = x"00") then
br <= cnt;
rlengthd <= cnt;
currentState <= a63;
else
rd <= std_logic_vector(unsigned(rd) srl 1);
currentState <= a61;
end if;
when a32 =>
cnt_elem <= (others => '0');
cnt <= (others => '0');
currentState <= a31;
when a33 =>
m1_address := mac1;
currentState <= a35;
when a34 =>
if (cnt_elem = std_logic_vector(unsigned(relem) - x"0001")) then
br <= rmin;
currentState <= a30;
else
cnt_elem <= std_logic_vector(unsigned(cnt_elem) + 1);
currentState <= a33;
end if;
when a35 =>
br <= m1(to_integer(unsigned(m1_address)));
mac1 <= std_logic_vector(unsigned(mac1) + 1);
currentState <= a65;
when a36 =>
br <= m1(to_integer(unsigned(m1_address)));
mac1 <= std_logic_vector(unsigned(mac1) + 1);
currentState <= a66;
when a37 =>
rt1 <= std_logic_vector(unsigned(rmask) and unsigned(rt2));
currentState <= a74;
when a38 =>
shcnt <= (others => '0');
currentState <= a37;
when a39 =>
rt2 <= std_logic_vector(unsigned(rt1) - unsigned(rmin));
cnt_m1_m3 <= std_logic_vector(unsigned(cnt_m1_m3) - 1);
currentState <= a38;
when a40 =>
if (br = x"ff") then
m2_address := mac2;
currentState <= a19;
else
m2_address := mac2;
currentState <= a21;
end if;
when a41 =>
if (br = x"ff") then
m2_address := mac2;
currentState <= a20;
else
m2_address := mac2;
currentState <= a21;
end if;
when a42 =>
if (br = x"ff") then
mac1 <= (others => '0');
shcnt <= (others => '0');
currentState <= a12;
else
m2_address := mac2;
currentState <= a21;
end if;
when a43 =>
if (br = x"ff") then
m2_address := mac2;
currentState <= a18;
else
m2_address := mac2;
currentState <= a21;
end if;
when a44 =>
rt2 <= br;
currentState <= a22;
when a45 =>
m3_address := mac1;
m3(to_integer(unsigned(m3_address))) <= br;
cnt_m1_m3 <= std_logic_vector(unsigned(cnt_m1_m3) + 1);
currentState <= a46;
when a46 =>
mac1 <= std_logic_vector(unsigned(mac1) + 1);
currentState <= a59;
when a47 =>
if (rt1 = x"00") then
shcnt <= std_logic_vector(unsigned(shcnt) + 1);
bitcnt <= std_logic_vector(unsigned(bitcnt) + 1);
currentState <= a48;
else
rbyte(0) <= '1';
currentState <= a50;
end if;
when a48 =>
if (shcnt = rlengthd) then
br <= std_logic_vector(unsigned(rbyte) + unsigned(rmin));
shcnt <= (others => '0');
currentState <= a45;
elsif (not (shcnt = rlengthd) and bitcnt = x"8" and cnt_elem = relem and cnt_m1_m3 = rfilelength) then
decodcomplete <= '1';
rwrite2m3 <= cnt_m1_m3;
currentState <= a1;
idle <= '1';
elsif (not (shcnt = rlengthd) and bitcnt = x"8" and cnt_elem = relem and not (cnt_m1_m3 = rfilelength)) then
m2_address := mac2;
currentState <= a11;
elsif (not (shcnt = rlengthd) and bitcnt = x"8" and not (cnt_elem = relem)) then
m2_address := mac2;
currentState <= a28;
else
rt1 <= std_logic_vector(unsigned(rmask) and unsigned(rt2));
currentState <= a51;
end if;
when a49 =>
rbyte <= std_logic_vector(unsigned(rbyte) sll 1);
currentState <= a47;
when a50 =>
shcnt <= std_logic_vector(unsigned(shcnt) + 1);
bitcnt <= std_logic_vector(unsigned(bitcnt) + 1);
currentState <= a48;
when a51 =>
rt2 <= std_logic_vector(unsigned(rt2) sll 1);
currentState <= a49;
when a52 =>
if (bitcnt = x"8" and cnt_elem = relem and cnt_m1_m3 = rfilelength) then
decodcomplete <= '1';
rwrite2m3 <= cnt_m1_m3;
currentState <= a1;
idle <= '1';
elsif (bitcnt = x"8" and cnt_elem = relem and not (cnt_m1_m3 = rfilelength)) then
m2_address := mac2;
currentState <= a11;
elsif (bitcnt = x"8" and not (cnt_elem = relem)) then
m2_address := mac2;
currentState <= a28;
else
rt1 <= std_logic_vector(unsigned(rmask) and unsigned(rt2));
currentState <= a51;
end if;
when a53 =>
m2_address := mac2;
currentState <= a54;
when a54 =>
br <= m2(to_integer(unsigned(m2_address)));
mac2 <= std_logic_vector(unsigned(mac2) + 1);
currentState <= a58;
when a55 =>
cnt_elem <= (others => '0');
currentState <= a23;
when a56 =>
cnt_elem <= std_logic_vector(unsigned(cnt_elem) + 1);
currentState <= a24;
when a57 =>
rmin <= br;
currentState <= a53;
when a58 =>
rlengthd <= br;
rmask <= x"80";
shcnt <= (others => '0');
currentState <= a55;
when a59 =>
rbyte <= x"00";
cnt_elem <= std_logic_vector(unsigned(cnt_elem) + 1);
currentState <= a52;
when a60 =>
mac2 <= std_logic_vector(unsigned(mac2) + 1);
currentState <= a75;
when a61 =>
cnt <= std_logic_vector(unsigned(cnt) + 1);
currentState <= a31;
when a62 =>
mac2 <= std_logic_vector(unsigned(mac2) + 1);
currentState <= a76;
when a63 =>
m2_address := mac2;
m2(to_integer(unsigned(m2_address))) <= br;
cnt_m2 <= std_logic_vector(unsigned(cnt_m2) + 1);
currentState <= a62;
when a64 =>
rt1 <= br;
currentState <= a39;
when a65 =>
if (br >= rmax) then
rmax <= br;
currentState <= a34;
elsif (not (br >= rmax) and br <= rmin) then
rmin <= br;
currentState <= a34;
elsif (not (br >= rmax) and not (br <= rmin) and cnt_elem = std_logic_vector(unsigned(relem) - x"0001")) then
br <= rmin;
currentState <= a30;
else
cnt_elem <= std_logic_vector(unsigned(cnt_elem) + 1);
currentState <= a33;
end if;
when a66 =>
rmax <= br;
rmin <= br;
cnt_elem <= std_logic_vector(unsigned(cnt_elem) + 1);
currentState <= a33;
when a67 =>
if (rt1 = x"00") then
shcnt <= std_logic_vector(unsigned(shcnt) + 1);
bitcnt <= std_logic_vector(unsigned(bitcnt) + 1);
currentState <= a71;
else
rbyte(0) <= '1';
currentState <= a73;
end if;
when a68 =>
if (shcnt = rlengthd and cnt_elem = std_logic_vector(unsigned(relem) - x"0001") and cnt_m1_m3 = x"0000") then
codcomplete <= '1';
rwrite2m2 <= cnt_m2;
currentState <= a1;
idle <= '1';
elsif (shcnt = rlengthd and cnt_elem = std_logic_vector(unsigned(relem) - x"0001") and not (cnt_m1_m3 = x"0000")) then
cnt_elem <= (others => '0');
rtemp1 <= mac1;
currentState <= a10;
elsif (shcnt = rlengthd and not (cnt_elem = std_logic_vector(unsigned(relem) - x"0001"))) then
cnt_elem <= std_logic_vector(unsigned(cnt_elem) + 1);
currentState <= a16;
else
rt1 <= std_logic_vector(unsigned(rmask) and unsigned(rt2));
currentState <= a74;
end if;
when a69 =>
mac2 <= std_logic_vector(unsigned(mac2) + 1);
currentState <= a77;
when a70 =>
m2_address := mac2;
m2(to_integer(unsigned(m2_address))) <= br;
cnt_m2 <= std_logic_vector(unsigned(cnt_m2) + 1);
currentState <= a69;
when a71 =>
if (bitcnt = x"8") then
br <= rbyte;
currentState <= a70;
elsif (not (bitcnt = x"8") and shcnt = rlengthd and cnt_elem = std_logic_vector(unsigned(relem) - x"0001") and cnt_m1_m3 = x"0000") then
codcomplete <= '1';
rwrite2m2 <= cnt_m2;
currentState <= a1;
idle <= '1';
elsif (not (bitcnt = x"8") and shcnt = rlengthd and cnt_elem = std_logic_vector(unsigned(relem) - x"0001") and not (cnt_m1_m3 = x"0000")) then
cnt_elem <= (others => '0');
rtemp1 <= mac1;
currentState <= a10;
elsif (not (bitcnt = x"8") and shcnt = rlengthd and not (cnt_elem = std_logic_vector(unsigned(relem) - x"0001"))) then
cnt_elem <= std_logic_vector(unsigned(cnt_elem) + 1);
currentState <= a16;
else
rt1 <= std_logic_vector(unsigned(rmask) and unsigned(rt2));
currentState <= a74;
end if;
when a72 =>
rbyte <= std_logic_vector(unsigned(rbyte) sll 1);
currentState <= a67;
when a73 =>
shcnt <= std_logic_vector(unsigned(shcnt) + 1);
bitcnt <= std_logic_vector(unsigned(bitcnt) + 1);
currentState <= a71;
when a74 =>
rt2 <= std_logic_vector(unsigned(rt2) sll 1);
currentState <= a72;
when a75 =>
rd <= std_logic_vector(unsigned(rmax) - unsigned(rmin));
currentState <= a32;
when a76 =>
if (rlengthd = x"00") then
cnt_m1_m3 <= std_logic_vector(unsigned(cnt_m1_m3) - unsigned(relem));
currentState <= a14;
else
shcnt <= (others => '0');
mac1 <= rtemp1;
rmask <= x"01";
currentState <= a15;
end if;
when a77 =>
bitcnt <= (others => '0');
rbyte <= x"00";
currentState <= a68;
end case;
end proc_Funcmi;
begin
if (rst = '1') then
bitcnt <= (others => '0');
br <= (others => '0');
cnt <= (others => '0');
cnt_elem <= (others => '0');
cnt_m1_m3 <= (others => '0');
cnt_m2 <= (others => '0');
codcomplete <= '0';
decodcomplete <= '0';
ext_in <= (others => '0');
idle <= '0';
mac1 <= (others => '0');
mac2 <= (others => '0');
rbyte <= (others => '0');
rd <= (others => '0');
relem <= (others => '0');
rfilelength <= (others => '0');
rlengthd <= (others => '0');
rmask <= (others => '0');
rmax <= (others => '0');
rmin <= (others => '0');
rt1 <= (others => '0');
rt2 <= (others => '0');
rtemp1 <= (others => '0');
rwrite2m2 <= (others => '0');
rwrite2m3 <= (others => '0');
shcnt <= (others => '0');
currentState <= a1;
idle <= '1';
elsif (clk'event and clk = '1') then
idle <= '0';
proc_Funcmi;
end if;
end process;
end ARC_Funcmi;