Loesung des Praktikums Systementwurf - Bjarne Hoesch - Bernhard Schoeffel
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.4KB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 start_ipcore : std_logic;
  26. signal done_ipcore : std_logic;
  27. signal a_readdata : std_logic_vector(31 downto 0);
  28. signal b_readdata : std_logic_vector(31 downto 0);
  29. signal result : std_logic_vector(31 downto 0);
  30. type CalcState is (
  31. CALC_IDLE,
  32. CALC_READ,
  33. CALC_PROCESS,
  34. CALC_WRITE
  35. );
  36. signal Calc_State : CalcState;
  37. begin
  38. u_float_add: entity work.float_add
  39. port map (
  40. clk => clk,
  41. reset => reset,
  42. start => start_ipcore,
  43. done => done_ipcore,
  44. A => a_readdata,
  45. B => b_readdata,
  46. sum => result
  47. );
  48. task_state_transitions : process ( current_task_state, task_start, index ) is
  49. begin
  50. next_task_state <= current_task_state;
  51. case current_task_state is
  52. when work.task.TASK_IDLE =>
  53. if ( task_start = '1' ) then
  54. next_task_state <= work.task.TASK_RUNNING;
  55. end if;
  56. when work.task.TASK_RUNNING =>
  57. if ( index = work.task.STREAM_LEN ) then
  58. next_task_state <= work.task.TASK_DONE;
  59. end if;
  60. when work.task.TASK_DONE =>
  61. if ( task_start = '1' ) then
  62. next_task_state <= work.task.TASK_RUNNING;
  63. end if;
  64. end case;
  65. end process task_state_transitions;
  66. sync : process ( clk, reset ) is
  67. begin
  68. if ( reset = '1' ) then
  69. current_task_state <= work.task.TASK_IDLE;
  70. Calc_State <= CALC_IDLE;
  71. index <= 0;
  72. elsif ( rising_edge( clk ) ) then
  73. current_task_state <= next_task_state;
  74. case next_task_state is
  75. when work.task.TASK_IDLE =>
  76. index <= 0;
  77. Calc_State <= CALC_IDLE;
  78. signal_write <= '0';
  79. when work.task.TASK_RUNNING =>
  80. case Calc_State is
  81. when CALC_IDLE =>
  82. Calc_State <= CALC_READ;
  83. when CALC_READ =>
  84. signal_write <= '0';
  85. signal_a_read <= '1';
  86. signal_b_read <= '1';
  87. Calc_State <= CALC_PROCESS;
  88. when CALC_PROCESS =>
  89. signal_a_read <= '0';
  90. signal_b_read <= '0';
  91. start_ipcore <= '1';
  92. if(done_ipcore = '1') then
  93. start_ipcore <= '0';
  94. Calc_State <= CALC_WRITE;
  95. end if;
  96. when CALC_WRITE =>
  97. Calc_State <= CALC_READ;
  98. index <= index + 1;
  99. signal_write <= '1';
  100. end case;
  101. when work.task.TASK_DONE =>
  102. index <= 0;
  103. Calc_State <= CALC_IDLE;
  104. signal_write <= '0';
  105. end case;
  106. end if;
  107. end process sync;
  108. signal_writedata <= result;
  109. a_readdata <= signal_a_readdata;
  110. b_readdata <= signal_b_readdata;
  111. task_state <= current_task_state;
  112. end architecture rtl;