Studentenversion des ESY6/A Praktikums "signal_processing".
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.

add.vhd 4.5KB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. library work;
  5. use work.reg32.all;
  6. use work.task.all;
  7. entity add is
  8. port (
  9. clk : in std_logic;
  10. reset : in std_logic;
  11. task_start : in std_logic;
  12. task_state : out work.task.State;
  13. signal_a_read : out std_logic;
  14. signal_a_readdata : in std_logic_vector( 31 downto 0 );
  15. signal_b_read : out std_logic;
  16. signal_b_readdata : in std_logic_vector( 31 downto 0 );
  17. signal_write : out std_logic;
  18. signal_writedata : out std_logic_vector( 31 downto 0 )
  19. );
  20. end entity add;
  21. -- tbd
  22. -- if _read is 1 _readdata is read
  23. -- if _write is 1 _writedata is written
  24. -- float_add instanziieren
  25. -- state machine that sets taskState and write signals
  26. architecture rtl of add is
  27. component float_add
  28. port (
  29. clk : in std_logic;
  30. reset : in std_logic;
  31. start : in std_logic;
  32. A : in std_logic_vector( 31 downto 0 );
  33. B : in std_logic_vector( 31 downto 0 );
  34. done : out std_logic;
  35. sum : out std_logic_vector( 31 downto 0 )
  36. );
  37. end component float_add;
  38. signal current_task_state : work.task.State;
  39. signal next_task_state : work.task.State;
  40. signal index : integer range 0 to work.task.STREAM_LEN;
  41. signal float_add_start : std_logic;
  42. signal float_add_A : std_logic_vector( 31 downto 0 );
  43. signal float_add_B : std_logic_vector( 31 downto 0 );
  44. signal float_add_done : std_logic;
  45. signal float_add_sum : std_logic_vector( 31 downto 0 );
  46. signal add_state : integer range 0 to 3;
  47. signal flag_index : bit;
  48. begin
  49. float_adder : float_add
  50. port map (
  51. clk => clk,
  52. reset => reset,
  53. start => float_add_start,
  54. A => float_add_A, -- feed readdata into float adder
  55. B => float_add_B, -- feed readdata into float adder
  56. done => float_add_done, -- write signal when float addition is finished
  57. sum => float_add_sum -- feed output of float adder into writedata
  58. );
  59. task_state_transitions : process ( current_task_state, task_start, index ) is
  60. begin
  61. next_task_state <= current_task_state;
  62. case current_task_state is
  63. when work.task.TASK_IDLE =>
  64. if ( task_start = '1' ) then
  65. next_task_state <= work.task.TASK_RUNNING;
  66. end if;
  67. when work.task.TASK_RUNNING =>
  68. if ( index = work.task.STREAM_LEN - 1 ) then
  69. next_task_state <= work.task.TASK_DONE;
  70. end if;
  71. when work.task.TASK_DONE =>
  72. if ( task_start = '1' ) then
  73. next_task_state <= work.task.TASK_RUNNING;
  74. end if;
  75. end case;
  76. end process task_state_transitions;
  77. sync : process ( clk, reset ) is
  78. begin
  79. if ( reset = '1' ) then
  80. current_task_state <= work.task.TASK_IDLE;
  81. index <= 0;
  82. elsif ( rising_edge( clk ) ) then
  83. current_task_state <= next_task_state;
  84. case next_task_state is
  85. when work.task.TASK_IDLE =>
  86. index <= 0;
  87. -- signal_write <= '0';
  88. when work.task.TASK_RUNNING => -- signal_writedata <= result???
  89. if ( flag_index = '1' ) then
  90. index <= index + 1;
  91. end if;
  92. -- signal_write <= '1';
  93. -- signal_writedata <= ( others => '0' );
  94. when work.task.TASK_DONE =>
  95. index <= 0;
  96. -- signal_write <= '0';
  97. end case;
  98. end if;
  99. end process sync;
  100. add : process (clk, reset) is
  101. begin
  102. if ( reset = '1' ) then
  103. signal_a_read <= '0';
  104. signal_b_read <= '0';
  105. signal_write <= '0';
  106. signal_writedata <= ( others => '0');
  107. float_add_start <= '0';
  108. float_add_A <= ( others => '0');
  109. float_add_B <= ( others => '0');
  110. elsif ( rising_edge( clk ) ) then
  111. case add_state is
  112. when 0 =>
  113. if ( current_task_state = work.task.TASK_RUNNING ) then
  114. add_state <= 1;
  115. end if;
  116. when 1 =>
  117. signal_a_read <= '1';
  118. signal_b_read <= '1';
  119. float_add_start <= '1';
  120. float_add_A <= signal_a_readdata;
  121. float_add_B <= signal_b_readdata;
  122. if ( float_add_done = '1' ) then
  123. add_state <= 2;
  124. end if;
  125. when 2 =>
  126. signal_write <= '1';
  127. signal_writedata <= float_add_sum;
  128. float_add_start <= '0';
  129. signal_a_read <= '0';
  130. signal_b_read <= '0';
  131. flag_index <= '1';
  132. add_state <= 3;
  133. when 3 =>
  134. signal_write <= '0';
  135. flag_index <= '0';
  136. add_state <= 0;
  137. end case;
  138. end if;
  139. end process add;
  140. task_state <= current_task_state;
  141. end architecture rtl;