Trying to verify Verilog/VHDL designs with formal methods and tools
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.

75 lines
1.6 KiB

  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. entity counter is
  5. generic (
  6. InitVal : natural := 0;
  7. EndVal : natural := 16;
  8. Formal : boolean := true
  9. );
  10. port (
  11. Reset_n_i : in std_logic;
  12. Clk_i : in std_logic;
  13. Data_o : out std_logic_vector(31 downto 0)
  14. );
  15. end entity counter;
  16. architecture rtl of counter is
  17. begin
  18. process (Reset_n_i, Clk_i) is
  19. begin
  20. if (Reset_n_i = '0') then
  21. Data_o <= std_logic_vector(to_unsigned(InitVal, Data_o'length));
  22. elsif (rising_edge(Clk_i)) then
  23. if (to_integer(unsigned(Data_o)) < EndVal) then
  24. Data_o <= std_logic_vector(unsigned(Data_o) + 1);
  25. end if;
  26. end if;
  27. end process;
  28. FormalG : if Formal generate
  29. signal s_data : unsigned(Data_o'range);
  30. begin
  31. -- VHDL helper logic
  32. process is
  33. begin
  34. wait until rising_edge(Clk_i);
  35. s_data <= unsigned(Data_o);
  36. end process;
  37. default clock is rising_edge(Clk_i);
  38. -- Initial reset
  39. INITIAL_RESET : restrict {Reset_n_i = '0'[*2]; Reset_n_i = '1'[+]}[*1];
  40. AFTER_RESET : assert always
  41. not Reset_n_i -> Data_o = (Data_o'range => '0');
  42. COUNT_UP : assert always
  43. Reset_n_i and unsigned(Data_o) < to_unsigned(EndVal, 32) -> next unsigned(Data_o) = s_data + 1;
  44. END_VALUE : assert always
  45. unsigned(Data_o) = to_unsigned(EndVal, 32) -> next unsigned(Data_o) = s_data;
  46. VALID_RANGE : assert always
  47. unsigned(Data_o) >= to_unsigned(InitVal, 32) and
  48. unsigned(Data_o) <= to_unsigned(EndVal, 32);
  49. end generate FormalG;
  50. end architecture rtl;