简体   繁体   English

如何在I / O端口中使用chisel3.experimental.ChiselEnum?

[英]How to use a chisel3.experimental.ChiselEnum in an I/O port?

Consider this code: 考虑以下代码:

import chisel3.experimental.ChiselEnum

object MyEnum extends ChiselEnum {
  val A, B = Value
}

class UseEnumIO extends Module {
  val io = IO(new Bundle {
    val in = Input(UInt(1.W))
    val out = Output(Bool())
  })

  io.out := MuxLookup(io.in, false.B, Array(
    MyEnum.A -> true.B,
    MyEnum.B -> true.B
  ))
}

I need to use an IO port which is supposed to be a ChiselEnum object in a MuxLookup . 我需要使用一个IO端口,它应该是ChiselEnum中的MuxLookup对象。

This is the error message I got from SBT: 这是我从SBT收到的错误消息:

[error]  found   : scala.collection.mutable.WrappedArray[(MyEnum.Type, chisel3.core.Bool)]

while Scala inferred that [S <: chisel3.UInt,T <: chisel3.Data] 而Scala推断[S <: chisel3.UInt,T <: chisel3.Data]

I also tried val in = Input(MyEnum.Type) which gave me a more serious error. 我也尝试了val in = Input(MyEnum.Type) ,这给了我一个更严重的错误。

val defaultVersions = Map(
  "chisel3" -> "3.2-SNAPSHOT
)

I'm not quite sure why this doesn't work, but the following work-around might help. 我不太确定为什么这不起作用,但以下解决方法可能会有所帮助。 Try 尝试

  io.out := MuxLookup(io.in, false.B, Seq(
    MyEnum.A.asUInt -> true.B,
    MyEnum.B.asUInt -> true.B
  ))

it seems to work to me. 它似乎对我有用。 I'll keep looking for a reason that the more obvious simple syntax does not work. 我会继续寻找一个更明显的简单语法不起作用的原因。

MuxLookup requires UInts (or Bools) for the selector. MuxLookup需要选择器的UInts(或Bools)。 From the API docs : 来自API文档

def apply[S <: UInt, T <: Data](key: S, default: T, mapping: Seq[(S, T)]): T

This is probably an oversight, MuxLookup predates ChiselEnum by a lot of time so it wasn't made with it in mind, I have filed an issue to support this use case. 这可能是一种疏忽, MuxLookup之前ChiselEnum了很多时间,所以它没有考虑到它,我提出了一个问题来支持这个用例。 You can use Chick's workaround in the meantime. 在此期间,您可以使用Chick的解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM