From 500f41f4b7294995e49b2c50f1cabccd46f9f153 Mon Sep 17 00:00:00 2001 From: tmeissner Date: Mon, 1 Dec 2014 23:52:43 +0100 Subject: [PATCH] add init() procedure to t_list_queue type to configure the maximal depth of the linked-list queue --- sim/QueueP.vhd | 18 ++++++++++-------- test/QueueT.vhd | 14 ++++++++++++-- test/SimT.vhd | 8 ++++++++ test/SpiT.vhd | 16 ++++++++++++++++ test/WishBoneT.vhd | 7 +++++++ 5 files changed, 53 insertions(+), 10 deletions(-) diff --git a/sim/QueueP.vhd b/sim/QueueP.vhd index 34b120a..d6f2e4e 100644 --- a/sim/QueueP.vhd +++ b/sim/QueueP.vhd @@ -30,7 +30,7 @@ package QueueP is procedure push (data : in std_logic_vector); procedure pop (data : inout std_logic_vector); - procedure logging (logging : in boolean); + procedure init (depth : in natural; logging : in boolean := false); impure function is_empty return boolean; impure function is_full return boolean; impure function fillstate return natural; @@ -112,7 +112,8 @@ package body QueueP is -- linked liste queue implementation type t_list_queue is protected body - constant C_QUEUE_DEPTH : natural := 64; + + variable v_queue_depth : natural := 0; constant C_QUEUE_WIDTH : natural := 8; type t_entry; @@ -126,7 +127,7 @@ package body QueueP is variable v_head : t_entry_ptr; variable v_tail : t_entry_ptr; - variable v_count : natural range 0 to C_QUEUE_DEPTH := 0; + variable v_count : natural := 0; variable v_logging : boolean := false; -- write one entry into queue by @@ -167,10 +168,11 @@ package body QueueP is end if; end procedure pop; - procedure logging (logging : in boolean) is + procedure init (depth : in natural; logging : in boolean := false) is begin - v_logging := logging; - end procedure logging; + v_queue_depth := depth; + v_logging := logging; + end procedure init; -- returns true if queue is empty, false otherwise impure function is_empty return boolean is @@ -181,7 +183,7 @@ package body QueueP is -- returns true if queue is full, false otherwise impure function is_full return boolean is begin - return v_count = C_QUEUE_DEPTH; + return v_count = v_queue_depth; end function is_full; -- returns number of filled slots in queue @@ -193,7 +195,7 @@ package body QueueP is -- returns number of free slots in queue impure function freeslots return natural is begin - return C_QUEUE_DEPTH - v_count; + return v_queue_depth - v_count; end function freeslots; end protected body t_list_queue; diff --git a/test/QueueT.vhd b/test/QueueT.vhd index 643f683..742e54d 100644 --- a/test/QueueT.vhd +++ b/test/QueueT.vhd @@ -16,6 +16,8 @@ end entity QueueT; architecture sim of QueueT is + constant C_QUEUE_DEPTH : natural := 64; + shared variable sv_simple_queue : t_simple_queue; shared variable sv_list_queue : t_list_queue; @@ -23,6 +25,14 @@ architecture sim of QueueT is begin + QueueInitP : process is + begin + sv_list_queue.init(C_QUEUE_DEPTH); + wait; + end process QueueInitP; + + + SimpleQueueTestP : process is variable v_data : std_logic_vector(63 downto 0); begin @@ -50,13 +60,13 @@ begin begin -- check initial emptiness assert_true(sv_list_queue.is_empty, "Queue should be empty!"); - for i in 0 to 63 loop + for i in 0 to C_QUEUE_DEPTH-1 loop sv_list_queue.push(std_logic_vector(to_unsigned(i, 8))); end loop; -- check that it's full assert_true(sv_list_queue.is_full, "Queue should be full!"); -- empty the queue - for i in 0 to 63 loop + for i in 0 to C_QUEUE_DEPTH-1 loop sv_list_queue.pop(v_data); assert_equal(v_data, std_logic_vector(to_unsigned(i, 8))); end loop; diff --git a/test/SimT.vhd b/test/SimT.vhd index d2d34ef..cc523a1 100644 --- a/test/SimT.vhd +++ b/test/SimT.vhd @@ -53,6 +53,14 @@ begin s_clk <= not(s_clk) after C_PERIOD when not(and_reduce(s_tests_done)) else '0'; + QueueInitP : process is + begin + sv_mosi_queue.init(32); + sv_miso_queue.init(32); + wait; + end process QueueInitP; + + SimTestP : process is variable v_time : time; begin diff --git a/test/SpiT.vhd b/test/SpiT.vhd index 2609435..72c9ad4 100644 --- a/test/SpiT.vhd +++ b/test/SpiT.vhd @@ -137,6 +137,14 @@ begin begin + QueueInitP : process is + begin + sv_mosi_queue.init(32); + sv_miso_queue.init(32); + wait; + end process QueueInitP; + + --* Stimuli generator and BFM for the valid-accept interface --* on the local data input of the DUT --* @@ -288,6 +296,14 @@ begin begin + QueueInitP : process is + begin + sv_mosi_queue.init(32); + sv_miso_queue.init(32); + wait; + end process QueueInitP; + + --* Unit test of spi master procedure, checks all combinations --* of cpol & cpha against spi slave procedure SpiMasterP : process is diff --git a/test/WishBoneT.vhd b/test/WishBoneT.vhd index cce740b..09e37b9 100644 --- a/test/WishBoneT.vhd +++ b/test/WishBoneT.vhd @@ -139,6 +139,13 @@ begin s_wb_reset <= '0' after C_PERIOD * 5; + QueueInitP : process is + begin + sv_wishbone_queue.init(2**C_ADDRESS_WIDTH); + wait; + end process QueueInitP; + + WbMasterLocalP : process is variable v_random : RandomPType; variable v_wbmaster_data : std_logic_vector(C_DATA_WIDTH-1 downto 0);