⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arpsnd.vhd

📁 设计ip协议的vhdl实现
💻 VHD
📖 第 1 页 / 共 2 页
字号:
						nextWrData <= DEVICE_IP (7 downto 0);

					-- Target Hardware Address byte 0
					when "10010" =>
						nextWrData <= latchedMAC (47 downto 40);

					-- Target Hardware Address byte 1
					when "10011" =>
						nextWrData <= latchedMAC (39 downto 32);

					-- Target Hardware Address byte 2
					when "10100" =>
						nextWrData <= latchedMAC (31 downto 24);

					-- Target Hardware Address byte 3
					when "10101" =>
						nextWrData <= latchedMAC (23 downto 16);

					-- Target Hardware Address byte 4
					when "10110" =>
						nextWrData <= latchedMAC (15 downto 8);

					-- Target Hardware Address byte 5
					when "10111" =>
						nextWrData <= latchedMAC (7 downto 0);

					-- Target IP Address byte 0
					when "11000" =>
						nextWrData <= latchedIP (31 downto 24);

					-- Target IP Address byte 1
					when "11001" =>
						nextWrData <= latchedIP (23 downto 16);

					-- Target IP Address byte 2
					when "11010" =>
						nextWrData <= latchedIP (15 downto 8);

					-- Target IP Address byte 3
					when "11011" =>
						nextWrData <= latchedIP (7 downto 0);

				when others =>
				end case;
			
			-- store the ARP reply for the Ethernet sender
			when stStoreARPReply =>
				if complete = '0' then
					nextState <= stStoreARPReply;
					wrRAM <= '1';
					wrAddr <= "00" & x"000" & cnt;
				-- if we've finished storing the ARP reply, then inform the ethernet layer to send it
				-- and wait for the ethernet layer to then tell us that it has sent it
				elsif cnt = "11011" then
					-- if the frame has been sent, return to idle
					if frameSent = '1' then
						nextState <= stIdle;
					else
						nextState <= stStoreARPReply;
						genFrame <= '1';
						-- give the ethernet sender the MAC address to send the reply to and tell it 
						-- to send an ARP message
						targetMAC <= latchedMAC;
						frameType <= '0';
					end if;
				-- if not finished, continue to create the reply
				else
					nextState <= stGenARPReply;
					incCnt <= '1';
				end if;		
				
			-----------------------------------------------------------------------------------
			-- handle frames passed on to us from the Internet layer
			-- check to the see if the desired IP is in the ARP table
			when stCheckARPEntry =>
				nextState <= stCheckARPEntry2;
				lookupIP <= latchedIP;

			-- check to see if the ARP entry is valid
			when stCheckARPEntry2 =>
				lookupIP <= latchedIP;
				-- if it's not a valid ARP entry, then generate an ARP request to find the
				-- desired MAC address
				if ARPEntryValid = '0' then
					nextState <= stGenArpRequest;
				-- otherwise latch the target MAC and pass on the frame to the ethernet layer
				else
					nextState <= stGenEthFrame;
					latchTargetMAC <= '1';
				end if;

			-- create each byte of the ARP request according to cnt
			when stGenARPRequest =>
				nextState <= stStoreARPRequest;
				case cnt is
					-- Hardware type MSB
					when "00000" =>
						nextWrData <= (others => '0');
					
					-- Hardware type LSB
					when "00001" =>
						nextWrData <= x"01";
						
					-- Protocol type MSB
					when "00010" =>
						nextWrData <= x"08";
					
					-- Protocol type LSB
					when  "00011" =>
						nextWrData <= (others => '0');
						
					-- Hardware Address length in bytes
					when "00100" =>
						nextWrData <= x"06";
						
					-- IP Address length in bytes
					when "00101" =>
						nextWrData <= x"04";
					
					-- Operation MSB
					when "00110" =>
						nextWrData <= x"00";
					
					-- Operation LSB
					when "00111" =>
						nextWrData <= x"01";
					
					-- Sender Hardware Address byte 0
					when "01000" =>
						nextWrData <= DEVICE_MAC (47 downto 40);
						
					-- Sender Hardware Address byte 1
					when "01001" =>
						nextWrData <= DEVICE_MAC (39 downto 32);

					-- Sender Hardware Address byte 2
					when "01010" =>
						nextWrData <= DEVICE_MAC (31 downto 24);
						
					-- Sender Hardware Address byte 3
					when "01011" =>
						nextWrData <= DEVICE_MAC (23 downto 16);
						
					-- Sender Hardware Address byte 4
					when "01100" =>
						nextWrData <= DEVICE_MAC (15 downto 8);
						
					-- Sender Hardware Address byte 5
					when "01101" =>
						nextWrData <= DEVICE_MAC (7 downto 0);
					
					-- Sender IP Address byte 0
					when "01110" =>
						nextWrData <= DEVICE_IP (31 downto 24);

					-- Sender IP Address byte 1
					when "01111" =>
						nextWrData <= DEVICE_IP (23 downto 16);

					-- Sender IP Address byte 2
					when "10000" =>
						nextWrData <= DEVICE_IP (15 downto 8);

					-- Sender IP Address byte 3
					when "10001" =>
						nextWrData <= DEVICE_IP (7 downto 0);

					-- Target Hardware Address byte 0
					-- should be 0's for an ARP request
					when "10010" =>
						nextWrData <= x"00";

					-- Target Hardware Address byte 1
					when "10011" =>
						nextWrData <= x"00";

					-- Target Hardware Address byte 2
					when "10100" =>
						nextWrData <= x"00";

					-- Target Hardware Address byte 3
					when "10101" =>
						nextWrData <= x"00";

					-- Target Hardware Address byte 4
					when "10110" =>
						nextWrData <= x"00";

					-- Target Hardware Address byte 5
					when "10111" =>
						nextWrData <= x"00";

					-- Target IP Address byte 0
					when "11000" =>
						nextWrData <= latchedIP (31 downto 24);

					-- Target IP Address byte 1
					when "11001" =>
						nextWrData <= latchedIP (23 downto 16);

					-- Target IP Address byte 2
					when "11010" =>
						nextWrData <= latchedIP (15 downto 8);

					-- Target IP Address byte 3
					when "11011" =>
						nextWrData <= latchedIP (7 downto 0);

				when others =>
				end case;

			-- store the ARP request 
			when stStoreARPRequest =>
				if complete = '0' then
					nextState <= stStoreARPRequest;
					wrRAM <= '1';
					wrAddr <= "00" & x"000" & cnt;
				-- once the ARP request has been generated, inform the ethernet layer to send it
				-- wait for the ethernet layer to inform us that it's sent before continuing
				elsif cnt = "11011" then
					if frameSent = '1' then
						nextState <= stWaitForValidEntry;
						-- reset the ARP timeout counter to start counting
						rstARPCnt <= '1';
					else
						nextState <= stStoreARPRequest;
						genFrame <= '1';
						targetMAC <= x"FFFFFFFFFFFF";
						frameType <= '0';
					end if;
				-- if the ARP request hasn't been fully generated then continue creating and 
				-- storing it
				else
					nextState <= stGenARPRequest;
					incCnt <= '1';
				end if;	
			
			-- wait for the ARP entry to become valid
			when stWaitForValidEntry =>
				-- if the ARP entry becomes valid then we fire off the reply
				if ARPEntryValid = '1' then
					nextState <= stGenEthFrame;
					latchTargetMAC <= '1';
				-- otherwise give a certain amount of time for the ARP reply to come
				-- back in (21.5 secs on a 50MHz clock)
				else
					-- if the reply doesn't come back, then inform the above layer that the
					-- frame was sent.  Assume the higher level protocol can account for this
					-- problem, or possibly an error signal could be created once a higher level
					-- protocol has been written that can accomodate this
					if ARPCntOverflow = '1' then
						nextState <= stIdle;
						sendingFrame <= '1';
					else				
						nextState <= stWaitForValidEntry;
					end if;
				end if;
				lookupIP <= latchedIP;
					
			-- send the requested frame
			when stGenEthFrame =>
				-- wait for the ethernet layer to tell us that the frame was sent, and then
				-- inform the internet layer that the frame was sent
				if frameSent = '1' then
					nextState <= stIdle;
					sendingFrame <= '1';
				-- keep telling the ethernet layer to send the frame until it is sent
				else 
					nextState <= stGenEthFrame;
					genFrame <= '1';
					frameType <= '1';
					targetMAC <= latchedMAC;
					frameSize <= latchedFrameSize;
				end if;
				
			when others =>
		end case;
	end process;

end ARPSnd_arch;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -