Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write to a conditional output

Tags:

chisel

In my code I have defined a conditional output:

class EccGenerate[D <: Data](data: D, doubleBit : Boolean = true) extends Module {
  val eccBits = calcCodeBits(data.getWidth)

  val io = IO(new Bundle {
    val in = Input(data.cloneType)
    val out = Output(UInt(eccBits.W))
    val par = if (doubleBit) Some(Output(Bool())) else None
  })

Trying to use the := operator on the par output fails, because it is not always an output. When using conditional inputs, I would use io.par.get() to retrieve the current value of the input, is there a corresponding primitive, operator or function call I can use to set the value of a conditional output?

like image 327
Guy Hutchison Avatar asked Apr 18 '26 10:04

Guy Hutchison


1 Answers

The issue is that you can't connect to par because it's type is Option[Bool] and := isn't define for Option. You need to unpack it and assign to the Bool inside if the option contains something.

The functional programming way of doing this would be:

io.par.foreach(_ := foo)

You can also be more verbose about it if you want:

io.par match {
  case Some(a) => a := foo
  case None    =>
}

An if statement would also work:

if (par.nonEmpty) {
  io.par.get := foo
}
like image 65
seldridge Avatar answered Apr 23 '26 08:04

seldridge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!