繁体   English   中英

如何在chisel中编写异步复位

[英]How to code a asynchronous reset in chisel

编写Chisel代码时如何将reset信号添加到生成的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 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

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

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

暂无
暂无

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

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