【发布时间】:2023-03-13 08:23:01
【问题描述】:
我正在将 Verilog 项目重写为 Chisel HDL。该项目有几个解耦的子组件,例如(ex.v、mem.v 或wb.v)和一个名为defines.v 的配置文件,即子组件中的`included。例如,
defines.v中的内容
`define RstEnable 1'b1
`define RstDisable 1'b0
`define ZeroWord 32'h00000000
`define WriteEnable 1'b1
`define WriteDisable 1'b0
`define ReadEnable 1'b1
`define ReadDisable 1'b0
... ...
ex.v中的内容
`include "defines.v"
module ex(
input wire rst,
input wire[`AluOpBus] aluop_i,
input wire[`AluSelBus] alusel_i,
input wire[`RegBus] reg1_i,
input wire[`RegBus] reg2_i,
... ...
);
always @ (*) begin
if(rst == `RstEnable) begin
logicout <= `ZeroWord;
end else begin
case (aluop_i);
`EXE_OR_OP: begin
logicout <= reg1_i | reg2_i;
end
`EXE_AND_OP: begin
logicout <= reg1_i & reg2_i;
end
... ...
default: begin
logicout <= `ZeroWord;
end
endcase
end //if
end //always
... ...
endmodule
我不熟悉 Scala,所以它新的 LISP 风格的宏系统有点过于强大,我无法完全理解。我想要的只是一个简单的 C/C++ 预处理器样式的宏,它可以进行文本替换。
我尝试过使用变量
package cpu
import chisel3._
import chisel3.util._
object Defines {
val RstEnable = "b1".U(1.W)
val RstDisable = "b0".U(1.W)
... ...
}
Scala 中使用的变量定义如下
class Ex extends Module {
val io = IO(new Bundle {
... ...
val aluop_i = Input(UInt(AluOpBus))
... ...
})
... ...
logicout := io.aluop_i match {
case EXE_OR_OP => logicout
case _ => 0.U
}
}
这几乎可以工作,除了以下错误表明match 对变量不满意
[error] /Users/nalzok/Developer/DonkeyMIPS/chisel/src/main/scala/cpu/ex/Ex.scala:88:10: type mismatch;
[error] found : chisel3.UInt
[error] required: Unit
[error] case EXE_OR_OP => logicout
[error] ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 3 s, completed Jun 14, 2020 9:42:13 AM
【问题讨论】:
标签: scala macros verilog hdl chisel