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.

73 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. default clock is rising_edge(Clk_i);
  30. -- Initial reset
  31. INITIAL_RESET : restrict {not Reset_n_i[*2]; Reset_n_i[+]}[*1];
  32. -- Asynchronous (unclocked) Reset asserts
  33. AFTER_RESET : process (all) is
  34. begin
  35. if (not Reset_n_i) then
  36. RESET_DATA : assert unsigned(Data_o) = to_unsigned(InitVal, Data_o'length);
  37. end if;
  38. end process AFTER_RESET;
  39. COUNT_UP : assert always
  40. Reset_n_i and unsigned(Data_o) < to_unsigned(EndVal, Data_o'length)
  41. ->
  42. next unsigned(Data_o) = unsigned(prev(Data_o)) + 1;
  43. END_VALUE : assert always
  44. unsigned(Data_o) = to_unsigned(EndVal, Data_o'length)
  45. ->
  46. next Data_o = prev(Data_o);
  47. VALID_RANGE : assert always
  48. unsigned(Data_o) >= to_unsigned(InitVal, Data_o'length) and
  49. unsigned(Data_o) <= to_unsigned(EndVal, Data_o'length);
  50. end generate FormalG;
  51. end architecture rtl;