From dda64c1dee16b5da15ac690bd3cd6759c3d5c032 Mon Sep 17 00:00:00 2001 From: Wesley W. Terpstra Date: Thu, 15 Sep 2016 19:08:30 -0700 Subject: Decoupled: cast DecoupledIO to IrrevocableIO as an input (#280) --- src/main/scala/chisel3/util/Decoupled.scala | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/scala/chisel3/util/Decoupled.scala b/src/main/scala/chisel3/util/Decoupled.scala index b2634bec..77990777 100644 --- a/src/main/scala/chisel3/util/Decoupled.scala +++ b/src/main/scala/chisel3/util/Decoupled.scala @@ -66,6 +66,19 @@ class IrrevocableIO[+T <: Data](gen: T) extends ReadyValidIO[T](gen) object Irrevocable { def apply[T <: Data](gen: T): IrrevocableIO[T] = new IrrevocableIO(gen) + + /** Take a DecoupledIO and cast it to an IrrevocableIO. + * This cast is only safe to do in cases where the IrrevocableIO + * is being consumed as an input. + */ + def apply[T <: Data](dec: DecoupledIO[T]): IrrevocableIO[T] = { + require(dec.bits.dir == INPUT, "Only safe to cast consumed Decoupled bits to Irrevocable.") + val i = Wire(new IrrevocableIO(dec.bits)) + dec.bits := i.bits + dec.valid := i.valid + i.ready := dec.ready + i + } } -- cgit v1.2.3