2016-01-11 15:05:21 -05:00
|
|
|
/* verilator lint_off STMTDLY */
|
2015-11-03 14:16:50 -05:00
|
|
|
module dv_ctrl(/*AUTOARG*/
|
|
|
|
// Outputs
|
2016-02-24 14:23:30 -05:00
|
|
|
nreset, clk1, clk2, start,
|
2015-11-03 14:16:50 -05:00
|
|
|
// Inputs
|
|
|
|
dut_active, stim_done, test_done
|
|
|
|
);
|
|
|
|
|
2016-02-24 14:23:30 -05:00
|
|
|
parameter CFG_CLK1_PERIOD = 10;
|
|
|
|
parameter CFG_CLK1_PHASE = CFG_CLK1_PERIOD/2;
|
|
|
|
parameter CFG_CLK2_PERIOD = 100;
|
|
|
|
parameter CFG_CLK2_PHASE = CFG_CLK2_PERIOD/2;
|
2016-02-26 17:01:24 -05:00
|
|
|
parameter CFG_TIMEOUT = 50000;
|
2015-11-03 14:16:50 -05:00
|
|
|
|
|
|
|
output nreset; // async active low reset
|
2016-02-24 14:23:30 -05:00
|
|
|
output clk1; // main clock
|
|
|
|
output clk2; // secondary clock
|
2015-11-03 14:16:50 -05:00
|
|
|
output start; // start test (level)
|
|
|
|
|
|
|
|
input dut_active; // reset sequence is done
|
|
|
|
input stim_done; //stimulus is done
|
|
|
|
input test_done; //test is done
|
|
|
|
|
|
|
|
//signal declarations
|
2016-02-24 14:23:30 -05:00
|
|
|
reg nreset;
|
|
|
|
reg start;
|
|
|
|
reg clk1=0;
|
|
|
|
reg clk2=0;
|
|
|
|
reg [6:0] clk1_phase;
|
|
|
|
reg [6:0] clk2_phase;
|
|
|
|
integer seed,r;
|
|
|
|
|
|
|
|
//#################################
|
|
|
|
// RANDOM NUMBER GENERATOR
|
|
|
|
// (SEED SUPPLIED EXERNALLY)
|
|
|
|
//#################################
|
|
|
|
initial
|
|
|
|
begin
|
|
|
|
r=$value$plusargs("SEED=%s", seed);
|
|
|
|
$display("SEED=%d", seed);
|
|
|
|
`ifdef CFG_RANDOM
|
|
|
|
clk1_phase = {$random(seed)}; //generate random values
|
|
|
|
clk2_phase = {$random(seed)}; //generate random values
|
|
|
|
`else
|
|
|
|
clk1_phase = CFG_CLK1_PHASE;
|
|
|
|
clk2_phase = CFG_CLK2_PHASE;
|
|
|
|
`endif
|
|
|
|
$display("clk1_phase=%d clk2_phase=%d", clk1_phase,clk2_phase);
|
|
|
|
end
|
2015-11-03 19:56:27 -05:00
|
|
|
|
2016-02-24 14:23:30 -05:00
|
|
|
//#################################
|
|
|
|
//CLK1 GENERATOR
|
|
|
|
//#################################
|
|
|
|
always
|
|
|
|
#(clk1_phase + 1) clk1 = ~clk1; //add one to avoid "DC" state
|
|
|
|
|
|
|
|
//#################################
|
|
|
|
//CLK2 GENERATOR
|
|
|
|
//#################################
|
|
|
|
always
|
|
|
|
#(clk2_phase + 1) clk2 = ~clk2;
|
|
|
|
|
|
|
|
//#################################
|
2016-01-10 15:58:28 -05:00
|
|
|
//RESET
|
2016-02-24 14:23:30 -05:00
|
|
|
//#################################
|
2015-11-03 14:16:50 -05:00
|
|
|
initial
|
|
|
|
begin
|
2016-01-11 20:47:06 -05:00
|
|
|
#(1)
|
|
|
|
nreset = 'b0;
|
2016-02-26 17:01:24 -05:00
|
|
|
#(clk1_phase * 20 + 100) //hold reset for 20 clk cycles
|
2016-01-10 15:58:28 -05:00
|
|
|
nreset = 'b1;
|
2015-11-03 14:16:50 -05:00
|
|
|
end
|
|
|
|
|
2016-01-10 15:58:28 -05:00
|
|
|
//START TEST
|
2016-02-24 14:23:30 -05:00
|
|
|
always @ (posedge clk1 or negedge nreset)
|
2015-11-03 14:16:50 -05:00
|
|
|
if(!nreset)
|
|
|
|
start = 1'b0;
|
|
|
|
else if(dut_active)
|
|
|
|
start = 1'b1;
|
|
|
|
|
2016-01-10 15:58:28 -05:00
|
|
|
//STOP SIMULATION
|
2016-02-24 14:23:30 -05:00
|
|
|
always @ (posedge clk1)
|
2015-11-03 19:56:27 -05:00
|
|
|
if(stim_done & test_done)
|
2016-02-24 14:23:30 -05:00
|
|
|
#(CFG_TIMEOUT) $finish;
|
2016-01-10 15:58:28 -05:00
|
|
|
|
|
|
|
//WAVEFORM DUMP
|
2015-11-03 14:16:50 -05:00
|
|
|
//Better solution?
|
2016-01-11 15:05:21 -05:00
|
|
|
`ifndef VERILATOR
|
2015-11-03 14:16:50 -05:00
|
|
|
initial
|
|
|
|
begin
|
2016-01-10 15:58:28 -05:00
|
|
|
$dumpfile("waveform.vcd");
|
2016-01-11 20:47:06 -05:00
|
|
|
$dumpvars(0, dv_top);
|
2015-11-03 14:16:50 -05:00
|
|
|
end
|
2016-01-11 15:05:21 -05:00
|
|
|
`endif
|
2016-01-10 15:58:28 -05:00
|
|
|
|
2015-11-03 19:56:27 -05:00
|
|
|
endmodule // dv_ctrl
|
2015-11-03 14:16:50 -05:00
|
|
|
|
|
|
|
|
2015-11-06 11:25:05 -05:00
|
|
|
|