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.

120 lines
2.4 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. use ieee.numeric_std.all;
  38. entity issue is
  39. port (
  40. clk : in std_logic
  41. );
  42. end entity issue;
  43. architecture psl of issue is
  44. signal a, b, c, d : std_logic;
  45. begin
  46. -- 01234567890
  47. SEQ_A : entity work.sequencer generic map ("_-____-____") port map (clk, a);
  48. SEQ_B : entity work.sequencer generic map ("___-_____-_") port map (clk, b);
  49. -- 01234567890
  50. SEQ_C : entity work.sequencer generic map ("_-___-_____") port map (clk, c);
  51. SEQ_D : entity work.sequencer generic map ("_____-___-_") port map (clk, d);
  52. default clock is rising_edge(clk);
  53. -- Should hold, but fails at cycle 3
  54. -- Potential GHDL bug?
  55. -- This is similar to waveform 2.9(i) on page 16
  56. -- in the book "A practical introduction to PSL"
  57. BEFORE_0_a : assert always (a -> next (b before_ a))
  58. report "BEFORE_0_a failed";
  59. -- Should hold but does not at cycle 9
  60. -- Potential GHDL bug?
  61. -- This is similar to waveform 2.9(ii) on page 16
  62. -- in the book "A practical introduction to PSL"
  63. BEFORE_1_a : assert always (c -> next (d before_ c))
  64. report "BEFORE_1_a failed";
  65. end architecture psl;
  66. library ieee;
  67. use ieee.std_logic_1164.all;
  68. use std.env.all;
  69. entity test_issue is
  70. end entity test_issue;
  71. architecture sim of test_issue is
  72. signal clk : std_logic := '1';
  73. begin
  74. clk <= not clk after 500 ps;
  75. DUT : entity work.issue(psl) port map (clk);
  76. -- stop simulation after 30 cycles
  77. process
  78. variable index : natural := 10;
  79. begin
  80. loop
  81. wait until rising_edge(clk);
  82. index := index - 1;
  83. exit when index = 0;
  84. end loop;
  85. stop(0);
  86. end process;
  87. end architecture sim;