diff options
| author | Jim Lawson | 2016-09-15 15:42:21 -0700 |
|---|---|---|
| committer | Jim Lawson | 2016-09-15 15:42:21 -0700 |
| commit | dbf4278afbc5ce157ab1b946681a364f20778352 (patch) | |
| tree | 9e4d83e2af522847f0a04856bff7f93098654197 | |
| parent | 64e4df3d92727d83d5d627114d7002b97f901052 (diff) | |
move AddMethodsToDecoupled to ReadyValid
| -rw-r--r-- | src/main/scala/chisel3/util/Decoupled.scala | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/src/main/scala/chisel3/util/Decoupled.scala b/src/main/scala/chisel3/util/Decoupled.scala index d178cec5..14637c9b 100644 --- a/src/main/scala/chisel3/util/Decoupled.scala +++ b/src/main/scala/chisel3/util/Decoupled.scala @@ -21,26 +21,9 @@ abstract class ReadyValidIO[+T <: Data](gen: T) extends Bundle val bits = Output(gen.chiselCloneType) } -object DecoupledIO { - /** Adds a ready-valid handshaking protocol to any interface. - * The standard used is that the consumer uses the flipped interface. - */ - def apply[T <: Data](gen: T): DecoupledIO[T] = new DecoupledIO(gen) +object ReadyValidIO { - /** Take an IrrevocableIO and cast it to a DecoupledIO. - * This cast is only safe to do in cases where the IrrevocableIO - * is being produced as an output. - */ - def apply[T <: Data](irr: IrrevocableIO[T]): DecoupledIO[T] = { - require(getFirrtlDirection(irr.bits) == OUTPUT, "Only safe to cast produced Irrevocable bits to Decoupled.") - val d = Wire(new DecoupledIO(irr.bits)) - d.bits := irr.bits - d.valid := irr.valid - irr.ready := d.ready - d - } - - implicit class AddMethodsToDecoupled[T<:Data](val target: DecoupledIO[T]) extends AnyVal { + implicit class AddMethodsToReadyValid[T<:Data](val target: ReadyValidIO[T]) extends AnyVal { def fire(): Bool = target.ready && target.valid /** push dat onto the output bits of this interface to let the consumer know it has happened. @@ -77,6 +60,26 @@ object DecoupledIO { target.ready := Bool(false) } } +} + +object DecoupledIO { + /** Adds a ready-valid handshaking protocol to any interface. + * The standard used is that the consumer uses the flipped interface. + */ + def apply[T <: Data](gen: T): DecoupledIO[T] = new DecoupledIO(gen) + + /** Take an IrrevocableIO and cast it to a DecoupledIO. + * This cast is only safe to do in cases where the IrrevocableIO + * is being produced as an output. + */ + def apply[T <: Data](irr: IrrevocableIO[T]): DecoupledIO[T] = { + require(getFirrtlDirection(irr.bits) == OUTPUT, "Only safe to cast produced Irrevocable bits to Decoupled.") + val d = Wire(new DecoupledIO(irr.bits)) + d.bits := irr.bits + d.valid := irr.valid + irr.ready := d.ready + d + } // override def cloneType: this.type = { // DeqIO(gen).asInstanceOf[this.type] // } |
