Assertions

In addition to Scala run-time assertions assert(condition : Boolean, message : String), you can add hardware assertions using the following syntax:

assert(assertion : Bool, message : String = null, severity: AssertNodeSeverity = Error)

严重性等级是:

名称

描述

NOTE

用于报告提示性消息

WARNING

用于报告异常情况

ERROR

用于报告不应该发生的情况

FAILURE

用于报告致命情况并关闭仿真

一个实际的例子是检查当 ready 为低电平时,握手协议的 valid 信号不应该由高变低:

class TopLevel extends Component {
  val valid = RegInit(False)
  val ready = in Bool()

  when(ready) {
    valid := False
  }
  // some logic

  assert(
    assertion = !(valid.fall && !ready),
    message   = "Valid dropped when ready was low",
    severity  = ERROR
  )
}

备注

Scala run time assertions assert(condition : Boolean, message : String) do not provide support for a severity level, and if triggered, will always stop the current elaboration/simulation.