Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying of clock for blackbox module #731

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/scala/BlackBox.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class VerilogParameters {
* // Implement functionality of DSP to allow simulation verification
* } }}}
*/
abstract class BlackBox extends Module {
abstract class BlackBox( bbClock: Option[Clock] = None, bbReset: Option[Bool] = None) extends Module( bbClock, bbReset ) {
Driver.blackboxes += this
private val clockMapping = new HashMap[String, String]

Expand Down
15 changes: 15 additions & 0 deletions src/test/resources/BlackBoxSuite_UserMod_1.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module BlackBoxSuite_UserMod_1(
input [3:0] io_in,
output[3:0] io_out
);

wire[3:0] userbb_out;


assign io_out = userbb_out;
UserBB userbb(
.in( io_in ),
.out( userbb_out )
);
endmodule

35 changes: 35 additions & 0 deletions src/test/resources/BlackBoxSuite_UserMod_2.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module BlackBoxSuite_UserMod_2(input clk, input usrClk, input reset,
input [3:0] io_in,
output[3:0] io_out
);

reg [3:0] inDelay;
wire[3:0] T0;
wire[3:0] userbb_out;

`ifndef SYNTHESIS
// synthesis translate_off
integer initvar;
initial begin
#0.002;
inDelay = {1{$random}};
end
// synthesis translate_on
`endif

assign T0 = reset ? 4'h0 : io_in;
assign io_out = userbb_out;
UserClockedBB userbb(.clkIn(usrClk), .rst(reset),
.in( inDelay ),
.out( userbb_out )
);

always @(posedge clk) begin
if(reset) begin
inDelay <= 4'h0;
end else begin
inDelay <= io_in;
end
end
endmodule

72 changes: 72 additions & 0 deletions src/test/scala/BlackBoxSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

import org.junit.Assert._
import org.junit.Test
import org.junit.Ignore

import Chisel._

class BlackBoxSuite extends TestSuite {

class UserBB extends BlackBox {
val io = new Bundle {
val in = UInt( INPUT, 4 )
val out = UInt( OUTPUT, 4 )
}
io.in.setName("in")
io.out.setName("out")
setModuleName("UserBB")
io.out := io.in
}

class UserClockedBB( clkIn : Clock ) extends BlackBox( bbClock = clkIn ) {
val io = new Bundle {
val in = UInt( INPUT, 4 )
val out = UInt( OUTPUT, 4 )
}
io.in.setName("in")
io.out.setName("out")
setModuleName("UserClockedBB")
io.out := Reg( init = UInt(0, 4), next = io.in )
renameClock( clkIn, "clkIn" )
renameReset("rst")
}

@Test def userBBTest {

class UserMod extends Module {
val io = new Bundle {
val in = UInt( INPUT, 4 )
val out = UInt( OUTPUT, 4 )
}
val userbb = Module( new UserBB )
userbb.io <> io
}

chiselMain(Array[String]("--backend", "v",
"--targetDir", dir.getPath.toString()),
() => Module(new UserMod))
assertFile("BlackBoxSuite_UserMod_1.v")
}

@Test def userClockedBBTest {

class UserMod extends Module {
val io = new Bundle {
val in = UInt( INPUT, 4 )
val out = UInt( OUTPUT, 4 )
}
val inDelay = Reg( init = UInt( 0, 4 ), next = io.in )
val usrClk = Clock( src = clock, period = 2 )
usrClk.setName("usrClk")
val userbb = Module( new UserClockedBB( usrClk ) )
userbb.io.in := inDelay
io.out := userbb.io.out
}

chiselMain(Array[String]("--backend", "v",
"--targetDir", dir.getPath.toString()),
() => Module(new UserMod))
assertFile("BlackBoxSuite_UserMod_2.v")
}

}