Library of reusable VHDL components
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.

73 lines
1.7 KiB

  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. library osvvm;
  5. use osvvm.RandomPkg.all;
  6. library libvhdl;
  7. use libvhdl.AssertP.all;
  8. entity StackT is
  9. end entity StackT;
  10. architecture sim of StackT is
  11. constant C_STACK_DEPTH : natural := 64;
  12. package SlvStack is new libvhdl.StackP
  13. generic map (
  14. STACK_TYPE => std_logic_vector(63 downto 0),
  15. MAX_LEN => C_STACK_DEPTH,
  16. to_string => to_hstring
  17. );
  18. shared variable sv_stack : SlvStack.t_stack;
  19. begin
  20. StackInitP : process is
  21. begin
  22. sv_stack.init(false);
  23. wait;
  24. end process StackInitP;
  25. StackTestP : process is
  26. variable v_data : std_logic_vector(63 downto 0);
  27. variable v_random : RandomPType;
  28. type t_scoreboard is array (natural range <>) of std_logic_vector(63 downto 0);
  29. variable v_scoreboard : t_scoreboard(0 to C_STACK_DEPTH-1);
  30. begin
  31. -- Check initial emptiness
  32. assert_true(sv_stack.is_empty, "Stack should be empty!");
  33. -- Fill stack
  34. v_random.InitSeed(v_random'instance_name);
  35. for i in 0 to C_STACK_DEPTH-1 loop
  36. v_data := v_random.RandSlv(64);
  37. v_scoreboard(i) := v_data;
  38. sv_stack.push(v_data);
  39. end loop;
  40. -- Check that it's full
  41. assert_true(sv_stack.is_full, "Stack should be full!");
  42. -- Check number of entries
  43. assert_equal(sv_stack.fillstate, C_STACK_DEPTH, "Stack should have" & integer'image(C_STACK_DEPTH) & "entries");
  44. -- Empty the stack
  45. for i in C_STACK_DEPTH-1 downto 0 loop
  46. sv_stack.pop(v_data);
  47. assert_equal(v_data, v_scoreboard(i));
  48. end loop;
  49. -- Check emptiness
  50. assert_true(sv_stack.is_empty, "Stack should be empty!");
  51. report "INFO: t_stack test finished successfully";
  52. wait;
  53. end process StackTestP;
  54. end architecture sim;