blob: 4809cf29ef42a97065fdc6453b9084da11597151 (
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// SPDX-License-Identifier: Apache-2.0
package chisel3
import chisel3.internal._
object withClockAndReset {
/** 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 parentClock = Builder.currentClock
val parentReset = Builder.currentReset
Builder.currentClock = Some(clock)
Builder.currentReset = Some(reset)
val res = block // execute block
// Return to old scope
Builder.currentClock = parentClock
Builder.currentReset = parentReset
res
}
}
object withClock {
/** 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 = {
// Save parentScope
val parentClock = Builder.currentClock
Builder.currentClock = Some(clock)
val res = block // execute block
// Return to old scope
Builder.currentClock = parentClock
res
}
}
object withReset {
/** 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 = {
// Save parentScope
val parentReset = Builder.currentReset
Builder.currentReset = Some(reset)
val res = block // execute block
// Return to old scope
Builder.currentReset = parentReset
res
}
}
|