Reputation: 441
when I was trying to use Chisel to build an FSM, I used Enum() as the Chisel Tutorial said. However, I encountered such errors.
my code:
val sIdle::s1::s2::s3::s4::Nil = Enum(UInt(), 5)
however, when I executed sbt run, it printed out that
[error] /Users/xxx.scala:28:3: object java.lang.Enum is not a value
[error] Enum(UInt(),5)
[error] ^
My build sbt file is
scalaVersion := "2.11.12"
resolvers ++= Seq(
Resolver.sonatypeRepo("snapshots"),
Resolver.sonatypeRepo("releases")
)
libraryDependencies += "edu.berkeley.cs" %% "chisel3" % "3.1.+"
Please help!
Upvotes: 2
Views: 926
Reputation: 6064
Turning my comment into a full answer so it's more obvious for future people.
In chisel3
, a lot of things that were in package Chisel
in Chisel2 were moved in to package chisel3.util
. You can use the ScalaDoc API to search for things like Enum
or switch
to see where they are located (and other associated documentation).
Also in chisel3, Enum(type, size)
has been deprecated in favor if Enum(size)
, ie. you should use:
import chisel3._
import chisel3.util.Enum
val sIdle :: s1 :: s2 :: s3 :: s4 :: Nil = Enum(5)
I would also like to mention we have a new "ChiselEnum" coming that provides more functionality than the existing API and we intend to extend it's functionality further. If you build chisel3 from source you can use it already, or you can wait for the release of 3.2. Example of new enum:
import chisel3._
import chisel3.experimental.ChiselEnum
object EnumExample extends ChiselEnum {
val e0, e1, e2 = Value // Assigns default values starting at 0
val e100 = Value(100.U) // Can provide specific values if desired
}
import EnumExample._
val myState = Reg(EnumExample()) // Can give a register the actual type instead of just UInt
myState := e100
Upvotes: 2
Reputation: 14224
By default Enum
references java.lang.Enum
. Chisel has its own Enum
object, which you have to import before using:
import Chisel.Enum
import Chisel.UInt
val sIdle::s1::s2::s3::s4::Nil = Enum(UInt(), 5)
// Or an alternative way to unpack a List:
// val List(sIdle, s1, s2, s3, s4) = Enum(UInt(), 5)
Upvotes: 1