如何生成异步重置verilog总是用凿子阻塞

时间:2015-04-21 08:40:46

标签: verilog fpga chisel

Chisel始终生成只有灵敏度列表中的时钟的块:

always @posedge(clk) begin
  [...]
end

是否可以将Module配置为使用异步复位并生成这样的always块?

always @(posedge clk or posedge reset) begin
   [...]
end

2 个答案:

答案 0 :(得分:4)

看起来这个问题已在其他地方的互联网上被问过......答案是Chisel本身并没有内置这个功能。

看起来在Chisel中执行此操作的方法是使用同步重置:

always @posedge(clk) begin
  if (reset) begin
  [...]
  end 
  else 
  [...]
  end
end

有关该主题的更多讨论: https://groups.google.com/forum/#!topic/chisel-users/4cc4SyB5mk8

答案 1 :(得分:2)

自Chisel 3.2.0起,支持同步,异步和抽象重置类型。根据显式指定或推断的重置类型,您将获得规范的同步或异步Verilog输出。

要尝试更全面地显示此内容,请考虑以下MultiIOModule,该重置具有三个重置:

  • 具有抽象重置类型(这是“抽象重置”)的隐式reset输入
  • 具有syncReset类型(这是“同步重置”)的显式Bool输入
  • 具有asyncReset类型(这是“异步重置”)的显式AsyncReset输入

使用withReset,然后可以将特定的复位连接用于设计中的不同寄存器:

import chisel3._
import chisel3.stage.ChiselStage

class Foo extends MultiIOModule {
  val syncReset  = IO(Input(Bool()      ))
  val asyncReset = IO(Input(AsyncReset()))

  val in          = IO(Input( Bool()))
  val outAbstract = IO(Output(Bool()))
  val outSync     = IO(Output(Bool()))
  val outAsync    = IO(Output(Bool()))

  val regAbstract =                         RegNext(in, init=0.U)
  val regSync     = withReset(syncReset)  { RegNext(in, init=0.U) }
  val regAsync    = withReset(asyncReset) { RegNext(in, init=0.U) }

  outAbstract := regAbstract
  outSync     := regSync
  outAsync    := regAsync
}

然后使用(new ChiselStage).emitVerilog(new Foo)编译时,将产生以下Verilog:

module Foo(
  input   clock,
  input   reset,
  input   syncReset,
  input   asyncReset,
  input   in,
  output  outAbstract,
  output  outSync,
  output  outAsync
);
  reg  regAbstract;
  reg  regSync;
  reg  regAsync;
  assign outAbstract = regAbstract;
  assign outSync = regSync;
  assign outAsync = regAsync;
  always @(posedge clock) begin
    if (reset) begin
      regAbstract <= 1'h0;
    end else begin
      regAbstract <= in;
    end
    if (syncReset) begin
      regSync <= 1'h0;
    end else begin
      regSync <= in;
    end
  end
  always @(posedge clock or posedge asyncReset) begin
    if (asyncReset) begin
      regAsync <= 1'h0;
    end else begin
      regAsync <= in;
    end
  end
endmodule

注意:在Chisel 3.2中,顶层抽象重置将始终设置为同步重置。在Chisel 3.3.0中,添加了两个特征:RequireSyncResetRequireAsyncReset。这些可用于将连接到regAbstract的寄存器的重置类型从同步更改为异步。使用(new ChiselStage).emitVerilog(new Foo with RequireAsyncReset)重新编译设计,将regAbstract逻辑更改为

always @(posedge clock or posedge reset) begin
  if (reset) begin
    regAbstract <= 1'h0;
  end else begin
    regAbstract <= in;
  end
end

有关更多信息,请访问Chisel website has more information on resets