diff options
| author | Jack Koenig | 2019-08-13 15:06:58 +0530 |
|---|---|---|
| committer | GitHub | 2019-08-13 15:06:58 +0530 |
| commit | 24dddea6dccea5a570cece78324a5db624c7303a (patch) | |
| tree | b03fa616d0b8796548604a3d2b564fd17cf4e2d8 /chiselFrontend/src/main/scala/chisel3/RawModule.scala | |
| parent | fddb5943b1d36925a5435d327c3312572e98ca58 (diff) | |
Add support for asynchronous reset (#1011)
Adds new AsyncReset and "abstract" Reset types. Reset is inferred
in FIRRTL to be either AsyncReset or Bool. The "reset type" of a
register is set by the type of its reset signal:
val asyncReset: AsyncReset = IO(Input(AsyncReset()))
val syncReset: Bool = IO(Input(Bool()))
val abstractReset: Reset = IO(Input(Reset()))
val asyncReg = withReset(asyncReset) { RegInit(0.U) }
val syncReg = withReset(syncReset) { RegInit(0.U) }
val inferredReg = withReset(abstractReset) { RegInit(0.U) }
AsyncReset can be cast to and from Bool. Whereas synchronous reset is
equivalent to a mux in front of a flip-flop and thus can be driven by
logic, asynchronous reset requires that the reset value is a constant.
This is checked in FIRRTL.
Inference of the concrete type of a Reset occurs based on the type the
Reset's drivers. This inference is very simple, it is simple forward propagation
of the type, but it allows for writing blocks and modules that are agnostic
to the reset type. In particular, the implicit `reset` value in MultiIOModule
and thus Module is now concretely an instance of Reset and thus will be
inferred in FIRRTL.
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3/RawModule.scala')
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/RawModule.scala | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/RawModule.scala b/chiselFrontend/src/main/scala/chisel3/RawModule.scala index 6d316074..8f201ce6 100644 --- a/chiselFrontend/src/main/scala/chisel3/RawModule.scala +++ b/chiselFrontend/src/main/scala/chisel3/RawModule.scala @@ -143,7 +143,11 @@ abstract class MultiIOModule(implicit moduleCompileOptions: CompileOptions) extends RawModule { // Implicit clock and reset pins val clock: Clock = IO(Input(Clock())) - val reset: Reset = IO(Input(Bool())) + val reset: Reset = { + // Top module and compatibility mode use Bool for reset + val inferReset = _parent.isDefined && moduleCompileOptions.inferModuleReset + IO(Input(if (inferReset) Reset() else Bool())) + } // Setup ClockAndReset Builder.currentClock = Some(clock) @@ -219,14 +223,7 @@ abstract class LegacyModule(implicit moduleCompileOptions: CompileOptions) pushCommand(DefInvalid(sourceInfo, io.ref)) } - override_clock match { - case Some(override_clock) => clock := override_clock - case _ => clock := Builder.forcedClock - } - - override_reset match { - case Some(override_reset) => reset := override_reset - case _ => reset := Builder.forcedReset - } + clock := override_clock.getOrElse(Builder.forcedClock) + reset := override_reset.getOrElse(Builder.forcedReset) } } |
