初始化整数数组

Initialize array of integer

我有关于整数初始化的问题。

package mytypes is
    type gamma_cor_array is array (NATURAL RANGE <>) of integer range 15 downto 0;
end mytypes;

library UNISIM;
use UNISIM.VComponents.all;
use work.mytypes.all;

entity gamma_correction is
    GENERIC (DEPH : natural:=4; GAMMA_COR : real:=1.0);
    Port ( clk : in  STD_LOGIC;
        gamma_cor_array_s : out gamma_cor_array(2**DEPH-1 downto 0):= (others => 0));

end gamma_correction;

architecture Behavioral of gamma_correction is

begin
    PROCESS (clk) BEGIN
        IF rising_edge(clk) THEN
            for i in 0 to (2**DEPH - 1) loop
                gamma_cor_array_s(i) <= integer(((real(i)/real(2**DEPH - 1))**GAMMA_COR)*real(2**DEPH - 1));
            end loop;
        end if;
    end process;
end Behavioral;

我收到这些警告:

WARNING:Xst:2404 - FFs/Latches <1:1>> (without init value) have a constant value of 0 in block .

WARNING:Xst:2404 - FFs/Latches <1:2>> (without init value) have a constant value of 0 in block .

WARNING:Xst:2404 - FFs/Latches <1:2>> (without init value) have a constant value of 0 in block .

WARNING:Xst:2404 - FFs/Latches <1:2>> (without init value) have a constant value of 0 in block .

WARNING:Xst:2404 - FFs/Latches <3:3>> (without init value) have a constant value of 0 in block .

WARNING:Xst:2404 - FFs/Latches <1:3>> (without init value) have a constant value of 0 in block .

WARNING:Xst:2404 - FFs/Latches <1:4>> (without init value) have a constant value of 0 in block .

在测试台中,我的代码运行正常。初始值为 0,但警告仍然存在。我怎样才能摆脱它们?

为什么 gamma_cor_array_s class 不是常量? GAMMA_CORDEPH 一样是 class 常数,你不需要触发器,写一个函数来初始化 gamma_cor_s 使用它的地方,不要使用 entity/architecture对.

因为 gamma_cor_s 的值是 (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15) 在 rising_edge (clk) 之后:

library ieee;
use ieee.std_logic_1164.all;
use work.mytypes.all;  -- type gamma_cor_array

entity gam_cor_tb is
end entity;
architecture foo of gam_cor_tb is
    signal clk: std_logic := '0';
    constant DEPH:  natural := 4;
    constant GAMMA_COR: real := 1.0;
    signal gamma_cor_array_s:  
                gamma_cor_array (2 ** DEPH - 1 downto 0) ;
begin
CLOCK:
    process
    begin
        wait for 10 ns;
        clk <= not clk;
        wait for 10 ns;
        wait;   -- one ping only
    end process;
DUT:
    entity work.gamma_correction
        generic map (
            DEPH => DEPH,
            GAMMA_COR => GAMMA_COR
        )
        port map (
            clk => clk,
            gamma_cor_array_s => gamma_cor_array_s
        );
MONITOR:
    process (gamma_cor_array_s)
    begin
        for i in 0 to (2 ** DEPH - 1) loop
            report "gamma_cor_array_s(" & integer'image(i) & ") = " &
                    integer'image(gamma_cor_array_s(i));
        end loop;
    end process;
end architecture;

结果:

