Advertisement
pyrohaz

HSEL - SPI Test Code

Feb 11th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.25 KB | None | 0 0
  1. library ieee;
  2.  
  3. use ieee.std_logic_1164.all;
  4. use ieee.numeric_std.all;
  5.  
  6. entity SPITest1 is
  7. generic(
  8.     DLen: integer := 8;
  9.     Prescaler: integer := 6;
  10.     TestDSize: integer := 8
  11. );
  12.  
  13. port(
  14.     CS: out std_logic;
  15.     Dat: out std_logic;
  16.     ClkO: out std_logic;
  17.     Bell: out std_logic;
  18.     Clk: in std_logic
  19. );
  20.  
  21. end entity SPITest1;
  22.  
  23. architecture ST of SPITest1 is
  24.     signal PresC: unsigned(Prescaler downto 0) := to_unsigned(0, Prescaler+1);
  25.     signal SPS: unsigned(2 downto 0) := "000";
  26.     signal DCnt: unsigned(4 downto 0) := to_unsigned(0, 5);
  27.     signal TestD: unsigned(TestDSize-1 downto 0) := to_unsigned(0, TestDSize);
  28.  
  29. begin
  30.     process(Clk)
  31.     begin
  32.         if(rising_edge(Clk)) then
  33.         PresC <= PresC+1;
  34.         Bell <= '1';
  35.        
  36.             if(PresC = 0) then
  37.                
  38.                 if(SPS = "000") then
  39.                     CS <= '0';
  40.                     SPS <= "001";
  41.                 elsif(SPS = "001") then
  42.                     ClkO <= '0';
  43.                     Dat <= TestD((DLen-1)-to_integer(DCnt));
  44.                     SPS <= "010";
  45.                 elsif(SPS = "010") then
  46.                     ClkO <= '1';
  47.                     DCnt <= DCnt + 1;
  48.                    
  49.                     if(DCnt = DLen) then
  50.                         DCnt <= to_unsigned(0, 5);
  51.                         ClkO <= '0';
  52.                         Dat <= '0';
  53.                         CS <= '1';
  54.                         SPS <= "000";
  55.                         TestD <= TestD + 1;
  56.                     else
  57.                         SPS <= "001";
  58.                     end if;
  59.                 end if;
  60.             end if;
  61.         end if;
  62.     end process;
  63. end ST;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement