记录 VHDL TEXTIO 库读入 integer 类型的一个问题

错误提示

image

第一种写法

use ieee.std_logic_textio.all;
use std.textio.all;
use ieee.numeric_std.all;
--
    file fin : text open read_mode is
    "file_path";

    read_file_proc : process (clk, rst)
        variable v_in_line : line;
        variable v_din     : integer;
    begin
        if (rst = '1') then
            din  <= (others => '0');
        else
            if (clk'event and clk = '1') then
                if (not endfile(fin)) then
                    readline(fin, v_in_line);
                    read(v_in_line, v_din);
                    din  <= std_logic_vector(to_signed(v_din, 32));
                else
                    din  <= (others => '0');
                end if;
            end if;
        end if;
    end process;

最初是这种写法出现问题的。

第二种写法

use ieee.std_logic_textio.all;
use std.textio.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
--
    file fin : text open read_mode is
    "file_path";

    read_file_proc : process (clk, rst)
        variable v_in_line : line;
        variable v_din     : integer;
    begin
        if (rst = '1') then
            din  <= (others => '0');
        else
            if (clk'event and clk = '1') then
                if (not endfile(fin)) then
                    readline(fin, v_in_line);
                    read(v_in_line, v_din);
                    din  <= conv_std_logic_vector(v_din, 32));
                else
                    din  <= (others => '0');
                end if;
            end if;
        end if;
    end process;

后来改用 synopsys 的 arith 和 unsigned 库,依旧不行,换 signed 也不行。

问题

>> nextpow2(4283236186)
>> ans =
    32

在 matlab 中可以看到没有超过 32 位的范围。

https://www.fdi.ucm.es/profesor/jjruz/LEC/Temas/Manual Usuario VHDL87.pdf

https://standards.ieee.org/ieee/1076/1609/

查阅 vhdl 1987 标准 3.1.2 节,
image

数值不能超过 2^31,必须是有符号的整数。

            $dec_tmp = sprintf "%d\n",hex($hex_num);
            if ($dec_tmp>2**31) {
                $dec = $dec_tmp - 2**32; 
            } else {
                $dec = $dec_tmp;
            }
            printf OUT_FH "%d\n",$dec;

修改 perl 脚本进制转换的逻辑,问题解决。

posted @ 2023-05-30 11:32  devindd  阅读(50)  评论(0编辑  收藏  举报