Skip to content

Make wrapper class like DecoupledIO as functor #1072

@haedaal

Description

@haedaal

Type of issue: feature request

Impact: API addition (no impact on existing code)

Development Phase: request | proposal

Other information
Bit tired of writing boiler plate to connect DecoupledIO for every tiny job, I started to feel it neccessary to have 'map' on DecoupledIO
What's just working is

object ChiselFunctor {
  implicit class DecoupledFuntor[T1 <: Bundle](d: DecoupledIO[T1]) {
    def map[T2 <: Data](f: T1 => T2) : DecoupledIO[T2] = {
      val new_bits = f(d.bits)
      val new_decoupled = Wire(Decoupled(chiselTypeOf(new_bits)))
      new_decoupled.ready := d.ready
      new_decoupled.valid := d.valid
      new_decoupled.bits := new_bits
      new_decoupled
    }
  }
}

And after writing, I thought It would be great if this kind of functionality can be integrated, managed, and supported officially.

thanks for reading!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions