classTopextendsComponent{ val a = in Bits(8 bits) val b = RegNext(a) init 0 }
默认会得到一个clk,reset时钟复位信号,并且SpinalHDL复位默认是上升沿
1 2 3 4 5 6 7 8 9 10 11 12 13
module Top ( input [7:0] a, input clk, input reset); reg [7:0] b; always @ (posedge clk orposedge reset) begin if (reset) begin b <= (8'b00000000); endelsebegin b <= a; end end endmodule
module Top ( input myclk, input myrst, input [7:0] a, output [7:0] b); reg [7:0] _zz_1_; assign b = _zz_1_; always @ (posedge myclk orposedge myrst) begin if (myrst) begin _zz_1_ <= (8'b00000000); endelsebegin _zz_1_ <= a; end end endmodule
classSubextendsComponent{ val a = in Bits(8 bits) val b = out(RegNext(a) init 0) } classTopextendsComponent{ val myclk,myrst = in Bool() val mycd = ClockDomain(myclk,myrst) val u_sub0 = mycd(newSub) //mycd时钟包裹Sub模块的例化 }
生成的verilog可以看到,子模块的时钟复位信号都被修改过来了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
module Sub ( input [7:0] a, outputreg [7:0] b, input myclk, input myrst); always @ (posedge myclk ornegedge myrst) begin if (!myrst) begin b <= (8'b00000000); endelsebegin b <= a; end end endmodule module Top ( ... endmodule
classInternalClockWithPllExampleextendsComponent{ val io = newBundle { val clk100M = in Bool val aReset = in Bool val result = out UInt (4 bits) } // myClockDomain.clock will be named myClockName_clk // myClockDomain.reset will be named myClockName_reset val myClockDomain = ClockDomain.internal("myClockName") // Instanciate a PLL (probably a BlackBox) val pll = newPll() pll.io.clkIn := io.clk100M
// Do whatever you want with myClockDomain val myArea = newClockingArea(myClockDomain){ val myReg = Reg(UInt(4 bits)) init(7) myReg := myReg + 1
io.result := myReg } }
时钟门控处理
目前Spinal在处理门控的时候还是需要手动例化,
1 2 3 4 5 6
classTopextendsComponent{ val u_cgCell0 = newCG val u_cgCell1 = newCG ... val cgd0 = ClockDomain(u_cgCell0.ECK, clockDomain.readResetWire) val cgd1 = ClockDomain(u_cgCell1.ECK, clockDomain.readResetWire)