在SpinalHDL中使用之前已有的Verilog等代码的时候需要将这些代码包在一个BlackBox里面,但是如果这些代码里面有时钟和复位,我们需要怎么将时钟和复位端口和SpinalHDL中已有的时钟域连接起来呢?
当BlackBox中只有一个时钟的时候可以直接使用mapClockDomain完成时钟信号和复位信号的赋值。在mapClockDomain中如果没有指定时钟域的话就采用的是默认时钟域。
import spinal.core._ import spinal.lib._ class BK extends BlackBox{ val clka = in Bool() val rsta = in Bool() val din = in Bool() val dout = out Bool() mapClockDomain(clock = clka, reset = rsta) } class TestBlackBox extends Component { val din = in Bool() val dout = out Bool() val bk = new BK bk.din <> din bk.dout <> dout } object TestBlackBox extends App{ SpinalVerilog(new TestBlackBox) }
当有两个时钟域的时候,就需要把时钟域给指定一下了,在下面代码中将时钟域通过参数的方式传了进来。
import spinal.core._ import spinal.lib._ class BK(clockDomaina: ClockDomain, clockDomainb: ClockDomain) extends BlackBox{ val clka = in Bool() val rsta = in Bool() val clkb = in Bool() val rstb = in Bool() val din = in Bool() val dout = out Bool() mapClockDomain(clockDomaina,clock = clka, reset = rsta) mapClockDomain(clockDomainb,clock = clkb, reset = rstb) } class TestBlackBox extends Component { val din = in Bool() val dout = out Bool() val clkb = in Bool() val resetb = in Bool() val clockDomainb = ClockDomain(clock = clkb,reset = resetb) val bk = new BK(this.clockDomain,clockDomainb)//默认时钟域和新建的时钟域b bk.din <> din bk.dout <> dout } object TestBlackBox extends App{ SpinalVerilog(new TestBlackBox) }
因为在SpinalHDL中默认时钟域是高复位的,但是我们已有的IP可能是低复位的,这个时候就需要在mapClockDomain中指定一下复位信号是HIGH还是LOW。在下面代码中就将时钟域b下面的复位指定为低复位。
import spinal.core._ import spinal.lib._ class BK(clockDomaina: ClockDomain, clockDomainb: ClockDomain) extends BlackBox{ val clka = in Bool() val rsta = in Bool() val clkb = in Bool() val rstb = in Bool() val din = in Bool() val dout = out Bool() mapClockDomain(clockDomaina,clock = clka, reset = rsta) mapClockDomain(clockDomainb,clock = clkb, reset = rstb, resetActiveLevel = LOW) } class TestBlackBox extends Component { val din = in Bool() val dout = out Bool() val clkb = in Bool() val resetb = in Bool() val clockDomainb = ClockDomain(clock = clkb,reset = resetb) val bk = new BK(this.clockDomain,clockDomainb) bk.din <> din bk.dout <> dout } object TestBlackBox extends App{ SpinalVerilog(new TestBlackBox) }
以上三种情况应该足够应对一般情况下BlackBox的时钟域的赋值了。
审核编辑:汤梓红
全部0条评论
快来发表一下你的评论吧 !