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.

hardware_timestamp.vhd 2.8KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 timer 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. );
  17. end entity timer;
  18. architecture rtl of timer is
  19. type Registers is (
  20. REG_STATE,
  21. REG_CYCLE_COUNT
  22. );
  23. constant REG_STATE_POS : natural := Registers'pos( REG_STATE );
  24. constant REG_CYCLE_COUNT_POS : natural := Registers'pos( REG_CYCLE_COUNT );
  25. constant REG_COUNT : natural := Registers'pos( Registers'right ) + 1;
  26. constant REG_ACCESS_TYPES : work.reg32.AccessArray( 0 to REG_COUNT - 1 ) := (
  27. READ_WRITE,
  28. READ_ONLY
  29. );
  30. signal reg_index : integer range 0 to REG_COUNT - 1;
  31. signal current_avalon_state : work.avalon_slave.State;
  32. signal next_avalon_state : work.avalon_slave.State;
  33. signal running : std_logic;
  34. signal cycle_count : unsigned( 31 downto 0 );
  35. begin
  36. u_avalon_slave_transitions: entity work.avalon_slave_transitions
  37. generic map (
  38. REG_COUNT => REG_COUNT,
  39. REG_ACCESS_TYPES => REG_ACCESS_TYPES
  40. )
  41. port map (
  42. address => address,
  43. read => read,
  44. write => write,
  45. current_state => current_avalon_state,
  46. next_state => next_avalon_state,
  47. reg_index => reg_index
  48. );
  49. sync : process ( clk, reset ) is
  50. begin
  51. if ( reset = '1' ) then
  52. current_avalon_state <= SLAVE_IDLE;
  53. running <= '0';
  54. elsif ( rising_edge( clk ) ) then
  55. current_avalon_state <= next_avalon_state;
  56. if ( running = '1' ) then
  57. cycle_count <= cycle_count + 1;
  58. end if;
  59. case next_avalon_state is
  60. when SLAVE_IDLE =>
  61. null;
  62. when SLAVE_READ =>
  63. readdata <= ( others => '0' );
  64. if ( reg_index = REG_STATE_POS ) then
  65. readdata( 0 ) <= running;
  66. elsif ( reg_index = REG_CYCLE_COUNT_POS ) then
  67. readdata <= std_logic_vector( cycle_count );
  68. end if;
  69. when SLAVE_READ_DATA =>
  70. null;
  71. when SLAVE_WRITE =>
  72. if ( reg_index = REG_STATE_POS ) then
  73. running <= writedata( 0 );
  74. if ( writedata( 0 ) = '1' ) then
  75. cycle_count <= ( others => '0' );
  76. end if;
  77. end if;
  78. end case;
  79. end if;
  80. end process sync;
  81. end architecture rtl;