- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的要求是从输入文件中读取数据位并将数据写入 vhdl 中的内存阵列(输出)。由于我不知道输入文件中的数据量,因此我需要声明未知大小的数组并在稍后阶段将数据分配给内存。
我的代码如下:
声明:
PACKAGE io IS
type memory is array (natural range<>) of std_logic_vector(3 downto 0);
END;
entity File_io is
port (
clk: in std_logic;
Data_memory: out memory
);
end entity;
architecture behav of File_io is
signal mem: memory;
begin
process(clk)
begin
for i in 0 to 15 loop -- Took just 16 values for explaination purpose.
-- i may need more values to be written which is unknown.
mem(i) <= std_logic_vector(to_unsigned(i, 4));
end loop;
Data_memory <= mem;
end process;
end architecture behav;
我已将实际代码最小化到我的确切要求。如果有任何语法错误,请忽略。
问题是我无法为不受约束的数组赋值,即未定义大小。我该怎么做呢 ?有什么建议或替代方案吗?指导我
最佳答案
查看您的其他问题 - How to Eliminate whitespaces while Reading a file in VHDL提供了一个示例内存初始化文件以及读取它的问题。
合并该修复程序并使用方法方法 J.H. Bonarius 建议产生一个 Minimal, Complete and Verifiable example :
library ieee;
use ieee.std_logic_1164.all;
PACKAGE io IS
type memory is array (natural range<>) of std_logic_vector(3 downto 0);
function iswhitespace (inpstr: in string) return boolean;
END;
package body io is
function iswhitespace (inpstr: in string) return boolean is
constant NBSP: character := character'val(128);
begin
for i in inpstr'range loop
if inpstr(i) /= ' ' and inpstr(i) /= NBSP and inpstr(i) /= HT then
exit;
elsif i = inpstr'RIGHT then
return TRUE;
end if;
end loop;
return FALSE;
end function;
end package body;
library ieee;
use ieee.std_logic_1164.all;
use work.io.all;
entity File_io is
generic (
constant MEMORY_SIZE: natural := 42;
constant filename: string := "C:\Users\ChowdaryS\Downloads\topo.bin"
);
port (
clk: in std_logic;
Data_memory: out memory (0 to MEMORY_SIZE - 1)
);
end entity;
architecture foo of File_io is
signal mem: memory (0 to MEMORY_SIZE - 1); -- ADDED subtype indication
use ieee.numeric_std.all; -- MISSING cntext item
use std.textio.all;
signal mem_inited: boolean := FALSE; -- ADDED
begin
process(clk)
file f: text open read_mode is filename;
variable L: line;
variable i: integer:= 0;
variable b: bit_vector(3 downto 0);
begin
if not mem_inited then
i := 0;
while not endfile(f) loop
readline(f, L);
while L.all'length >= b'length and not iswhitespace(L.all) loop
read(L, b);
mem(i) <= to_stdlogicvector(b);
i := i + 1;
end loop;
end loop;
report "mem values loaded = " & integer'image(i);
mem_inited <= TRUE;
end if;
end process;
Data_memory <= mem;
end architecture foo;
有变化。函数 iswhitespace 已添加到包 io 中。您可以查看上面引用的权衡问题以及是否需要。
输出端口的分配已移出流程。假定您将在该过程中对 mem 进行某种写入。
还有一个测试台实例化 file_io 并确定内存数组的大小,将其作为通用传递。
library ieee;
use ieee.std_logic_1164.all;
use work.io.all;
entity file_io_tb is
end entity;
architecture foo of file_io_tb is
constant MEMSIZ: natural := 16;
constant filename: string := "topo.bin"; -- found locally.
signal clk: std_logic := '0';
signal Data_memory: memory (0 to MEMSIZ - 1);
use std.textio.all;
impure function getarraysize return natural is
variable L: Line;
variable i: natural;
variable b: bit_vector (3 downto 0);
file f: text open read_mode is filename;
begin
i := 0;
while not endfile(f) loop
readline(f, L);
while L.all'length >= b'length and not iswhitespace(L.all) loop
read(L, b);
i := i + 1;
end loop;
end loop;
report " memory size = " & integer'image(i);
return i;
end function;
begin
DUT:
entity work.file_io
generic map (MEMORY_SIZE => getarraysize, filename => filename)
port map (
clk => clk,
Data_memory => Data_memory
);
CLOCK:
process
begin
wait for 10 ns;
clk <= not clk;
if now > 50 ns then
wait;
end if;
end process;
end architecture;
该功能是在细化时执行文件读取以设置泛型。
我们看到这个初始化内存:
使用的 topo.bin 副本在第一行有四个尾随空格:
10101100 11010100 10101100 11010100
11111110 10111001 11111110 10111001
波形中显示的值与 topo.bin 中的上述两行匹配。
(所有这些都是为了在另一个问题中找到空白问题而写的)。
关于arrays - VHDL 数组 - 我如何声明一个未知大小的数组并使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42583061/
同时使用 VHDL-2019 IEEE 规范部分。 5.2.3.1.一般 "However, an implementation shall allow the declaration of any
我正在设计通用移位算术运算符。除了以下面介绍的方式使用 32 位多路复用器(解码器)之外,还有更好的方法来实现它吗? ENTITY isra IS PORT ( clk: in std_lo
描述:我正在尝试编写一个具有 4 个输入和 3 个输出的 LUT(查找表)的 vhdl 模块。我希望我的 3 位输出是一个二进制数,等于输入中 1 的个数。 我的真值表: ABCD|XYZ 0000|
我想使用 vhdl 制作幂函数,其中幂是浮点数,数字是整数(将始终为“2”)。 2^ 一些浮点数。 我使用 ieee 库和(fixed_float_types.all、fixed_pkg.all 和
是否有可能有一个通用的包? 这意味着当我实例化实体时,我提供了一些泛型,包将依赖于它。 我有一个块,我想多次使用,每次使用不同的包(即不同的参数) 我必须使用包,因为我想使用数组数组,而我只能使用包来
使用 VHDL,我希望有一些寄存器在每个寄存器中存储 16 位。 所以我发现 VHDL 有一个内置数组,我想用它在 iy 中的每个元素中存储 16 位,所以我想知道 VHDL 是否将此数组映射到实际寄
在 vhdl 中我可以定义我自己的枚举类型并创建这种类型的信号: type tp is (red,green,blue,yellow); signal sg: tp := red; 但现在我想要一个
我是 VHDL 的新手。 有一行,如下所示: constant TIME_DELTA : time := 100 ns; 这是什么字time在行吗?是不是和integer一样的数据类型?当我在互联网上
A <= 3 * B; 上面语句中的3是一个整数或自然数。如果它是自然数,如果我在那里使用负数怎么办? VHDL 是否将其识别为整数? 最佳答案 整数文字属于匿名预定义类型universal_inte
我为以下 vhdl 代码编写了测试平台: library ieee; USE ieee.std_logic_1164.all; ---USE ieee.std_logic_unsigned.all;
我有使用 Verilog/SystemVerilog 的经验,但我是 VHDL 新手,我试图弄清楚何时应该使用组件实例化或实体实例化。我所说的组件实例化是指在实例化实体组件之前声明实体组件的传统方式。
我一直无法理解如何在 VHDL 中取消引用指针。 我想到的是一个 C 代码,如: int a; int* ptr_a; a = 42; ptr_a=&a; *ptr_a=451;/
我为以下 vhdl 代码编写了测试平台: library ieee; USE ieee.std_logic_1164.all; ---USE ieee.std_logic_unsigned.all;
我想知道VHDL中是否定义了整数溢出。我在 2002 年规范中找不到任何内容。 作为示例(注意,这可能无法编译,它只是一个通用示例...): entity foo is port ( clk
如何组合/捆绑语句以供进一步使用和更好地处理?例如,像这样的一些赋值会在以后的例程调用中多次使用。 ADDR_PC '0'); constant OP_NOP: std
我正在编写一个 IP 核,根据用户选择的通用参数,并非所有 OUT/IN 端口都是必需的。是否可以有可选端口?我知道类似的事情应该是可能的,因为当我使用 Xilinx IP-Cores 时,根据参数,
我有一个数组: type offsets_type is array (4 downto 0) of std_logic_vector (4 downto 0); signal av : of
type有什么区别和 subtype在 VHDL 中,我应该在哪里使用它们? 我的理解是subtype只是主要类型之一的缩小版本,例如 integer :subtype small_integer i
我试图更好地使用 VHDL protected 类型,所以我将以下测试放在一起(当然只是为了说明 - 我的实际用例要复杂得多): type prot_type1 is protected proc
首先,我想声明这是我参加的模拟考试。我知道答案是:cout = 4ns,S = 7ns。只是在寻找一点解释。提前致谢。 对于下面所示的全加器的 VHDL 实现,输出 cout 和 S 何时稳定在它们的
我是一名优秀的程序员,十分优秀!