2017-01-27 00:15:48 +01:00
|
|
|
// See LICENSE.SiFive for license details.
|
|
|
|
|
2017-01-27 06:27:34 +01:00
|
|
|
// If you know two clocks are related with a N:1 or 1:N relationship, you
|
|
|
|
// can cross the clock domains with lower latency than an AsyncQueue.
|
|
|
|
// This clock crossing behaves almost identically to a TLBuffer(2):
|
|
|
|
// - It adds one cycle latency to each clock domain.
|
|
|
|
// - All outputs of TLRational are registers (bits, valid, and ready).
|
|
|
|
// - It costs 3*bits registers as opposed to 2*bits in a TLBuffer(2)
|
|
|
|
|
2017-07-07 19:48:16 +02:00
|
|
|
package freechips.rocketchip.tilelink
|
2017-01-27 00:15:48 +01: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._
|
2017-01-27 00:15:48 +01:00
|
|
|
|
|
|
|
class TLRationalCrossingSource(implicit p: Parameters) extends LazyModule
|
|
|
|
{
|
|
|
|
val node = TLRationalSourceNode()
|
|
|
|
|
|
|
|
lazy val module = new LazyModuleImp(this) {
|
2017-09-14 03:06:03 +02:00
|
|
|
(node.in zip node.out) foreach { case ((in, edgeIn), (out, edgeOut)) =>
|
2017-01-27 00:15:48 +01:00
|
|
|
val bce = edgeIn.manager.anySupportAcquireB && edgeIn.client.anySupportProbe
|
2017-02-17 04:19:00 +01:00
|
|
|
val direction = edgeOut.manager.direction
|
2017-01-27 00:15:48 +01:00
|
|
|
|
2017-02-17 04:19:00 +01:00
|
|
|
out.a <> ToRational(in.a, direction)
|
|
|
|
in.d <> FromRational(out.d, direction.flip)
|
2017-01-27 00:15:48 +01:00
|
|
|
|
|
|
|
if (bce) {
|
2017-02-17 04:19:00 +01:00
|
|
|
in.b <> FromRational(out.b, direction.flip)
|
|
|
|
out.c <> ToRational(in.c, direction)
|
|
|
|
out.e <> ToRational(in.e, direction)
|
2017-01-27 00:15:48 +01:00
|
|
|
} else {
|
|
|
|
in.b.valid := Bool(false)
|
|
|
|
in.c.ready := Bool(true)
|
|
|
|
in.e.ready := Bool(true)
|
|
|
|
out.b.ready := Bool(true)
|
|
|
|
out.c.valid := Bool(false)
|
|
|
|
out.e.valid := Bool(false)
|
|
|
|
out.b.sink := UInt(0)
|
|
|
|
out.c.source := UInt(0)
|
|
|
|
out.e.source := UInt(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-17 04:19:00 +01:00
|
|
|
class TLRationalCrossingSink(direction: RationalDirection = Symmetric)(implicit p: Parameters) extends LazyModule
|
2017-01-27 00:15:48 +01:00
|
|
|
{
|
2017-02-17 04:19:00 +01:00
|
|
|
val node = TLRationalSinkNode(direction)
|
2017-01-27 00:15:48 +01:00
|
|
|
|
|
|
|
lazy val module = new LazyModuleImp(this) {
|
2017-09-14 03:06:03 +02:00
|
|
|
(node.in zip node.out) foreach { case ((in, edgeIn), (out, edgeOut)) =>
|
2017-01-27 00:15:48 +01:00
|
|
|
val bce = edgeOut.manager.anySupportAcquireB && edgeOut.client.anySupportProbe
|
2017-02-17 04:19:00 +01:00
|
|
|
val direction = edgeIn.manager.direction
|
2017-01-27 00:15:48 +01:00
|
|
|
|
2017-02-17 04:19:00 +01:00
|
|
|
out.a <> FromRational(in.a, direction)
|
|
|
|
in.d <> ToRational(out.d, direction.flip)
|
2017-01-27 00:15:48 +01:00
|
|
|
|
|
|
|
if (bce) {
|
2017-02-17 04:19:00 +01:00
|
|
|
in.b <> ToRational(out.b, direction.flip)
|
|
|
|
out.c <> FromRational(in.c, direction)
|
|
|
|
out.e <> FromRational(in.e, direction)
|
2017-01-27 00:15:48 +01:00
|
|
|
} else {
|
|
|
|
out.b.ready := Bool(true)
|
|
|
|
out.c.valid := Bool(false)
|
|
|
|
out.e.valid := Bool(false)
|
|
|
|
in.b.valid := Bool(false)
|
|
|
|
in.c.ready := Bool(true)
|
|
|
|
in.e.ready := Bool(true)
|
|
|
|
in.b.source := UInt(0)
|
|
|
|
in.c.sink := UInt(0)
|
|
|
|
in.e.sink := UInt(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object TLRationalCrossingSource
|
|
|
|
{
|
|
|
|
// applied to the TL source node; y.node := TLRationalCrossingSource()(x.node)
|
|
|
|
def apply()(x: TLOutwardNode)(implicit p: Parameters, sourceInfo: SourceInfo): TLRationalOutwardNode = {
|
|
|
|
val source = LazyModule(new TLRationalCrossingSource)
|
2017-09-08 00:07:08 +02:00
|
|
|
source.node :=? x
|
2017-01-27 00:15:48 +01:00
|
|
|
source.node
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object TLRationalCrossingSink
|
|
|
|
{
|
|
|
|
// applied to the TL source node; y.node := TLRationalCrossingSink()(x.node)
|
2017-02-17 04:19:00 +01:00
|
|
|
def apply(direction: RationalDirection = Symmetric)(x: TLRationalOutwardNode)(implicit p: Parameters, sourceInfo: SourceInfo): TLOutwardNode = {
|
|
|
|
val sink = LazyModule(new TLRationalCrossingSink(direction))
|
2017-09-08 00:07:08 +02:00
|
|
|
sink.node :=? x
|
2017-01-27 00:15:48 +01:00
|
|
|
sink.node
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-17 04:19:00 +01:00
|
|
|
class TLRationalCrossing(direction: RationalDirection = Symmetric)(implicit p: Parameters) extends LazyModule
|
2017-01-27 00:15:48 +01:00
|
|
|
{
|
|
|
|
val source = LazyModule(new TLRationalCrossingSource)
|
2017-02-17 04:19:00 +01:00
|
|
|
val sink = LazyModule(new TLRationalCrossingSink(direction))
|
2017-09-23 09:04:50 +02:00
|
|
|
val node = NodeHandle(source.node, sink.node)
|
2017-01-27 00:15:48 +01:00
|
|
|
|
2017-09-23 01:55:12 +02:00
|
|
|
sink.node := source.node
|
2017-01-27 00:15:48 +01:00
|
|
|
|
|
|
|
lazy val module = new LazyModuleImp(this) {
|
2017-09-14 03:06:03 +02:00
|
|
|
val io = IO(new Bundle {
|
2017-01-27 00:15:48 +01:00
|
|
|
val in_clock = Clock(INPUT)
|
|
|
|
val in_reset = Bool(INPUT)
|
|
|
|
val out_clock = Clock(INPUT)
|
|
|
|
val out_reset = Bool(INPUT)
|
2017-09-14 03:06:03 +02:00
|
|
|
})
|
2017-01-27 00:15:48 +01:00
|
|
|
|
|
|
|
source.module.clock := io.in_clock
|
|
|
|
source.module.reset := io.in_reset
|
|
|
|
sink.module.clock := io.out_clock
|
|
|
|
sink.module.reset := io.out_reset
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Synthesizeable unit tests */
|
2017-07-07 19:48:16 +02:00
|
|
|
import freechips.rocketchip.unittest._
|
2017-01-27 00:15:48 +01:00
|
|
|
|
2017-05-17 20:56:01 +02:00
|
|
|
class TLRAMRationalCrossingSource(name: String, txns: Int)(implicit p: Parameters) extends LazyModule {
|
2017-09-14 03:06:03 +02:00
|
|
|
val node = TLRationalIdentityNode()
|
2017-05-17 20:56:01 +02:00
|
|
|
val fuzz = LazyModule(new TLFuzzer(txns))
|
2017-04-13 20:51:10 +02:00
|
|
|
val model = LazyModule(new TLRAMModel(name))
|
2017-01-27 00:15:48 +01:00
|
|
|
|
|
|
|
model.node := fuzz.node
|
2017-02-17 14:16:45 +01:00
|
|
|
node := TLRationalCrossingSource()(TLDelayer(0.25)(model.node))
|
2017-01-27 00:15:48 +01:00
|
|
|
|
2017-02-17 14:16:45 +01:00
|
|
|
lazy val module = new LazyModuleImp(this) {
|
2017-09-14 03:06:03 +02:00
|
|
|
val io = IO(new Bundle {
|
2017-02-17 14:16:45 +01:00
|
|
|
val finished = Bool(OUTPUT)
|
2017-09-14 03:06:03 +02:00
|
|
|
})
|
2017-01-27 00:15:48 +01:00
|
|
|
io.finished := fuzz.module.io.finished
|
2017-02-17 14:16:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TLRAMRationalCrossingSink(direction: RationalDirection)(implicit p: Parameters) extends LazyModule {
|
2017-09-14 03:06:03 +02:00
|
|
|
val node = TLRationalIdentityNode()
|
2017-02-17 14:16:45 +01:00
|
|
|
val ram = LazyModule(new TLRAM(AddressSet(0x0, 0x3ff)))
|
|
|
|
|
|
|
|
ram.node := TLFragmenter(4, 256)(TLDelayer(0.25)(TLRationalCrossingSink(direction)(node)))
|
2017-01-27 00:15:48 +01:00
|
|
|
|
2017-09-14 03:06:03 +02:00
|
|
|
lazy val module = new LazyModuleImp(this) { }
|
2017-02-17 14:16:45 +01:00
|
|
|
}
|
2017-01-27 00:15:48 +01:00
|
|
|
|
2017-05-17 20:56:01 +02:00
|
|
|
class TLRAMRationalCrossing(txns: Int)(implicit p: Parameters) extends LazyModule {
|
|
|
|
val sym_fast_source = LazyModule(new TLRAMRationalCrossingSource("RationalCrossing sym_fast", txns))
|
2017-02-17 14:16:45 +01:00
|
|
|
val sym_slow_sink = LazyModule(new TLRAMRationalCrossingSink(Symmetric))
|
|
|
|
sym_slow_sink.node := sym_fast_source.node
|
|
|
|
|
2017-05-17 20:56:01 +02:00
|
|
|
val sym_slow_source = LazyModule(new TLRAMRationalCrossingSource("RationalCrossing sym_slow", txns))
|
2017-02-17 14:16:45 +01:00
|
|
|
val sym_fast_sink = LazyModule(new TLRAMRationalCrossingSink(Symmetric))
|
|
|
|
sym_fast_sink.node := sym_slow_source.node
|
|
|
|
|
2017-05-17 20:56:01 +02:00
|
|
|
val fix_fast_source = LazyModule(new TLRAMRationalCrossingSource("RationalCrossing fast", txns))
|
2017-02-17 14:16:45 +01:00
|
|
|
val fix_slow_sink = LazyModule(new TLRAMRationalCrossingSink(FastToSlow))
|
|
|
|
fix_slow_sink.node := fix_fast_source.node
|
2017-01-27 00:15:48 +01:00
|
|
|
|
2017-05-17 20:56:01 +02:00
|
|
|
val fix_slow_source = LazyModule(new TLRAMRationalCrossingSource("RationalCrossing slow", txns))
|
2017-02-17 14:16:45 +01:00
|
|
|
val fix_fast_sink = LazyModule(new TLRAMRationalCrossingSink(SlowToFast))
|
|
|
|
fix_fast_sink.node := fix_slow_source.node
|
|
|
|
|
2017-09-14 03:06:03 +02:00
|
|
|
lazy val module = new LazyModuleImp(this) with UnitTestModule {
|
2017-02-17 14:16:45 +01:00
|
|
|
io.finished :=
|
|
|
|
sym_fast_source.module.io.finished &&
|
|
|
|
sym_slow_source.module.io.finished &&
|
|
|
|
fix_fast_source.module.io.finished &&
|
|
|
|
fix_slow_source.module.io.finished
|
|
|
|
|
|
|
|
// Generate faster clock (still divided so verilator approves)
|
2017-07-07 19:48:16 +02:00
|
|
|
val fast = Module(new Pow2ClockDivider(1))
|
2017-02-17 14:16:45 +01:00
|
|
|
sym_fast_source.module.clock := fast.io.clock_out
|
|
|
|
sym_fast_sink .module.clock := fast.io.clock_out
|
|
|
|
fix_fast_source.module.clock := fast.io.clock_out
|
|
|
|
fix_fast_sink .module.clock := fast.io.clock_out
|
|
|
|
|
|
|
|
// Generate slower clock
|
2017-07-07 19:48:16 +02:00
|
|
|
val slow = Module(new Pow2ClockDivider(2))
|
2017-02-17 14:16:45 +01:00
|
|
|
fix_slow_source.module.clock := slow.io.clock_out
|
|
|
|
fix_slow_sink .module.clock := slow.io.clock_out
|
2017-05-15 00:11:29 +02:00
|
|
|
|
2017-07-07 19:48:16 +02:00
|
|
|
val odd = Module(new ClockDivider3)
|
2017-05-15 00:11:29 +02:00
|
|
|
odd.io.clk_in := clock
|
|
|
|
sym_slow_source.module.clock := odd.io.clk_out
|
|
|
|
sym_slow_sink .module.clock := odd.io.clk_out
|
2017-01-27 00:15:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 20:56:01 +02:00
|
|
|
class TLRAMRationalCrossingTest(txns: Int = 5000, timeout: Int = 500000)(implicit p: Parameters) extends UnitTest(timeout) {
|
|
|
|
io.finished := Module(LazyModule(new TLRAMRationalCrossing(txns)).module).io.finished
|
2017-01-27 00:15:48 +01:00
|
|
|
}
|