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

📄 generic_ram.vhd

📁 一个电驴上下的51的CORE
💻 VHD
字号:
-- Standard RAM with input and output Data Bus
-- December 2000
--
-- Arnaud DEPAIGNE
-- Nicolas JOURDAN
-- Ecole polytechnique de l'Universite de Nantes
-- 

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.STD_LOGIC_ARITH.all;

entity RamChip is
	generic(Data_Size: integer := 8;
		Bus_Size: integer := 4);
	
	port (RST : in std_logic;
	      Address	: in unsigned(Bus_Size-1 downto 0);
              InData	: in unsigned(Data_Size-1 downto 0);
              OutData   : buffer unsigned(Data_Size-1 downto 0);
              CS, WE, OE: in std_logic);
end RamChip;

architecture Behaviour of RamChip is
	    subtype Word is unsigned(Data_size-1 downto 0);
	    type MemType is array (0 to (2**Bus_Size)-1) of Word;
	    signal Memory: MemType;
begin
	
    	process(RST,CS)
	begin
		if( RST = '1' ) then
			for i in 0 to (2**Bus_Size)-1 loop
				Memory <= (others => Word'(others=>'-'));            
			end loop;
			OutData <= Word'(others=>'Z');
		elsif(CS = '0') then
			if (conv_integer(Address) < (2**Bus_Size)) then
      				if OE = '1' then                  -- Read operation
        				OutData <= Memory(conv_integer(Address));
	      			elsif WE = '1' then               -- Write operation
	        			Memory(conv_integer(Address)) <= InData;
	      			end if;
	      		end if;
	      	else
			OutData <= Word'(others=>'Z');	      	
		end if;
  	end process;
end;

library IEEE; 
use IEEE.std_logic_1164.all; 
use IEEE.STD_LOGIC_ARITH.all;

-- *****************************************
-- *              ADDRESS DECODER
-- *****************************************

entity Add_decoder is 
	generic(Decod_Size: integer := 8);
	
       	port(a: in unsigned(Decod_Size-1 downto 0); 
       	     s: out unsigned((2**Decod_Size)-1 downto 0));
end Add_decoder;

architecture Structural of Add_decoder is 
begin 
	process(a)
		variable int_a: integer; -- range 0 to (2**Decod_Size)-1
		variable test: std_logic;
	begin 

		test := '1';

		for j in 0 to Decod_Size-1 loop
			if not(a(j) = '1') and not(a(j) = '0') then
				test := '0';
			end if;
            	end loop;

		for i in 0 to (2**Decod_Size)-1 loop
			s(i) <= '1';
        	end loop;
            	
            	if (test = '1') then
            		s(conv_integer(a)) <= '0';
		end if;            		
            	
	end process; 	
end Structural;

-- *****************************************
-- *              GENERIC_RAM STRUCTURE 
-- *****************************************

library IEEE; 
use IEEE.std_logic_1164.all; 
use IEEE.STD_LOGIC_ARITH.all;

entity GENERIC_RAM is
	generic(Data_Ram: integer := 8;
		Addr_Ram: integer := 8;
		Bus_Size_Unit : integer := 4);

	port (	RST : in std_logic;
		abus: in unsigned(Addr_Ram-1 downto 0);
	      	indbus: in unsigned(Data_Ram-1 downto 0);
	      	outdbus: buffer unsigned(Data_Ram-1 downto 0);
              	WE, OE : in std_logic);
end GENERIC_RAM; 

architecture Structural of GENERIC_RAM is

	component RamChip
		generic(Data_Size: integer := 8;
			Bus_size: integer := 4);

		port (RST : in std_logic;
		      Address	: in unsigned(Bus_Size-1 downto 0);
	              InData	: in unsigned(Data_Size-1 downto 0);
	              OutData   : buffer unsigned(Data_Size-1 downto 0);
	              CS, WE, OE: in std_logic);			      
	end component;

	component Add_decoder
		generic(Decod_Size: integer := 4);
		
		port(a: in unsigned (Decod_Size downto 0); 
       	     	     s: out unsigned((2**Decod_Size)-1 downto 0));
	end component;

	signal CSI: unsigned((2**(Addr_Ram-Bus_Size_Unit))-1 downto 0);
begin

	rams : for i in 0 to (2**(Addr_Ram-Bus_Size_Unit))-1 generate
		ram : RamChip generic map(Data_Ram, Bus_Size_Unit) port map (RST, abus(Bus_Size_Unit-1 downto 0), indbus, outdbus, CSI(i), WE, OE);
	end generate rams;

	dec : Add_decoder generic map(Addr_Ram-Bus_Size_Unit) port map(abus(Addr_Ram-1 downto Bus_Size_Unit), CSI);

end Structural;

⌨️ 快捷键说明

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