library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.numeric_std.ALL; --------------------------Entity-Beschreibung---------------------------------------- entity packet_read is Port ( clk : in std_logic; data_in : in std_logic; rdy : out std_logic; frame_out : out std_logic; synchron_out : out std_logic; code_err2 : out std_logic; kout : out std_logic; sync_found_out: out std_logic; sync_reset : out std_logic; data_out : out std_logic_vector (7 downto 0); sc_out : out std_logic_vector (15 downto 0); --schieber : out std_logic_vector (9 downto 0); counter_out : out std_logic_vector (9 downto 0) ); end packet_read; ----------------Signale-innerhalb-der--Architecture------------------------------ architecture Behavioral of packet_read is signal counter : INTEGER RANGE 0 to 9; signal sc : INTEGER range 0 to 15; signal data_i : std_logic_VECTOR (7 downto 0); signal schieber_i : std_logic_VECTOR (9 downto 0); signal sync_i : std_logic_VECTOR (59 downto 0); signal ce : std_logic; signal rdy_i : std_logic; signal synchron_i : std_logic; signal sync_found : std_logic; signal framebeginn_i: std_logic; --signal frame_start : std_logic; signal kout_i : std_logic; signal sync_res : std_logic; constant s1 : std_logic_vector (9 downto 0) := "0010111100"; constant s2 : std_logic_vector (9 downto 0) := "1101000011"; --------------------Componenten-bekanntmachen-------------------------------------- component decoder_b8b10b port ( clk: IN std_logic; din: IN std_logic_VECTOR(9 downto 0); dout: OUT std_logic_VECTOR(7 downto 0); kout: OUT std_logic; ce: IN std_logic; code_err: OUT std_logic ); end component; attribute box_type : string; attribute box_type of decoder_b8b10b : component is "black_box"; ----------------------Beginn-Architecture----------------------------------- BEGIN ----------------------BITS-EINES-BYTES-ZÄHLEN-UND-PARALELISIEREN--------------------- bitcount:process (clk) variable bitcounter : INTEGER RANGE 0 to 9; variable bc_schieber : std_logic_vector (9 downto 0); begin -- schieben und zählen if clk'event and clk='1' then bc_schieber := bc_schieber(8 downto 0)& data_in; if sync_res = '1' or bitcounter=9 then bitcounter := 0; else bitcounter := bitcounter + 1; end if; end if; -- Ready Signal erzeugen if bitcounter = 3 then rdy_i <= '1'; else rdy_i <='0'; end if; -- Freigabe für B8B10 Decoder if bitcounter = 2 then ce <= '1'; else ce <= '0'; end if; schieber_i<=bc_schieber; end process bitcount; rdy<=rdy_i; ---------------------BYTES-EINES-DATENPAKETES-ZÄHLEN----------------------------------- bytecount:process (clk) variable bytecounter : INTEGER range 0 to 521; begin if clk'event and clk='1' then if sync_res = '1' or bytecounter=520 then bytecounter :=0; else if rdy_i ='1' then bytecounter := bytecounter + 1; end if; end if; end if; counter <= bytecounter; counter_out<=CONV_STD_LOGIC_VECTOR(bytecounter,10); end process bytecount; ------------------------Decoder-B8B10-Einbinden-------------------------------------------------------------- u0 :decoder_b8b10b port map (clk => clk,din => schieber_i,dout => Data_i,kout => kout_i,code_err => code_err2,ce => ce); kout <= kout_i; data_out<= data_i; ---------FINDEN-EINER-SYNCHRONMARKE-(nur-fuer-neu-synchronisierung)-------------------------------------- syncsearch:process (clk) begin if clk'event and clk='1' then sync_i <= sync_i(58 downto 0)& data_in; if (sync_i (9 downto 0) = s1 or sync_i (9 downto 0) = s2) and (sync_i (19 downto 10) = s1 or sync_i (19 downto 10) = s2) and (sync_i (29 downto 20) = s1 or sync_i (29 downto 20) = s2) and (sync_i (39 downto 30) = s1 or sync_i (39 downto 30) = s2) and (sync_i (49 downto 40) = s1 or sync_i (49 downto 40) = s2) and (sync_i (59 downto 50) = s1 or sync_i (59 downto 50) = s2) then sync_found<='1'; else sync_found<='0'; end if; end if; end process syncsearch; sync_found_out<=sync_found; ---------------------WARTEN-BIS-PACKET-START------------------------------------------ framestart:process (clk) variable framecounter : INTEGER range 0 to 65535; begin if clk'event and clk='1' then if sync_found ='1' then framecounter := 0; else framecounter := framecounter +1; end if; if framecounter = 25 then framebeginn_i <= '1'; else framebeginn_i <='0'; end if; end if; frame_out<=framebeginn_i; end process framestart; ------------FINDEN-EINER-SYNCHRONMARKE-(Auf-Byteebene)-------------------------------------------------------------- synccount:process (clk) variable sc_a :integer range 0 to 65535; begin if clk'event and clk='1' then if rdy_i = '1' then if counter > 511 and counter < 518 and kout_i='1' and data_i = "00011100" then sc_a := sc_a + 1; else sc_a := 0; end if; end if; end if; sc<=sc_a; end process synccount; syncset:process (clk) variable synchron :std_logic ; begin if clk'event and clk='1' then if counter = 518 then if sc=6 then synchron:='1'; else synchron:='0'; end if; end if; end if; synchron_i <= synchron; end process syncset; sc_out<=CONV_STD_LOGIC_VECTOR(sc,16); synchron_out<=synchron_i; -----------------BEI-BEDARF-NEU-SYNCHRONISIEREN----------------------------------------- sync_res <= not synchron_i and framebeginn_i; sync_reset<=sync_res; ---------------------------------------------------------------------------------------- end Behavioral;