I am having a device added to the rocket chip, it has its control & status registers and also an internal ram. To have the ability to access it with software I have added it into the regmap() in the next way :
val mem = Module(new SinglePortMemory(32,128, 7))
// init //
mem.io.re := false.B
mem.io.we := false.B
mem.io.addr := 0.U
mem.io.din := 0.S
val dout = RegNext(mem.io.dout)
regmap((
Seq(
0x0 -> Seq(RegField(1,enable,RegFieldDesc("enable","This bit enable my device")))
++ Seq.tabulate(128) {j =>
(0x50 + (j*4)) -> Seq(RegField(32,
RegReadFn(ready => {
when(ready) {
mem.io.addr := j.asUInt
mem.io.re := true.B
}
(true.B,dout.asUInt)
}),
RegWriteFn((valid,data) => {
when(valid) {
mem.io.addr := j.asUInt
mem.io.we := true.B
mem.io.din := data.asSInt
}
true.B
}),
RegFieldDesc(s"mem_${j}","")
))}
):_*)
Now this works , but I'm not sure if that is the best way to do that (I mean adding the memory to regmap). Can someone advise on a different / better way to do that ?