
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.MATH_REAL.ALL;
use ieee.numeric_std.all;

library ieee_proposed;
use ieee_proposed.fixed_float_types.all;
use ieee_proposed.fixed_pkg.all;

library work;
use work.utils_pkg.all;
use work.fixed_util_pkg.all;
use work.filter_pkg.all;

-------------------------------------------------------------------------------
package fir_iterative_pkg is
	
	type fir_iterative_mode_t is (normal, symmetric);

	function taps_nbits(ntaps : integer; mode : fir_iterative_mode_t) return integer;
	function ntaps_addr(ntaps : integer; mode : fir_iterative_mode_t) return integer;
	
end; -- package fir_iterative_pkg;

-------------------------------------------------------------------------------
package body fir_iterative_pkg is

	function taps_nbits(ntaps : integer; mode : fir_iterative_mode_t) return integer is
	variable res : integer;
	begin
		res := integer(NextExpBaseTwo(real(ntaps_addr(ntaps, mode))));
		return res;
	end taps_nbits;	
	
	function ntaps_addr(ntaps : integer; mode : fir_iterative_mode_t) return integer is
	constant ntaps_is_even : boolean := (ntaps mod 2) = 0;
	variable res : integer := ntaps;
	begin
		if mode = symmetric then
			if ntaps_is_even then
				res := ntaps/2;
			else
				res := (ntaps-1)/2 + 1;
			end if;	
		end if;	
		return res;
	end ntaps_addr;	

end; -- package fir_iterative_pkg;

-------------------------------------------------------------------------------
