初始化整数

时间:2017-01-14 10:12:09

标签: vhdl hdl

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

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;

我收到了这些警告:

  

警告:Xst:2404 - FFs / Latches&lt; 1:1&gt;&gt; (不   init值)在块中具有常量值0。

     

警告:Xst:2404 - FFs / Latches&lt; 1:2&gt;&gt; (不   init值)在块中具有常量值0。

     

警告:Xst:2404 - FFs / Latches&lt; 1:2&gt;&gt; (不   init值)在块中具有常量值0。

     

警告:Xst:2404 - FFs / Latches&lt; 1:2&gt;&gt; (不   init值)在块中具有常量值0。

     

警告:Xst:2404 - FFs / Latches&lt; 3:3&gt;&gt; (不   init值)在块中具有常量值0。

     

警告:Xst:2404 - FFs / Latches&lt; 1:3&gt;&gt; (不   init值)在块中具有常量值0。

     

警告:Xst:2404 - FFs / Latches&lt; 1:4&gt;&gt; (不   init值)在块中具有常量值0。

在testbench中,我的代码工作正常。 Init值为0,但警告仍然存在。我该怎样摆脱它们?

2 个答案:

答案 0 :(得分:2)

为什么gamma_cor_array_s类不变? GAMMA_CORDEPH的类常量,你不需要触发器,编写一个函数来初始化gamma_cor_s使用它并且不使用实体/体系结构对。

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

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 :(报告说明):gamma_cor_array_s(0)   = 0 gamma_corrections.vhdl:75:13:@ 0ms :(报告说明):gamma_cor_array_s(1)= 0 gamma_corrections.vhdl:75:13:@ 0ms :(报告   注):gamma_cor_array_s(2)= 0   gamma_corrections.vhdl:75:13:@ 0ms :(报告说明):gamma_cor_array_s(3)   = 0 gamma_corrections.vhdl:75:13:@ 0ms :(报告说明):gamma_cor_array_s(4)= 0 gamma_corrections.vhdl:75:13:@ 0ms :(报告   注):gamma_cor_array_s(5)= 0   gamma_corrections.vhdl:75:13:@ 0ms :(报告说明):gamma_cor_array_s(6)   = 0 gamma_corrections.vhdl:75:13:@ 0ms :(报告说明):gamma_cor_array_s(7)= 0 gamma_corrections.vhdl:75:13:@ 0ms :(报告   注):gamma_cor_array_s(8)= 0   gamma_corrections.vhdl:75:13:@ 0ms :(报告说明):gamma_cor_array_s(9)   = 0 gamma_corrections.vhdl:75:13:@ 0ms :(报告说明):gamma_cor_array_s(10)= 0 gamma_corrections.vhdl:75:13:@ 0ms :(报告   注):gamma_cor_array_s(11)= 0   gamma_corrections.vhdl:75:13:@ 0ms :(报告说明):gamma_cor_array_s(12)   = 0 gamma_corrections.vhdl:75:13:@ 0ms :(报告说明):gamma_cor_array_s(13)= 0 gamma_corrections.vhdl:75:13:@ 0ms :(报告   注):gamma_cor_array_s(14)= 0   gamma_corrections.vhdl:75:13:@ 0ms :(报告说明):gamma_cor_array_s(15)   = 0 gamma_corrections.vhdl:75:13:@ 10ns :(报告说明):gamma_cor_array_s(0)= 0 gamma_corrections.vhdl:75:13:@ 10ns :(报告   注意):gamma_cor_array_s(1)= 1   gamma_corrections.vhdl:75:13:@ 10ns :(报告说明):gamma_cor_array_s(2)   = 2 gamma_corrections.vhdl:75:13:@ 10ns :(报告说明):gamma_cor_array_s(3)= 3 gamma_corrections.vhdl:75:13:@ 10ns :(报告   注):gamma_cor_array_s(4)= 4   gamma_corrections.vhdl:75:13:@ 10ns :(报告说明):gamma_cor_array_s(5)   = 5 gamma_corrections.vhdl:75:13:@ 10ns :(报告说明):gamma_cor_array_s(6)= 6 gamma_corrections.vhdl:75:13:@ 10ns :(报告   注):gamma_cor_array_s(7)= 7   gamma_corrections.vhdl:75:13:@ 10ns :(报告说明):gamma_cor_array_s(8)   = 8 gamma_corrections.vhdl:75:13:@ 10ns :(报告说明):gamma_cor_array_s(9)= 9 gamma_corrections.vhdl:75:13:@ 10ns :(报告   注):gamma_cor_array_s(10)= 10   gamma_corrections.vhdl:75:13:@ 10ns :(报告说明):   gamma_cor_array_s(11)= 11 gamma_corrections.vhdl:75:13:@ 10ns :(报告   注):gamma_cor_array_s(12)= 12   gamma_corrections.vhdl:75:13:@ 10ns :(报告说明):   gamma_cor_array_s(13)= 13 gamma_corrections.vhdl:75:13:@ 10ns :(报告   注):gamma_cor_array_s(14)= 14   gamma_corrections.vhdl:75:13:@ 10ns :(报告说明):   gamma_cor_array_s(15)= 15

