在类参数化中不能使用Bool来反转复位极性

时间:2016-04-25 22:16:54

标签: scala verilog fpga chisel

我刚刚开始使用Chisel并写了一个简单的计数器来闪烁一个led。 FPGA板(Lattice iCEstick)有一个反向复位信号,而不是改变生成的verilog中的极性,我想在Chisel中设置它。

我发现Module有一个类型为Chisel.Bool的_reset参数,可以设置为false来反转复位信号。 Here是其他人使用它的示例。但是我收到的错误似乎无法解决。首先,代码:

import Chisel._

class Blink( rstPol: Bool = null ) extends Module( _reset = rstPol ) {
  val io = new Bundle {
    val led = UInt( OUTPUT, 1 )
  }

  val cnt_next = UInt()
  val counter  = Reg( init = UInt( 0, 24 ), next = cnt_next )

  cnt_next := counter + UInt( 1 )

  io.led := counter( 23 )
}

object blinkmain {
  def main( args: Array[ String ] ): Unit = {
    chiselMain( Array( "--backend", "v" ),
      () => Module( new Blink( Bool( false ) ) )
    )
  }
}

我得到的错误:

[error] Blink.scala:19 < /*??*/ Chisel.Bool(OUTPUT, width=1, connect to 0 inputs: ()) > doesn't have its component,yet. in class blinkmain$$anonfun$main$1$$anonfun$apply$1

如果我不提供Bool( false )参数,那么我没有错误,但我的重置极性当然仍然是正确的。

我已经尝试了rstPol: Bool = Bool( false )Module( _reset = Bool( false ) )但是我在第3行遇到了同样的错误。似乎它试图将Bool分配给没有宽度的东西,但我没有想法怎么可能。

我查看了我正在使用的Chisel版本,它是2.2.33。这是我的build.sbt文件,以防它很重要:

scalaVersion := "2.11.7"

libraryDependencies += "edu.berkeley.cs" %% "chisel" $ "latest.version"

scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked", "-language:reflectiveCalls")

1 个答案:

答案 0 :(得分:0)

由于我是Scala和Chisel的新手,我错误地认为_reset的{​​{1}}参数是Module,以指示正或负复位信号是否为产生。您可以将Bool INPUT Bool相关联,但与_reset OUTPUT 相反,因为错误消息会提及。

这就是我修复它的方法(我确实用计数器宽度参数Bool展开了它,但那是无关紧要的):

swidth

所以我创建了一个import Chisel._ class Blink( swidth: Int, rst: Bool = null ) extends Module( _reset = rst ) { val io = new Bundle { val led = UInt( OUTPUT, 5 ) } val counter = Reg( init = UInt( 0, width = swidth ) ) counter := counter + UInt( 1 ) io.led := counter( swidth - 1, swidth - 5 ) } class Top extends Module { val io = new Bundle { val led = UInt( OUTPUT, 5 ) val rstn = Bool( INPUT ) } val rst = Reg( next = Reg( next = !io.rstn ) ) val blink = Module( new Blink( 27, rst ) ) blink.io.led <> io.led } object BlinkMain { def main( args: Array[ String ] ): Unit = { chiselMain( Array( "--backend", "v", "--targetDir", "verilog" ), () => Module( new Top() ) ) } } 模块来实例化Top,它接受​​反向重置输入(Blink),将其反转,并将其分配给rstn。为了更好地衡量,我还将_reset路由到两个触发器,以使其与输入时钟信号同步。