Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow DataView of Reset <=> [UInt<1>, AsyncReset] (backport #3181) #3258

Merged
merged 1 commit into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions core/src/main/scala/chisel3/experimental/dataview/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,19 @@ package object dataview {
val tex = unfoldView(te).find(targetContains).getOrElse(err("Target", te))
val vex = unfoldView(ve).find(viewFieldLookup.contains).getOrElse(err("View", ve))

if (tex.getClass != vex.getClass) {
val fieldName = viewFieldName(vex)
throw InvalidViewException(s"Field $fieldName specified as view of non-type-equivalent value $tex")
(tex, vex) match {
/* Allow views where the types are equal. */
case (a, b) if a.getClass == b.getClass =>
/* allow bool <=> reset views. */
case (a: Bool, _: Reset) =>
case (_: Reset, a: Bool) =>
/* Allow AsyncReset <=> Reset views. */
case (a: AsyncReset, _: Reset) =>
case (_: Reset, a: AsyncReset) =>
/* All other views produce a runtime error. */
case _ =>
val fieldName = viewFieldName(vex)
throw InvalidViewException(s"Field $fieldName specified as view of non-type-equivalent value $tex")
}
// View width must be unknown or match target width
if (vex.widthKnown && vex.width != tex.width) {
Expand Down
34 changes: 34 additions & 0 deletions src/test/scala/chiselTests/experimental/DataView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,40 @@ class DataViewSpec extends ChiselFlatSpec {
chirrtl should include("dataOut <= vec[addrReg]")
}

it should "allow views between reset types" in {
class A extends Bundle {
val bool = Bool()
val asyncreset = AsyncReset()
}

class B extends Bundle {
val reset_0 = Reset()
val reset_1 = Reset()
}

class Foo extends RawModule {
val a = Wire(new A)
val b = Wire(new B)

implicit val view = DataView[A, B](
_ => new B,
_.bool -> _.reset_0,
_.asyncreset -> _.reset_1
)

a.viewAs[B] := b
}

(ChiselStage
.emitCHIRRTL(new Foo, Array("--full-stacktrace"))
.split('\n')
.map(_.takeWhile(_ != '@'))
.map(_.trim) should contain).allOf(
"a.bool <= b.reset_0",
"a.asyncreset <= b.reset_1"
)
}

it should "error if you try to dynamically index a Vec view that does not correspond to a Vec target" in {
class MyModule extends Module {
val inA, inB = IO(Input(UInt(8.W)))
Expand Down