Examples of using PSL for functional and formal verification of VHDL with GHDL (and SymbiYosys)
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.

180 lines
3.9 KiB

  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. entity sequencer is
  4. generic (
  5. seq : string
  6. );
  7. port (
  8. clk : in std_logic;
  9. data : out std_logic
  10. );
  11. end entity sequencer;
  12. architecture rtl of sequencer is
  13. signal index : natural := seq'low;
  14. function to_bit (a : in character) return std_logic is
  15. variable ret : std_logic;
  16. begin
  17. case a is
  18. when '0' | '_' => ret := '0';
  19. when '1' | '-' => ret := '1';
  20. when others => ret := 'X';
  21. end case;
  22. return ret;
  23. end function to_bit;
  24. begin
  25. process (clk) is
  26. begin
  27. if rising_edge(clk) then
  28. if (index < seq'high) then
  29. index <= index + 1;
  30. end if;
  31. end if;
  32. end process;
  33. data <= to_bit(seq(index));
  34. end architecture rtl;
  35. library ieee;
  36. use ieee.std_logic_1164.all;
  37. entity hex_sequencer is
  38. generic (
  39. seq : string
  40. );
  41. port (
  42. clk : in std_logic;
  43. data : out std_logic_vector(3 downto 0)
  44. );
  45. end entity hex_sequencer;
  46. architecture rtl of hex_sequencer is
  47. signal index : natural := seq'low;
  48. function to_hex (a : in character) return std_logic_vector is
  49. variable ret : std_logic_vector(3 downto 0);
  50. begin
  51. case a is
  52. when '0' | '_' => ret := x"0";
  53. when '1' => ret := x"1";
  54. when '2' => ret := x"2";
  55. when '3' => ret := x"3";
  56. when '4' => ret := x"4";
  57. when '5' => ret := x"5";
  58. when '6' => ret := x"6";
  59. when '7' => ret := x"7";
  60. when '8' => ret := x"8";
  61. when '9' => ret := x"9";
  62. when 'a' | 'A' => ret := x"A";
  63. when 'b' | 'B' => ret := x"B";
  64. when 'c' | 'C' => ret := x"C";
  65. when 'd' | 'D' => ret := x"D";
  66. when 'e' | 'E' => ret := x"E";
  67. when 'f' | 'F' | '-' => ret := x"F";
  68. when others => ret := x"X";
  69. end case;
  70. return ret;
  71. end function to_hex;
  72. begin
  73. process (clk) is
  74. begin
  75. if rising_edge(clk) then
  76. if (index < seq'high) then
  77. index <= index + 1;
  78. end if;
  79. end if;
  80. end process;
  81. data <= to_hex(seq(index));
  82. end architecture rtl;
  83. library ieee;
  84. use ieee.std_logic_1164.all;
  85. use ieee.numeric_std.all;
  86. entity issue is
  87. port (
  88. clk : in std_logic
  89. );
  90. end entity issue;
  91. architecture psl of issue is
  92. signal a, c : std_logic;
  93. signal b : std_logic_vector(3 downto 0);
  94. begin
  95. -- 012345678901234567892345
  96. SEQ_A : entity work.sequencer generic map ("_-______________-_______") port map (clk, a);
  97. SEQ_B : entity work.hex_sequencer generic map ("443334477444433355555555") port map (clk, b);
  98. SEQ_C : entity work.sequencer generic map ("_____-___---______--_--_") port map (clk, c);
  99. -- All is sensitive to rising edge of clk
  100. default clock is rising_edge(clk);
  101. -- Check for one possible value of b
  102. -- Both assertions should hold
  103. -- These are similar to waveform 2.6(a) on page 13
  104. -- in the book "A practical introduction to PSL"
  105. -- This assertion doesn't hold, assuming GHDL bug
  106. -- Comparing to the next example, GHDL seems to have a problem with conditions
  107. -- other than the given one (b = x"4"), even if the "enable" condition (b = "1") isn't true.
  108. NEXT_EVENT_0_a : assert always ((a and b = x"4") -> next_event_a(c)[1 to 4](b = x"4"))
  109. report "NEXT_EVENT_0_a failed";
  110. -- Assertion holds.
  111. NEXT_EVENT_1_a : assert always ((a and b = x"5") -> next_event_a(c)[1 to 4](b = x"5"))
  112. report "NEXT_EVENT_1_a failed";
  113. end architecture psl;
  114. library ieee;
  115. use ieee.std_logic_1164.all;
  116. use std.env.all;
  117. entity test_issue is
  118. end entity test_issue;
  119. architecture sim of test_issue is
  120. signal clk : std_logic := '1';
  121. begin
  122. clk <= not clk after 500 ps;
  123. DUT : entity work.issue(psl) port map (clk);
  124. -- stop simulation after 30 cycles
  125. process
  126. variable index : natural := 30;
  127. begin
  128. loop
  129. wait until rising_edge(clk);
  130. index := index - 1;
  131. exit when index = 0;
  132. end loop;
  133. stop(0);
  134. end process;
  135. end architecture sim;