diff options
| author | mergify[bot] | 2022-07-28 22:27:29 +0000 |
|---|---|---|
| committer | GitHub | 2022-07-28 22:27:29 +0000 |
| commit | e52739f2fe587cedd657a331b7d7ba0c75b919c6 (patch) | |
| tree | 457db80a10e9cfb56b631a4f418d88eb4eba7478 /src/main/scala/chisel3/util | |
| parent | b8f884e15114b7c9f29b1ec8f23a4216bcbfca76 (diff) | |
Implement DecoupledIO.map utility (#2646) (#2649)
(cherry picked from commit b20df1d6cda03f6eef28ee480e0aade914c5face)
Co-authored-by: Jared Barocsi <82000041+jared-barocsi@users.noreply.github.com>
Diffstat (limited to 'src/main/scala/chisel3/util')
| -rw-r--r-- | src/main/scala/chisel3/util/Decoupled.scala | 17 |
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 { |
