未分配的寄存器(Unassigned register)

一、简介

SpinalHDL将会检查所有设计中有用的寄存器都被分配了。

二、例子

下述代码:

class TopLevel extends Component {
  val result = out(UInt(8 bits))
  val a = Reg(UInt(8 bits))
  result := a
}

会报错:

UNASSIGNED REGISTER (toplevel/a :  UInt[8 bits]), defined at
  ***
  Source file location of the toplevel/a definition via the stack trace
  ***

可以修复为:

class TopLevel extends Component {
  val result = out(UInt(8 bits))
  val a = Reg(UInt(8 bits))
  a := 42
  result := a
}

三、只有初始化的寄存器(Register with only init)

在某些情况下, 可能由于硬件参数化, 生成只有init描述但无分配的寄存器也是有意义的。

class TopLevel extends Component {
  val result = out(UInt(8 bits))
  val a = Reg(UInt(8 bits)) init(42)

  if(something)
    a := somethingElse  //有问题,这个可综合
  result := a
}

会报错:

UNASSIGNED REGISTER (toplevel/a :  UInt[8 bits]), defined at
  ***
  Source file location of the toplevel/a definition via the stack trace
  ***

为了修复它, 可以让SpinalHDL转换该只有init描述但未分配的寄存器为一个组合逻辑:

class TopLevel extends Component {
  val result = out(UInt(8 bits))
  val a = Reg(UInt(8 bits)).init(42).allowUnsetRegToAvoidLatch

  if(something)
    a := somethingElse
  result := a
}