我正在创建一个具有多个定义的包,类似于以下内容
-- Control Register Address Type Declaration
SUBTYPE ctrl_reg_addr_type IS std_logic_vector( ADDR_BITS-1 DOWNTO 0 );
-- Control Register Data Type Declaration
SUBTYPE ctrl_reg_data_type IS std_logic_vector( DATA_BITS-1 DOWNTO 0 );
-- Control Register Type Declaration
SUBTYPE ctrl_reg_word_type IS std_logic_vector( CTRL_BITS-1 DOWNTO 0 );
-- Left/Right Line-In Control Type Declarations
CONSTANT LINE_IN_VOL_BITS : integer := 5;
SUBTYPE line_in_volume_type IS natural
RANGE 0 TO ( 2**LINE_IN_VOL_BITS )-1;
TYPE line_in_ctrl_type IS RECORD
-- Left/Right Channel Line Input Volume (4:0)
-- Registers: LINVOL/RINVOL
-- 0x1F = +12.0dB
-- ... = 1.5dB steps
-- 0x00 = -34.5dB
-- 0x17 - 0dB (Default)
volume : std_logic_vector( LINE_IN_VOL_BITS-1 DOWNTO 0 );
-- Left/Right Channel Line Input Mute to ADC (7)
-- Registers: LINMUTE/RINMUTE
-- 0x1 = Enable Mute
-- 0x0 = Disable Mute
mute : std_logic;
-- Left/Right Channel Line Input Volume and Mute Load (8)
-- Registers: LRINBOTH/RLINBOTH
-- 0x1 = Enable Simultaneous Load of LINVOL/LINMUTE <-> RINVOL/RINMUTE
-- 0x0 = Disable Simultaneous Load
both : std_logic;
END RECORD line_in_ctrl_type;
我想使用类似于以下的函数来修改记录类型中的字段。
-- Left/Right Line-In Increase Volume Function Body
FUNCTION increase_volume( ctrl : line_in_ctrl_type )
RETURN line_in_ctrl_type IS
VARIABLE volume : line_in_volume_type := 0;
VARIABLE tmp : line_in_ctrl_type;
BEGIN
tmp := ctrl;
volume := natural( to_integer( unsigned( ctrl.volume ) ) );
IF ( volume < line_in_volume_type'HIGH ) THEN
volume := volume + 1;
tmp.volume := std_logic_vector(
to_unsigned( volume, LINE_IN_VOL_BITS ) );
END IF;
RETURN ( tmp );
END FUNCTION increase_volume;
-- Left/Right Line-In Increase Volume Function Body
FUNCTION increase_volume( ctrl : line_in_ctrl_type;
step : natural )
RETURN line_in_ctrl_type IS
VARIABLE volume : line_in_volume_type := 0;
VARIABLE tmp : line_in_ctrl_type;
BEGIN
tmp := ctrl;
volume := natural( to_integer( unsigned( ctrl.volume ) ) );
IF ( volume < ( line_in_volume_type'HIGH - step ) ) THEN
volume := volume + step;
tmp.volume := std_logic_vector(
to_unsigned( volume, LINE_IN_VOL_BITS ) );
ELSE
tmp := increase_volume( tmp );
END IF;
RETURN ( tmp );
END FUNCTION increase_volume;
我的问题是,将使用类似于所示示例的函数,使用比显式修改记录值更多的 LE。