summaryrefslogtreecommitdiff
path: root/chiselFrontend/src/main/scala/chisel3/core/MultiClock.scala
blob: 6af4da4131701a806ef1fa094d60134c13cc828a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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: Reset)

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: Reset)(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: Reset)(block: => T): T =
    withClockAndReset(Module.clock, reset)(block)
}