2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_arith.all;
4 use ieee.std_logic_signed.all;
6 --------------------------------------------------------------------------------
10 IRF_ADR_W : integer := 5;
12 SCALE_OFF : integer := 5;
13 PHASE_BASE : integer := 16;
14 VECTOR_OFF : integer := 0;
15 SCALED_OFF : integer := 1;
16 VECTOR_W : integer := 10);
18 -- Primary slave intefrace
19 ACK_O : out std_logic;
23 -- Multiplier interface
24 MUL_A : out std_logic_vector (15 downto 0);
25 MUL_B : out std_logic_vector (15 downto 0);
26 MUL_PROD : in std_logic_vector (31 downto 0);
27 -- Shared dual-port memory
28 IRF_ACK_I : in std_logic;
29 IRF_ADR_O : out std_logic_vector (IRF_ADR_W-1 downto 0);
30 IRF_DAT_I : in std_logic_vector (15 downto 0);
31 IRF_DAT_O : out std_logic_vector (15 downto 0);
32 IRF_STB_O : out std_logic := '0';
33 IRF_WE_O : out std_logic := '0');
34 end entity vector_scale;
36 --------------------------------------------------------------------------------
38 architecture behavioral of vector_scale is
40 constant SCALE_SUBDIV : integer := 10;
42 type state_t is (ready, load_scale, load_vector, save_scaled, done);
43 subtype irf_adr_t is std_logic_vector (IRF_ADR_W-1 downto 0);
45 constant SCALE_ADR : irf_adr_t := conv_std_logic_vector(BASE + SCALE_OFF, IRF_ADR_W);
46 constant VECTOR_ADR : irf_adr_t := conv_std_logic_vector(PHASE_BASE + VECTOR_OFF, IRF_ADR_W);
47 constant SCALED_ADR : irf_adr_t := conv_std_logic_vector(PHASE_BASE + SCALED_OFF, IRF_ADR_W);
49 signal state : state_t := ready;
51 signal INNER_ACK : std_logic := '0';
54 function twos_to_biased (twos : std_logic_vector) return std_logic_vector is
55 variable result : std_logic_vector (twos'RANGE);
58 result(result'HIGH) := not twos(twos'HIGH);
62 function biased_to_twos (biased : std_logic_vector) return std_logic_vector is
63 variable result : std_logic_vector (biased'range);
66 result(result'HIGH) := not biased(biased'HIGH);
70 --------------------------------------------------------------------------------
74 ACK_O <= STB_I and INNER_ACK;
76 IRF_DAT_O <= "000000" & twos_to_biased(conv_std_logic_vector(signed(MUL_PROD(15+SCALE_SUBDIV downto SCALE_SUBDIV)), 10));
79 FSM : process (CLK_I, RST_I) is
81 if rising_edge(CLK_I) then
93 IRF_ADR_O <= SCALE_ADR;
99 IRF_ADR_O <= VECTOR_ADR;
102 state <= save_scaled;
103 IRF_ADR_O <= SCALED_ADR;
110 MUL_B <= conv_std_logic_vector(signed(biased_to_twos(IRF_DAT_I(VECTOR_W-1 downto 0))), 16);
124 end architecture behavioral;