简体   繁体   English

如何在chisel中编写异步复位

[英]How to code a asynchronous reset in chisel

How to add the reset signal to the sensitivity list in the generated Verilog code when writing a Chisel code, for example the code below for D flip flop:编写Chisel代码时如何将reset信号添加到生成的Verilog代码中的灵敏度列表中,例如下面的D触发器代码:

val x = Reg(init = UInt(0, width = 1))
    x := io.D
    io.Q := x 

will generate a Verilog code as this:将生成一个 Verilog 代码,如下所示:

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

as seen the reset is synchronous with the clock, how to code Chisel to generate something like this:如所见,复位与时钟同步,如何编码 Chisel 以生成如下内容:

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

where the reset signal is in the sensitivity list and hence asynchronous.其中重置信号在敏感列表中,因此是异步的。

Edit: As pointed by chrisvp there is another question here and a discussion in chisel-users google group here编辑:正如指出的chrisvp还有另外一个问题, 在这里,并在讨论凿谷歌用户群在这里

Since Chisel 3.2.0, asynchronous reset is supported.从 Chisel 3.2.0 开始,支持异步复位。 The example code can be implemented with the following:示例代码可以通过以下方式实现:

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
}

This will then produce the following Verilog logic for register x :这将为寄存器x生成以下 Verilog 逻辑:

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

To use synchronous reset, change the type of reset from AsyncReset to Bool .要使用同步重置, reset类型从AsyncReset更改为Bool

This question is a copy of How to generate an asynchronous reset verilog always blocks with chisel这个问题是How to generate an asynchronous reset verilog always blocks with chisel的副本

If really required, you could consider forcing this by considering the rst as a second clock domain as described in the Chisel manual , though I wouldn't recommend to do so.如果确实需要,您可以考虑通过将第一个时钟域视为Chisel 手册中所述的第二个时钟域来强制执行此操作,尽管我不建议这样做。

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

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