Skip to content

Commit

Permalink
Fix := of Reset and AsyncReset to DontCare (#1336) (#1338)
Browse files Browse the repository at this point in the history
(cherry picked from commit bcad26c)

Co-authored-by: Jack Koenig <jack.koenig3@gmail.com>
  • Loading branch information
mergify[bot] and jackkoenig authored Feb 12, 2020
1 parent 351b9c3 commit b160f0b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions chiselFrontend/src/main/scala/chisel3/Bits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ final class ResetType(private[chisel3] val width: Width = Width(1)) extends Elem
this.getClass == that.getClass

override def connect(that: Data)(implicit sourceInfo: SourceInfo, connectCompileOptions: CompileOptions): Unit = that match {
case _: Reset => super.connect(that)(sourceInfo, connectCompileOptions)
case _: Reset | DontCare => super.connect(that)(sourceInfo, connectCompileOptions)
case _ => super.badConnect(that)(sourceInfo)
}

Expand Down Expand Up @@ -983,7 +983,7 @@ sealed class AsyncReset(private[chisel3] val width: Width = Width(1)) extends El
this.getClass == that.getClass

override def connect(that: Data)(implicit sourceInfo: SourceInfo, connectCompileOptions: CompileOptions): Unit = that match {
case _: AsyncReset => super.connect(that)(sourceInfo, connectCompileOptions)
case _: AsyncReset | DontCare => super.connect(that)(sourceInfo, connectCompileOptions)
case _ => super.badConnect(that)(sourceInfo)
}

Expand Down
22 changes: 22 additions & 0 deletions src/test/scala/chiselTests/AsyncResetSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,32 @@ class AsyncResetQueueTester extends BasicTester {
}
}

class AsyncResetDontCareModule extends RawModule {
import chisel3.util.Valid
val monoPort = IO(Output(AsyncReset()))
monoPort := DontCare
val monoWire = Wire(AsyncReset())
monoWire := DontCare
val monoAggPort = IO(Output(Valid(AsyncReset())))
monoAggPort := DontCare
val monoAggWire = Wire(Valid(AsyncReset()))
monoAggWire := DontCare

// Can't bulk connect to Wire so only ports here
val bulkPort = IO(Output(AsyncReset()))
bulkPort <> DontCare
val bulkAggPort = IO(Output(Valid(AsyncReset())))
bulkAggPort <> DontCare
}

class AsyncResetSpec extends ChiselFlatSpec {

behavior of "AsyncReset"

it should "be able to be connected to DontCare" in {
elaborate(new AsyncResetDontCareModule)
}

it should "be allowed with literal reset values" in {
elaborate(new BasicTester {
withReset(reset.asAsyncReset)(RegInit(123.U))
Expand Down
22 changes: 22 additions & 0 deletions src/test/scala/chiselTests/ResetSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,33 @@ class ResetAgnosticModule extends RawModule {
out := reg
}

class AbstractResetDontCareModule extends RawModule {
import chisel3.util.Valid
val monoPort = IO(Output(Reset()))
monoPort := DontCare
val monoWire = Wire(Reset())
monoWire := DontCare
val monoAggPort = IO(Output(Valid(Reset())))
monoAggPort := DontCare
val monoAggWire = Wire(Valid(Reset()))
monoAggWire := DontCare

// Can't bulk connect to Wire so only ports here
val bulkPort = IO(Output(Reset()))
bulkPort <> DontCare
val bulkAggPort = IO(Output(Valid(Reset())))
bulkAggPort <> DontCare
}


class ResetSpec extends ChiselFlatSpec {

behavior of "Reset"

it should "be able to be connected to DontCare" in {
elaborate(new AbstractResetDontCareModule)
}

it should "allow writing modules that are reset agnostic" in {
val sync = compile(new Module {
val io = IO(new Bundle {
Expand Down

0 comments on commit b160f0b

Please sign in to comment.