OpenCores
URL https://opencores.org/ocsvn/udp_ip_stack/udp_ip_stack/trunk

Subversion Repositories udp_ip_stack

[/] [udp_ip_stack/] [trunk/] [rtl/] [vhdl/] [IPv4_RX.vhd] - Diff between revs 6 and 18

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 6 Rev 18
Line 22... Line 22...
-- Revision 0.03 - Added handling of broadcast address
-- Revision 0.03 - Added handling of broadcast address
-- Additional Comments: 
-- Additional Comments: 
--
--
----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
library IEEE;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.ALL;
use IEEE.NUMERIC_STD.all;
use work.axi.all;
use work.axi.all;
use work.ipv4_types.all;
use work.ipv4_types.all;
use work.arp_types.all;
use work.arp_types.all;
 
 
entity IPv4_RX is
entity IPv4_RX is
    Port (
  port (
                        -- IP Layer signals
                        -- IP Layer signals
                        ip_rx                                           : out ipv4_rx_type;
                        ip_rx                                           : out ipv4_rx_type;
                        ip_rx_start                             : out std_logic;                                                                        -- indicates receipt of ip frame.
                        ip_rx_start                             : out std_logic;                                                                        -- indicates receipt of ip frame.
                        -- system signals
                        -- system signals
                        clk                                             : in  STD_LOGIC;                                                                        -- same clock used to clock mac data and ip data
    clk               : in  std_logic;  -- same clock used to clock mac data and ip data
                        reset                                   : in  STD_LOGIC;
    reset             : in  std_logic;
                        our_ip_address          : in STD_LOGIC_VECTOR (31 downto 0);
    our_ip_address    : in  std_logic_vector (31 downto 0);
                        rx_pkt_count                    : out STD_LOGIC_VECTOR(7 downto 0);                      -- number of IP pkts received for us
    rx_pkt_count      : out std_logic_vector(7 downto 0);   -- number of IP pkts received for us
                        -- MAC layer RX signals
                        -- MAC layer RX signals
                        mac_data_in                     : in  STD_LOGIC_VECTOR (7 downto 0);             -- ethernet frame (from dst mac addr through to last byte of frame)
    mac_data_in       : in  std_logic_vector (7 downto 0);  -- ethernet frame (from dst mac addr through to last byte of frame)
                        mac_data_in_valid       : in  STD_LOGIC;                                                                        -- indicates data_in valid on clock
    mac_data_in_valid : in  std_logic;  -- indicates data_in valid on clock
                        mac_data_in_last                : in  STD_LOGIC                                                                 -- indicates last data in frame
    mac_data_in_last  : in  std_logic   -- indicates last data in frame
                        );
                        );
end IPv4_RX;
end IPv4_RX;
 
 
architecture Behavioral of IPv4_RX is
architecture Behavioral of IPv4_RX is
 
 
Line 157... Line 157...
                ip_rx.hdr.data_length <= data_len;
                ip_rx.hdr.data_length <= data_len;
                ip_rx.hdr.src_ip_addr <= src_ip;
                ip_rx.hdr.src_ip_addr <= src_ip;
                ip_rx.hdr.num_frame_errors <= std_logic_vector(frame_err_cnt);
                ip_rx.hdr.num_frame_errors <= std_logic_vector(frame_err_cnt);
                ip_rx.hdr.last_error_code <= error_code_reg;
                ip_rx.hdr.last_error_code <= error_code_reg;
                ip_rx.hdr.is_broadcast <= is_broadcast_reg;
                ip_rx.hdr.is_broadcast <= is_broadcast_reg;
                rx_pkt_count <= STD_LOGIC_VECTOR(rx_pkt_counter);
    rx_pkt_count               <= std_logic_vector(rx_pkt_counter);
 
 
                -- transfer data upstream if in user data phase
                -- transfer data upstream if in user data phase
                if rx_state = USER_DATA then
                if rx_state = USER_DATA then
                        ip_rx.data.data_in <= mac_data_in;
                        ip_rx.data.data_in <= mac_data_in;
                        ip_rx.data.data_in_valid <= mac_data_in_valid;
                        ip_rx.data.data_in_valid <= mac_data_in_valid;
