Skip to content
Snippets Groups Projects
Commit bf6d1bba authored by Eric Kooistra's avatar Eric Kooistra
Browse files

Added pack_complex() and unpack_complex_re()/im() functions.

parent 43c6e607
No related branches found
No related tags found
1 merge request!198Clarified reading one WPFB unit into sp_subband_powers_arr2. Updated comments....
Pipeline #24503 passed
...@@ -139,6 +139,9 @@ PACKAGE common_pkg IS ...@@ -139,6 +139,9 @@ PACKAGE common_pkg IS
TYPE t_natural_2arr_2 IS ARRAY (INTEGER RANGE <>) OF t_natural_arr(1 DOWNTO 0); TYPE t_natural_2arr_2 IS ARRAY (INTEGER RANGE <>) OF t_natural_arr(1 DOWNTO 0);
TYPE t_complex_integer_arr2 IS ARRAY (NATURAL RANGE <>) OF t_integer_arr(1 DOWNTO 0);
TYPE t_complex_real_arr2 IS ARRAY (NATURAL RANGE <>) OF t_real_arr(1 DOWNTO 0);
-- STRUCTURE DECLARATIONS --------------------------------------------------- -- STRUCTURE DECLARATIONS ---------------------------------------------------
-- Clock and Reset -- Clock and Reset
...@@ -201,6 +204,12 @@ PACKAGE common_pkg IS ...@@ -201,6 +204,12 @@ PACKAGE common_pkg IS
FUNCTION not_int(n: IN INTEGER) RETURN INTEGER; -- if 0 then return 1 else 0 FUNCTION not_int(n: IN INTEGER) RETURN INTEGER; -- if 0 then return 1 else 0
FUNCTION pack_complex(re, im : INTEGER; w : NATURAL) RETURN INTEGER; -- pack order: im & re
FUNCTION unpack_complex_re(data : INTEGER; w : NATURAL) RETURN INTEGER; -- pack order: im & re
FUNCTION unpack_complex_re(data : STD_LOGIC_VECTOR; w : NATURAL) RETURN INTEGER; -- pack order: im & re
FUNCTION unpack_complex_im(data : INTEGER; w : NATURAL) RETURN INTEGER; -- pack order: im & re
FUNCTION unpack_complex_im(data : STD_LOGIC_VECTOR; w : NATURAL) RETURN INTEGER; -- pack order: im & re
FUNCTION to_natural_arr(n : t_integer_arr; to_zero : BOOLEAN) RETURN t_natural_arr; -- if to_zero=TRUE then negative numbers are forced to zero, otherwise they will give a compile range error FUNCTION to_natural_arr(n : t_integer_arr; to_zero : BOOLEAN) RETURN t_natural_arr; -- if to_zero=TRUE then negative numbers are forced to zero, otherwise they will give a compile range error
FUNCTION to_natural_arr(n : t_nat_natural_arr) RETURN t_natural_arr; FUNCTION to_natural_arr(n : t_nat_natural_arr) RETURN t_natural_arr;
FUNCTION to_integer_arr(n : t_natural_arr) RETURN t_integer_arr; FUNCTION to_integer_arr(n : t_natural_arr) RETURN t_integer_arr;
...@@ -711,6 +720,43 @@ PACKAGE BODY common_pkg IS ...@@ -711,6 +720,43 @@ PACKAGE BODY common_pkg IS
RETURN sel_a_b(n = 0, 1, 0); RETURN sel_a_b(n = 0, 1, 0);
END; END;
FUNCTION pack_complex(re, im : INTEGER; w : NATURAL) RETURN INTEGER IS
CONSTANT c_complex_w : NATURAL := 2 * w;
CONSTANT c_complex_slv : STD_LOGIC_VECTOR(c_complex_w-1 DOWNTO 0) := TO_SVEC(im, w) & TO_SVEC(re, w);
BEGIN
ASSERT c_complex_w <= c_word_w REPORT "common_pkg: Complex value to large to pack into 32 bit integer" SEVERITY FAILURE;
IF c_complex_w < c_word_w THEN -- fits in 31 bit unsigned NATURAL
RETURN TO_UINT(c_complex_slv);
ELSE -- need to use 32 bit signed INTEGER
RETURN TO_SINT(c_complex_slv);
END IF;
END;
FUNCTION unpack_complex_re(data : STD_LOGIC_VECTOR; w : NATURAL) RETURN INTEGER IS
BEGIN
RETURN TO_SINT(data(w-1 DOWNTO 0)); -- Re in LS part
END;
FUNCTION unpack_complex_re(data : INTEGER; w : NATURAL) RETURN INTEGER IS
CONSTANT c_complex_w : NATURAL := 2 * w;
CONSTANT c_complex_slv : STD_LOGIC_VECTOR(c_complex_w-1 DOWNTO 0) := TO_SVEC(data, c_complex_w);
BEGIN
RETURN TO_SINT(c_complex_slv(w-1 DOWNTO 0)); -- Re in LS part
END;
FUNCTION unpack_complex_im(data : STD_LOGIC_VECTOR; w : NATURAL) RETURN INTEGER IS
BEGIN
RETURN TO_SINT(data(2*w-1 DOWNTO w)); -- Im in MS part
END;
FUNCTION unpack_complex_im(data : INTEGER; w : NATURAL) RETURN INTEGER IS
CONSTANT c_complex_w : NATURAL := 2 * w;
CONSTANT c_complex_slv : STD_LOGIC_VECTOR(c_complex_w-1 DOWNTO 0) := TO_SVEC(data, c_complex_w);
BEGIN
RETURN TO_SINT(c_complex_slv(c_complex_w-1 DOWNTO w)); -- Im in MS part
END;
FUNCTION to_natural_arr(n : t_integer_arr; to_zero : BOOLEAN) RETURN t_natural_arr IS FUNCTION to_natural_arr(n : t_integer_arr; to_zero : BOOLEAN) RETURN t_natural_arr IS
VARIABLE vN : t_integer_arr(n'LENGTH-1 DOWNTO 0); VARIABLE vN : t_integer_arr(n'LENGTH-1 DOWNTO 0);
VARIABLE vR : t_natural_arr(n'LENGTH-1 DOWNTO 0); VARIABLE vR : t_natural_arr(n'LENGTH-1 DOWNTO 0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment