www.pudn.com > project_2.zip > cauculator.vhd, change:2016-01-05,size:4590b


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity cauculator is
    Port (clk, en: in std_logic; cin0: in integer; cin1: in std_logic_vector(511 downto 0); cin2: in std_logic_vector(255 downto 0); c_en: out std_logic; cout: out std_logic_vector(511 downto 0));
end cauculator;

architecture Behavioral of cauculator is

component fft_unit is
    Port (clk, en: in std_logic; a, b, c, d, x, y: in std_logic_vector(31 downto 0); cout1, cout2, cout3, cout4: out std_logic_vector(31 downto 0); c_en: out std_logic);
end component;

signal state: integer range 0 to 8;
signal a, b, c, d, x, y, cout1, cout2, cout3, cout4: std_logic_vector(31 downto 0);
signal f_en, final, start: std_logic;

begin
    u1: fft_unit port map(clk=>clk, en=>f_en, a=>a(31 downto 0), b=>b, c=>c, d=>d, x=>x, y=>y, cout1=>cout1, cout2=>cout2, cout3=>cout3, cout4=>cout4, c_en=>final);
    
    p1: process(clk, en, final)
    variable tmp_en, tmp_final, tmp_start: std_logic;
    begin
--        if(en'event and en='1')then
--            state<=1;
--        elsif(final' event and final='1' and state/=0)then
--            state<=state+1;
--        elsif(start='1' and state/=0)then
--            state<=state+1;   
--        end if;
        if(clk'event and clk='1')then
            if(en='1' and tmp_en/='1')then
                state<=1;
            elsif(final='1' and tmp_final/='1' and state/=0)then
                state<=state+1;
            elsif(start='1' and tmp_start/='1' and state/=0)then
                state<=state+1;
            end if;
            tmp_en:=en;
            tmp_final:=final;
            tmp_start:=start;
        end if;
    end process p1;
    
    p2: process(state)
    variable v, tmp0: integer range 0 to 7;
    variable step: integer;
    begin
        case state is
            when 1| 3| 5| 7=>
                if(state=1)then
                    step:=2**cin0;
                    tmp0:=2**(cin0-1);
                    v:=0;
                else
                    tmp0:=tmp0-1;
                    if(tmp0/=0)then
                        v:=v+2;
                    else
                        v:=v+step+2;
                        tmp0:=2**(cin0-1);
                    end if;
                end if;
                
                a<=cin1(511-v*32 downto 480-v*32);
                b<=cin1(511-(v+1)*32 downto 480-(v+1)*32);
                c<=cin1(511-(v+step)*32 downto 480-(v+step)*32);
                d<=cin1(511-(v+step+1)*32 downto 480-(v+step+1)*32);
                case cin0 is
                    when 1=>                            --W8(0)
                        x<=cin2(255 downto 224);
                        y<=cin2(223 downto 192);
                    when 2=>
                        if(state=1 or state=5)then      --W8(0)
                            x<=cin2(255 downto 224);
                            y<=cin2(223 downto 192);
                        elsif(state=3 or state=7)then   --W8(2)
                            x<=cin2(127 downto 96);
                            y<=cin2(95 downto 64);
                        end if;
                    when 3=>
                        if(state=1)then                 --W8(0)
                            x<=cin2(255 downto 224);
                            y<=cin2(223 downto 192);
                        elsif(state=3)then              --W8(1)
                            x<=cin2(191 downto 160);
                            y<=cin2(159 downto 128);
                        elsif(state=5)then              --W8(2)
                            x<=cin2(127 downto 96);
                            y<=cin2(95 downto 64);
                        elsif(state=7)then              --W8(3)
                            x<=cin2(63 downto 32);
                            y<=cin2(31 downto 0);
                        end if;
                    when others=>
                end case;
                f_en<='1';
                start<='0';
            when 2| 4| 6| 8=>
                cout(511-v*32 downto 480-v*32)<=cout1;
                cout(511-(v+1)*32 downto 480-(v+1)*32)<=cout2;
                cout(511-(v+step)*32 downto 480-(v+step)*32)<=cout3;
                cout(511-(v+step+1)*32 downto 480-(v+step+1)*32)<=cout4;
                start<='1';
                f_en<='0';
                if(state=8)then
                    c_en<='1';
                else
                    c_en<='0';
                end if;
            when others=>
                start<='0';
                c_en<='0';
        end case;
    end process p2;
                
end Behavioral;