FPGA開発日記

カテゴリ別記事インデックス https://msyksphinz.github.io/github_pages , English Version https://fpgadevdiary.hatenadiary.com/

Chisel-3.2 RC2でAsynchronous Resetを生成してみる

https://cdn-ak.f.st-hatena.com/images/fotolife/m/msyksphinz/20181105/20181105012126.png

Chisel-3.2 RC2がリリースされている。いくつかの新機能が加わっているが、気になるのはAsynchronous Resetのサポートだ。

www.chisel-lang.org

これだけ見ても良く分からないので、ChiselリポジトリのPull Requestを見て何となく使い方を調べてみた。

github.com

テストする前に、build.sbtのChiselのバージョンを上げておく。

  • build.sbt
// Provide a managed dependency on X if -DXVersion="" is supplied on the command line.
val defaultVersions = Map(
  "chisel3" -> "3.2.0-RC2",
  "chisel-iotesters" -> "1.2.+",
  "dsptools" -> "1.1.+"
)

テスト回路を書いてみる。

package async_reset

import chisel3._
import chisel3.util._
import chisel3.Bool


class AsyncResetTest extends Module {
  val io = IO(new Bundle {
    val asyncReset: AsyncReset = Input(AsyncReset())
    val in  = Input(UInt(32.W))
    val out = Output(UInt(32.W))
  })

  val ff = withReset(io.asyncReset) { RegInit(0.U(32.W)) }

  ff := io.in
  io.out := ff

}

object main extends App {
  chisel3.Driver.emitVerilog(new AsyncResetTest())
}

ポイントとしてはwithResetasyncReset信号を使用しており、これで入力信号asyncResetに応じて非同期リセットがかけられるようになるらしい。 上記のffは非同期リセットになっている。

sbt 'runMain async_reset.main

生成されるVerilogは以下となる。これ、Negative Edgeにはできないのかな?FIRRTLのソースコードをみて、Negativeにする方法がないか調べてみよう。

module AsyncResetTest(
  input         clock,
  input         reset,
  input         io_asyncReset,
  input  [31:0] io_in,
  output [31:0] io_out
);
..
  always @(posedge clock or posedge io_asyncReset) begin
    if (io_asyncReset) begin
      ff <= 32'h0;
    end else begin
      ff <= io_in;
    end
  end
endmodule