Is there a way to get the reset value of a RegInit
by probing members of the type that is produces? I can see that a RegInit will return the type (e.g. UInt
). For example I will have a register which I want to be controlled via a regmap
val myRWReg = RegInit(3.U(10.W))
// ...
node.regmap(
0x0 -> Seq(RegField(10.W, myRWReg,
RegFieldDesc("myRWReg", "A RW Register.", reset = myRWReg.init)))
)
.init
is not an accessible member, but is shown here to imply it's what I'm looking for.
Is there a way to do this so that anytime a RegFieldDesc
is used the reset description can match the hardware without having to keep another variable?
A workaround/solution is to make 3.U
in my example a val
that is changed based on any parameters and simply pass that, but wasn't sure if there was something else that could be used.
I ended up coming up with something that may be useful for others. One of the things I wanted to also be able to do was not have to explicitly declare a Reg
. I wanted this to be inferred by the connection. For example, I have a SW register that is driving an 8bit "port" on a Bundle
. I could make a Reg
but then I need to keep up with the size if it changes based on parameters.
object WavRWReg{
def apply[T <: Data](connection : T, reset: T, name: String, desc: String = ""): RegField = {
//val reg = RegInit(reset)
val reg = RegInit(connection.cloneType, reset)
reg.suggestName("swi_" + name)
connection := reg
//litValue returns the Bigint value
val rf = RegField(reg.getWidth, reg.asUInt, RegFieldDesc(name, desc, access=RegFieldAccessType.RW , reset=Some(reset.litValue)))
rf
}
}
So this creates the Reginit
to the specified reset val, and the width is inferred from the connection type. The reset value is also sent to the RegFieldDesc
so I don't have to manually keep up with it in two places, keeping down on errors.