-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Toy example of using instrumentation
It monitors and bins signal values
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// See LICENSE for license details. | ||
|
||
package examples | ||
|
||
import chisel3._ | ||
import chisel3.experimental.FixedPoint | ||
import dsptools.DspTester | ||
import dsptools.numbers._ | ||
import org.scalatest.{FlatSpec, Matchers} | ||
|
||
//scalastyle:off magic.number | ||
|
||
class InstrumentingAdder[T <: Data:Ring](gen:() => T) extends Module { | ||
val io = IO(new Bundle { | ||
val a1: T = Input(gen()) | ||
val a2: T = Input(gen()) | ||
val c = Output(gen()) | ||
}) | ||
|
||
val register1 = Reg(gen()) | ||
|
||
register1 := io.a1 + io.a2 | ||
|
||
io.c := register1 | ||
} | ||
|
||
class InstrumentingAdderTester[T<:Data:Ring](c: InstrumentingAdder[T]) extends DspTester(c) { | ||
for { | ||
i <- -2.0 to 1.0 by 0.25 | ||
j <- -2.0 to 4.0 by 0.5 | ||
} { | ||
poke(c.io.a1, i) | ||
poke(c.io.a2, j) | ||
step(1) | ||
|
||
val result = peek(c.io.c) | ||
|
||
expect(c.io.c, i + j, s"parameterize adder tester $i + $j => $result should have been ${i + j}") | ||
} | ||
} | ||
|
||
class InstrumentingAdderSpec extends FlatSpec with Matchers { | ||
|
||
behavior of "parameterized adder circuit on blackbox real" | ||
|
||
it should "run while being instrumented" in { | ||
def getFixed: FixedPoint = FixedPoint(32.W, 16.BP) | ||
|
||
dsptools.Driver.execute(() => new InstrumentingAdder(getFixed _), | ||
Array("-fimbu", "-fimof", "signals.csv", "-fimhb", "16")) { c => | ||
new InstrumentingAdderTester(c) | ||
} should be (true) | ||
} | ||
} |