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.

163 lines
4.5 KiB

  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. entity vai_reg is
  5. port (
  6. Reset_n_i : in std_logic;
  7. Clk_i : in std_logic;
  8. -- req
  9. Din_i : in std_logic_vector(7 downto 0);
  10. DinValid_i : in std_logic;
  11. DinStart_i : in std_logic;
  12. DinStop_i : in std_logic;
  13. DinAccept_o : out std_logic;
  14. -- ack
  15. Dout_o : out std_logic_vector(7 downto 0);
  16. DoutValid_o : out std_logic;
  17. DoutStart_o : out std_logic;
  18. DoutStop_o : out std_logic;
  19. DoutAccept_i : in std_logic
  20. );
  21. end entity vai_reg;
  22. architecture rtl of vai_reg is
  23. constant C_READ : std_logic_vector(3 downto 0) := x"0";
  24. constant C_WRITE : std_logic_vector(3 downto 0) := x"1";
  25. type t_fsm_state is (IDLE, GET_HEADER, GET_DATA,
  26. SET_DATA, SEND_HEADER, SEND_DATA, SEND_FOOTER);
  27. signal s_fsm_state : t_fsm_state;
  28. type t_register is array(0 to 7) of std_logic_vector(7 downto 0);
  29. signal s_register : t_register;
  30. signal s_header : std_logic_vector(7 downto 0);
  31. signal s_data : std_logic_vector(7 downto 0);
  32. signal s_error : boolean;
  33. alias a_addr : std_logic_vector(3 downto 0) is s_header(7 downto 4);
  34. begin
  35. process (Reset_n_i, Clk_i) is
  36. begin
  37. if (Reset_n_i = '0') then
  38. DinAccept_o <= '0';
  39. DoutStart_o <= '0';
  40. DoutStop_o <= '0';
  41. DoutValid_o <= '0';
  42. Dout_o <= (others => '0');
  43. s_header <= (others => '0');
  44. s_data <= (others => '0');
  45. s_register <= (others => (others => '0'));
  46. s_error <= false;
  47. s_fsm_state <= IDLE;
  48. elsif (rising_edge(Clk_i)) then
  49. case s_fsm_state is
  50. when IDLE =>
  51. DinAccept_o <= '0';
  52. DoutStart_o <= '0';
  53. DoutStop_o <= '0';
  54. DoutValid_o <= '0';
  55. Dout_o <= (others => '0');
  56. s_header <= (others => '0');
  57. s_data <= (others => '0');
  58. s_error <= false;
  59. s_fsm_state <= GET_HEADER;
  60. when GET_HEADER =>
  61. DinAccept_o <= '1';
  62. if (DinValid_i = '1' and DinStart_i = '1') then
  63. DinAccept_o <= '0';
  64. s_header <= Din_i;
  65. if (Din_i(3 downto 0) = C_READ and DinStop_i = '1') then
  66. s_fsm_state <= GET_DATA;
  67. elsif (Din_i(3 downto 0) = C_WRITE and DinStop_i = '0') then
  68. s_fsm_state <= SET_DATA;
  69. else
  70. s_fsm_state <= IDLE;
  71. end if;
  72. end if;
  73. when GET_DATA =>
  74. if (unsigned(a_addr) <= 7) then
  75. s_data <= s_register(to_integer(unsigned(a_addr)));
  76. else
  77. s_error <= true;
  78. s_data <= (others => '0');
  79. end if;
  80. s_fsm_state <= SEND_HEADER;
  81. when SET_DATA =>
  82. DinAccept_o <= '1';
  83. if (DinValid_i = '1') then
  84. DinAccept_o <= '0';
  85. if (DinStop_i = '1') then
  86. if (unsigned(a_addr) <= 7) then
  87. -- Following line results in a Segmentation Fault
  88. s_register(to_integer(unsigned(a_addr))) <= Din_i;
  89. -- Following line results in following error:
  90. -- ERROR: Unsupported cell type $dlatchsr for cell $verific$wide_dlatchrs_8.$verific$i1$172.
  91. s_register(0) <= Din_i;
  92. else
  93. s_error <= true;
  94. end if;
  95. s_fsm_state <= SEND_HEADER;
  96. else
  97. s_fsm_state <= IDLE;
  98. end if;
  99. end if;
  100. when SEND_HEADER =>
  101. DoutValid_o <= '1';
  102. DoutStart_o <= '1';
  103. Dout_o <= s_header;
  104. if (DoutAccept_i = '1') then
  105. DoutValid_o <= '0';
  106. DoutStart_o <= '0';
  107. if (s_header(3 downto 0) = C_WRITE) then
  108. s_fsm_state <= SEND_FOOTER;
  109. else
  110. s_fsm_state <= SEND_DATA;
  111. end if;
  112. end if;
  113. when SEND_DATA =>
  114. DoutValid_o <= '1';
  115. Dout_o <= s_data;
  116. if (DoutAccept_i = '1') then
  117. DoutValid_o <= '0';
  118. s_fsm_state <= SEND_FOOTER;
  119. end if;
  120. when SEND_FOOTER =>
  121. DoutValid_o <= '1';
  122. DoutStop_o <= '1';
  123. Dout_o <= x"01" when s_error else x"00";
  124. if (DoutAccept_i = '1') then
  125. Dout_o <= (others => '0');
  126. DoutValid_o <= '0';
  127. DoutStop_o <= '0';
  128. s_fsm_state <= IDLE;
  129. end if;
  130. when others => null;
  131. end case;
  132. end if;
  133. end process;
  134. end architecture rtl;