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.

test_hardware_task.vhd 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. use work.test_utility.all;
  8. use work.test_avalon_slave.all;
  9. use work.task.all;
  10. package test_hardware_task is
  11. procedure read_state( signal clk : in std_logic;
  12. signal req : out work.avalon_slave.Request;
  13. signal rsp : in work.avalon_slave.Response;
  14. variable state : out std_logic_vector );
  15. procedure assert_state_eq( signal clk : in std_logic;
  16. signal req : out work.avalon_slave.Request;
  17. signal rsp : in work.avalon_slave.Response;
  18. variable state : std_logic_vector );
  19. procedure assert_cycle_count_eq( signal clk : in std_logic;
  20. signal req : out work.avalon_slave.Request;
  21. signal rsp : in work.avalon_slave.Response;
  22. variable cycle_count : std_logic_vector );
  23. procedure write_start( signal clk : in std_logic;
  24. signal req : out work.avalon_slave.Request );
  25. procedure write_config( signal clk : in std_logic;
  26. signal req : out work.avalon_slave.Request;
  27. variable index : in integer;
  28. variable config : in std_logic_vector );
  29. procedure assert_config_eq( signal clk : in std_logic;
  30. signal req : out work.avalon_slave.Request;
  31. signal rsp : in work.avalon_slave.Response;
  32. variable index : in integer;
  33. variable config : in std_logic_vector );
  34. procedure write_and_assert_config_eq( signal clk : in std_logic;
  35. signal req : out work.avalon_slave.Request;
  36. signal rsp : in work.avalon_slave.Response;
  37. variable index : in integer;
  38. variable config : in std_logic_vector );
  39. procedure assert_output_steam_data_eq( signal clk : in std_logic;
  40. signal write : std_logic;
  41. signal writedata : std_logic_vector;
  42. signal expected : work.reg32.RegArray );
  43. procedure test_execute( signal clk : in std_logic;
  44. signal req : out work.avalon_slave.Request;
  45. signal rsp : in work.avalon_slave.Response;
  46. signal write : in std_logic;
  47. signal writedata : in std_logic_vector );
  48. end package test_hardware_task;
  49. package body test_hardware_task is
  50. procedure read_state( signal clk : in std_logic;
  51. signal req : out work.avalon_slave.Request;
  52. signal rsp : in work.avalon_slave.Response;
  53. variable state : out std_logic_vector ) is
  54. variable address : std_logic_vector( 3 downto 0 );
  55. begin
  56. wait until falling_edge( clk );
  57. address := std_logic_vector( to_unsigned( 1, address'length ) );
  58. work.test_avalon_slave.read( clk => clk,
  59. address => address,
  60. req => req,
  61. rsp => rsp,
  62. data => state );
  63. end procedure read_state;
  64. procedure assert_state_eq( signal clk : in std_logic;
  65. signal req : out work.avalon_slave.Request;
  66. signal rsp : in work.avalon_slave.Response;
  67. variable state : std_logic_vector ) is
  68. variable address : std_logic_vector( 3 downto 0 );
  69. begin
  70. wait until falling_edge( clk );
  71. address := std_logic_vector( to_unsigned( 1, address'length ) );
  72. work.test_avalon_slave.assert_readdata_eq( clk => clk,
  73. address => address,
  74. req => req,
  75. rsp => rsp,
  76. expected => state,
  77. message => TEST_FAIL & " assert_state_eq" );
  78. end procedure assert_state_eq;
  79. procedure assert_cycle_count_eq( signal clk : in std_logic;
  80. signal req : out work.avalon_slave.Request;
  81. signal rsp : in work.avalon_slave.Response;
  82. variable cycle_count : std_logic_vector ) is
  83. variable address : std_logic_vector( 3 downto 0 );
  84. begin
  85. wait until falling_edge( clk );
  86. address := std_logic_vector( to_unsigned( 2, address'length ) );
  87. work.test_avalon_slave.assert_readdata_eq( clk => clk,
  88. address => address,
  89. req => req,
  90. rsp => rsp,
  91. expected => cycle_count,
  92. message => TEST_FAIL & " assert_cycle_count_eq" );
  93. end procedure assert_cycle_count_eq;
  94. procedure write_start( signal clk : in std_logic;
  95. signal req : out work.avalon_slave.Request ) is
  96. variable address : std_logic_vector( 3 downto 0 );
  97. variable start : std_logic_vector( 31 downto 0 ) := ( others => '0' );
  98. begin
  99. wait until falling_edge( clk );
  100. address := std_logic_vector( to_unsigned( 0, address'length ) );
  101. work.test_avalon_slave.write( clk => clk,
  102. address => address,
  103. req => req,
  104. data => START );
  105. end procedure write_start;
  106. procedure write_config( signal clk : in std_logic;
  107. signal req : out work.avalon_slave.Request;
  108. variable index : in integer;
  109. variable config : in std_logic_vector ) is
  110. variable address : std_logic_vector( 3 downto 0 );
  111. begin
  112. wait until falling_edge( clk );
  113. address := std_logic_vector( to_unsigned( 3 + index, address'length ) );
  114. work.test_avalon_slave.write( clk => clk,
  115. address => address,
  116. req => req,
  117. data => config );
  118. end procedure write_config;
  119. procedure assert_config_eq( signal clk : in std_logic;
  120. signal req : out work.avalon_slave.Request;
  121. signal rsp : in work.avalon_slave.Response;
  122. variable index : in integer;
  123. variable config : in std_logic_vector ) is
  124. variable address : std_logic_vector( 3 downto 0 );
  125. begin
  126. wait until falling_edge( clk );
  127. address := std_logic_vector( to_unsigned( 3 + index, address'length ) );
  128. work.test_avalon_slave.assert_readdata_eq( clk => clk,
  129. address => address,
  130. req => req,
  131. rsp => rsp,
  132. expected => config,
  133. message => TEST_FAIL & " assert_config_eq" );
  134. end procedure assert_config_eq;
  135. procedure write_and_assert_config_eq( signal clk : in std_logic;
  136. signal req : out work.avalon_slave.Request;
  137. signal rsp : in work.avalon_slave.Response;
  138. variable index : in integer;
  139. variable config : in std_logic_vector ) is
  140. variable address : std_logic_vector( 3 downto 0 );
  141. begin
  142. write_config( clk => clk, req => req, index => index, config => config );
  143. assert_config_eq( clk => clk, req => req, rsp => rsp, index => index, config => config );
  144. end procedure write_and_assert_config_eq;
  145. procedure assert_output_steam_data_eq( signal clk : in std_logic;
  146. signal write : std_logic;
  147. signal writedata : std_logic_vector;
  148. signal expected : work.reg32.RegArray ) is
  149. begin
  150. end procedure assert_output_steam_data_eq;
  151. procedure test_execute( signal clk : in std_logic;
  152. signal req : out work.avalon_slave.Request;
  153. signal rsp : in work.avalon_slave.Response;
  154. signal write : in std_logic;
  155. signal writedata : in std_logic_vector ) is
  156. variable expected_readdata : std_logic_vector( 31 downto 0 );
  157. variable state : std_logic_vector( 31 downto 0 );
  158. variable index : integer := 0;
  159. begin
  160. std.textio.write( std.textio.OUTPUT, " test_execute ... " );
  161. expected_readdata := to_std_logic_vector( TASK_IDLE, expected_readdata'length );
  162. assert_state_eq( clk => clk, req => req, rsp => rsp, state => expected_readdata );
  163. write_start( clk => clk, req => req );
  164. expected_readdata := to_std_logic_vector( TASK_RUNNING, expected_readdata'length );
  165. assert_state_eq( clk => clk, req => req, rsp => rsp, state => expected_readdata );
  166. while true loop
  167. work.test_hardware_task.read_state( clk => clk, req => req, rsp => rsp, state => state );
  168. if ( state = to_std_logic_vector( TASK_DONE, expected_readdata'length ) ) then
  169. exit;
  170. end if;
  171. end loop;
  172. std.textio.write( std.textio.OUTPUT, TEST_OK );
  173. end procedure test_execute;
  174. end package body test_hardware_task;