如何在凿子中编写异步复位代码
How to code a asynchronous reset in chisel
如何在编写Chisel代码时将复位信号添加到生成的Verilog代码中的灵敏度列表,例如下面的D触发器代码:
val x = Reg(init = UInt(0, width = 1))
x := io.D
io.Q := x
将生成如下 Verilog 代码:
always @(posedge clk) begin
if(reset) begin
x <= 1'h0;
end else begin
x <= io_D;
end
end
正如所见,重置与时钟同步,如何编写 Chisel 代码以生成如下内容:
always @(posedge clk or posedge reset) begin
if(reset) begin
x <= 1'h0;
end else begin
x <= io_D;
end
end
其中重置信号在敏感列表中,因此是异步的。
编辑:
正如 chrisvp 所指出的,还有另一个问题 and a discussion in chisel-users google group here
这个问题是
的副本
如果确实需要,您可以考虑通过将第一个时钟域视为 Chisel manual 中所述的第二个时钟域来强制执行此操作,但我不建议这样做。
从 Chisel 3.2.0 开始,支持异步重置。示例代码可以通过以下方式实现:
import chisel3._
import chisel3.stage.ChiselStage
class Foo extends RawModule {
val clk = IO(Input(Clock()))
val reset = IO(Input(AsyncReset()))
val io = IO(Input(new Bundle{ val D = UInt(1.W) }))
val out = IO(Output(Bool()))
val x = withClockAndReset(clk, reset) { RegNext(io.D, init=0.U) }
out := x
}
这将为寄存器 x
生成以下 Verilog 逻辑:
always @(posedge clk or posedge reset) begin
if (reset) begin
x <= 1'h0;
end else begin
x <= io_D;
end
end
要使用同步重置,请将 reset
的类型从 AsyncReset
更改为 Bool
。
如何在编写Chisel代码时将复位信号添加到生成的Verilog代码中的灵敏度列表,例如下面的D触发器代码:
val x = Reg(init = UInt(0, width = 1))
x := io.D
io.Q := x
将生成如下 Verilog 代码:
always @(posedge clk) begin
if(reset) begin
x <= 1'h0;
end else begin
x <= io_D;
end
end
正如所见,重置与时钟同步,如何编写 Chisel 代码以生成如下内容:
always @(posedge clk or posedge reset) begin
if(reset) begin
x <= 1'h0;
end else begin
x <= io_D;
end
end
其中重置信号在敏感列表中,因此是异步的。
编辑:
正如 chrisvp 所指出的,还有另一个问题
这个问题是
如果确实需要,您可以考虑通过将第一个时钟域视为 Chisel manual 中所述的第二个时钟域来强制执行此操作,但我不建议这样做。
从 Chisel 3.2.0 开始,支持异步重置。示例代码可以通过以下方式实现:
import chisel3._
import chisel3.stage.ChiselStage
class Foo extends RawModule {
val clk = IO(Input(Clock()))
val reset = IO(Input(AsyncReset()))
val io = IO(Input(new Bundle{ val D = UInt(1.W) }))
val out = IO(Output(Bool()))
val x = withClockAndReset(clk, reset) { RegNext(io.D, init=0.U) }
out := x
}
这将为寄存器 x
生成以下 Verilog 逻辑:
always @(posedge clk or posedge reset) begin
if (reset) begin
x <= 1'h0;
end else begin
x <= io_D;
end
end
要使用同步重置,请将 reset
的类型从 AsyncReset
更改为 Bool
。