summaryrefslogtreecommitdiff
path: root/src/main/scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala')
-rw-r--r--src/main/scala/chisel3/util/Decoupled.scala17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/main/scala/chisel3/util/Decoupled.scala b/src/main/scala/chisel3/util/Decoupled.scala
index f02a4116..b21bd04f 100644
--- a/src/main/scala/chisel3/util/Decoupled.scala
+++ b/src/main/scala/chisel3/util/Decoupled.scala
@@ -99,7 +99,22 @@ object ReadyValidIO {
* of ready or valid.
* @param gen the type of data to be wrapped in DecoupledIO
*/
-class DecoupledIO[+T <: Data](gen: T) extends ReadyValidIO[T](gen)
+class DecoupledIO[+T <: Data](gen: T) extends ReadyValidIO[T](gen) {
+
+ /** Applies the supplied functor to the bits of this interface, returning a new
+ * typed DecoupledIO interface.
+ * @param f The function to apply to this DecoupledIO's 'bits' with return type B
+ * @return a new DecoupledIO of type B
+ */
+ def map[B <: Data](f: T => B): DecoupledIO[B] = {
+ val _map_bits = f(bits)
+ val _map = Wire(Decoupled(chiselTypeOf(_map_bits)))
+ _map.bits := _map_bits
+ _map.valid := valid
+ ready := _map.ready
+ _map
+ }
+}
/** This factory adds a decoupled handshaking protocol to a data bundle. */
object Decoupled {