VHDL中的部分约束向量和数组

发布于 2025-01-21 18:10:25 字数 1115 浏览 0 评论 0原文

有什么方法可以在包装中定义别名,功能或亚型来定义受约束矢量声明周围的句法糖?

我经常在VHDL中声明端口,为std_logic_vector(n -1 down至0)。我想要一些句法糖。与此类似的事情:

context work.common;

entity X is
    generic(
        byteSize : integer := 8
    );
    port(
        DataIn : in logic_bus(byteSize);
        DataOut : out logic_bus(byteSize)
    );
end entity;

architecture X_arch of X is
    signal DataSignal : logic_bus(byteSize);
begin
    DataOut <= DataSignal;
    DataSignal <= DataIn;
end architecture;

我想在我的项目中定义这种句法糖,即,如果可能的话,避免在体系结构中定义亚型。我对open自然范围&lt;&gt;的用法感到非常困惑,代码>,以及什么样的功能可以返回。

关于限制推理,

我想强调的是,我正在寻找一种方法来抽象类似向量约束的定义。

离开我的矢量完全不受限制的提议,虽然聪明的解决方法,但我想避免使用的字符串:

  • 它与类型casting 请参阅此处。
  • 它不会传达端口之间的关系(例如,
  • 允许允许较大尺寸的总线设计通过错误(意外含义)允许较大尺寸的总线设计的数据和数据之类的大小传达

由于这个原因, 给它,因此我的工作场所编码样式已禁止端口中的无约束类型,而有利于仿制药。感谢您的理解。

Is there some way to define an alias, function or subtype in a package to define syntactic sugar around constrained vector declaration?

I often declare port and signals in VHDL as std_logic_vector(N - 1 downto 0). I would like some syntactic sugar around this. something similar to this:

context work.common;

entity X is
    generic(
        byteSize : integer := 8
    );
    port(
        DataIn : in logic_bus(byteSize);
        DataOut : out logic_bus(byteSize)
    );
end entity;

architecture X_arch of X is
    signal DataSignal : logic_bus(byteSize);
begin
    DataOut <= DataSignal;
    DataSignal <= DataIn;
end architecture;

I would like to have this syntactic sugar defined all over my project, i.e., avoid defining a subtype in the architecture if possible. I'm very confused with the usage of open, natural range <>, the difference between type and subtype, and what kind of things functions can return.

regarding constraints inference

I would like to stress that I'm looking for a way to abstract away the definition of similar vector constraints.

The proposal to leave my vector completely unconstrained, while a clever workaround, has strings attached to it that I would like to avoid :

  • It is not compatible with type casting see here.
  • It doesn't communicate the relationship between ports (for instance it doesn't communicate that DataIn and DataOut are supposed to be the same size)
  • It risks to allow badly sized bus designs to pass synthesis by mistake (accidental meaning)

For this reasons, my workplace coding style has banned unconstrained types in ports in favor of generics. Thank you for your understanding.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百思不得你姐 2025-01-28 18:10:25

我假设您想要logic_bus(x)是某种函数/别名/子类型来抽象std_logic_vector(n-1 down to 0),在约束矢量声明上工作。

在数字方面,VHDL的用户群很小。您可以使用哪种语言的大部分是高度依赖工具的。确保您已经在开发环境中阅读了VHDL-2008的支持功能。作为Xilinx UG901的主要用户,我要去Vivado。即使支持一项功能,您可能有时可能需要添加一个保留属性以使其在合成中不受优化。

自从几年前,Vivado对VHDL-2008

无限阵列得到了完全的支持。
通用软件包刚刚看到了一天的光芒,在导师和Xilinx解释中似乎有些不同,但是您可以实现它。
通用类型是该语言的一部分,但是我从来没有按照我需要的方式工作。 (我总是尝试在实体中保持SL和SLV)

因为我不确定您的环境,我只能回答我的环境。

通过避免通过避免使用它,可以避免使用完整的VHDL-2008支持

不受约束的SLV

围绕受约束向量定义的

entity X is
    port(
        DataIn : in std_logic_vector;
        DataOut : out std_logic_vector
    );
end entity;

