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.

119 lines
2.5 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. begin
  69. -- 0123456789
  70. SEQ_A : hex_sequencer generic map ("4444444444") port map (clk, a);
  71. SEQ_B : hex_sequencer generic map ("4444544444") port map (clk, b);
  72. -- All is sensitive to rising edge of clk
  73. default clock is rising_edge(clk);
  74. -- Holds
  75. STABLE_0 : assert always stable(a);
  76. -- Doesn't hold at cycle 4
  77. STABLE_1 : assert always stable(b);
  78. -- Triggers GHDL bug
  79. STABLE_2 : assert always stable(a(1 downto 0));
  80. STABLE_3 : assert always stable(b(1 downto 0));
  81. -- Holds
  82. PREV_0 : assert always a = prev(a);
  83. -- Doesn't hold at cycle 4
  84. PREV_1 : assert always b = prev(b);
  85. -- Triggers GHDL bug
  86. PREV_2 : assert always always a(1 downto 0) = prev(a(1 downto 0));
  87. PREV_3 : assert always always b(1 downto 0) = prev(b(1 downto 0));
  88. end architecture psl;