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.

99 lines
2.4 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. -- Unit test of spi master procedure, checks all combinations
  32. -- of cpol & cpha against spi slave procedure
  33. SpiMasterP : process is
  34. variable v_slave_data : std_logic_vector(7 downto 0);
  35. begin
  36. for mode in 0 to 3 loop
  37. for i in 0 to 255 loop
  38. spi_master (data_in => std_logic_vector(to_unsigned(i, 8)),
  39. data_out => v_slave_data,
  40. sclk => s_sclk,
  41. ste => s_ste,
  42. mosi => s_mosi,
  43. miso => s_miso,
  44. cpol => mode / 2,
  45. cpha => mode mod 2,
  46. period => 1 us
  47. );
  48. assert_equal(v_slave_data, std_logic_vector(to_unsigned(i, 8)));
  49. end loop;
  50. end loop;
  51. wait;
  52. end process SpiMasterP;
  53. -- Unit test of spi slave procedure, checks all combinations
  54. -- of cpol & cpha against spi master procedure
  55. SpiSlaveP : process is
  56. variable v_master_data : std_logic_vector(7 downto 0);
  57. begin
  58. for mode in 0 to 3 loop
  59. for i in 0 to 255 loop
  60. spi_slave (data_in => std_logic_vector(to_unsigned(i, 8)),
  61. data_out => v_master_data,
  62. sclk => s_sclk,
  63. ste => s_ste,
  64. mosi => s_mosi,
  65. miso => s_miso,
  66. cpol => mode / 2,
  67. cpha => mode mod 2
  68. );
  69. assert_equal(v_master_data, std_logic_vector(to_unsigned(i, 8)));
  70. end loop;
  71. end loop;
  72. wait;
  73. report "INFO: SimP tests finished successfully";
  74. end process SpiSlaveP;
  75. end architecture sim;