Line 306... Line 306...
                                                                when x"000d" => set_ip2 <= '1';
                                                                when x"000d" => set_ip2 <= '1';
                                                                when x"000e" => set_ip1 <= '1';
                                                                when x"000e" => set_ip1 <= '1';
                                                                when x"000f" => set_ip0 <= '1';
                                                                when x"000f" => set_ip0 <= '1';
 
 
                                                                when x"0010" => set_dst_ip3 <= '1';
                                                                when x"0010" => set_dst_ip3 <= '1';
 
                  if ((mac_data_in /= our_ip_address(31 downto 24)) and
 
                      (mac_data_in /= IP_BC_ADDR(31 downto 24)))then  -- ignore pkts that are not addressed to us
 
                    next_rx_state <= WAIT_END;
 
                    set_rx_state  <= '1';
 
                  end if;
                                                                when x"0011" => set_dst_ip2 <= '1';
                                                                when x"0011" => set_dst_ip2 <= '1';
 
                  if ((mac_data_in /= our_ip_address(23 downto 16)) and
 
                      (mac_data_in /= IP_BC_ADDR(23 downto 16)))then  -- ignore pkts that are not addressed to us
 
                    next_rx_state <= WAIT_END;
 
                    set_rx_state  <= '1';
 
                  end if;
                                                                when x"0012" => set_dst_ip1 <= '1';
                                                                when x"0012" => set_dst_ip1 <= '1';
 
                  if ((mac_data_in /= our_ip_address(15 downto 8)) and
 
                      (mac_data_in /= IP_BC_ADDR(15 downto 8)))then  -- ignore pkts that are not addressed to us
 
                    next_rx_state <= WAIT_END;
 
                    set_rx_state  <= '1';
 
                  end if;
 
 
                                                                when x"0013" =>
                                                                when x"0013" =>
 
                  if ((mac_data_in /= our_ip_address(7 downto 0)) and
 
                      (mac_data_in /= IP_BC_ADDR(7 downto 0)))then  -- ignore pkts that are not addressed to us
 
                    next_rx_state <= WAIT_END;
 
                    set_rx_state  <= '1';
 
                  else
 
                    next_rx_state   <= USER_DATA;
 
                    set_pkt_cnt     <= INCR;                         -- count another pkt
 
                    set_rx_state    <= '1';
 
                    set_ip_rx_start <= SET;
 
                  end if;
 
 
                                                                        -- now have the dst IP addr
                                                                        -- now have the dst IP addr
                                                                        dst_ip_rx <= dst_ip & mac_data_in;
                                                                        dst_ip_rx <= dst_ip & mac_data_in;
                                                                        if dst_ip_rx = IP_BC_ADDR then
                                                                        if dst_ip_rx = IP_BC_ADDR then
                                                                                set_is_broadcast <= SET;
                                                                                set_is_broadcast <= SET;
                                                                        else
                                                                        else
                                                                                set_is_broadcast <= CLR;
                                                                                set_is_broadcast <= CLR;
                                                                        end if;
                                                                        end if;
                                                                        set_hdr_valid <= SET;   -- header values are now valid, although the pkt may not be for us                                                                      
                                                                        set_hdr_valid <= SET;   -- header values are now valid, although the pkt may not be for us                                                                      
 
 
                                                                        if dst_ip_rx = our_ip_address  or  dst_ip_rx = IP_BC_ADDR then
                  --if dst_ip_rx = our_ip_address or dst_ip_rx = IP_BC_ADDR then
                                                                                next_rx_state <= USER_DATA;
                  --  next_rx_state   <= USER_DATA;
                                                                                set_pkt_cnt <= INCR;                                                                                            -- count another pkt received
                  --  set_pkt_cnt     <= INCR;  -- count another pkt received
                                                                                set_rx_state <= '1';
                  --  set_rx_state    <= '1';
                                                                                set_ip_rx_start <= SET;
                  --  set_ip_rx_start <= SET;
                                                                        else
                  --else
                                                                                next_rx_state <= WAIT_END;
                  --  next_rx_state <= WAIT_END;
                                                                                set_rx_state <= '1';
                  --  set_rx_state  <= '1';
                                                                        end if;
                  --end if;
 
 
                                                                when others => -- ignore other bytes in ip header                                                                               
                                                                when others => -- ignore other bytes in ip header                                                                               
                                                        end case;
                                                        end case;
                                                end if;
                                                end if;
                                end case;
                                end case;
Line 398... Line 424...
 
 
        -----------------------------------------------------------------------------
        -----------------------------------------------------------------------------
        -- sequential process to action control signals and change states and outputs
        -- sequential process to action control signals and change states and outputs
        -----------------------------------------------------------------------------
        -----------------------------------------------------------------------------
 
 
        rx_sequential : process (clk,reset)
  rx_sequential : process (clk)--, reset)
        begin
        begin
                if rising_edge(clk) then
                if rising_edge(clk) then
                        if reset = '1' then
                        if reset = '1' then
                                -- reset state variables
                                -- reset state variables
                                rx_state <= IDLE;
                                rx_state <= IDLE;

powered by: WebSVN 2.1.0

© copyright 1999-2022 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.