From 878a357a0d264ae3a532a05e4661427c978335f4 Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Mon, 5 Mar 2018 11:22:24 -0800 Subject: [PATCH] RegFieldDesc: Add utilities for generating and describing registers at the same time. --- src/main/scala/util/DescribedReg.scala | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/main/scala/util/DescribedReg.scala diff --git a/src/main/scala/util/DescribedReg.scala b/src/main/scala/util/DescribedReg.scala new file mode 100644 index 00000000..bf1a2e5d --- /dev/null +++ b/src/main/scala/util/DescribedReg.scala @@ -0,0 +1,40 @@ +// See LICENSE for license details. +package freechips.rocketchip.util + +import Chisel._ +import chisel3.experimental._ +import chisel3.{Input, Output} + +import freechips.rocketchip.regmapper.{RegFieldDesc} + +object DescribedReg { + import freechips.rocketchip.regmapper.RegFieldAccessType._ + + def apply[T <: Data]( + gen: => T, + name: String, + desc: String, + reset: Option[T], + access: RegFieldAccessType = RW, + enumerations: Map[BigInt, (String, String)] = Map()): (T, RegFieldDesc) = { + val rdesc = RegFieldDesc(name, desc, None, None, + access, reset.map{_.litValue}, enumerations) + val reg = reset.map{i => RegInit(i)}.getOrElse(Reg(gen)) + reg.suggestName(name + "_reg") + (reg, rdesc) + } + + def async( + width: Int, + name: String, + desc: String, + reset: Int, + access: RegFieldAccessType = RW, + enumerations: Map[BigInt, (String, String)] = Map()): (SimpleRegIO, RegFieldDesc) = { + val rdesc = RegFieldDesc(name, desc, None, None, + access, Some(reset), enumerations) + val reg = Module(new AsyncResetRegVec(w = width, init = reset)) + reg.suggestName(name + "_reg") + (reg.io, rdesc) + } +}