【问题标题】:How to represent array literals in VHDL?如何在 VHDL 中表示数组文字?
【发布时间】:2012-11-07 15:43:12
【问题描述】:

我有以下类型声明:

type cachesubset is record
                      tag     : std_logic_vector(3 downto 0);
                      word0   : w32;
                      word1   : w32;
                      dirty   : std_logic;
                      valid   : std_logic;
                    end record;

type    cacheset is record
                      lru : std_logic;
                      subsets: array(0 to 1) of cachesubset
                    end record;

我要定义空缓存集常量:

constant 
empty_cachesubset : cachesubset := (
                                    tag   => "0000",
                                    word0 => "00000000000000000000000000000000",
                                    word1 => "00000000000000000000000000000000",
                                    dirty => '0',
                                    valid => '0'
                                   );

constant 
empty_cacheset    : cacheset    := (
                                    lru     => '0',
                                    subsets => ???
                                   );

关键是我不知道如何创建数组字面量。

一些注意事项...

请不要介意我使用两个单独的字段来处理子集中的单词,而我可能会为缓存集和子集做同样的事情......关键是我还将为单词应用一个数组在一个子集中...

【问题讨论】:

    标签: vhdl hdl modelsim


    【解决方案1】:

    你可以这样做:

    library ieee;
    use ieee.std_logic_1164.all;
    
    package test is
        subtype w32 is std_logic_vector(31 downto 0);
    
        type cachesubset is record
            tag   : std_logic_vector(3 downto 0);
            word0 : w32;
            word1 : w32;
            dirty : std_logic;
            valid : std_logic;
        end record;
    
        type subsetst is array (0 to 1) of cachesubset;
    
        type cacheset is record
            lru     : std_logic;
            subsets : subsetst;
        end record;
    
        constant empty_cachesubset : cachesubset := (
            tag => (others => '0'),
            word0 => (others => '0'),
            word1 => (others => '0'),
            dirty => '0',
            valid => '0'
        );
    
        constant empty_cacheset : cacheset := (
            lru         => '0',
            subsets     => (
                0 => empty_cachesubset,
                1 => (
                    tag => (others => '0'),
                    word0 => (others => '0'),
                    word1 => (others => '0'),
                    dirty => '0',
                    valid => '0'
                )
            )
        );
    end package test;
    

    【讨论】:

      【解决方案2】:
      subsets => ???
      

      最简单的方法是将数组中的每个条目设置为相同的值...

      subsets => (others => empty_cachesubset);
      

      正如另一个答案所示,您可以将单个元素设置为不同的值 - 然后使用“其他”来默认其余部分。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-01-17
        • 2011-06-22
        • 1970-01-01
        • 1970-01-01
        • 2018-09-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多