Reputation: 95
I have a SlaveFactory and I'd like to save some flags in registers as SpinalEnums. Is it possible to cast Bits to my SpinalEnum on write operation?
Upvotes: 1
Views: 96
Reputation: 95
I figured it out. Basically on AxiLite4SlaveFactory
side I have something like this:
val gen_stop_type = RegInit(StopType.stop_frame.asBits)
busCtrl.write(gen_stop_type, JumboBridgeAXIReg.GEN_STOP.id)
io.gen_stop_type_o.assignFromBits(gen_stop_type)
StopType
is my SpinalEnum
. So going line by line:
.asBits
, when initialising with a default value – it is in Bits
type, but with correct bit length according to StopType
length when encoded in hardware.SlaveFactory.write
method (which now references to Bits
register, not StopType
register, what caused errors before)..assignFromBits
, which I found, when looking through docs. Basically every hardware type has this method (and SpinalEnum
is a hardware type), so it's possible to "convert" Bits
(with width previously derived from the enum) to StopType
enum.Upvotes: 1