gpt4 book ai didi

Chisel:将单独的输入和输出端口映射到 inout 引脚

转载 作者:行者123 更新时间:2023-12-02 07:09:06 33 4
gpt4 key购买 nike

我从 Chisel 3 源代码生成 Verilog,并使用 UCF 文件将 Verilog 的顶部模块端口映射到 FPGA 引脚。

我的设计中有一组输入输出引脚(SDRAM 数据引脚),它们在 Chisel 端必须表示为单独的输入和输出端口。问题是,我不能(AFAIK)然后将 Verilog 输入端口和输出端口映射到同一个 FPGA 引脚(如果我直接编写 Verilog,这些将是单个输入输出信号,因此这不会成为问题)并且我不知道如何强制 Chisel 3 从两个输入/输出 Chisel 端口生成单个 Verilog 输入输出端口。

Chisel (3) 中通常如何解决这个问题?

最佳答案

我们正在努力在 Chisel 3 中对 Verilog inout 提供一定程度的支持,但在该 API 完全充实之前,您应该编写一个 Verilog 包装器,将 inout 转换为输入、输出和某个方向。

例如,假设我有一些带有输入输出引脚的 Verilog,可用于设置或读取某个寄存器:

module Inout(
input clock,
input write,
inout [31:0] data
);

reg [31:0] value;

assign data = (write) ? 32'dz : value;

always @(posedge clock) begin
if (write)
value <= data;
else
value <= value;
end
endmodule

通过一个简单的包装器,我可以公开一个不使用 inout 的不同接口(interface):

module InoutWrapper(
input clock,
input write,
input [31:0] dataIn,
output [31:0] dataOut
);
wire [31:0] bus;

assign bus = (write)? dataIn : 32'dz;
assign dataOut = bus;

Inout mod (
.clock(clock),
.write(write),
.data(bus)
);
endmodule

此包装器接口(interface)可以在 Chisel 设计中用作 BlackBox:

class InoutWrapper extends BlackBox {
val io = IO(new Bundle {
val clock = Input(Clock())
val write = Input(Bool())
val dataIn = Input(UInt(32.W))
val dataOut = Output(UInt(32.W))
})
}

这是一个额外的简单健全性测试,表明它有效:

class InoutTester extends BasicTester {

val mod = Module(new InoutWrapper)

val (cycle, done) = Counter(true.B, 4)
when (done) { stop(); stop() }

mod.io.clock := this.clock // BlackBoxes require explicit clock assignment
mod.io.write := false.B // default assignments
mod.io.dataIn := "hdeadbeef".U

when (cycle === 1.U) {
mod.io.write := true.B
mod.io.dataIn := 123.U
}
when (cycle === 2.U) {
assert(mod.io.dataOut === 123.U)
}
}

如果输入输出端口位于设计的顶部,您可以为设计的顶部创建类似的包装器。

关于Chisel:将单独的输入和输出端口映射到 inout 引脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40961550/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com