Marek Pikuła
Marek Pikuła

Reputation: 95

Can I use SpinalEnum as field in RegIf?

I want to use SpinalEnum as RegIf field. Here is an example code, which doesn't seem to work:

object SourceEnum extends SpinalEnum {
  val src1, src2, src3 = newElement()
}

...

val busif = BusInterface(...)

// Control Register
val ctrl = busif.newReg("Control register")
val source = ctrl.field(SourceEnum.C, RW, doc = "Data source")

It shows a following error during compilation: value C is not a member of object regiftest.SourceEnum. I was using the .C type "extraction" before, and it worked, but clearly it doesn't work in this case. What am I doing wrong?

Currently, as a workaround I'm using B(SourceEnum().getBitsWidth) with dest.assignFromBits(source), but it's not as elegant.

Upvotes: 0

Views: 67

Answers (1)

Jijing.Guo
Jijing.Guo

Reputation: 3

no, you can't put SpinalEnum in. the RegIf REG.file() only accept HardType like

val busif = BusInterface(...)

// Control Register
val ctrl = busif.newReg("Control register")
val source = ctrl.field(Bits(8 bit), RW, doc = "Data source")
val reg1 = ctrl.field(UInt(8 bit), RW, doc = "....")
val reg2 = ctrl.field(SInt(8 bit), RW, doc = "....")
val reg3 = ctrl.field(Bool(), RW, doc = "....")

or old way

val reg1 = ctrl.field(8 bit, RW, doc = "....")
val reg2 = ctrl.field(8 bit, RW, doc = "....")
val reg3 = ctrl.field(1 bit, RW, doc = "....")

For details, please refer to https://spinalhdl.github.io/SpinalDoc-RTD/master/SpinalHDL/Libraries/regIf.html#

Upvotes: 0

Related Questions