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.

164 lines
4.4 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. signal s_dout_accepted : boolean;
  34. alias a_addr : std_logic_vector(3 downto 0) is s_header(7 downto 4);
  35. begin
  36. s_dout_accepted <= true when DoutValid_o = '1' and DoutAccept_i = '1' else
  37. false;
  38. process (Reset_n_i, Clk_i) is
  39. begin
  40. if (Reset_n_i = '0') then
  41. DinAccept_o <= '0';
  42. DoutStart_o <= '0';
  43. DoutStop_o <= '0';
  44. DoutValid_o <= '0';
  45. Dout_o <= (others => '0');
  46. s_header <= (others => '0');
  47. s_data <= (others => '0');
  48. s_register <= (others => (others => '0'));
  49. s_error <= false;
  50. s_fsm_state <= IDLE;
  51. elsif (rising_edge(Clk_i)) then
  52. case s_fsm_state is
  53. when IDLE =>
  54. DinAccept_o <= '0';
  55. DoutStart_o <= '0';
  56. DoutStop_o <= '0';
  57. DoutValid_o <= '0';
  58. Dout_o <= (others => '0');
  59. s_header <= (others => '0');
  60. s_data <= (others => '0');
  61. s_error <= false;
  62. DinAccept_o <= '1';
  63. s_fsm_state <= GET_HEADER;
  64. when GET_HEADER =>
  65. if (DinValid_i = '1' and DinStart_i = '1') then
  66. s_header <= Din_i;
  67. if (Din_i(3 downto 0) = C_READ and DinStop_i = '1') then
  68. DinAccept_o <= '0';
  69. s_fsm_state <= GET_DATA;
  70. elsif (Din_i(3 downto 0) = C_WRITE and DinStop_i = '0') then
  71. s_fsm_state <= SET_DATA;
  72. else
  73. DinAccept_o <= '0';
  74. s_fsm_state <= IDLE;
  75. end if;
  76. end if;
  77. when GET_DATA =>
  78. if (unsigned(a_addr) <= 7) then
  79. s_data <= s_register(to_integer(unsigned(a_addr)));
  80. else
  81. s_error <= true;
  82. s_data <= (others => '0');
  83. end if;
  84. s_fsm_state <= SEND_HEADER;
  85. when SET_DATA =>
  86. if (DinValid_i = '1') then
  87. DinAccept_o <= '0';
  88. if (DinStop_i = '1') then
  89. if (unsigned(a_addr) <= 7) then
  90. s_register(to_integer(unsigned(a_addr))) <= Din_i;
  91. else
  92. s_error <= true;
  93. end if;
  94. s_fsm_state <= SEND_HEADER;
  95. else
  96. s_fsm_state <= IDLE;
  97. end if;
  98. end if;
  99. when SEND_HEADER =>
  100. DoutValid_o <= '1';
  101. DoutStart_o <= '1';
  102. Dout_o <= s_header;
  103. if (s_dout_accepted) then
  104. DoutValid_o <= '0';
  105. DoutStart_o <= '0';
  106. if (s_header(3 downto 0) = C_WRITE) then
  107. s_fsm_state <= SEND_FOOTER;
  108. else
  109. s_fsm_state <= SEND_DATA;
  110. end if;
  111. end if;
  112. when SEND_DATA =>
  113. DoutValid_o <= '1';
  114. Dout_o <= s_data;
  115. if (s_dout_accepted) then
  116. DoutValid_o <= '0';
  117. s_fsm_state <= SEND_FOOTER;
  118. end if;
  119. when SEND_FOOTER =>
  120. DoutValid_o <= '1';
  121. DoutStop_o <= '1';
  122. Dout_o <= x"01" when s_error else x"00";
  123. if (s_dout_accepted) then
  124. Dout_o <= (others => '0');
  125. DoutValid_o <= '0';
  126. DoutStop_o <= '0';
  127. s_fsm_state <= IDLE;
  128. end if;
  129. when others => null;
  130. end case;
  131. end if;
  132. end process;
  133. end architecture rtl;