architecture X_arch of X is
    -- guiding DataSignal with to have a relationship with some signal is usally needed  
    signal DataSignal : std_logic_vector(DataIn'range);
begin
    assert DataIn'length = DataOut'length
        report "length missmatch of input and output data"
        severity ERROR;
    
    DataOut <= DataSignal;
    DataSignal <= DataIn;
end architecture;

。需要启用断言以进行综合,以太进行运行或附加到综合策略中。 (有关Xilinx或Check dendor Docs,请参见UG901)

不受约束的矢量需要在顶级限制。有时在多层组件设计中有些薄弱。信号通常对它们的推断有所不同。

我通常认为更高维度的数据也可能是不受约束的

type slv_2d is array(natural range <>) of std_logic_vector;

-- Constrain multiple dimensions at once 
-- (this might still be broken in GHDL, open issue last time i checked) 
-- synthesis/implementation in Vivado works
-- simulates in Modelsim/Questa works
signal test_signal : slv_2d(0 to 5)(7 downto 0);


-- constants can de inferred from assignment
constant test_signal : slv_2d := ("001", "010", "011", "100" ); 

subtype,我通常认为将类型进一步限制。

-- integer may be any value within -2147483648 to +2147483647.
-- I might have an issue or a design restriction to highlight
-- I usually don't use subtypes 
subtype my_range is integer range 0 to 255;

-- Will throw error if outside of range 0 to 255.
variable cnt : my_range := 0; 

我真的建议阅读最新版本的UG901“支持的VHDL-2008功能”部分,即使您不使用Xilinx。 Dolus在VHDL-2008上有一些非常好的文章,这些文章可能会引起您的喜好,并会谈论与您想要的相关功能。

I assume that you want logic_bus(x) to be some kind function/alias/subtype to abstract away std_logic_vector(N-1 downto 0), working around constrained vector declaration.

VHDL have a quite small user base in terms of numbers. So much of what of the language you can use is highly tool dependent. Make sure you have read up on the supported features of vhdl-2008 for your development environment. As a main user of Xilinx UG901 is my go to for Vivado. Even though a feature is supported you might sometime be required to add an keep attribute to make it not be optimized away in synthesis.

Since a few years back Vivado have a quite full support for vhdl-2008

Unbounded arrays have been supported for even longer.
Generic package have just seen the light of day and seems to be a bit different in Mentor and Xilinx interpretation, but you can make it implement.
Generic types is a part of the language, but I have never got it to work the way I needed it to. (I always try to keep to sl and slv in entity)

As I'm not sure about your environment I can only answer for mine.

Full VHDL-2008 support is assumed

Unconstrained slv

Working around constrained vector definition by avoiding it.

entity X is
    port(
        DataIn : in std_logic_vector;
        DataOut : out std_logic_vector
    );
end entity;

architecture X_arch of X is
    -- guiding DataSignal with to have a relationship with some signal is usally needed  
    signal DataSignal : std_logic_vector(DataIn'range);
begin
    assert DataIn'length = DataOut'length
        report "length missmatch of input and output data"
        severity ERROR;
    
    DataOut <= DataSignal;
    DataSignal <= DataIn;
end architecture;

Asserts will need to be enabled for synthesis, ether for the run or appended to the synthesis strategy. (see ug901, for Xilinx or check vendor docs)

Unconstrained vectors need to be constrained at the top level. Some times a bit flakey in multi layered component designs. Signals are usually a bit iffy about how they get inferred.

Higher dimensional data can also be unconstrained

type slv_2d is array(natural range <>) of std_logic_vector;

-- Constrain multiple dimensions at once 
-- (this might still be broken in GHDL, open issue last time i checked) 
-- synthesis/implementation in Vivado works
-- simulates in Modelsim/Questa works
signal test_signal : slv_2d(0 to 5)(7 downto 0);


-- constants can de inferred from assignment
constant test_signal : slv_2d := ("001", "010", "011", "100" ); 

subtype I usually think about as limiting a type further.

-- integer may be any value within -2147483648 to +2147483647.
-- I might have an issue or a design restriction to highlight
-- I usually don't use subtypes 
subtype my_range is integer range 0 to 255;

-- Will throw error if outside of range 0 to 255.
variable cnt : my_range := 0; 

I really recommend reading ug901 "Supported VHDL-2008 Features" section of the latest release, even if you don't work with Xilinx. Dolus have a few really good writeups on vhdl-2008 that might strike your fancy and will talk about related features to what you are looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文