你声明64个触发器,将它们初始化为所有&#39; 0&#39;其中只有30个被改为&#39; 1&#39; - 你没有显示所有警告(这里可以忽略)。使用real类型是不可移植的(实际值是近似值)。

实体gamma_correction的context子句应该是:

    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的通用常量传递的常量的范围内。

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

请注意,没有信号根据事件在进程之间传递值。您分配了gamma_cor_array_s的值从未更改过(实体gamma_correction&#39; s架构中的驱动程序)。

输出值为:

  

gamma_corrections.vhdl:126:13:@ 0ms :(报告说明):gamma_cor_array_s(0)   = 0 gamma_corrections.vhdl:126:13:@ 0ms :(报告说明):gamma_cor_array_s(1)= 1 gamma_corrections.vhdl:126:13:@ 0ms :(报告   注):gamma_cor_array_s(2)= 2   gamma_corrections.vhdl:126:13:@ 0ms :(报告说明):gamma_cor_array_s(3)   = 3 gamma_corrections.vhdl:126:13:@ 0ms :(报告说明):gamma_cor_array_s(4)= 4 gamma_corrections.vhdl:126:13:@ 0ms :(报告   注):gamma_cor_array_s(5)= 5   gamma_corrections.vhdl:126:13:@ 0ms :(报告说明):gamma_cor_array_s(6)   = 6 gamma_corrections.vhdl:126:13:@ 0ms :(报告说明):gamma_cor_array_s(7)= 7 gamma_corrections.vhdl:126:13:@ 0ms :(报告   注):gamma_cor_array_s(8)= 8   gamma_corrections.vhdl:126:13:@ 0ms :(报告说明):gamma_cor_array_s(9)   = 9 gamma_corrections.vhdl:126:13:@ 0ms :(报告说明):gamma_cor_array_s(10)= 10 gamma_corrections.vhdl:126:13:@ 0ms :(报告   注):gamma_cor_array_s(11)= 11   gamma_corrections.vhdl:126:13:@ 0ms :(报告说明):   gamma_cor_array_s(12)= 12 gamma_corrections.vhdl:126:13:@ 0ms :(报告   注):gamma_cor_array_s(13)= 13   gamma_corrections.vhdl:126:13:@ 0ms :(报告说明):   gamma_cor_array_s(14)= 14 gamma_corrections.vhdl:126:13:@ 0ms :(报告   注意):gamma_cor_array_s(15)= 15

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

可以使gamma_cor_array_s成为一个信号,在动态分配的情况下,这要求所有分配都在一个过程中完成(并发语句将详细说明分配过程)

答案 1 :(得分:0)

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;