Verification Engineerの戯言
Bluespec SystemVerilog : COUNTERを学ぶ(その1)
Bluespec SystemVerilog : COUNTERを学ぶ(その2)
Bluespec SystemVerilog : COUNTERを学ぶ(その3)
Bluespec SystemVerilog : COUNTERを学ぶ(その4)
Bluespec SystemVerilog : COUNTERを学ぶ(その2)
Bluespec SystemVerilog : COUNTERを学ぶ(その3)
Bluespec SystemVerilog : COUNTERを学ぶ(その4)
SystemVerilogのクラスにパラメータがあるようにBluespec SystemVerilogにも同様な機能があります。
下記に示すCounterインターフェースは、カウンタのビット幅をパラメータとして設定可能にしています。
最初の記述
interface Counter;
method Bit#(8) read();
method Action increment();
method Action decrement();
method Action load(Bit#(8) newval);
endinterface
パラメータ化した場合
interface Counter#(type size_t);
method Bit#(size_t) read();
method Action increment();
method Action decrement();
method Action load(Bit#(size_t) newval);
endinterface
Counterの後の#(type size_t)がパラメータになります。#(8)の部分をすべて#(size_t)に変えます。
(SystemVerilogでは#(int size_t)という記述になります。)
(SystemVerilogでは#(int size_t)という記述になります。)
これにより、mkCounterモジュールも変更します。
最初の記述
module mkCounter(Counter);
Reg#(Bit#(8)) value <- mkReg(0);
method Bit#(8) read();
return value;
endmethod
method Action load(Bit#(8) newval);
value <= newval;
endmethod
パラメータ化した場合
module mkCounter(Counter#(size_t));
Reg#(Bit#(size_t)) value <- mkReg(0);
method Bit#(size_t) read();
return value;
endmethod
method Action load(Bit#(size_t) newval);
value <= newval;
endmethod
(Bluespec SystemVerilogでは、パラメータの名前は小文字から始まるようにする必要があるようです)そして、テストベンチの記述も変更します。
最初の記述
Counter counter <- mkCounter();
パラメータ化した場合
Counter#(8) counter <- mkCounter();
ここでコンパイルすると、何とエラーが発生します。
% bsc -u -verilog TbCounter.bsv Error: "MyCounter.bsv", line 10, column 8: (T0043) Cannot synthesize `mkCounter': Its interface is polymorphic.
これは、mkCounterモジュールが合成できないというエラーで、
mkCounterのインターフェースがパラメータを持つため、RTLには合成できないためです。
そこで、mkCounterモジュールの記述の前にある(* synthesize *)を削除し、
mkCounterモジュールを直接、Verilog HDLに変換しないようにします。
mkCounterのインターフェースがパラメータを持つため、RTLには合成できないためです。
そこで、mkCounterモジュールの記述の前にある(* synthesize *)を削除し、
mkCounterモジュールを直接、Verilog HDLに変換しないようにします。
検証、Verification、Bluespec SystemVerilog