gamma_corrections.vhdl:75:13:@0ms:(report note): gamma_cor_array_s(0) = 0 gamma_corrections.vhdl:75:13:@0ms:(report note): gamma_cor_array_s(1) = 0 gamma_corrections.vhdl:75:13:@0ms:(report note): gamma_cor_array_s(2) = 0 gamma_corrections.vhdl:75:13:@0ms:(report note): gamma_cor_array_s(3) = 0 gamma_corrections.vhdl:75:13:@0ms:(report note): gamma_cor_array_s(4) = 0 gamma_corrections.vhdl:75:13:@0ms:(report note): gamma_cor_array_s(5) = 0 gamma_corrections.vhdl:75:13:@0ms:(report note): gamma_cor_array_s(6) = 0 gamma_corrections.vhdl:75:13:@0ms:(report note): gamma_cor_array_s(7) = 0 gamma_corrections.vhdl:75:13:@0ms:(report note): gamma_cor_array_s(8) = 0 gamma_corrections.vhdl:75:13:@0ms:(report note): gamma_cor_array_s(9) = 0 gamma_corrections.vhdl:75:13:@0ms:(report note): gamma_cor_array_s(10) = 0 gamma_corrections.vhdl:75:13:@0ms:(report note): gamma_cor_array_s(11) = 0 gamma_corrections.vhdl:75:13:@0ms:(report note): gamma_cor_array_s(12) = 0 gamma_corrections.vhdl:75:13:@0ms:(report note): gamma_cor_array_s(13) = 0 gamma_corrections.vhdl:75:13:@0ms:(report note): gamma_cor_array_s(14) = 0 gamma_corrections.vhdl:75:13:@0ms:(report note): gamma_cor_array_s(15) = 0 gamma_corrections.vhdl:75:13:@10ns:(report note): gamma_cor_array_s(0) = 0 gamma_corrections.vhdl:75:13:@10ns:(report note): gamma_cor_array_s(1) = 1 gamma_corrections.vhdl:75:13:@10ns:(report note): gamma_cor_array_s(2) = 2 gamma_corrections.vhdl:75:13:@10ns:(report note): gamma_cor_array_s(3) = 3 gamma_corrections.vhdl:75:13:@10ns:(report note): gamma_cor_array_s(4) = 4 gamma_corrections.vhdl:75:13:@10ns:(report note): gamma_cor_array_s(5) = 5 gamma_corrections.vhdl:75:13:@10ns:(report note): gamma_cor_array_s(6) = 6 gamma_corrections.vhdl:75:13:@10ns:(report note): gamma_cor_array_s(7) = 7 gamma_corrections.vhdl:75:13:@10ns:(report note): gamma_cor_array_s(8) = 8 gamma_corrections.vhdl:75:13:@10ns:(report note): gamma_cor_array_s(9) = 9 gamma_corrections.vhdl:75:13:@10ns:(report note): gamma_cor_array_s(10) = 10 gamma_corrections.vhdl:75:13:@10ns:(report note): gamma_cor_array_s(11) = 11 gamma_corrections.vhdl:75:13:@10ns:(report note): gamma_cor_array_s(12) = 12 gamma_corrections.vhdl:75:13:@10ns:(report note): gamma_cor_array_s(13) = 13 gamma_corrections.vhdl:75:13:@10ns:(report note): gamma_cor_array_s(14) = 14 gamma_corrections.vhdl:75:13:@10ns:(report note): gamma_cor_array_s(15) = 15

您声明了 64 个触发器,将它们初始化为全“0”,并且只有 30 个被更改为“1”——您没有显示所有警告(此处可以忽略)。使用类型 real 是 non-portable(实际值是近似值)。

实体 gamma_correction 的上下文子句应为:

    library ieee; 
    ieee.std_logic_1164.all; -- for type std_logic, function rising_edge
    use ieee.math_real.all;  -- for function "**" [integer, real return real]
    use work.mytypes.all;    -- for type gamma_cor_array

不需要对 unisim 的引用。

为了初始化常量而不是使用在单独的实体和体系结构中生成的信号:

architecture fum of gam_cor_tb is
    signal clk: std_logic := '0';
    constant DEPH:  natural := 4;
    constant GAMMA_COR: real := 1.0;
    -- signal gamma_cor_array_s:
    --             gamma_cor_array (2 ** DEPH - 1 downto 0) ;

    function gamma_correct return gamma_cor_array is  -- added pure function
        use ieee.math_real.all;
        variable gamma_cor_array_s: gamma_cor_array(2 ** DEPH - 1 downto 0);
    begin
        for i in 0 to (2 ** DEPH - 1) loop
            gamma_cor_array_s(i) := integer (
                ( (real(i) / real (2 ** DEPH - 1) ) ** GAMMA_COR ) * 
                  real(2 ** DEPH - 1)
            );
        end loop;
        return gamma_cor_array_s;
    end function;

    constant gamma_cor_array_s:  -- previously a signal
                gamma_cor_array (2 ** DEPH - 1 downto 0) := gamma_correct;
