diff options
| author | Jack Koenig | 2017-02-16 11:02:21 -0800 |
|---|---|---|
| committer | GitHub | 2017-02-16 11:02:21 -0800 |
| commit | 563f348ca3e4a984ad23caba9e980dab8fa808bb (patch) | |
| tree | 46dfe1e3a0a76b2f106a48332e55237ef237f441 /chiselFrontend/src/main/scala/chisel3/core/MultiClock.scala | |
| parent | d00a3fe9a3df5ce888b5c461181aadbd4a293bf3 (diff) | |
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.
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3/core/MultiClock.scala')
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/core/MultiClock.scala | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/MultiClock.scala b/chiselFrontend/src/main/scala/chisel3/core/MultiClock.scala new file mode 100644 index 00000000..62163318 --- /dev/null +++ b/chiselFrontend/src/main/scala/chisel3/core/MultiClock.scala @@ -0,0 +1,54 @@ +// See LICENSE for license details. + +package chisel3.core + +import scala.language.experimental.macros + +import chisel3.internal._ +import chisel3.internal.Builder.pushCommand +import chisel3.internal.firrtl._ +import chisel3.internal.sourceinfo.{SourceInfo} + +private[chisel3] final case class ClockAndReset(clock: Clock, reset: Bool) + +object withClockAndReset { // scalastyle:ignore object.name + /** Creates a new Clock and Reset scope + * + * @param clock the new implicit Clock + * @param reset the new implicit Reset + * @param block the block of code to run with new implicit Clock and Reset + * @return the result of the block + */ + def apply[T](clock: Clock, reset: Bool)(block: => T): T = { + // Save parentScope + val parentScope = Builder.currentClockAndReset + Builder.currentClockAndReset = Some(ClockAndReset(clock, reset)) + val res = block // execute block + // Return to old scope + Builder.currentClockAndReset = parentScope + res + } +} + +object withClock { // scalastyle:ignore object.name + /** Creates a new Clock scope + * + * @param clock the new implicit Clock + * @param block the block of code to run with new implicit Clock + * @return the result of the block + */ + def apply[T](clock: Clock)(block: => T): T = + withClockAndReset(clock, Module.reset)(block) +} + +object withReset { // scalastyle:ignore object.name + /** Creates a new Reset scope + * + * @param reset the new implicit Reset + * @param block the block of code to run with new implicit Reset + * @return the result of the block + */ + def apply[T](reset: Bool)(block: => T): T = + withClockAndReset(Module.clock, reset)(block) +} + |
