未赋值的寄存器(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
}
只有初始化(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
***
要修复这个问题,如果寄存器有一个 init
语句但没有赋值,你可以让SpinalHDL将该未赋值的寄存器转换为组合逻辑:
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
}