From 563f348ca3e4a984ad23caba9e980dab8fa808bb Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Thu, 16 Feb 2017 11:02:21 -0800 Subject: Add support for clock and reset scoping (#509) withClockAndReset, withReset, and withClock allow changing the implicit clock and reset. Module.clock and Module.reset provide access to the current implicit clock and reset. --- chiselFrontend/src/main/scala/chisel3/core/Module.scala | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'chiselFrontend/src/main/scala/chisel3/core/Module.scala') diff --git a/chiselFrontend/src/main/scala/chisel3/core/Module.scala b/chiselFrontend/src/main/scala/chisel3/core/Module.scala index 3ff68772..1388fb80 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Module.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Module.scala @@ -32,11 +32,13 @@ object Module { Builder.readyForModuleConstr = true val parent: Option[Module] = Builder.currentModule val whenDepth: Int = Builder.whenDepth + val clockAndReset: Option[ClockAndReset] = Builder.currentClockAndReset // Execute the module, this has the following side effects: // - set currentModule // - unset readyForModuleConstr // - reset whenDepth to 0 + // - set currentClockAndReset val m = bc.setRefs() m._commands.prepend(DefInvalid(childSourceInfo, m.io.ref)) // init module outputs @@ -50,6 +52,7 @@ object Module { } Builder.currentModule = parent // Back to parent! Builder.whenDepth = whenDepth + Builder.currentClockAndReset = clockAndReset // Back to clock and reset scope val ports = m.computePorts // Blackbox inherits from Module so we have to match on it first TODO fix @@ -69,6 +72,11 @@ object Module { } m } + + /** Returns the implicit Clock */ + def clock: Clock = Builder.forcedClock + /** Returns the implicit Reset */ + def reset: Bool = Builder.forcedReset } /** Abstract base class for Modules, which behave much like Verilog modules. @@ -156,6 +164,9 @@ extends HasId { val clock = Port(Input(Clock())) val reset = Port(Input(Bool())) + // Setup ClockAndReset + Builder.currentClockAndReset = Some(ClockAndReset(clock, reset)) + private[chisel3] def addId(d: HasId) { _ids += d } private[core] def ports: Seq[(String,Data)] = Vector( -- cgit v1.2.3