Lösung 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.

hardware_task_control.vhd 4.1KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. use work.avalon_slave.all;
  8. entity hardware_task_control is
  9. port (
  10. clk : in std_logic;
  11. reset : in std_logic;
  12. address : in std_logic_vector( 3 downto 0 );
  13. read : in std_logic;
  14. readdata : out std_logic_vector( 31 downto 0 );
  15. write : in std_logic;
  16. writedata : in std_logic_vector( 31 downto 0 );
  17. task_start : out std_logic;
  18. task_state : in work.task.State;
  19. task_config : out work.reg32.RegArray( 0 to 2 )
  20. );
  21. end entity hardware_task_control;
  22. architecture rtl of hardware_task_control is
  23. type Registers is (
  24. REG_START,
  25. REG_STATE,
  26. REG_CYCLE_COUNT,
  27. REG_CONFIG_0,
  28. REG_CONFIG_1,
  29. REG_CONFIG_2
  30. );
  31. constant REG_START_POS : natural := Registers'pos( REG_START );
  32. constant REG_STATE_POS : natural := Registers'pos( REG_STATE );
  33. constant REG_CYCLE_COUNT_POS : natural := Registers'pos( REG_CYCLE_COUNT );
  34. constant REG_CONFIG_0_POS : natural := Registers'pos( REG_CONFIG_0 );
  35. constant REG_CONFIG_1_POS : natural := Registers'pos( REG_CONFIG_1 );
  36. constant REG_CONFIG_2_POS : natural := Registers'pos( REG_CONFIG_2 );
  37. constant REG_COUNT : natural := registers'pos( registers'right ) + 1;
  38. constant REG_ACCESS_TYPES : work.reg32.AccessArray( 0 to REG_COUNT - 1 ) := (
  39. WRITE_ONLY,
  40. READ_ONLY,
  41. READ_ONLY,
  42. READ_WRITE,
  43. READ_WRITE,
  44. READ_WRITE
  45. );
  46. -- Internal control and data signals
  47. signal reg_index : integer range 0 to REG_COUNT - 1;
  48. -- Internal registers
  49. signal current_state : work.avalon_slave.State;
  50. signal next_state : work.avalon_slave.State;
  51. signal reg_data : RegArray( 0 to REG_COUNT - 1 );
  52. signal task_running : std_logic;
  53. begin
  54. u_avalon_slave_transitions: entity work.avalon_slave_transitions
  55. generic map (
  56. REG_COUNT => REG_COUNT,
  57. REG_ACCESS_TYPES => REG_ACCESS_TYPES
  58. )
  59. port map (
  60. address => address,
  61. read => read,
  62. write => write,
  63. current_state => current_state,
  64. next_state => next_state,
  65. reg_index => reg_index
  66. );
  67. sync : process ( clk, reset ) is
  68. begin
  69. if ( reset = '1' ) then
  70. current_state <= SLAVE_IDLE;
  71. reg_data( Registers'pos( REG_CYCLE_COUNT ) ) <= ( others => '0' );
  72. reg_data( Registers'pos( REG_CONFIG_0 ) ) <= ( others => '0' );
  73. elsif ( rising_edge( clk ) ) then
  74. current_state <= next_state;
  75. task_start <= '0';
  76. if ( task_state = work.task.TASK_DONE ) then
  77. task_running <= '0';
  78. end if;
  79. case next_state is
  80. when SLAVE_IDLE =>
  81. null;
  82. when SLAVE_READ =>
  83. readdata <= ( others => '0' );
  84. if ( reg_index = REG_STATE_POS ) then
  85. readdata <= to_std_logic_vector( task_state, work.reg32.word'length );
  86. elsif ( reg_index = REG_CYCLE_COUNT_POS ) then
  87. readdata <= reg_data( REG_CYCLE_COUNT_POS );
  88. else
  89. readdata <= reg_data( reg_index );
  90. end if;
  91. when SLAVE_READ_DATA =>
  92. null;
  93. when SLAVE_WRITE =>
  94. if ( reg_index = REG_START_POS ) then
  95. task_start <= '1';
  96. reg_data( REG_CYCLE_COUNT_POS ) <= ( others => '0' );
  97. task_running <= '1';
  98. else
  99. reg_data( reg_index ) <= writedata;
  100. end if;
  101. end case;
  102. if ( task_running = '1' ) then
  103. reg_data( REG_CYCLE_COUNT_POS ) <=
  104. std_logic_vector(
  105. unsigned(
  106. reg_data( REG_CYCLE_COUNT_POS ) ) + 1 );
  107. end if;
  108. end if;
  109. end process sync;
  110. task_config <= reg_data( REG_CONFIG_0_POS to REG_CONFIG_2_POS );
  111. end architecture rtl;