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.

108 lines
2.8 KiB

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