Projektdaten für das ESY1B Praktikum im Sommersemester 2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

random_tl.sv 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Project: ESY-Praktikum-Testbench
  2. // File: random_tl.sv
  3. // Title: Random Testbench Toplevel
  4. // Description: Creates a Testbench that tests the Toplevel-Design with random based verifikation
  5. //
  6. //
  7. // --------------------------------------------------------------------
  8. //
  9. //------------------------------------------------------------
  10. // Notes:
  11. //
  12. //
  13. //------------------------------------------------------------
  14. // Development History:
  15. //
  16. // __DATE__ _BY_ _REV_ _DESCRIPTION___________________________
  17. // 14/06/22 JU/TL 1.0 Initial testbench design
  18. //
  19. //------------------------------------------------------------
  20. // Dependencies:
  21. // Toplevel-Design
  22. //
  23. //
  24. //------------------------------------------------------------
  25. //------------------------------------------------------------
  26. //
  27. //
  28. // Testbench
  29. //
  30. //------------------------------------------------------------
  31. class Taster_rnd;
  32. rand bit [1:0] data;
  33. constraint Rst_rnd
  34. {
  35. data dist {0:=70,1 :=30};
  36. }
  37. endclass
  38. class Data_ADC_rnd;
  39. rand bit [7:0] data;
  40. endclass
  41. `timescale 1ns/1ps
  42. module testbench_toplevel_rnd;
  43. // inputs and outputs
  44. reg taster;
  45. reg [7:0]data_ADC;
  46. reg clk12M;
  47. wire RED;
  48. wire GRN;
  49. wire alarm;
  50. wire SI;
  51. wire SO;
  52. wire SCK;
  53. wire nCS;
  54. //random
  55. Taster_rnd taster_rnd = new();
  56. Data_ADC_rnd data_ADC_rnd = new();
  57. // connect module
  58. SPI_FRAM_Module fram_storage(.SI(SI),.SO(SO),.SCK(SCK),.nCS(nCS).opcode().addr(),.mem_data(),.stat_reg,.hibernate());
  59. initial
  60. begin
  61. clk12M=1'b0;
  62. end
  63. always
  64. #41.666666 clk12M=~clk12M; //clock generation
  65. //random test
  66. initial begin
  67. repeat (50) begin
  68. #50000
  69. Data_ADC_rnd.randomize();
  70. Taster_rnd.randomize();
  71. taster = taster_rnd.data;
  72. data_ADC = data_ADC_rnd.data;
  73. // assertions
  74. // assert color green
  75. assert property(@(posedge clk12M) disable iff (alarm) ((data_ADC < 100) |=> ##4 (!RED && GRN));
  76. //assert color yellow
  77. assert property(@(posedge clk12M) disable iff (alarm) ((data_ADC >= 100) && (data_ADC <= 168))|=> ##4 (RED && GRN));
  78. //assert color red + alarm
  79. assert property(@(posedge clk12M) (data_ADC > 168) |=> ##4 (RED && !GRN && alarm));
  80. $monitor("time=%t, data_ADC=%d, RED=%d, GRN=%d, taster=%d",$time,data_ADC, RED, GRN, taster);
  81. end
  82. $stop;
  83. end
  84. endmodule