简体   繁体   English

VHDL将自定义类型签名的integer转换为std_logic_vector

[英]VHDL casting a custom Type signed integer to a std_logic_vector

Hi I have a signal that is used in many places and subject to being altered down the track.嗨,我有一个在许多地方使用的信号,并且可能会在轨道上被更改。 So to simplify maintenance I have made a TYPE declaration called T_RowInt.因此,为了简化维护,我做了一个名为 T_RowInt 的 TYPE 声明。

I have made two signals "typed" and "untyped" which both equate to an integer range -63 to 63 to demonstrate the problem.我已经制作了两个信号“已键入”和“未键入”,它们都等同于 integer 范围 -63 到 63 来演示问题。

Code follows:代码如下:

type T_RowInt is range -63 to 63;
signal typed : T_RowInt;
signal untyped : integer range -63 to 63;

signal text_col : integer range 0 to 127 := 0;
signal bank : std_logic_vector(2 downto 0) := "111";
signal page : std_logic_vector(3 downto 0) := "0000";

I use the above in the following expressions:我在以下表达式中使用上述内容:

addr_r_dram(19 downto 0)<= bank & page & std_logic_vector(to_unsigned(typed,6)) & std_logic_vector(to_unsigned(text_col, 7));

This fails syntax checking with "to_unsigned can not have such operands in this context" However, this expression:这使语法检查失败,“to_unsigned 在此上下文中不能有这样的操作数”但是,这个表达式:

addr_r_dram(19 downto 0)<= bank & page & std_logic_vector(to_unsigned(untyped,6)) & std_logic_vector(to_unsigned(text_col, 7));

Is ok没问题

Is there a way to force conversion of a custom TYPED signal?有没有办法强制转换自定义 TYPED 信号?

Thanks谢谢

Mark标记

If you use type then you have defined a completely new type as far as VHDL is concerned.如果您使用type ,那么就 VHDL 而言,您已经定义了一个全新的类型。 However, how about using a subtype , eg但是,如何使用subtype ,例如

subtype T_RowInt is integer range -63 to 63;

then VHDL will not consider T_RowInt as being a completely different type.那么 VHDL 不会将T_RowInt视为完全不同的类型。 Your signal untyped is actually using a subtype, a so-called _anonymous subtype`:您的untyped信号实际上是使用一个子类型,即所谓的 _anonymous 子类型:

signal untyped : integer range -63 to 63;

Perhaps you can see the similarity between these two lines of code?或许你能看出这两行代码的相似之处?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM