チゼルで回路の制御ロジックを作成しようとしていたときに、使用していた switch ステートメントに関連する複数のエラーを受け取りました。問題を特定するために、公式のchisel チュートリアルの 9 ページと 10 ページにある switch ステートメントのサンプル コードを実行することにしました。
スカラコード:
package Testbed
import Chisel._
class Testbed extends Module {
val io = new Bundle {
val nickel = Bool(dir = INPUT)
val dime = Bool(dir = INPUT)
val rdy = Bool(dir = OUTPUT) }
val s_idle :: s_5 :: s_10 :: s_15 :: s_ok :: Nil = Enum(UFix(), 5)
val state = Reg(init = s_idle)
switch (state) {
is (s_idle) {
when (io.nickel) { state := s_5 }
when (io.dime) { state := s_10 }
} is (s_5) {
when (io.nickel) { state := s_10 }
when (io.dime) { state := s_15 }
} is (s_10) {
when (io.nickel) { state := s_15 }
when (io.dime) { state := s_ok }
} is (s_15) {
when (io.nickel) { state := s_ok }
when (io.dime) { state := s_ok }
} is (s_ok) {
state := s_idle
}
}
io.rdy := (state === s_ok)
}
class TestbedTests(c: Testbed) extends Tester(c) {
}
object Testbed {
def main(args: Array[String]): Unit = {
val tutArgs = args.slice(1, args.length)
chiselMainTest(tutArgs, () => Module(new Testbed())) {
c => new TestbedTests(c) }
}
}
しかし、UFix に関連するエラーが発生します。
[error] /home/chisel-tutorial/test/Testbed.scala:12: not found: value UFix
[error] val s_idle :: s_5 :: s_10 :: s_15 :: s_ok :: Nil = Enum(UFix(), 5)
[error] ^
[error] /home/chisel-tutorial/test/Testbed.scala:13: inferred type arguments [Any] do not conform to method apply's type parameter bounds [T <: Chisel.Data]
[error] val state = Reg(init = s_idle)
[error] ^
[error] /home/chisel-tutorial/test/Testbed.scala:16: overloaded method value apply with alternatives:
[error] (v: Iterable[Chisel.Bits])(block: => Unit)Unit <and>
[error] (v: Chisel.Bits,vr: Chisel.Bits*)(block: => Unit)Unit <and>
[error] (v: Chisel.Bits)(block: => Unit)Unit
[error] cannot be applied to (Any)
[error] is (s_idle) {
[error] ^
[error] three errors found
[error] (compile:compile) Compilation failed
チュートリアルでは、実際には大文字の I を使用して UFIx として記述されていましたが、両方の方法で試してみましたが、役に立ちませんでした。これは単なる古い型だと思ったので、UFix を UInt に置き換えましたが、他のすべては同じままにしました。次に、次のエラーが表示されます。
[error] /home/chisel-tutorial/test/Testbed.scala:19: value is is not a member of Unit
[error] possible cause: maybe a semicolon is missing before `value is'?
[error] } is (s_5) {
[error] ^
[error] one error found
[error] (compile:compile) Compilation failed
エラー メッセージに注意して、最初のステートメントを除くすべての "is" ステートメントの前にセミコロンを追加して、エラーを解決しようとしました。
package Testbed
import Chisel._
class Testbed extends Module {
val io = new Bundle {
val nickel = Bool(dir = INPUT)
val dime = Bool(dir = INPUT)
val rdy = Bool(dir = OUTPUT) }
val s_idle :: s_5 :: s_10 :: s_15 :: s_ok :: Nil = Enum(UInt(), 5)
val state = Reg(init = s_idle)
switch (state) {
is (s_idle) {
when (io.nickel) { state := s_5 }
when (io.dime) { state := s_10 }
}; is (s_5) {
when (io.nickel) { state := s_10 }
when (io.dime) { state := s_15 }
}; is (s_10) {
when (io.nickel) { state := s_15 }
when (io.dime) { state := s_ok }
}; is (s_15) {
when (io.nickel) { state := s_ok }
when (io.dime) { state := s_ok }
}; is (s_ok) {
state := s_idle
}
}
io.rdy := (state === s_ok)
}
class TestbedTests(c: Testbed) extends Tester(c) {
}
object Testbed {
def main(args: Array[String]): Unit = {
val tutArgs = args.slice(1, args.length)
chiselMainTest(tutArgs, () => Module(new Testbed())) {
c => new TestbedTests(c) }
}
}
結果のコードは、最終的に Verilog の生成に成功しました。次に、セミコロンを削除しようとしましたが、上記の行の前の switch ステートメントから閉じ中かっこを入れても機能しました。
package Testbed
import Chisel._
class Testbed extends Module {
val io = new Bundle {
val nickel = Bool(dir = INPUT)
val dime = Bool(dir = INPUT)
val rdy = Bool(dir = OUTPUT) }
val s_idle :: s_5 :: s_10 :: s_15 :: s_ok :: Nil = Enum(UInt(), 5)
val state = Reg(init = s_idle)
switch (state) {
is (s_idle) {
when (io.nickel) { state := s_5 }
when (io.dime) { state := s_10 }}
is (s_5) {
when (io.nickel) { state := s_10 }
when (io.dime) { state := s_15 }}
is (s_10) {
when (io.nickel) { state := s_15 }
when (io.dime) { state := s_ok }}
is (s_15) {
when (io.nickel) { state := s_ok }
when (io.dime) { state := s_ok }}
is (s_ok) {
state := s_idle
}
}
io.rdy := (state === s_ok)
}
class TestbedTests(c: Testbed) extends Tester(c) {
}
object Testbed {
def main(args: Array[String]): Unit = {
val tutArgs = args.slice(1, args.length)
chiselMainTest(tutArgs, () => Module(new Testbed())) {
c => new TestbedTests(c) }
}
}
私の懸念は、chisel チュートリアルで提示されているバージョンの switch ステートメントが他の人でも機能するかどうかです。機能する場合、switch ステートメントを非常に特殊な方法でフォーマットするように注意する必要がある理由を誰かが知っていますか?正しく動作するには?その場合、修正するにはどうすればよいですか?