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.

138 lines
3.1 KiB

  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. entity hex_sequencer is
  4. generic (
  5. seq : string
  6. );
  7. port (
  8. clk : in std_logic;
  9. data : out std_logic_vector(3 downto 0)
  10. );
  11. end entity hex_sequencer;
  12. architecture rtl of hex_sequencer is
  13. signal index : natural := seq'low;
  14. function to_hex (a : in character) return std_logic_vector is
  15. variable ret : std_logic_vector(3 downto 0);
  16. begin
  17. case a is
  18. when '0' | '_' => ret := x"0";
  19. when '1' => ret := x"1";
  20. when '2' => ret := x"2";
  21. when '3' => ret := x"3";
  22. when '4' => ret := x"4";
  23. when '5' => ret := x"5";
  24. when '6' => ret := x"6";
  25. when '7' => ret := x"7";
  26. when '8' => ret := x"8";
  27. when '9' => ret := x"9";
  28. when 'a' | 'A' => ret := x"A";
  29. when 'b' | 'B' => ret := x"B";
  30. when 'c' | 'C' => ret := x"C";
  31. when 'd' | 'D' => ret := x"D";
  32. when 'e' | 'E' => ret := x"E";
  33. when 'f' | 'F' | '-' => ret := x"F";
  34. when others => ret := x"X";
  35. end case;
  36. return ret;
  37. end function to_hex;
  38. begin
  39. process (clk) is
  40. begin
  41. if rising_edge(clk) then
  42. if (index < seq'high) then
  43. index <= index + 1;
  44. end if;
  45. end if;
  46. end process;
  47. data <= to_hex(seq(index));
  48. end architecture rtl;
  49. library ieee;
  50. use ieee.std_logic_1164.all;
  51. use ieee.numeric_std.all;
  52. entity issue is
  53. port (
  54. clk : in std_logic
  55. );
  56. end entity issue;
  57. architecture psl of issue is
  58. component hex_sequencer is
  59. generic (
  60. seq : string
  61. );
  62. port (
  63. clk : in std_logic;
  64. data : out std_logic_vector(3 downto 0)
  65. );
  66. end component hex_sequencer;
  67. signal a, b : std_logic_vector(3 downto 0);
  68. signal prev_valid : boolean := false;
  69. begin
  70. process is
  71. begin
  72. wait until rising_edge(clk);
  73. prev_valid <= true;
  74. end process;
  75. -- 0123456789
  76. SEQ_A : hex_sequencer generic map ("4444444444") port map (clk, a);
  77. SEQ_B : hex_sequencer generic map ("4444544444") port map (clk, b);
  78. -- All is sensitive to rising edge of clk
  79. default clock is rising_edge(clk);
  80. -- Holds
  81. STABLE_0 : assert always prev_valid -> stable(a);
  82. -- Doesn't hold at cycle 4
  83. STABLE_1 : assert always prev_valid -> stable(b);
  84. -- Triggers GHDL bug
  85. -- EDIT: works since fix of ghdl issue #1367
  86. -- Holds
  87. STABLE_2 : assert always prev_valid -> stable(a(1 downto 0));
  88. -- Triggers GHDL bug
  89. -- EDIT: works since fix of ghdl issue #1367
  90. -- Doesn't hold at cycle 4
  91. STABLE_3 : assert always prev_valid -> stable(b(1 downto 0));
  92. -- Holds
  93. PREV_0 : assert always prev_valid -> a = prev(a);
  94. -- Doesn't hold at cycle 4
  95. PREV_1 : assert always prev_valid -> b = prev(b);
  96. -- Triggers GHDL bug
  97. -- EDIT: works since fix of ghdl issue #1367
  98. -- Holds
  99. PREV_2 : assert always always prev_valid -> a(1 downto 0) = prev(a(1 downto 0));
  100. -- Triggers GHDL bug
  101. -- EDIT: works since fix of ghdl issue #1367
  102. -- Doesn't hold at cycle 4
  103. PREV_3 : assert always always prev_valid -> b(1 downto 0) = prev(b(1 downto 0));
  104. end architecture psl;