chisel fsm

26 views
Skip to first unread message

jian wang

unread,
Oct 28, 2022, 8:14:05 AM10/28/22
to chisel-users
Hi all:
I am writing a fsm, but encountering an error with scala type mismatch, so I try an example , but still not work.

sbt error message:
error] C:\Users\JianWang\Project\chisel\chisel-decoder-cc\src\main\scala\gcd\FSMTest.scala:21:24: polymorphic expression cannot be instantiated to expected type;
[error]  found   : Set         (in scala.collection)
[error]  required: Set[BigInt] (in scala.collection.immutable)
[error]         switch (state) {
[error]                        ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 8 s, completed 2022-10-28 20:02:51

chisel code below:
class FSMTest extends Module{
        val io = IO(new Bundle {
                            val in = Input(Bool())
                            val out = Output(Bool())
                    })
        val sNone :: sOne1 :: sTwo1s :: Nil = Enum(3)
        val state = RegInit(sNone)

        io.out := (state === sTwo1s)

        switch (state) {
                is (sNone) {
                        when (io.in) {
                                state := sOne1
                        }
                }
                is (sOne1) {
                        when (io.in) {
                                state := sTwo1s
                        } .otherwise {
                                state := sNone
                        }
                }
                is (sTwo1s) {
                        when (!io.in) {
                                state := sNone
                        }
                }
        }
}

sbt config below:
ThisBuild / scalaVersion     := "2.13.8"
ThisBuild / version          := "0.1.0"
ThisBuild / organization     := "%ORGANIZATION%"

val chiselVersion = "3.5.1"

lazy val root = (project in file("."))
  .settings(
    name := "%NAME%",
    libraryDependencies ++= Seq(
      "edu.berkeley.cs" %% "chisel3" % chiselVersion,
      "edu.berkeley.cs" %% "chiseltest" % "0.5.1" % "test"
    ),
    scalacOptions ++= Seq(
      "-language:reflectiveCalls",
      "-deprecation",
      "-feature",
      "-Xcheckinit",
      "-P:chiselplugin:genBundleElements",
    ),
    addCompilerPlugin("edu.berkeley.cs" % "chisel3-plugin" % chiselVersion cross CrossVersion.full),
   
    addCompilerPlugin("edu.berkeley.cs" % "chisel3-plugin" % chiselVersion cross CrossVersion.full),
  )

Øyvind Harboe

unread,
Oct 29, 2022, 5:55:52 AM10/29/22
to chisel-users
Reply all
Reply to author
Forward
0 new messages