summaryrefslogtreecommitdiff
path: root/src/main/scala/chisel3
diff options
context:
space:
mode:
authorWesley W. Terpstra2016-09-15 19:08:30 -0700
committerAndrew Waterman2016-09-15 19:08:30 -0700
commitdda64c1dee16b5da15ac690bd3cd6759c3d5c032 (patch)
treefc15efb612db7203996e90a3aa0235f768e11e54 /src/main/scala/chisel3
parent2ff229dac5f915e7f583cbf9cc8118674a4e52a5 (diff)
Decoupled: cast DecoupledIO to IrrevocableIO as an input (#280)
Diffstat (limited to 'src/main/scala/chisel3')
-rw-r--r--src/main/scala/chisel3/util/Decoupled.scala13
1 files changed, 13 insertions, 0 deletions
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
+ }
}