begin
-- CLOCK:
--     process
--     begin
--         wait for 10 ns;
--         clk <= not clk;
--         wait for 10 ns;
--         wait;   -- one ping only
--     end process;
-- DUT:
--     entity work.gamma_correction
--         generic map (
--             DEPH => DEPH,
--             GAMMA_COR => GAMMA_COR
--         )
--         port map (
--             clk => clk,
--             gamma_cor_array_s => gamma_cor_array_s
--         );
MONITOR:
    process -- (gamma_cor_array_s)
    begin
        for i in 0 to (2 ** DEPH - 1) loop
            report "gamma_cor_array_s(" & integer'image(i) & ") = " &
                    integer'image(gamma_cor_array_s(i));
        end loop;
        wait;
    end process;
end architecture;

函数规范需要在先前作为通用常量传递给实体 gamma_correction 的常量范围内。

该函数用于初始化一个常量,该常量是一个查找table以确定伽马校正。

请注意,没有基于事件在进程之间传递值的信号。您分配的一个 gamma_cor_array_s 值从未更改(实体 gamma_correction 架构中进程中的驱动程序)。

输出值为:

gamma_corrections.vhdl:126:13:@0ms:(report note): gamma_cor_array_s(0) = 0 gamma_corrections.vhdl:126:13:@0ms:(report note): gamma_cor_array_s(1) = 1 gamma_corrections.vhdl:126:13:@0ms:(report note): gamma_cor_array_s(2) = 2 gamma_corrections.vhdl:126:13:@0ms:(report note): gamma_cor_array_s(3) = 3 gamma_corrections.vhdl:126:13:@0ms:(report note): gamma_cor_array_s(4) = 4 gamma_corrections.vhdl:126:13:@0ms:(report note): gamma_cor_array_s(5) = 5 gamma_corrections.vhdl:126:13:@0ms:(report note): gamma_cor_array_s(6) = 6 gamma_corrections.vhdl:126:13:@0ms:(report note): gamma_cor_array_s(7) = 7 gamma_corrections.vhdl:126:13:@0ms:(report note): gamma_cor_array_s(8) = 8 gamma_corrections.vhdl:126:13:@0ms:(report note): gamma_cor_array_s(9) = 9 gamma_corrections.vhdl:126:13:@0ms:(report note): gamma_cor_array_s(10) = 10 gamma_corrections.vhdl:126:13:@0ms:(report note): gamma_cor_array_s(11) = 11 gamma_corrections.vhdl:126:13:@0ms:(report note): gamma_cor_array_s(12) = 12 gamma_corrections.vhdl:126:13:@0ms:(report note): gamma_cor_array_s(13) = 13 gamma_corrections.vhdl:126:13:@0ms:(report note): gamma_cor_array_s(14) = 14 gamma_corrections.vhdl:126:13:@0ms:(report note): gamma_cor_array_s(15) = 15

与时钟上升沿后前一个信号的值匹配。

可以让gamma_cor_array_s一个信号,动态赋值,这需要所有的赋值都在一个进程中完成(并发语句会为一个赋值详细说明一个过程)

Xst 报告这些警告是因为一些数组元素停留在零,因此不需要寄存器并且可以优化掉。要消除警告,您必须删除寄存器描述。或者只是忽略警告。或在 ISE 中将其过滤掉。

其余数组元素在第一个时钟边沿后具有恒定值。如果您不关心初始值(在第一个时钟边沿之前),则移除数组输出的初始值。现在,也可以删除这些数组元素的寄存器。

如果始终需要恒定值,则不需要时钟。该过程现在可以减少到

PROCESS BEGIN
    for i in 0 to (2**DEPH - 1) loop
        gamma_cor_array_s(i) <= integer(((real(i)/real(2**DEPH - 1))**GAMMA_COR)*real(2**DEPH - 1));
    end loop;
    wait;
end process;