Advertisement
HimikoWerckmeister

Untitled

Mar 31st, 2015
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.04 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.std_logic_1164.all;
  3. use IEEE.std_logic_arith.all;
  4.  
  5. entity CAM is
  6.     port( addr: in std_logic_vector(1 downto 0);
  7.         data: in std_logic_vector(11 downto 0);
  8.         cs: in std_logic;
  9.         r: in std_logic;
  10.         mv: out std_logic_vector(3 downto 0)
  11.         hit: out std_logic);
  12. end CAM;
  13.  
  14. architecture behav of CAM is
  15.     signal eq: boolean;
  16.     type states is (WT,R0,R1,R2,STO,R3);
  17.     type CAM is array (0 to 3) of std_logic_vector(11 downto 0);
  18.     signal newstates: states;
  19.  
  20. begin
  21. -- State Transition Process
  22.     process is
  23.         variable current: states := R3;
  24.     begin
  25.         if clk = '1' then
  26.             case current is
  27.                 when WT =>
  28.                     if cs = '0' then
  29.                         current := WT;
  30.                     end if;
  31.                     if (cs = '1') and (r = '1') then
  32.                         current := R0;
  33.                     end if;
  34.                    
  35.                     if (cs = '1') and (r = '0') then
  36.                         current := STO;
  37.                     end if;
  38.                 when R0 =>
  39.                     current := R1;
  40.                 when R1 =>
  41.                     if eq = '1' then
  42.                         current := R3;
  43.                     end if;
  44.                    
  45.                     if eq = '0' then
  46.                         current := R2;
  47.                     end if;
  48.                    
  49.                 when R2 =>
  50.                     current := R0;
  51.                 when R3 =>
  52.                     if cs = '1' then
  53.                         current := R3;
  54.                     end if;
  55.                    
  56.                     if cs = '0' then
  57.                         current := WT;
  58.                     end if;
  59.                 when STO =>
  60.                     if cs = '1' then
  61.                         current := STO;
  62.                     end if;
  63.                    
  64.                     if cs = '0' then
  65.                         current := WT;
  66.                     end if;
  67.             end case;
  68.             newstates <= current;
  69.         end if;
  70.     wait on clk;
  71.     end process;
  72. -- Asserted Outputs process    
  73.     process is
  74.         variable i: std_logic_vector(3 downto 0);
  75.         variable CAMHolder: CAM;
  76.         variable addrHolder: integer;
  77.         variable iHolder: integer;
  78.     begin
  79.         addrHolder := to_integer(addr);
  80.         case newstates is
  81.             when WT =>
  82.                 i := "0000";
  83.                 mv <= "0000";
  84.                 hit <= '0';
  85.             when R0 =>
  86.                 eq <= ( i = "0011");
  87.             when R1 =>
  88.             when R2 =>
  89.                 iHolder := to_integer(i);
  90.                 mv(i) <= (CAMHolder(addrHolder) := data);
  91.                 i := i + "0001";
  92.             when R3 =>
  93.                 hit <= not(mv = "0000");
  94.             when STO =>
  95.                 CAMHolder(addrHolder) := data;
  96.         end case;
  97.     wait on newstates;
  98.     end process;
  99.    
  100.    
  101. end behav;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement