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

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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; --signal_read wird als Bestätigung gesetzt, dass die Daten gelesen wurden, d.h. bei der nächsten rising edge werden die nächsten Daten angelegt.
  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. --hier noch einige Signale anlegen
  26. signal done_flag : std_logic;
  27. signal start_flag : std_logic;
  28. --Zustände für die Zustandsmaschine für die Berechnung
  29. type CalcState is (
  30. CALC_IDLE,
  31. CALC_ADD,
  32. CALC_STORE_RESULT
  33. );
  34. --Signale für die Zustandsmaschine für die Berechnung
  35. signal current_calc_state : CalcState;
  36. signal next_calc_state : CalcState;
  37. signal ergebnis : signed( 31 downto 0); --das hier vielleicht zu std_logic_vector oder float
  38. signal ergebnis_valid : std_logic;
  39. begin
  40. u_float_add : entity work.float_add --Das hier ist der IP Core !!!
  41. port map(
  42. clk => clk,
  43. reset => reset,
  44. start => start_flag,
  45. done => done_flag,
  46. A => signal_a_readdata,
  47. B => signal_b_readdata,
  48. sum => signal_writedata
  49. );
  50. --task_state_transitions wird nicht geaendert
  51. --Übergangsschaltnetz der Zustandsmaschine zu Steuerung der Tasks
  52. task_state_transitions : process ( current_task_state, task_start, index ) is
  53. begin
  54. next_task_state <= current_task_state;
  55. case current_task_state is
  56. when work.task.TASK_IDLE =>
  57. if ( task_start = '1' ) then
  58. next_task_state <= work.task.TASK_RUNNING;
  59. end if;
  60. when work.task.TASK_RUNNING =>
  61. if ( index = work.task.STREAM_LEN - 1 ) then
  62. next_task_state <= work.task.TASK_DONE;
  63. end if;
  64. when work.task.TASK_DONE =>
  65. if ( task_start = '1' ) then
  66. next_task_state <= work.task.TASK_RUNNING;
  67. end if;
  68. end case;
  69. end process task_state_transitions;
  70. --Übergangsschaltnetz der Zustandsmaschine für die Berechnung ###Fertig
  71. calc_state_transitions: process (all) is
  72. begin
  73. next_calc_state <= current_calc_state;
  74. case current_calc_state is
  75. when CALC_IDLE=>
  76. if (current_task_state= work.task.TASK_RUNNING) then
  77. next_calc_state <= CALC_ADD;
  78. end if;
  79. when CALC_ADD =>
  80. if (done_flag = '1') then
  81. next_calc_state <= CALC_STORE_RESULT;
  82. end if;
  83. when CALC STORE RESULT =>
  84. next_calc_state <= CALC_IDLE;
  85. end case;
  86. end process calc state transitions;
  87. --Zustandsspeicher und Ausgangsschaltnetz zu der Steuerung der Tasks
  88. task_sync : process (clk, reset) is
  89. begin
  90. if (reset = '1') then
  91. current_task_state <= work.task.TASK_IDLE;
  92. elsif (rising_edge( clk)) then
  93. current_task_state <= next_task_state;
  94. case next_task_state is
  95. when work.task. TASK IDLE => null;
  96. when work.task. TASK_RUNNING => null;
  97. when work.task. TASK_DONE => null;
  98. end case;
  99. end if;
  100. end process task_sync;
  101. --Zustandsspeicher und Ausgangsschaltnetz zu Berechnung
  102. sync : process (clk, reset) is
  103. begin
  104. if (reset = '1') then
  105. index <= 0;
  106. current_calc_state <= CALC_IDLE;
  107. ergebnis <= (others => '0');
  108. ergebnis_valid <= '0';
  109. signal_write <= '0';
  110. signal_writedata <= (others => '0');
  111. elsif (rising_edge( clk)) then
  112. current_calc_state <= next_calc_state;
  113. ergebnis_valid <= '0';
  114. case next_calc_state is
  115. when CALC_IDLE =>
  116. start_flag <= '0';
  117. signal_read <= '0'; --Daten wurden noch nicht verwendet.
  118. signal_write <= '0';
  119. when CALC_ADD => --hier Berechnung mit IP Core?
  120. start_flag <= '1';
  121. when CALC_STORE_RESULT =>
  122. start_flag <= '0';
  123. index <= index + 1;
  124. signal_write <= '1';
  125. --signal_writedata <= std_logic_vector( ergebnis ); --Ergebnis schreiben, ergebnis direkt aus IP Core anschliessen
  126. signal_read <= '1' --mitteilen, dass die Daten gelesen wurden und jetzt neue Daten angelegt werden sollen
  127. end case;
  128. end if;
  129. end process sync;
  130. task_state <= current_task_state;
  131. end architecture rtl;