1

在编写 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 所指出的,这里有另一个问题,这里有凿子用户谷歌组的讨论

4

2 回答 2

2

从 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
}

这将为 register 生成以下 Verilog 逻辑x

always @(posedge clk or posedge reset) begin
  if (reset) begin
    x <= 1'h0;
  end else begin
    x <= io_D;
  end
end

要使用同步复位,请将resetfrom的类型更改AsyncResetBool

于 2020-05-20T17:10:51.987 回答
1

这个问题是How to generate a asynchronous reset verilog always blocks with chisel的副本

如果确实需要,您可以考虑通过将 rst 视为Chisel 手册中所述的第二个时钟域来强制执行此操作,但我不建议这样做。

于 2016-09-05T06:22:04.363 回答