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.

data_channel_control.vhd 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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.avalon_slave.all;
  7. entity data_channel_control is
  8. port (
  9. clk : in std_logic;
  10. reset : in std_logic;
  11. address : in std_logic_vector( 3 downto 0 );
  12. read : in std_logic;
  13. readdata : out std_logic_vector( 31 downto 0 );
  14. write : in std_logic;
  15. writedata : in std_logic_vector( 31 downto 0 );
  16. sink_config : out std_logic;
  17. source_config : out std_logic;
  18. clear : out std_logic;
  19. empty : in std_logic;
  20. full : in std_logic;
  21. level : in std_logic_vector( 9 downto 0 );
  22. sink_write : out std_logic;
  23. sink_writedata : out std_logic_vector( 31 downto 0 );
  24. source_read : out std_logic;
  25. source_readdata : in std_logic_vector( 31 downto 0 )
  26. );
  27. end entity data_channel_control;
  28. architecture rtl of data_channel_control is
  29. type Registers is (
  30. REG_CONFIG,
  31. REG_EMPTY,
  32. REG_FULL,
  33. REG_LEVEL,
  34. REG_SINK,
  35. REG_SOURCE,
  36. REG_CLEAR
  37. );
  38. constant REG_CONFIG_POS : natural := Registers'pos( REG_CONFIG );
  39. constant REG_EMPTY_POS : natural := Registers'pos( REG_EMPTY );
  40. constant REG_FULL_POS : natural := Registers'pos( REG_FULL );
  41. constant REG_LEVEL_POS : natural := Registers'pos( REG_LEVEL );
  42. constant REG_SINK_POS : natural := Registers'pos( REG_SINK );
  43. constant REG_SOURCE_POS : natural := Registers'pos( REG_SOURCE );
  44. constant REG_CLEAR_POS : natural := Registers'pos( REG_CLEAR );
  45. constant REG_COUNT : natural := registers'pos( registers'right ) + 1;
  46. constant REG_ACCESS_TYPES : work.reg32.AccessArray( 0 to REG_COUNT - 1 ) := (
  47. READ_WRITE,
  48. READ_ONLY,
  49. READ_ONLY,
  50. READ_ONLY,
  51. WRITE_ONLY,
  52. READ_ONLY,
  53. WRITE_ONLY
  54. );
  55. signal reg_index : integer range 0 to REG_COUNT - 1;
  56. -- Internal registers
  57. signal current_state : work.avalon_slave.State;
  58. signal next_state : work.avalon_slave.State;
  59. signal reg_data : RegArray( 0 to REG_COUNT - 1 );
  60. signal fifo_read_req : std_logic;
  61. begin
  62. u_avalon_slave_transitions: entity work.avalon_slave_transitions
  63. generic map (
  64. REG_COUNT => REG_COUNT,
  65. REG_ACCESS_TYPES => REG_ACCESS_TYPES
  66. )
  67. port map (
  68. address => address,
  69. read => read,
  70. write => write,
  71. current_state => current_state,
  72. next_state => next_state,
  73. reg_index => reg_index
  74. );
  75. sync : process ( clk, reset ) is
  76. begin
  77. if ( reset = '1' ) then
  78. current_state <= SLAVE_IDLE;
  79. reg_data( REG_CONFIG_POS ) <= ( others => '0' );
  80. fifo_read_req <= '0';
  81. clear <= '0';
  82. elsif ( rising_edge( clk ) ) then
  83. current_state <= next_state;
  84. sink_write <= '0';
  85. source_read <= '0';
  86. clear <= '0';
  87. case next_state is
  88. when SLAVE_IDLE =>
  89. null;
  90. when SLAVE_READ =>
  91. readdata <= ( others => '0' );
  92. if ( reg_index = REG_CONFIG_POS ) then
  93. readdata( 1 downto 0 ) <= reg_data( reg_index )( 1 downto 0 );
  94. elsif ( reg_index = REG_EMPTY_POS ) then
  95. readdata( 0 ) <= reg_data( reg_index )( 0 );
  96. elsif ( reg_index = REG_FULL_POS ) then
  97. readdata( 0 ) <= reg_data( reg_index )( 0 );
  98. elsif ( reg_index = REG_LEVEL_POS ) then
  99. readdata( 9 downto 0 ) <= reg_data( reg_index )( 9 downto 0 );
  100. elsif ( reg_index = REG_SINK_POS ) then
  101. readdata <= reg_data( reg_index );
  102. elsif ( reg_index = REG_SOURCE_POS ) then
  103. readdata <= source_readdata;
  104. source_read <= '1';
  105. end if;
  106. when SLAVE_READ_DATA =>
  107. null;
  108. when SLAVE_WRITE =>
  109. if ( reg_index = REG_SINK_POS ) then
  110. sink_write <= '1';
  111. sink_writedata <= writedata;
  112. elsif ( reg_index = REG_CLEAR_POS ) then
  113. clear <= '1';
  114. else
  115. reg_data( reg_index ) <= writedata;
  116. end if;
  117. end case;
  118. reg_data( REG_EMPTY_POS )( 0 ) <= empty;
  119. reg_data( REG_FULL_POS )( 0 ) <= full;
  120. reg_data( REG_LEVEL_POS )( level'left downto level'right ) <= level;
  121. end if;
  122. end process sync;
  123. sink_config <= reg_data( REG_CONFIG_POS )( 0 );
  124. source_config <= reg_data( REG_CONFIG_POS )( 1 );
  125. end architecture rtl;