Advertisement
Lauda

Untitled

Dec 14th, 2012
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 6.74 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    10:40:06 12/14/2011
  6. -- Design Name:
  7. -- Module Name:    small_ram - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. use IEEE.numeric_std.ALL;
  23.  
  24.  
  25. ---- Uncomment the following library declaration if instantiating
  26. ---- any Xilinx primitives in this code.
  27. --library UNISIM;
  28. --use UNISIM.VComponents.all;
  29.  
  30. entity small_ram is
  31.     Port ( iCLK : in  STD_LOGIC;
  32.            inRST : in  STD_LOGIC;
  33.            iRNW : in  STD_LOGIC;
  34.            iADDRESS : in  STD_LOGIC_VECTOR (1 downto 0);
  35.            ioDATA : inout  STD_LOGIC_VECTOR (3 downto 0));
  36. end small_ram;
  37.  
  38. architecture Behavioral of small_ram is
  39.   signal sR0, sR1, sR2, sR3: std_logic_vector(3 DOWNTO 0);
  40.   signal sWE: std_logic_vector(3 DOWNTO 0);
  41.   signal sOE: std_logic_vector(3 DOWNTO 0);
  42.  
  43. begin
  44.  
  45.   -- registri
  46.  
  47.   process (iCLK) begin
  48.     if (rising_edge(iCLK)) then
  49.       if (inRST = '0') then
  50.         sR0 <= (others => '0');
  51.       elsif (sWE(0) = '1') then
  52.         sR0 <= ioDATA;
  53.       end if;
  54.     end if;
  55.   end process;
  56.  
  57.   process (iCLK) begin
  58.     if (rising_edge(iCLK)) then
  59.       if (inRST = '0') then
  60.         sR1 <= (others => '0');
  61.       elsif (sWE(1) = '1') then
  62.         sR1 <= ioDATA;
  63.       end if;
  64.     end if;
  65.   end process;
  66.  
  67.   process (iCLK) begin
  68.     if (rising_edge(iCLK)) then
  69.       if (inRST = '0') then
  70.         sR2 <= (others => '0');
  71.       elsif (sWE(2) = '1') then
  72.         sR2 <= ioDATA;
  73.       end if;
  74.     end if;
  75.   end process;
  76.  
  77.   process (iCLK) begin
  78.     if (rising_edge(iCLK)) then
  79.       if (inRST = '0') then
  80.         sR3 <= (others => '0');
  81.       elsif (sWE(3) = '1') then
  82.         sR3 <= ioDATA;
  83.       end if;
  84.     end if;
  85.   end process;
  86.  
  87.   -- dekoderi
  88.  
  89.   PROCESS(iADDRESS, iRNW) BEGIN
  90.     IF (iRNW = '0') THEN
  91.       CASE iADDRESS IS
  92.         WHEN "00" => sWE <= "0001"; -- upis u R0
  93.         WHEN "01" => sWE <= "0010"; -- upis u R1
  94.         WHEN "10" => sWE <= "0100"; -- upis u R2
  95.         WHEN "11" => sWE <= "1000"; -- upis u R3
  96.         WHEN OTHERS => sWE <= "0000"; -- nema upisa
  97.       END CASE;
  98.     ELSE
  99.       sWE <= "0000"; -- nema upisa
  100.     END IF;
  101.   END PROCESS;
  102.          
  103.   PROCESS(iADDRESS, iRNW) BEGIN
  104.     IF (iRNW = '1') THEN
  105.       CASE iADDRESS IS
  106.         WHEN "00" => sOE <= "0001"; -- upis u R0
  107.         WHEN "01" => sOE <= "0010"; -- upis u R1
  108.         WHEN "10" => sOE <= "0100"; -- upis u R2
  109.         WHEN "11" => sOE <= "1000"; -- upis u R3
  110.         WHEN OTHERS => sOE <= "0000"; -- nema upisa
  111.       END CASE;
  112.     ELSE
  113.       sOE <= "0000"; -- nema upisa
  114.     END IF;
  115.   END PROCESS;  
  116.  
  117.   -- baferi sa 3 stanja
  118.  
  119.   ioDATA <= (OTHERS => 'Z') WHEN (sOE(0) = '0') ELSE sR0;
  120.   ioDATA <= (OTHERS => 'Z') WHEN (sOE(1) = '0') ELSE sR1;
  121.   ioDATA <= (OTHERS => 'Z') WHEN (sOE(2) = '0') ELSE sR2;
  122.   ioDATA <= (OTHERS => 'Z') WHEN (sOE(3) = '0') ELSE sR3;      
  123.          
  124.  
  125. end Behavioral;
  126.  
  127. --------------------------------------------------------------------------------
  128. -- Company:
  129. -- Engineer:
  130. --
  131. -- Create Date:   10:50:39 12/14/2011
  132. -- Design Name:  
  133. -- Module Name:   F:/lprs1_aud_vezbe/k2_priprema/base/group2_1/small_ram_tb.vhd
  134. -- Project Name:  group2_1
  135. -- Target Device:  
  136. -- Tool versions:  
  137. -- Description:  
  138. --
  139. -- VHDL Test Bench Created by ISE for module: small_ram
  140. --
  141. -- Dependencies:
  142. --
  143. -- Revision:
  144. -- Revision 0.01 - File Created
  145. -- Additional Comments:
  146. --
  147. -- Notes:
  148. -- This testbench has been automatically generated using types std_logic and
  149. -- std_logic_vector for the ports of the unit under test.  Xilinx recommends
  150. -- that these types always be used for the top-level I/O of a design in order
  151. -- to guarantee that the testbench will bind correctly to the post-implementation
  152. -- simulation model.
  153. --------------------------------------------------------------------------------
  154. LIBRARY ieee;
  155. USE ieee.std_logic_1164.ALL;
  156. USE ieee.std_logic_unsigned.all;
  157. USE ieee.numeric_std.ALL;
  158.  
  159. ENTITY small_ram_tb IS
  160. END small_ram_tb;
  161.  
  162. ARCHITECTURE behavior OF small_ram_tb IS
  163.  
  164.     -- Component Declaration for the Unit Under Test (UUT)
  165.  
  166.     COMPONENT small_ram
  167.     PORT(
  168.          iCLK : IN  std_logic;
  169.          inRST : IN  std_logic;
  170.          iRNW : IN  std_logic;
  171.          iADDRESS : IN  std_logic_vector(1 downto 0);
  172.          ioDATA : INOUT  std_logic_vector(3 downto 0)
  173.         );
  174.     END COMPONENT;
  175.    
  176.    --Constants    
  177.    constant iCLK_period : time := 10ns;
  178.    
  179.    --Inputs
  180.    signal iCLK : std_logic := '0';
  181.    signal inRST : std_logic := '0';
  182.    signal iRNW : std_logic := '0';
  183.    signal iADDRESS : std_logic_vector(1 downto 0) := (others => '0');
  184.  
  185.     --BiDirs
  186.    signal ioDATA : std_logic_vector(3 downto 0);
  187.  
  188. BEGIN
  189.  
  190.     -- Instantiate the Unit Under Test (UUT)
  191.    uut: small_ram PORT MAP (
  192.           iCLK => iCLK,
  193.           inRST => inRST,
  194.           iRNW => iRNW,
  195.           iADDRESS => iADDRESS,
  196.           ioDATA => ioDATA
  197.         );
  198.  
  199.  
  200.    -- Clock process definitions
  201.    iCLK_process :process
  202.    begin
  203.           iCLK <= '0';
  204.           wait for iCLK_period/2;
  205.           iCLK <= '1';
  206.           wait for iCLK_period/2;
  207.    end process;
  208.  
  209.    -- Stimulus process
  210.    stim_proc: process
  211.    begin       
  212.        -- ciklus 1
  213.       inRST <= '0';
  214.       iRNW <= '0';
  215.       iADDRESS <= std_logic_vector(to_unsigned(0,2));
  216.       ioDATA <= (others => 'Z');
  217.       wait for iCLK_period;
  218.      
  219.        -- ciklus 2
  220.       inRST <= '1';
  221.       iRNW <= '0';
  222.       iADDRESS <= std_logic_vector(to_unsigned(0,2));
  223.       ioDATA <= x"3"; -- heksadecimalan format
  224.       wait for iCLK_period;
  225.  
  226.        -- ciklus 3
  227.       inRST <= '1';
  228.       iRNW <= '0';
  229.       iADDRESS <= std_logic_vector(to_unsigned(1,2));
  230.       ioDATA <= x"2";
  231.       wait for iCLK_period;
  232.      
  233.        -- ciklus 4
  234.       inRST <= '1';
  235.       iRNW <= '0';
  236.       iADDRESS <= std_logic_vector(to_unsigned(2,2));
  237.       ioDATA <= x"1";
  238.       wait for iCLK_period;
  239.  
  240.        -- ciklus 5
  241.       inRST <= '1';
  242.       iRNW <= '1';
  243.       iADDRESS <= std_logic_vector(to_unsigned(2,2));
  244.       ioDATA <= (others => 'Z');
  245.       wait for iCLK_period;
  246.  
  247.        -- ciklus 6
  248.       inRST <= '1';
  249.       iRNW <= '1';
  250.       iADDRESS <= std_logic_vector(to_unsigned(1,2));
  251.       ioDATA <= (others => 'Z');
  252.       wait for iCLK_period;
  253.  
  254.        -- ciklus 7
  255.       inRST <= '1';
  256.       iRNW <= '1';
  257.       iADDRESS <= std_logic_vector(to_unsigned(0,2));
  258.       ioDATA <= (others => 'Z');
  259.       wait for iCLK_period;
  260.  
  261.       wait;
  262.    end process;
  263.  
  264. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement