Library of reusable VHDL components
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
1.9 KiB

  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. library libvhdl;
  5. use libvhdl.StringP.all;
  6. use libvhdl.AssertP.all;
  7. use libvhdl.SimP.all;
  8. entity SimT is
  9. end entity SimT;
  10. architecture sim of SimT is
  11. constant C_PERIOD : time := 5 ns;
  12. signal s_done : boolean := false;
  13. signal s_clk : std_logic := '0';
  14. signal s_sclk : std_logic;
  15. signal s_ste : std_logic;
  16. signal s_mosi : std_logic;
  17. signal s_miso : std_logic;
  18. begin
  19. s_clk <= not(s_clk) after C_PERIOD when not(s_done) else '0';
  20. SimTestP : process is
  21. variable v_time : time;
  22. begin
  23. wait until s_clk = '1';
  24. v_time := now;
  25. wait_cycles(s_clk, 10);
  26. assert (now - v_time) = C_PERIOD * 20
  27. severity failure;
  28. s_done <= true;
  29. wait;
  30. end process SimTestP;
  31. SpiMasterP : process is
  32. variable v_slave_data : std_logic_vector(7 downto 0);
  33. begin
  34. for i in 0 to 255 loop
  35. spi_master (data_in => std_logic_vector(to_unsigned(i, 8)),
  36. data_out => v_slave_data,
  37. sclk => s_sclk,
  38. ste => s_ste,
  39. mosi => s_mosi,
  40. miso => s_miso,
  41. cpol => 1,
  42. period => 1 us
  43. );
  44. assert_equal(v_slave_data, std_logic_vector(to_unsigned(i, 8)));
  45. end loop;
  46. wait;
  47. end process SpiMasterP;
  48. SpiSlaveP : process is
  49. variable v_master_data : std_logic_vector(7 downto 0);
  50. begin
  51. for i in 0 to 255 loop
  52. spi_slave (data_in => std_logic_vector(to_unsigned(i, 8)),
  53. data_out => v_master_data,
  54. sclk => s_sclk,
  55. ste => s_ste,
  56. mosi => s_mosi,
  57. miso => s_miso,
  58. cpol => 1
  59. );
  60. assert_equal(v_master_data, std_logic_vector(to_unsigned(i, 8)));
  61. end loop;
  62. wait;
  63. report "INFO: SimP tests finished successfully";
  64. end process SpiSlaveP;
  65. end architecture sim;