あなたの他の質問を見てみると - How to Eliminate whitespaces while Reading a file in VHDL提供メモリ初期化ファイルの例とそれを読む際の問題です。
この修正を組み込み、メソッドメソッドJ.Hを使用します。ボナリウスは、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;
この関数は、エラボレーション時にファイルを読み取り、ジェネリックを設定します。
は、そして、私たちは、これがMEMを初期化参照:トポの
コピーを。binには最初の行に4つの末尾スペースがあります。
10101100 11010100 10101100 11010100
11111110 10111001 11111110 10111001
上記の2つの値は、topo.binと一致しています。
(これはすべて、他の質問の空白で問題を見つけるために書かれています)。
ちょうどあなたがいくつかの検索エンジンを試しましたか?私はVHDLの教祖ではない。しかし、そのトピックに関する様々な議論があるようです... – GhostCat
私はさまざまなリンクで議論を行ってきましたが、私が得たものは、ある値でサイズを宣言する必要があります(可能な限り最大値かもしれません)。 –
私は不思議に思っています:最終的にVHDLは "ハードウェア"を構築することではありませんか?では、実際のハードウェアでは「未知のサイズの」配列は何をしていますか? – GhostCat