123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- // Project: ESY-Praktikum-Testbench
- // File: random_tl.sv
- // Title: Random Testbench Toplevel
- // Description: Creates a Testbench that tests the Toplevel-Design with random based verifikation
- //
- //
- // --------------------------------------------------------------------
- //
- //------------------------------------------------------------
- // Notes:
- //
- //
- //------------------------------------------------------------
- // Development History:
- //
- // __DATE__ _BY_ _REV_ _DESCRIPTION___________________________
- // 14/06/22 JU/TL 1.0 Initial testbench design
- //
- //------------------------------------------------------------
- // Dependencies:
- // Toplevel-Design
- //
- //
- //------------------------------------------------------------
-
-
-
- //------------------------------------------------------------
- //
- //
- // Testbench
- //
- //------------------------------------------------------------
-
- class Taster_rnd;
- rand bit [1:0] data;
- constraint Rst_rnd
- {
- data dist {0:=70,1 :=30};
- }
- endclass
-
- class Data_ADC_rnd;
- rand bit [7:0] data;
- endclass
-
-
- `timescale 1ns/1ps
- module testbench_toplevel_rnd;
-
- // inputs and outputs
- reg taster;
- reg [7:0]data_ADC;
- reg clk12M;
- wire RED;
- wire GRN;
- wire alarm;
- wire SI;
- wire SO;
- wire SCK;
- wire nCS;
-
- //random
- Taster_rnd taster_rnd = new();
- Data_ADC_rnd data_ADC_rnd = new();
-
- // connect module
- SPI_FRAM_Module fram_storage(.SI(SI),.SO(SO),.SCK(SCK),.nCS(nCS).opcode().addr(),.mem_data(),.stat_reg,.hibernate());
-
- initial
- begin
- clk12M=1'b0;
- end
- always
- #41.666666 clk12M=~clk12M; //clock generation
-
- //random test
- initial begin
- repeat (50) begin
- #50000
-
- Data_ADC_rnd.randomize();
- Taster_rnd.randomize();
-
- taster = taster_rnd.data;
- data_ADC = data_ADC_rnd.data;
-
- // assertions
-
- // assert color green
- assert property(@(posedge clk12M) disable iff (alarm) ((data_ADC < 100) |=> ##4 (!RED && GRN));
-
- //assert color yellow
-
- assert property(@(posedge clk12M) disable iff (alarm) ((data_ADC >= 100) && (data_ADC <= 168))|=> ##4 (RED && GRN));
-
- //assert color red + alarm
-
- assert property(@(posedge clk12M) (data_ADC > 168) |=> ##4 (RED && !GRN && alarm));
-
- $monitor("time=%t, data_ADC=%d, RED=%d, GRN=%d, taster=%d",$time,data_ADC, RED, GRN, taster);
- end
- $stop;
- end
-
- endmodule
-
|