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.

105 lines
2.6 KiB

  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. --+ including vhdl 2008 libraries
  5. library ieee_proposed;
  6. use ieee_proposed.standard_additions.all;
  7. use ieee_proposed.std_logic_1164_additions.all;
  8. use ieee_proposed.numeric_std_additions.all;
  9. library libvhdl;
  10. use libvhdl.AssertP.all;
  11. use libvhdl.SimP.all;
  12. entity SimT is
  13. end entity SimT;
  14. architecture sim of SimT is
  15. constant C_PERIOD : time := 5 ns;
  16. signal s_tests_done : boolean_vector(0 to 1) := (others => false);
  17. signal s_clk : std_logic := '0';
  18. signal s_sclk : std_logic;
  19. signal s_ste : std_logic;
  20. signal s_mosi : std_logic;
  21. signal s_miso : std_logic;
  22. begin
  23. s_clk <= not(s_clk) after C_PERIOD when not(and_reduce(s_tests_done)) else '0';
  24. SimTestP : process is
  25. variable v_time : time;
  26. begin
  27. wait until s_clk = '1';
  28. v_time := now;
  29. wait_cycles(s_clk, 10);
  30. assert (now - v_time) = C_PERIOD * 20
  31. severity failure;
  32. s_tests_done(0) <= true;
  33. wait;
  34. end process SimTestP;
  35. -- Unit test of spi master procedure, checks all combinations
  36. -- of cpol & cpha against spi slave procedure
  37. SpiMasterP : process is
  38. variable v_slave_data : std_logic_vector(7 downto 0);
  39. begin
  40. for mode in 0 to 3 loop
  41. for i in 0 to 255 loop
  42. spi_master (data_in => std_logic_vector(to_unsigned(i, 8)),
  43. data_out => v_slave_data,
  44. sclk => s_sclk,
  45. ste => s_ste,
  46. mosi => s_mosi,
  47. miso => s_miso,
  48. cpol => mode / 2,
  49. cpha => mode mod 2,
  50. period => 1 us
  51. );
  52. assert_equal(v_slave_data, std_logic_vector(to_unsigned(i, 8)));
  53. end loop;
  54. end loop;
  55. wait;
  56. end process SpiMasterP;
  57. -- Unit test of spi slave procedure, checks all combinations
  58. -- of cpol & cpha against spi master procedure
  59. SpiSlaveP : process is
  60. variable v_master_data : std_logic_vector(7 downto 0);
  61. begin
  62. for mode in 0 to 3 loop
  63. for i in 0 to 255 loop
  64. spi_slave (data_in => std_logic_vector(to_unsigned(i, 8)),
  65. data_out => v_master_data,
  66. sclk => s_sclk,
  67. ste => s_ste,
  68. mosi => s_mosi,
  69. miso => s_miso,
  70. cpol => mode / 2,
  71. cpha => mode mod 2
  72. );
  73. assert_equal(v_master_data, std_logic_vector(to_unsigned(i, 8)));
  74. end loop;
  75. end loop;
  76. report "INFO: SimP tests finished successfully";
  77. s_tests_done(1) <= true;
  78. wait;
  79. end process SpiSlaveP;
  80. end architecture sim;