-
Notifications
You must be signed in to change notification settings - Fork 218
/
GlobalResetConditionTests.scala
55 lines (43 loc) · 2.05 KB
/
GlobalResetConditionTests.scala
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 firesim.midasexamples
import chisel3._
import org.chipsalliance.cde.config.Parameters
import midas.targetutils._
import midas.widgets.{RationalClockBridge, PeekPokeBridge, RationalClock}
abstract class GlobalResetConditionTester(elaborator: (Bool) => Unit) extends RawModule {
val clockBridge = RationalClockBridge(RationalClock("HalfRate", 1, 2))
val List(clockA, clockB) = clockBridge.io.clocks.toList
val reset = WireInit(false.B)
// This reset will be used to mask off events (AutoCounter, Assertions,
// Printfs) that would be active in domains that have pipelined resets
// which may not be initially asserted.
GlobalResetCondition(reset)
val pipelinedResetA = withClock(clockA) { RegNext(RegNext(reset)) }
val pipelinedResetB = withClock(clockB) { RegNext(RegNext(reset)) }
def instantiateDomain(clock: Clock, reset: Bool) {
withClockAndReset(clock, reset) {
val reg = RegInit(1.U(8.W))
// Confuse CP with an additional assignment so that it doesn't optimize
// through our register and render our assertion vacuous
reg := Mux(reg =/= 0.U, 1.U, 0.U)
val stillInReset = reg === 0.U
elaborator(stillInReset)
}
}
instantiateDomain(clockA, pipelinedResetA)
instantiateDomain(clockB, pipelinedResetB)
val peekPokeBridge = PeekPokeBridge(clockA, reset)
}
class AssertGlobalResetCondition(implicit p: Parameters) extends GlobalResetConditionTester(
(inReset: Bool) => { assert(!inReset, s"This should not fire\n") }
)
class PrintfGlobalResetCondition(implicit p: Parameters) extends GlobalResetConditionTester(
(inReset: Bool) => {
when(inReset) { SynthesizePrintf(printf(s"This should not print. %b\n", inReset)) }
})
class AutoCounterGlobalResetCondition(implicit p: Parameters) extends GlobalResetConditionTester(
(inReset: Bool) => {
// Extra wire to workaround https://github.com/firesim/firesim/issues/789
val clockWire = WireDefault(Module.clock)
PerfCounter(inReset, clockWire, Module.reset, "ShouldBeZero", "This should not count")
})