1
0
mirror of https://github.com/aolofsson/oh.git synced 2025-01-17 20:02:53 +08:00
oh/common/dv/dv_ctrl.v

134 lines
3.1 KiB
Coq
Raw Normal View History

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
nreset, clk1, clk2, start, vdd, vss,
2015-11-03 14:16:50 -05:00
// Inputs
dut_active, stim_done, test_done
);
parameter CFG_CLK1_PERIOD = 10;
parameter CFG_CLK1_PHASE = CFG_CLK1_PERIOD/2;
parameter CFG_CLK2_PERIOD = 20;
parameter CFG_CLK2_PHASE = CFG_CLK2_PERIOD/2;
2020-02-15 21:58:17 -05:00
parameter CFG_TIMEOUT = 5000;
2015-11-03 14:16:50 -05:00
output nreset; // async active low reset
output clk1; // main clock
output clk2; // secondary clock
2015-11-03 14:16:50 -05:00
output start; // start test (level)
output vdd; // driving vdd
output vss; // driving vss
2015-11-03 14:16:50 -05:00
input dut_active; // reset sequence is done
input stim_done; //stimulus is done
input test_done; //test is done
//signal declarations
reg vdd;
reg vss;
reg nreset;
reg start;
reg clk1=0;
reg clk2=0;
reg [6:0] clk1_phase;
reg [6:0] clk2_phase;
integer seed,r;
reg [1023:0] testname;
//#################################
// RANDOM NUMBER GENERATOR
// (SEED SUPPLIED EXERNALLY)
//#################################
initial
begin
r=$value$plusargs("SEED=%s", seed);
r=$value$plusargs("TESTNAME=%s", testname[1023:0]);
$display("SEED=%d", seed);
`ifdef CFG_RANDOM
clk1_phase = 1 + {$random(seed)}; //generate random values
clk2_phase = 1 + {$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
//#################################
//CLK1 GENERATOR
//#################################
always
#(clk1_phase) clk1 = ~clk1; //add one to avoid "DC" state
//#################################
//CLK2 GENERATOR
//#################################
always
#(clk2_phase) clk2 = ~clk2;
//#################################
//ASYNC
//#################################
2015-11-03 14:16:50 -05:00
initial
begin
#(1)
nreset = 'b0;
vdd = 'b0;
vss = 'b0;
#(clk1_phase * 10 + 100) //ramping voltage
vdd = 'bx;
#(clk1_phase * 10 + 100) //voltage is safe
vdd = 'b1;
#(clk1_phase * 40 + 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
//#################################
//SYNCHRONOUS STIMULUS
//#################################
2016-01-10 15:58:28 -05:00
//START TEST
always @ (posedge clk1 or negedge nreset)
2015-11-03 14:16:50 -05:00
if(!nreset)
2016-08-25 11:45:20 -04:00
start <= 1'b0;
2015-11-03 14:16:50 -05:00
else if(dut_active)
2016-08-25 11:45:20 -04:00
start <= 1'b1;
2015-11-03 14:16:50 -05:00
2016-01-10 15:58:28 -05:00
//STOP SIMULATION
always @ (posedge clk1)
2020-02-15 21:58:17 -05:00
if(stim_done & test_done)
begin
//$display("TEST DONE");
//$finish;
end
//#################################
// TIMEOUT
//#################################
2020-02-17 07:43:41 -05:00
initial
2020-02-15 21:58:17 -05:00
begin
#(CFG_TIMEOUT)
$display("TEST %0s FAILED ON TIMEOUT",testname);
2020-02-15 21:58:17 -05:00
$finish;
end
//#################################
2016-01-10 15:58:28 -05:00
//WAVEFORM DUMP
2020-02-15 21:58:17 -05:00
//#################################
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");
$dumpvars(0, dv_top);
2015-11-03 14:16:50 -05:00
end
2016-01-11 15:05:21 -05:00
`endif
2020-02-15 21:58:17 -05:00
2016-01-10 15:58:28 -05:00
endmodule // dv_ctrl
2015-11-03 14:16:50 -05:00
2015-11-06 11:25:05 -05:00