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.

121 lines
2.3 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 issue is
  38. port (
  39. clk : in std_logic
  40. );
  41. end entity issue;
  42. architecture psl of issue is
  43. signal a, b, c, d : std_logic;
  44. begin
  45. -- async reset 100 ps after rising edge in cycle 1
  46. d <= '0', '1' after 1100 ps, '0' after 1400 ps;
  47. -- 0123456789
  48. SEQ_A : entity work.sequencer generic map ("-___-_____") port map (clk, a);
  49. SEQ_B : entity work.sequencer generic map ("_______-__") port map (clk, b);
  50. SEQ_C : entity work.sequencer generic map ("-_________") port map (clk, c);
  51. -- D : _|________
  52. -- All is sensitive to rising edge of clk
  53. default clock is rising_edge(clk);
  54. -- This assertion holds
  55. WITH_ABORT_0_a : assert (always a -> next (b before a)) abort c;
  56. -- This assertion should also hold, but it does not
  57. -- GHDL seems to implement abort as sync_abort instead of async_abort
  58. -- See 1850-2010 6.2.1.5.1 abort, async_abort, and sync_abort
  59. WITH_ABORT_1_a : assert (always a -> next (b before a)) abort d;
  60. end architecture psl;
  61. library ieee;
  62. use ieee.std_logic_1164.all;
  63. use std.env.all;
  64. entity test_issue is
  65. end entity test_issue;
  66. architecture sim of test_issue is
  67. signal clk : std_logic := '1';
  68. begin
  69. clk <= not clk after 500 ps;
  70. DUT : entity work.issue(psl) port map (clk);
  71. -- stop simulation after 30 cycles
  72. process
  73. variable index : natural := 29;
  74. begin
  75. loop
  76. wait until rising_edge(clk);
  77. index := index - 1;
  78. exit when index = 0;
  79. end loop;
  80. stop(0);
  81. end process;
  82. end architecture sim;