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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. architecture rtl of add is
  22. signal current_task_state : work.task.State;
  23. signal next_task_state : work.task.State;
  24. signal index : integer range 0 to work.task.STREAM_LEN;
  25. -- Zustände für die Zustandsmaschine zur Berechnung
  26. type SigState is (
  27. SIG_IDLE,
  28. SIG_READ,
  29. SIG_ADD,
  30. SIG_WRITE
  31. );
  32. signal current_sig_state : SigState;
  33. signal next_sig_state : SigState;
  34. signal signal_add_start : std_logic;
  35. signal signal_add_done : std_logic;
  36. begin
  37. u_float_add : entity work.float_add
  38. port map(
  39. clk => clk,
  40. reset => reset,
  41. start => signal_add_start,
  42. done => signal_add_done,
  43. A => signal_a_readdata,
  44. B => signal_b_readdata,
  45. sum => signal_writedata
  46. );
  47. task_state_transitions : process ( current_task_state, task_start, index ) is
  48. begin
  49. next_task_state <= current_task_state;
  50. case current_task_state is
  51. when work.task.TASK_IDLE =>
  52. if ( task_start = '1' ) then
  53. next_task_state <= work.task.TASK_RUNNING;
  54. end if;
  55. when work.task.TASK_RUNNING =>
  56. if ( index = work.task.STREAM_LEN) then
  57. next_task_state <= work.task.TASK_DONE;
  58. end if;
  59. when work.task.TASK_DONE =>
  60. if ( task_start = '1' ) then
  61. next_task_state <= work.task.TASK_RUNNING;
  62. end if;
  63. end case;
  64. end process task_state_transitions;
  65. sig_state_transitions : process (all) is
  66. begin
  67. next_sig_state <= current_sig_state;
  68. case current_sig_state is
  69. when SIG_IDLE =>
  70. if ( current_task_state = work.task.TASK_RUNNING ) then
  71. next_sig_state <= SIG_READ;
  72. end if;
  73. when SIG_READ =>
  74. next_sig_state <= SIG_ADD;
  75. when SIG_ADD =>
  76. if ( signal_add_done = '1') then
  77. next_sig_state <= SIG_WRITE;
  78. end if;
  79. when SIG_WRITE =>
  80. next_sig_state <= SIG_IDLE;
  81. end case;
  82. end process sig_state_transitions;
  83. task_sync : process ( clk, reset ) is
  84. begin
  85. if ( reset = '1' ) then
  86. current_task_state <= work.task.TASK_IDLE;
  87. --index <= 0;
  88. elsif ( rising_edge( clk ) ) then
  89. current_task_state <= next_task_state;
  90. case next_task_state is
  91. when work.task.TASK_IDLE =>
  92. null;
  93. -- signal_write <= '0';
  94. when work.task.TASK_RUNNING =>
  95. null;
  96. -- signal_write <= '1';
  97. -- signal_writedata <= ( others => '0' );
  98. when work.task.TASK_DONE =>
  99. null;
  100. -- signal_write <= '0';
  101. end case;
  102. end if;
  103. end process task_sync;
  104. sync : process (all) is
  105. begin
  106. if ( reset = '1' ) then
  107. current_sig_state <= SIG_IDLE;
  108. index <= 0;
  109. signal_a_read <= '0';
  110. signal_b_read <= '0';
  111. signal_add_start <= '0';
  112. signal_write <= '0';
  113. elsif ( rising_edge( clk ) ) then
  114. current_sig_state <= next_sig_state;
  115. signal_write <= '0';
  116. signal_a_read <= '0';
  117. signal_b_read <= '0';
  118. case next_sig_state is
  119. when SIG_IDLE =>
  120. if (index = 0) then
  121. current_sig_state <= SIG_ADD;
  122. end if;
  123. when SIG_READ =>
  124. signal_a_read <= '1';
  125. signal_b_read <= '1';
  126. when SIG_ADD =>
  127. signal_add_start <= '1';
  128. when SIG_WRITE =>
  129. signal_add_start <= '0';
  130. signal_write <= '1';
  131. index <= index + 1;
  132. end case;
  133. end if;
  134. end process sync;
  135. task_state <= current_task_state;
  136. end architecture rtl;