hamming.vhd

来自「This is the course for VHDL programming」· VHDL 代码 · 共 70 行

VHD
70
字号
--HAMMING ERROR CORRECTION CHIPlibrary ieee;use ieee.std_logic_1164.all;entity HAM_CHIP is	port (CPU_BUS:  inout std_logic_vector(8 downto 1);		RAM_BUS:  inout std_logic_vector(8 downto 1);		PRAM_BUS: inout std_logic_vector(3 downto 0);		MEMR_BAR,MEMW_BAR:in std_logic);end HAM_CHIP;architecture STRUCT of HAM_CHIP is	signal CORR_BUS: STD_LOGIC_VECTOR(8  DOWNTO  1);	signal SYNDROME,PARITY: STD_LOGIC_VECTOR(3  DOWNTO  0);	begin	RAM_BUS<=CPU_BUS when MEMW_BAR='0' else "ZZZZZZZZ";--	PARITY GENERATOR	PARITY(0)<= CPU_BUS(1) xor CPU_BUS(2) xor 			CPU_BUS(4) xor CPU_BUS(5) xor 			CPU_BUS(7) ; 	PARITY(1)<= CPU_BUS(1) xor CPU_BUS(3) xor 			CPU_BUS(4) xor CPU_BUS(6) xor 			CPU_BUS(7)  ;  	PARITY(2)<= CPU_BUS(2) xor CPU_BUS(3) xor 			CPU_BUS(4) xor CPU_BUS(8) ;			 	PARITY(3)<= CPU_BUS(5) xor CPU_BUS(6) xor 			CPU_BUS(7) xor CPU_BUS(8) ;			PRAM_BUS<=PARITY when MEMW_BAR='0' else "ZZZZ";--	SYNDROME GENERATOR	SYNDROME(0)<= RAM_BUS(1) xor RAM_BUS(2) xor 			RAM_BUS(4) xor RAM_BUS(5) xor 			RAM_BUS(7)  xor PRAM_BUS(0);  	SYNDROME(1)<= RAM_BUS(1) xor RAM_BUS(3) xor 			RAM_BUS(4) xor RAM_BUS(6) xor 			RAM_BUS(7)  xor PRAM_BUS(1);  	SYNDROME(2)<= RAM_BUS(2) xor RAM_BUS(3) xor 			RAM_BUS(4) xor RAM_BUS(8)			 xor PRAM_BUS(2);  	SYNDROME(3)<= RAM_BUS(5) xor RAM_BUS(6) xor 			RAM_BUS(7) xor RAM_BUS(8) 			 xor PRAM_BUS(3);  --	CORRECTION UNIT	CORR_PROC:process(RAM_BUS,SYNDROME)		variable temp: STD_LOGIC_VECTOR(8  DOWNTO 1 );	begin		temp:=RAM_BUS;		case SYNDROME is			when "0000"=>null;			when "0001"=>null;			when "0010"=>null;			when "0100"=>null;			when "1000"=>null;			when "0011"=>temp(1):=not temp(1);			when "0101"=>temp(2):=not temp(2);			when "0110"=>temp(3):=not temp(3);			when "0111"=>temp(4):=not temp(4);			when "1001"=>temp(5):=not temp(5);			when "1010"=>temp(6):=not temp(6);			when "1011"=>temp(7):=not temp(7);			when "1100"=>temp(8):=not temp(8);			when others=>temp:="XXXXXXXX";				assert false report "Unknown syndrome";		end case;		CORR_BUS<=temp;	end process CORR_PROC;	CPU_BUS<=CORR_BUS when MEMR_BAR='0' else "ZZZZZZZZ";end STRUCT;

⌨️ 快捷键说明

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