FabienM
FabienM

Reputation: 3761

Are Vec can be reduced in Chisel?

I'm trying to reduce a Vec of Bundle in an UInt, but got an error:

class DiffPair extends Bundle {
    val p = Bool()
    val n = Bool()
}

class TMDS extends Bundle {
    val clk  = new DiffPair()
    val data = Vec(3, new DiffPair())
}
val io = IO(new Bundle {
 //...
 val tmds = Output(new TMDS())
})

val O_tmds_data_p = IO(Output(UInt(3.W)))

If I use this reduce code :

O_tmds_data_p := gbHdmi.io.tmds.data.reduce((a,b) => Cat(a.p, b.p))

I've got this error :

[info] compiling 1 Scala source to /home/user/GbHdmi/target/scala-2.12/classes ...
[error] /home/user/GbHdmi/src/main/scala/topgbhdmi.scala:72:67: type mismatch;
[error]  found   : chisel3.UInt
[error]  required: gbhdmi.DiffPair
[error]       O_tmds_data_p := gbHdmi.io.tmds.data.reduce((a,b) => Cat(a.p, b.p))
[error]                                                                   ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 0 s, completed 31 août 2021, 15:04:08

I know that a and b are DiffPair, but a.p and b.p are Bool no ?

Upvotes: 1

Views: 845

Answers (2)

FabienM
FabienM

Reputation: 3761

The solution I found is to take 'p' value with map before reduce :

O_tmds_data_p := gbHdmi.io.tmds.data.map(_.p.asUInt).reduce((a,b) => Cat(a,b))

Or, in simplified way :

O_tmds_data_p := gbHdmi.io.tmds.data.map(_.p.asUInt).reduce(_ ## _)

And, that way didn't work, for an obscur reason to me :

O_tmds_data_p := gbHdmi.io.tmds.data.reduce(_.p.asUInt ## _.p.asUInt)

Error :

sbt:GbHdmi> runMain gbhdmi.TopGbHdmiDriver
[info] compiling 1 Scala source to /home/user/GbHdmi/target/scala-2.12/classes ...
[error] /home/user/GbHdmi/src/main/scala/topgbhdmi.scala:71:63: type mismatch;
[error]  found   : chisel3.UInt
[error]  required: gbhdmi.DiffPair
[error]       O_tmds_data_p :=  gbHdmi.io.tmds.data.reduce(_.p.asUInt ## _.p.asUInt)
[error]                                                               ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 0 s, completed Sep 1, 2021, 9:17:15 AM

Upvotes: 1

Chick Markley
Chick Markley

Reputation: 4051

Have you tried

O_tmds_data_p := gbHdmi.io.tmds.data.asUInt

I think that should work for you.

Upvotes: 0

Related Questions