diff options
| author | Jack Koenig | 2020-03-06 11:05:55 -0800 |
|---|---|---|
| committer | GitHub | 2020-03-06 19:05:55 +0000 |
| commit | a06c411ce2ce6ddf8c20b38f90f4074af7b33b3f (patch) | |
| tree | 3e129e07c524baaf4e7f7a85813fcefc69160189 | |
| parent | 1a4e0dd65ba3e64268beca8f592bd58d98c434a4 (diff) | |
Provide API to set concrete type of implicit reset (#1361)
Introduces mutually-exclusive traits RequireAsyncReset and
RequireSyncReset to set the type of the implicit reset in
MultiIOModules. The Scala-type remains Reset, but the Chisel
elaboration-time checks apply.
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/RawModule.scala | 14 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/ResetSpec.scala | 24 |
2 files changed, 36 insertions, 2 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/RawModule.scala b/chiselFrontend/src/main/scala/chisel3/RawModule.scala index ae3b6fe7..407ed931 100644 --- a/chiselFrontend/src/main/scala/chisel3/RawModule.scala +++ b/chiselFrontend/src/main/scala/chisel3/RawModule.scala @@ -134,6 +134,14 @@ abstract class RawModule(implicit moduleCompileOptions: CompileOptions) } } +trait RequireAsyncReset extends MultiIOModule { + override private[chisel3] def mkReset: AsyncReset = AsyncReset() +} + +trait RequireSyncReset extends MultiIOModule { + override private[chisel3] def mkReset: Bool = Bool() +} + /** Abstract base class for Modules, which behave much like Verilog modules. * These may contain both logic and state which are written in the Module * body (constructor). @@ -145,10 +153,12 @@ abstract class MultiIOModule(implicit moduleCompileOptions: CompileOptions) extends RawModule { // Implicit clock and reset pins val clock: Clock = IO(Input(Clock())) - val reset: Reset = { + val reset: Reset = IO(Input(mkReset)) + + private[chisel3] def mkReset: Reset = { // Top module and compatibility mode use Bool for reset val inferReset = _parent.isDefined && moduleCompileOptions.inferModuleReset - IO(Input(if (inferReset) Reset() else Bool())) + if (inferReset) Reset() else Bool() } // Setup ClockAndReset diff --git a/src/test/scala/chiselTests/ResetSpec.scala b/src/test/scala/chiselTests/ResetSpec.scala index 2a17d52f..d08be8fa 100644 --- a/src/test/scala/chiselTests/ResetSpec.scala +++ b/src/test/scala/chiselTests/ResetSpec.scala @@ -68,4 +68,28 @@ class ResetSpec extends ChiselFlatSpec { }) async should include ("always @(posedge clk or posedge rst)") } + + behavior of "Users" + + they should "be able to force implicit reset to be synchronous" in { + val fir = generateFirrtl(new MultiIOModule with RequireSyncReset { + reset shouldBe a [Bool] + }) + fir should include ("input reset : UInt<1>") + } + + they should "be able to force implicit reset to be asynchronous" in { + val fir = generateFirrtl(new MultiIOModule with RequireAsyncReset { + reset shouldBe an [AsyncReset] + }) + fir should include ("input reset : AsyncReset") + } + + "Chisel" should "error if sync and async modules are nested" in { + a [ChiselException] shouldBe thrownBy { + elaborate(new MultiIOModule with RequireAsyncReset { + val mod = Module(new MultiIOModule with RequireSyncReset) + }) + } + } } |
