简体   繁体   English

如何在 Chisel 中使用向量作为输入

[英]How to use a vector as input in Chisel

I am designing a Chisel module with the following code:我正在使用以下代码设计一个 Chisel 模块:

import chisel3._
import chisel3.util._

class DisplayDriver extends Module {
    val io = IO(new Bundle {
        val digits = Input(Vec(4, UInt(4.W)))

        val leds = Output(UInt(7.W))
        val selector = Output(UInt(4.W))
    })

    // Divisor de frecuencia
    val freqDiv = RegInit(0.U(11.W))
    val tick = freqDiv === (4000 - 1).U

    freqDiv := freqDiv + 1.U;
    when (tick) {
        freqDiv := 0.U
    }

    // Multiplexor de dígitos
    val digitSel = RegInit(0.U(2.W))
    when (tick) {
        digitSel := digitSel + 1.U
    }

    val digit = UInt(4.W)
    digit := io.digits(digitSel)

    // Decodificador para el selector
    io.selector := 0.U
    switch (digitSel) {
        is (0.U) { io.selector := "b1110".U }
        is (1.U) { io.selector := "b1101".U }
        is (2.U) { io.selector := "b1011".U }
        is (3.U) { io.selector := "b0111".U }
    }

    // Decodificador para los leds
    io.leds := 0.U
    switch (digit) {
        is (0.U) { io.leds := "b0000001".U }
        is (1.U) { io.leds := "b1001111".U }
        is (2.U) { io.leds := "b0010010".U }
        is (3.U) { io.leds := "b0000110".U }
        is (4.U) { io.leds := "b1001100".U }
        is (5.U) { io.leds := "b0100100".U }
        is (6.U) { io.leds := "b0100000".U }
        is (7.U) { io.leds := "b0001111".U }
        is (8.U) { io.leds := "b0000000".U }
        is (9.U) { io.leds := "b0000100".U }
        is (10.U) { io.leds := "b0001000".U }
        is (11.U) { io.leds := "b1100000".U }
        is (12.U) { io.leds := "b0110001".U }
        is (13.U) { io.leds := "b1000010".U }
        is (14.U) { io.leds := "b0110000".U }
        is (15.U) { io.leds := "b0111000".U }
    }
}

class Top extends Module {
    val io = IO(new Bundle {
        val leds = Output(UInt(7.W))
        val selector = Output(UInt(4.W))
    })

    val displayDriver = Module(new DisplayDriver())
    displayDriver.io.digits(3) := 1.U
    displayDriver.io.digits(2) := 2.U
    displayDriver.io.digits(1) := 3.U
    displayDriver.io.digits(0) := 4.U
    io.leds := displayDriver.io.leds
    io.selector := displayDriver.io.selector
}

But I get the following error when running it:但是运行它时出现以下错误:

[error] (run-main-0) chisel3.package$ExpectedHardwareException: data to be connected 'UInt<4>' must be hardware, not a bare Chisel type. Perhaps you forgot to wrap it in Wire(_) or IO(_)?
[error] chisel3.package$ExpectedHardwareException: data to be connected 'UInt<4>' must be hardware, not a bare Chisel type. Perhaps you forgot to wrap it in Wire(_) or IO(_)?

which apparently points to the line这显然指向这条线

digit := io.digits(digitSel)

I have tried many combinations with Wire around io.digits but it still does not compile.我在 io.digits 周围尝试了许多与 Wire 的组合,但它仍然无法编译。 Indeed, following other examples, I am not able to see why I'm getting this error, since the vector is inside an IO.实际上,按照其他示例,我无法理解为什么会出现此错误,因为向量位于 IO 内。 What is happening?怎么了?

The error comes from the left hand side of the connect operation: digit should be defined as Wire .错误来自连接操作的左侧: digit应定义为Wire

    val digit = Wire(UInt(4.W))
    digit := io.digits(digitSel)

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

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