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 3.7KB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. signal fpuDone : std_logic;
  26. signal START : std_logic;
  27. type AddState is (
  28. ADD_IDLE,
  29. ADD_SET_SIGNALS,
  30. ADD_RUNNING,
  31. ADD_DONE
  32. );
  33. signal current_add_state : AddState;
  34. signal next_add_state : AddState;
  35. begin
  36. f1:ENTITY work.float_add PORT MAP(CLK => CLK, RESET => RESET, START => START, A => signal_a_readdata, B => signal_b_readdata, done => fpuDone, sum => signal_writedata);
  37. task_state_transitions : process ( current_task_state, task_start, index ) is
  38. begin
  39. next_task_state <= current_task_state;
  40. case current_task_state is
  41. when work.task.TASK_IDLE =>
  42. if ( task_start = '1' ) then
  43. next_task_state <= work.task.TASK_RUNNING;
  44. end if;
  45. when work.task.TASK_RUNNING =>
  46. if ( index = work.task.STREAM_LEN - 1 ) then
  47. next_task_state <= work.task.TASK_DONE;
  48. end if;
  49. when work.task.TASK_DONE =>
  50. if ( task_start = '1' ) then
  51. next_task_state <= work.task.TASK_RUNNING;
  52. end if;
  53. end case;
  54. end process task_state_transitions;
  55. sync : process ( clk, reset ) is
  56. begin
  57. if ( reset = '1' ) then
  58. current_task_state <= work.task.TASK_IDLE;
  59. index <= 0;
  60. elsif ( rising_edge( clk ) ) then
  61. current_task_state <= next_task_state;
  62. case next_task_state is
  63. when work.task.TASK_IDLE =>
  64. index <= 0;
  65. when work.task.TASK_RUNNING =>
  66. if(current_add_state = ADD_DONE) then
  67. index <= index + 1;
  68. end if;
  69. when work.task.TASK_DONE =>
  70. index <= 0;
  71. end case;
  72. end if;
  73. end process sync;
  74. task_state <= current_task_state;
  75. add_state_transitions : process ( current_add_state, fpuDone, current_task_state)
  76. begin
  77. next_add_state <= current_add_state;
  78. case current_add_state is
  79. when ADD_IDLE =>
  80. if(current_task_state = work.task.TASK_RUNNING) then
  81. next_add_state <= ADD_SET_SIGNALS;
  82. end if;
  83. when ADD_SET_SIGNALS =>
  84. next_add_state <= ADD_RUNNING;
  85. when ADD_RUNNING =>
  86. if(fpuDone = '1') then
  87. next_add_state <= ADD_DONE;
  88. end if;
  89. when ADD_DONE =>
  90. next_add_state <= ADD_IDLE;
  91. end case;
  92. end process add_state_transitions;
  93. add : process (clk, reset) is
  94. begin
  95. if ( reset = '1' ) then
  96. current_add_state <= ADD_IDLE;
  97. elsif ( rising_edge( clk ) ) then
  98. current_add_state <= next_add_state;
  99. case next_add_state is
  100. when ADD_IDLE =>
  101. START <= '0';
  102. signal_write <= '0';
  103. when ADD_SET_SIGNALS =>
  104. signal_a_read <= '1';
  105. signal_b_read <= '1';
  106. when ADD_RUNNING =>
  107. signal_a_read <= '0';
  108. signal_b_read <= '0';
  109. START <= '1';
  110. when ADD_DONE =>
  111. START <= '0';
  112. signal_write <= '1';
  113. end case;
  114. end if;
  115. end process add;
  116. end architecture rtl;