From f46efb671de6b0d3fb0d97de311ccdce42a4f088 Mon Sep 17 00:00:00 2001 From: Howard Mao Date: Thu, 30 Jun 2016 17:39:10 -0700 Subject: [PATCH] add multi-transaction timer and add to Comparator --- groundtest/src/main/scala/comparator.scala | 7 +++++ groundtest/src/main/scala/util.scala | 36 +++++++++++++--------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/groundtest/src/main/scala/comparator.scala b/groundtest/src/main/scala/comparator.scala index a9744d64..1c0bd64e 100644 --- a/groundtest/src/main/scala/comparator.scala +++ b/groundtest/src/main/scala/comparator.scala @@ -283,6 +283,13 @@ class ComparatorClient(val target: Long)(implicit val p: Parameters) extends Mod val (idx, acq_done) = Counter( io.tl.acquire.fire() && io.tl.acquire.bits.first(), nOperations) debug(idx) + + val timer = Module(new Timer(8192, xacts)) + timer.io.start.valid := io.tl.acquire.fire() && io.tl.acquire.bits.first() + timer.io.start.bits := xact_id + timer.io.stop.valid := io.tl.grant.fire() && io.tl.grant.bits.first() + timer.io.stop.bits := io.tl.grant.bits.client_xact_id + assert(!timer.io.timeout, "Comparator TL client timed out") } class ComparatorSink(implicit val p: Parameters) extends Module diff --git a/groundtest/src/main/scala/util.scala b/groundtest/src/main/scala/util.scala index 9ce29de5..5bf03c67 100644 --- a/groundtest/src/main/scala/util.scala +++ b/groundtest/src/main/scala/util.scala @@ -7,36 +7,42 @@ import Chisel._ // ============ // Timer with a statically-specified period. +// Can take multiple inflight start-stop events with ID +// Will continue to count down so long as at least one inflight event -class Timer(initCount: Int) extends Module { +class Timer(initCount: Int, maxInflight: Int) extends Module { val io = new Bundle { - val start = Bool(INPUT) - val stop = Bool(INPUT) + val start = Valid(UInt(width = log2Up(maxInflight))).flip + val stop = Valid(UInt(width = log2Up(maxInflight))).flip val timeout = Bool(OUTPUT) } + val inflight = Reg(init = Vec.fill(maxInflight) { Bool(false) }) val countdown = Reg(UInt(width = log2Up(initCount))) - val active = Reg(init = Bool(false)) + val active = inflight.reduce(_ || _) - when (io.start) { - countdown := UInt(initCount - 1) - active := Bool(true) - } - .elsewhen (io.stop) { - active := Bool(false) - } - .elsewhen (active) { + when (active) { countdown := countdown - UInt(1) } + when (io.start.valid) { + inflight(io.start.bits) := Bool(true) + countdown := UInt(initCount - 1) + } + when (io.stop.valid) { + inflight(io.stop.bits) := Bool(false) + } + io.timeout := countdown === UInt(0) && active } object Timer { def apply(initCount: Int, start: Bool, stop: Bool): Bool = { - val timer = Module(new Timer(initCount)) - timer.io.start := start - timer.io.stop := stop + val timer = Module(new Timer(initCount, 1)) + timer.io.start.valid := start + timer.io.start.bits := UInt(0) + timer.io.stop.valid := stop + timer.io.stop.bits := UInt(0) timer.io.timeout } }