types - VHDL:使用 std_logic 数组与使用 std_logic_vector 子类型

标签 types vhdl subtype

我有多个属于一起的输入(在同一时钟等处采样),但在我需要修改的一段现有代码中逻辑上不是向量(即不是并行总线)。
以前,它们被定义为

type my_type is array (my_width - 1 downto 0) of std_logic;
signal my_signal : my_type;

到目前为止,为了这个目的,我总是使用这个:

subtype my_subtype is std_logic_vector(my_width - 1 downto 0);
signal my_signal : my_subtype;

对于大多数意图和目的,数组和向量的处理方式几乎相同,所以我的问题是:
这两种做事方式有什么优点吗?有首选/标准方式吗?

最佳答案

有一个区别,与 strong typing 有关。 .

使用第一段代码,您创建了一个新类型。它是独立的,不与其他类型兼容。只需考虑下一段代码:

entity e is end entity;
library ieee;
architecture a of e is
    use ieee.std_logic_1164.all;
    type slv1_t is array (15 downto 0) of std_logic;
    signal slv1 : slv1_t;
    type slv2_t is array (7 downto 0) of std_logic;
    signal slv2 : slv2_t;
begin
    slv2 <= slv1(7 downto 0);
end architecture;

在modelsim中编译时,这段代码会报错:

Error: C:/HDL/TypeVsSubtype/Type.vhd(10): Cannot resolve slice name as type slv2_t.

对于第二段代码,底层类型仍然是std_logic_vector。因此,子类型是兼容的。考虑下一段代码:

entity e is end entity;
library ieee;
architecture a of e is
    use ieee.std_logic_1164.all;
    subtype slv1_t is std_logic_vector(15 downto 0);
    signal slv1 : slv1_t;
    subtype slv2_t is std_logic_vector(7 downto 0);
    signal slv2 : slv2_t;
begin
    slv2 <= slv1(7 downto 0);
end architecture;

这确实可以编译(即没有错误)。

关于types - VHDL:使用 std_logic 数组与使用 std_logic_vector 子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46198216/

相关文章:

scala - scala中的 "not a simple type"警告是什么意思?

vhdl - 有没有办法在 ISim 中显示变量?

concurrency - 使用并发语句实现触发器

sql - 子类型数据库表

javascript - 在 TypeScript 中键入具有未知属性的对象。如何正确地做到这一点?

json - 如何使用 GROUP BY 子句将正确的属性名称设置为 json 聚合结果?

go - 在NewX函数上返回指针背后有充分的理由吗?

vhdl - 综合全局实例计数

c# - 如何使用 Json.Net 和带有子类型的 Xamarin 反序列化 JSON?

SQL 设计、连接类型和子类型