4

std_logicベクトル、bit_vector、またはその他のベクトルを文字列に変換するにはどうすればよいですか?

Signal a,b          : UNSIGNED(7 DOWNTO 0);
SIGNAL x,y,z    : BIT_VECTOR(7 DOWNTO 0);

...

report "value: " & BIT_VECTOR'Image(x) severity note;
report "and this one: " & to_string(a) severity note;

これは機能しないので、どうすればベクトルを文字列に変換できますか?

4

8 に答える 8

7

あなたが発見したように、 'image 属性は、配列やレコードではなく、スカラー型に対してのみ宣言されています。通常のアプローチは、設計の開始時にパッケージ内のto_stringまたは関数を含むテストユーティリティの独自のライブラリを作成し、全体でそれを使用することですimage.

これらのライブラリを標準化することは完全に可能であり、多くの潜在的な「テスト ユーティリティ」パッケージが見つかる可能性がありますが、標準になるに値するほど十分に普及しているものはありません。

そうは言っても、次のパッケージが出発点として役立つかもしれません。

いくつかのカスタム データ型をカプセル化し、それらに対する操作を行います。ジェネリックはありませんが、オーバーロードのおかげで、関数がジェネリックであるかのようにパッケージを使用できます。(ただし、関数本体が不完全であることに気付くでしょう!) それを拡張して型を追加することは、ほとんどの場合、簡単にカット アンド ペーストできます。また、メインのデザインが煩雑になるのを防ぎます。

型 declns と (テストベンチのみ) 関数を 2 つの別個のパッケージに分けたほうがよい場合があります。TypesTypes_Test_Utils。次に、タイプは設計全体で使用されますが、テスト ユーティリティはテストベンチにのみ公開されます。

library IEEE;
use IEEE.numeric_std.all;

package Types is
  subtype SmallNum is UNSIGNED(7 DOWNTO 0);
  subtype BiggerNum is UNSIGNED(19 DOWNTO 0);
  subtype Bits is BIT_VECTOR(7 DOWNTO 0);

  -- and operations on these types
  -- Simulate generic procedures using overloading

  function to_string(N : Unsigned) return String;
  function to_string(N : Bits) return String;  

  procedure eq_checker (name : string; sig,should : SmallNum; at : time);
  procedure eq_checker (name : string; sig,should : Bits; at : time);

end Types;

package body Types is

function to_string(N : Unsigned) return String is
variable temp : string(1 to (N'length + 3)/4) := (others => 'x');
begin
   -- not finished!
   return temp;
end to_string;

function to_string(N : Bits) return String is
begin
   return "hello";
end to_string;

procedure eq_checker(name : string; sig,should : SmallNum; at : time) is
begin
  if (at = now) then
    if sig = should then
      report to_string(sig) & "has same value" severity note;
    else
      report to_string(sig) & "has not same value as " & to_string(should) severity note;
    end if;
  end if;
end procedure eq_checker;

procedure eq_checker(name : string; sig,should : Bits; at : time) is
begin
   null;
end procedure eq_checker;

end Types;

そして、そのための簡単なテスター...

  use Work.Types.all;

  ENTITY tester IS
  END tester;

  ARCHITECTURE behavior OF tester IS 

  Signal a,b      : SmallNum := X"AA";
  Signal c        : BiggerNum := X"ABCDE";
  SIGNAL x,y      : Bits := X"BB";

  BEGIN

  process(a,x) is
  begin
     report "value: " & to_string(X) severity note;
     report "and this one: " & to_string(a) severity note;
     report "this one too: " & to_string(c) severity note;
  end process;

  END;
于 2013-03-14T12:56:19.713 に答える
6

std_logic_vector 型変数の範囲が戻り値に影響を与えない解決策を次に示します。

function to_string ( a: std_logic_vector) return string is
variable b : string (1 to a'length) := (others => NUL);
variable stri : integer := 1; 
begin
    for i in a'range loop
        b(stri) := std_logic'image(a((i)))(2);
    stri := stri+1;
    end loop;
return b;
end function;
于 2016-08-09T11:54:39.943 に答える
2
function slv_to_string ( a: std_logic_vector) return string is
    variable b : string (a'length-1 downto 1) := (others => NUL);
begin
        for i in a'length-1 downto 1 loop
        b(i) := std_logic'image(a((i-1)))(2);
        end loop;
    return b;
end function;
于 2016-03-17T14:42:40.623 に答える
0
package package_x is 
  subtype any_type is UNSIGNED(7 DOWNTO 0);

...
end package_x;

package body package_x is

  procedure someprocedure (signal sig: in any_type) is

  VARIABLE li   : line;
  file output : text open write_mode is "output";

  begin
    write(li, std_logic_vector(sig));
    writeline(output, li);
  end;
end package_x;
于 2013-03-14T11:12:58.433 に答える