-- -- utility_package.vhd -- -- Contains useful functions for -- converting between types. -- -- Darren Gould -- Kevin Grant -- Andrew Stanley-Jones -- -- EE 552 Project -- D. Elliott -- -- -- PACKAGE utility_package -- library ieee; use ieee.std_logic_1164.all; package utility_package is function slv_to_natural (slv: in std_logic_vector) return natural; end package; -- -- PACKAGE BODY utility_package -- library ieee; use ieee.std_logic_1164.all; library work; use work.project_package.address_bit_width; package body utility_package is -- This function converts a vector of -- standard logic values into a simple -- numerical value. The vector is -- assumed to represent an unsigned -- number. The method for this was -- derived from an example in the book -- "The Designer's Guide to VHDL" -- (Ashenden, 1996) that used bit vectors. function slv_to_natural (slv: in std_logic_vector) return natural is variable result: natural := 0; variable a_bit: natural; variable bits: bit_vector(slv'range); begin bits := to_bitvector(slv); for i in bits'range loop -- this starts at the LSB, virtually -- shifting the result to the left -- as each bit is added in if bits(i) = '1' then a_bit := 1; else a_bit := 0; end if; result := result + result + a_bit; end loop; return result; end function slv_to_natural; end package body;