Skip to content

Commit 82c46c2

Browse files
committed
fixup! [util] Add a withShadowLayer Queue
1 parent 95a3370 commit 82c46c2

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/main/scala/chisel3/util/Queue.scala

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,11 @@ class Queue[T <: Data](
158158
* @param layer the `Layer` in which this queue should be created
159159
* @return a layer-colored `Valid` interface of probe type
160160
*/
161-
def shadow[A <: Data](data: A, layer: Layer): Valid[A] = {
162-
(new Queue.ShadowFactory(enq = io.enq, deq = io.deq, entries, pipe, flow, useSyncReadMem, io.flush))(data, layer)
163-
}
161+
def shadow[A <: Data](data: A, layer: Layer): Valid[A] =
162+
withClockAndReset(BoringUtils.tapAndRead(clock), BoringUtils.tapAndRead(reset)) {
163+
val shadow = new Queue.ShadowFactory(enq = io.enq, deq = io.deq, entries, pipe, flow, useSyncReadMem, io.flush)
164+
shadow(data, layer)
165+
}
164166
}
165167

166168
/** Factory for a generic hardware queue. */
@@ -219,6 +221,12 @@ object Queue {
219221
useSyncReadMem: Boolean,
220222
flush: Option[Bool]) {
221223

224+
/** The clock used when building the original Queue. */
225+
private val clock = Module.clock
226+
227+
/** The reset used when elaborating the original Queue. */
228+
private val reset = Module.reset
229+
222230
/** Create a "shadow" `Queue` in a specific layer that will be queued and
223231
* dequeued in lockstep with an original `Queue`. Connections are made
224232
* using `BoringUtils.tapAndRead` which allows this method to be called
@@ -234,26 +242,27 @@ object Queue {
234242
* @param layer the `Layer` in which this queue should be created
235243
* @return a layer-colored `Valid` interface of probe type
236244
*/
237-
def apply[A <: Data](data: A, layer: Layer): Valid[A] = {
238-
val shadowDeq = Wire(Probe(Valid(chiselTypeOf(data)), layer))
245+
def apply[A <: Data](data: A, layer: Layer): Valid[A] =
246+
withClockAndReset(BoringUtils.tapAndRead(clock), BoringUtils.tapAndRead(reset)) {
247+
val shadowDeq = Wire(Probe(Valid(chiselTypeOf(data)), layer))
239248

240-
block(layer) {
241-
val shadowEnq = Wire(Decoupled(chiselTypeOf(data)))
242-
val probeEnq = BoringUtils.tapAndRead(enq)
243-
shadowEnq.valid :<= probeEnq.valid
244-
shadowEnq.bits :<= data
249+
block(layer) {
250+
val shadowEnq = Wire(Decoupled(chiselTypeOf(data)))
251+
val probeEnq = BoringUtils.tapAndRead(enq)
252+
shadowEnq.valid :<= probeEnq.valid
253+
shadowEnq.bits :<= data
245254

246-
val shadowQueue = Queue(shadowEnq, entries, pipe, flow, useSyncReadMem, flush.map(BoringUtils.tapAndRead))
255+
val shadowQueue = Queue(shadowEnq, entries, pipe, flow, useSyncReadMem, flush.map(BoringUtils.tapAndRead))
247256

248-
val _shadowDeq = Wire(Valid(chiselTypeOf(data)))
249-
_shadowDeq.valid :<= shadowQueue.valid
250-
_shadowDeq.bits :<= shadowQueue.bits
251-
shadowQueue.ready :<= BoringUtils.tapAndRead(deq).ready
252-
define(shadowDeq, ProbeValue(_shadowDeq))
253-
}
257+
val _shadowDeq = Wire(Valid(chiselTypeOf(data)))
258+
_shadowDeq.valid :<= shadowQueue.valid
259+
_shadowDeq.bits :<= shadowQueue.bits
260+
shadowQueue.ready :<= BoringUtils.tapAndRead(deq).ready
261+
define(shadowDeq, ProbeValue(_shadowDeq))
262+
}
254263

255-
shadowDeq
256-
}
264+
shadowDeq
265+
}
257266
}
258267

259268
/** Create a [[Queue]] and supply a [[DecoupledIO]] containing the product.

0 commit comments

Comments
 (0)