Various projects using Raspberry Pi
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.

212 lines
6.2 KiB

  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. entity FiRoCtrlE is
  5. generic (
  6. EXTRACT : boolean := true
  7. );
  8. port (
  9. --+ system if
  10. Clk_i : in std_logic;
  11. Reset_i : in std_logic;
  12. --+ ctrl/status
  13. Start_i : in std_logic;
  14. --+ rnd data
  15. DataValid_o : out std_logic;
  16. Data_o : out std_logic_vector(7 downto 0);
  17. -- firo
  18. Run_o : out std_logic;
  19. Data_i : in std_logic
  20. );
  21. end entity FiRoCtrlE;
  22. architecture rtl of FiRoCtrlE is
  23. signal s_clk_counter : unsigned(4 downto 0);
  24. signal s_run : std_logic;
  25. signal s_firo_valid : std_logic;
  26. type t_neumann_state is (BIT1, BIT2, BIT3, BIT4);
  27. signal s_neumann_state : t_neumann_state;
  28. signal s_neumann_buffer : std_logic_vector(2 downto 0);
  29. type t_register_state is (SLEEP, COLLECT);
  30. signal s_register_state : t_register_state;
  31. signal s_register_enable : std_logic;
  32. signal s_register_din : std_logic_vector(1 downto 0);
  33. signal s_register_data : std_logic_vector(8 downto 0);
  34. signal s_register_counter : unsigned(2 downto 0);
  35. signal s_register_length : natural range 1 to 2;
  36. signal s_data : std_logic_vector(3 downto 0);
  37. begin
  38. Run_o <= s_run when s_register_state = COLLECT else '0';
  39. s_data <= s_neumann_buffer & Data_i;
  40. ControllerP : process (Clk_i) is
  41. variable v_clk_cnt : unsigned(4 downto 0);
  42. begin
  43. if (rising_edge(Clk_i)) then
  44. if (s_register_state = SLEEP) then
  45. v_clk_cnt := (others => '1');
  46. s_run <= '0';
  47. s_firo_valid <= '0';
  48. else
  49. s_firo_valid <= '0';
  50. if (v_clk_cnt = 23 and s_run = '0') then
  51. s_run <= '1';
  52. v_clk_cnt := (others => '1');
  53. end if;
  54. if (v_clk_cnt = 12 and s_run = '1') then
  55. s_run <= '0';
  56. v_clk_cnt := (others => '1');
  57. end if;
  58. if (v_clk_cnt = 13 and s_run = '1') then
  59. s_firo_valid := '1';
  60. end if;
  61. v_clk_cnt := v_clk_cnt - 1;
  62. end if;
  63. end if;
  64. end process ControllerP;
  65. extractor : if EXTRACT generate
  66. VonNeumannP : process (Clk_i) is
  67. begin
  68. if (rising_edge(Clk_i)) then
  69. if (Reset_i = '0') then
  70. s_neumann_state <= BIT1;
  71. --s_neumann_buffer <= "000";
  72. --s_register_enable <= '0';
  73. --s_register_din <= "00";
  74. else
  75. case s_neumann_state is
  76. when BIT1 =>
  77. s_register_enable <= '0';
  78. if (s_firo_valid = '1') then
  79. s_neumann_buffer(2) <= Data_i;
  80. s_neumann_state <= BIT2;
  81. end if;
  82. when BIT2 =>
  83. if (s_firo_valid = '1') then
  84. s_neumann_buffer(1) <= Data_i;
  85. s_neumann_state <= BIT3;
  86. end if;
  87. when BIT3 =>
  88. if (s_firo_valid = '1') then
  89. s_neumann_buffer(0) <= Data_i;
  90. s_neumann_state <= BIT4;
  91. end if;
  92. when BIT4 =>
  93. if (s_firo_valid = '1') then
  94. s_register_enable <= '1';
  95. s_register_length <= 1;
  96. s_register_din <= "00";
  97. s_neumann_state <= BIT1;
  98. case (s_data) is
  99. when x"5" =>
  100. s_register_din <= "01";
  101. when x"1" | x"6" | x"7" =>
  102. s_register_length <= 2;
  103. when x"2" | x"9" | x"b" =>
  104. s_register_din <= "01";
  105. s_register_length <= 2;
  106. when x"4" | x"a" | x"d" =>
  107. s_register_din <= "10";
  108. s_register_length <= 2;
  109. when x"8" | x"c" | x"e" =>
  110. s_register_din <= "11";
  111. s_register_length <= 2;
  112. when x"0" | x"f" =>
  113. s_register_enable <= '0';
  114. when others => -- incl. x"3"
  115. null;
  116. end case;
  117. end if;
  118. when others =>
  119. null;
  120. end case;
  121. end if;
  122. end if;
  123. end process VonNeumannP;
  124. end generate;
  125. no_extractor : if not(EXTRACT) generate
  126. s_register_enable <= s_firo_valid;
  127. s_register_din(0) <= Data_i;
  128. s_register_length <= 1;
  129. end generate;
  130. Data_o <= s_register_data(7 downto 0);
  131. ShiftRegisterP : process (Clk_i) is
  132. begin
  133. if (rising_edge(Clk_i)) then
  134. if (Reset_i = '0') then
  135. s_register_counter <= (others => '1');
  136. s_register_state <= SLEEP;
  137. DataValid_o <= '0';
  138. else
  139. case s_register_state is
  140. when SLEEP =>
  141. if (Start_i = '1') then
  142. DataValid_o <= '0';
  143. s_register_state <= COLLECT;
  144. s_register_data(0) <= s_register_data(8);
  145. end if;
  146. when COLLECT =>
  147. if (s_register_enable = '1') then
  148. if (s_register_counter = 0) then
  149. s_register_data <= s_register_din(1) & s_register_data(6 downto 0) & s_register_din(0);
  150. DataValid_o <= '1';
  151. s_register_state <= SLEEP;
  152. elsif (s_register_counter = 1) then
  153. if (s_register_length = 1) then
  154. s_register_data(7 downto 0) <= s_register_data(6 downto 0) & s_register_din(0);
  155. end if;
  156. if (s_register_length = 2) then
  157. s_register_data(7 downto 0) <= s_register_data(5 downto 0) & s_register_din;
  158. DataValid_o <= '1';
  159. s_register_state <= SLEEP;
  160. end if;
  161. else
  162. if (s_register_length = 1) then
  163. s_register_data(7 downto 0) <= s_register_data(6 downto 0) & s_register_din(0);
  164. else
  165. s_register_data(7 downto 0) <= s_register_data(5 downto 0) & s_register_din;
  166. end if;
  167. end if;
  168. s_register_counter <= s_register_counter - s_register_length;
  169. end if;
  170. when others =>
  171. null;
  172. end case;
  173. end if;
  174. end if;
  175. end process ShiftRegisterP;
  176. end architecture rtl;