2016-11-28 01:16:37 +01:00
|
|
|
// See LICENSE.SiFive for license details.
|
2016-09-14 01:04:46 +02:00
|
|
|
|
2017-07-07 19:48:16 +02:00
|
|
|
package freechips.rocketchip.tilelink
|
2016-09-14 01:04:46 +02:00
|
|
|
|
|
|
|
import Chisel._
|
|
|
|
import chisel3.internal.sourceinfo.SourceInfo
|
2017-07-07 19:48:16 +02:00
|
|
|
import freechips.rocketchip.config.Parameters
|
|
|
|
import freechips.rocketchip.diplomacy._
|
|
|
|
import freechips.rocketchip.util._
|
2016-09-14 01:04:46 +02:00
|
|
|
|
2016-12-02 02:46:52 +01:00
|
|
|
class TLAsyncCrossingSource(sync: Int = 3)(implicit p: Parameters) extends LazyModule
|
2016-09-14 01:04:46 +02:00
|
|
|
{
|
2017-01-24 02:54:27 +01:00
|
|
|
val node = TLAsyncSourceNode(sync)
|
2016-09-14 01:04:46 +02:00
|
|
|
|
|
|
|
lazy val module = new LazyModuleImp(this) {
|
|
|
|
val io = new Bundle {
|
2016-09-30 02:32:18 +02:00
|
|
|
val in = node.bundleIn
|
|
|
|
val out = node.bundleOut
|
2016-09-14 01:04:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
((io.in zip io.out) zip (node.edgesIn zip node.edgesOut)) foreach { case ((in, out), (edgeIn, edgeOut)) =>
|
2016-10-07 23:05:34 +02:00
|
|
|
val sink_reset_n = out.a.sink_reset_n
|
2017-01-18 03:52:16 +01:00
|
|
|
val bce = edgeIn.manager.anySupportAcquireB && edgeIn.client.anySupportProbe
|
2016-09-30 02:32:18 +02:00
|
|
|
val depth = edgeOut.manager.depth
|
2016-09-14 01:04:46 +02:00
|
|
|
|
2016-10-05 07:28:56 +02:00
|
|
|
out.a <> ToAsyncBundle(in.a, depth, sync)
|
|
|
|
in.d <> FromAsyncBundle(out.d, sync)
|
2016-09-30 02:32:18 +02:00
|
|
|
|
|
|
|
if (bce) {
|
2016-10-05 07:28:56 +02:00
|
|
|
in.b <> FromAsyncBundle(out.b, sync)
|
|
|
|
out.c <> ToAsyncBundle(in.c, depth, sync)
|
|
|
|
out.e <> ToAsyncBundle(in.e, depth, sync)
|
2016-09-14 01:04:46 +02:00
|
|
|
} else {
|
|
|
|
in.b.valid := Bool(false)
|
|
|
|
in.c.ready := Bool(true)
|
|
|
|
in.e.ready := Bool(true)
|
2016-09-30 02:32:18 +02:00
|
|
|
out.b.ridx := UInt(0)
|
|
|
|
out.c.widx := UInt(0)
|
|
|
|
out.e.widx := UInt(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-02 02:46:52 +01:00
|
|
|
class TLAsyncCrossingSink(depth: Int = 8, sync: Int = 3)(implicit p: Parameters) extends LazyModule
|
2016-09-30 02:32:18 +02:00
|
|
|
{
|
2017-01-24 02:54:27 +01:00
|
|
|
val node = TLAsyncSinkNode(depth, sync)
|
2016-09-30 02:32:18 +02:00
|
|
|
|
|
|
|
lazy val module = new LazyModuleImp(this) {
|
|
|
|
val io = new Bundle {
|
|
|
|
val in = node.bundleIn
|
|
|
|
val out = node.bundleOut
|
|
|
|
}
|
|
|
|
|
|
|
|
((io.in zip io.out) zip (node.edgesIn zip node.edgesOut)) foreach { case ((in, out), (edgeIn, edgeOut)) =>
|
2016-10-07 23:05:34 +02:00
|
|
|
val source_reset_n = in.a.source_reset_n
|
2017-01-18 03:52:16 +01:00
|
|
|
val bce = edgeOut.manager.anySupportAcquireB && edgeOut.client.anySupportProbe
|
2016-09-30 02:32:18 +02:00
|
|
|
|
2016-10-05 07:28:56 +02:00
|
|
|
out.a <> FromAsyncBundle(in.a, sync)
|
|
|
|
in.d <> ToAsyncBundle(out.d, depth, sync)
|
2016-09-30 02:32:18 +02:00
|
|
|
|
|
|
|
if (bce) {
|
2016-10-05 07:28:56 +02:00
|
|
|
in.b <> ToAsyncBundle(out.b, depth, sync)
|
|
|
|
out.c <> FromAsyncBundle(in.c, sync)
|
|
|
|
out.e <> FromAsyncBundle(in.e, sync)
|
2016-09-30 02:32:18 +02:00
|
|
|
} else {
|
|
|
|
in.b.widx := UInt(0)
|
|
|
|
in.c.ridx := UInt(0)
|
|
|
|
in.e.ridx := UInt(0)
|
2016-09-14 01:04:46 +02:00
|
|
|
out.b.ready := Bool(true)
|
|
|
|
out.c.valid := Bool(false)
|
|
|
|
out.e.valid := Bool(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-29 00:11:05 +02:00
|
|
|
|
2016-09-30 10:48:47 +02:00
|
|
|
object TLAsyncCrossingSource
|
|
|
|
{
|
|
|
|
// applied to the TL source node; y.node := TLAsyncCrossingSource()(x.node)
|
2016-12-02 02:46:52 +01:00
|
|
|
def apply(sync: Int = 3)(x: TLOutwardNode)(implicit p: Parameters, sourceInfo: SourceInfo): TLAsyncOutwardNode = {
|
2016-09-30 10:48:47 +02:00
|
|
|
val source = LazyModule(new TLAsyncCrossingSource(sync))
|
|
|
|
source.node := x
|
|
|
|
source.node
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object TLAsyncCrossingSink
|
|
|
|
{
|
|
|
|
// applied to the TL source node; y.node := TLAsyncCrossingSink()(x.node)
|
2016-12-02 02:46:52 +01:00
|
|
|
def apply(depth: Int = 8, sync: Int = 3)(x: TLAsyncOutwardNode)(implicit p: Parameters, sourceInfo: SourceInfo): TLOutwardNode = {
|
2016-09-30 10:48:47 +02:00
|
|
|
val sink = LazyModule(new TLAsyncCrossingSink(depth, sync))
|
|
|
|
sink.node := x
|
|
|
|
sink.node
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-02 02:46:52 +01:00
|
|
|
class TLAsyncCrossing(depth: Int = 8, sync: Int = 3)(implicit p: Parameters) extends LazyModule
|
2016-09-30 02:32:18 +02:00
|
|
|
{
|
|
|
|
val nodeIn = TLInputNode()
|
|
|
|
val nodeOut = TLOutputNode()
|
2016-10-08 08:38:36 +02:00
|
|
|
val node = NodeHandle(nodeIn, nodeOut)
|
2016-09-30 02:32:18 +02:00
|
|
|
|
|
|
|
val source = LazyModule(new TLAsyncCrossingSource(sync))
|
|
|
|
val sink = LazyModule(new TLAsyncCrossingSink(depth, sync))
|
|
|
|
|
|
|
|
val _ = (sink.node := source.node) // no monitor
|
|
|
|
val in = (source.node := nodeIn)
|
|
|
|
val out = (nodeOut := sink.node)
|
|
|
|
|
|
|
|
lazy val module = new LazyModuleImp(this) {
|
|
|
|
val io = new Bundle {
|
|
|
|
val in = nodeIn.bundleIn
|
|
|
|
val in_clock = Clock(INPUT)
|
|
|
|
val in_reset = Bool(INPUT)
|
|
|
|
val out = nodeOut.bundleOut
|
|
|
|
val out_clock = Clock(INPUT)
|
|
|
|
val out_reset = Bool(INPUT)
|
|
|
|
}
|
|
|
|
|
|
|
|
source.module.clock := io.in_clock
|
|
|
|
source.module.reset := io.in_reset
|
|
|
|
in.foreach { lm =>
|
|
|
|
lm.module.clock := io.in_clock
|
|
|
|
lm.module.reset := io.in_reset
|
|
|
|
}
|
|
|
|
|
|
|
|
sink.module.clock := io.out_clock
|
|
|
|
sink.module.reset := io.out_reset
|
|
|
|
out.foreach { lm =>
|
|
|
|
lm.module.clock := io.out_clock
|
|
|
|
lm.module.reset := io.out_reset
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-29 00:11:05 +02:00
|
|
|
/** Synthesizeable unit tests */
|
2017-07-07 19:48:16 +02:00
|
|
|
import freechips.rocketchip.unittest._
|
2016-09-29 00:11:05 +02:00
|
|
|
|
2017-05-17 20:56:01 +02:00
|
|
|
class TLRAMAsyncCrossing(txns: Int)(implicit p: Parameters) extends LazyModule {
|
2017-04-13 20:51:10 +02:00
|
|
|
val model = LazyModule(new TLRAMModel("AsyncCrossing"))
|
2016-09-29 00:11:05 +02:00
|
|
|
val ram = LazyModule(new TLRAM(AddressSet(0x0, 0x3ff)))
|
2017-05-17 20:56:01 +02:00
|
|
|
val fuzz = LazyModule(new TLFuzzer(txns))
|
2016-09-29 00:11:05 +02:00
|
|
|
val cross = LazyModule(new TLAsyncCrossing)
|
|
|
|
|
|
|
|
model.node := fuzz.node
|
2017-03-11 02:10:41 +01:00
|
|
|
cross.node := TLFragmenter(4, 256)(TLDelayer(0.1)(model.node))
|
2016-10-08 08:38:36 +02:00
|
|
|
val monitor = (ram.node := cross.node)
|
2016-09-29 00:11:05 +02:00
|
|
|
|
|
|
|
lazy val module = new LazyModuleImp(this) with HasUnitTestIO {
|
|
|
|
io.finished := fuzz.module.io.finished
|
|
|
|
|
|
|
|
// Shove the RAM into another clock domain
|
2017-07-07 19:48:16 +02:00
|
|
|
val clocks = Module(new Pow2ClockDivider(2))
|
2016-09-29 00:11:05 +02:00
|
|
|
ram.module.clock := clocks.io.clock_out
|
|
|
|
|
|
|
|
// ... and safely cross TL2 into it
|
|
|
|
cross.module.io.in_clock := clock
|
|
|
|
cross.module.io.in_reset := reset
|
|
|
|
cross.module.io.out_clock := clocks.io.clock_out
|
|
|
|
cross.module.io.out_reset := reset
|
|
|
|
|
|
|
|
// Push the Monitor into the right clock domain
|
|
|
|
monitor.foreach { m =>
|
|
|
|
m.module.clock := clocks.io.clock_out
|
|
|
|
m.module.reset := reset
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 20:56:01 +02:00
|
|
|
class TLRAMAsyncCrossingTest(txns: Int = 5000, timeout: Int = 500000)(implicit p: Parameters) extends UnitTest(timeout) {
|
|
|
|
io.finished := Module(LazyModule(new TLRAMAsyncCrossing(txns)).module).io.finished
|
2016-09-29 00:11:05 +02:00
|
|
|
}
|