Verwendeter Programmcode in Studienarbeit für ESY1B zum Thema "Verifikation mit SystemVerilog und Python"
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.

wb_master_model.v 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. //////////////////////////////////////////////////////////////////////
  2. //// ////
  3. //// wb_master_model.v ////
  4. //// ////
  5. //// This file is part of the SPI IP core project ////
  6. //// http://www.opencores.org/projects/spi/ ////
  7. //// ////
  8. //// Author(s): ////
  9. //// - Simon Srot (simons@opencores.org) ////
  10. //// ////
  11. //// Based on: ////
  12. //// - i2c/bench/verilog/wb_master_model.v ////
  13. //// Copyright (C) 2001 Richard Herveille ////
  14. //// ////
  15. //// All additional information is avaliable in the Readme.txt ////
  16. //// file. ////
  17. //// ////
  18. //////////////////////////////////////////////////////////////////////
  19. //// ////
  20. //// Copyright (C) 2002 Authors ////
  21. //// ////
  22. //// This source file may be used and distributed without ////
  23. //// restriction provided that this copyright statement is not ////
  24. //// removed from the file and that any derivative work contains ////
  25. //// the original copyright notice and the associated disclaimer. ////
  26. //// ////
  27. //// This source file is free software; you can redistribute it ////
  28. //// and/or modify it under the terms of the GNU Lesser General ////
  29. //// Public License as published by the Free Software Foundation; ////
  30. //// either version 2.1 of the License, or (at your option) any ////
  31. //// later version. ////
  32. //// ////
  33. //// This source is distributed in the hope that it will be ////
  34. //// useful, but WITHOUT ANY WARRANTY; without even the implied ////
  35. //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
  36. //// PURPOSE. See the GNU Lesser General Public License for more ////
  37. //// details. ////
  38. //// ////
  39. //// You should have received a copy of the GNU Lesser General ////
  40. //// Public License along with this source; if not, download it ////
  41. //// from http://www.opencores.org/lgpl.shtml ////
  42. //// ////
  43. //////////////////////////////////////////////////////////////////////
  44. `include "timescale.v"
  45. module wb_master_model(clk, rst, adr, din, dout, cyc, stb, we, sel, ack, err, rty);
  46. parameter dwidth = 32;
  47. parameter awidth = 32;
  48. input clk, rst;
  49. output [awidth -1:0] adr;
  50. input [dwidth -1:0] din;
  51. output [dwidth -1:0] dout;
  52. output cyc, stb;
  53. output we;
  54. output [dwidth/8 -1:0] sel;
  55. input ack, err, rty;
  56. // Internal signals
  57. reg [awidth -1:0] adr;
  58. reg [dwidth -1:0] dout;
  59. reg cyc, stb;
  60. reg we;
  61. reg [dwidth/8 -1:0] sel;
  62. reg [dwidth -1:0] q;
  63. // Memory Logic
  64. initial
  65. begin
  66. adr = {awidth{1'bx}};
  67. dout = {dwidth{1'bx}};
  68. cyc = 1'b0;
  69. stb = 1'bx;
  70. we = 1'hx;
  71. sel = {dwidth/8{1'bx}};
  72. #1;
  73. end
  74. // Wishbone write cycle
  75. task wb_write;
  76. input delay;
  77. integer delay;
  78. input [awidth -1:0] a;
  79. input [dwidth -1:0] d;
  80. begin
  81. // wait initial delay
  82. repeat(delay) @(posedge clk);
  83. // assert wishbone signal
  84. #1;
  85. adr = a;
  86. dout = d;
  87. cyc = 1'b1;
  88. stb = 1'b1;
  89. we = 1'b1;
  90. sel = {dwidth/8{1'b1}};
  91. @(posedge clk);
  92. // wait for acknowledge from slave
  93. while(~ack) @(posedge clk);
  94. // negate wishbone signals
  95. #1;
  96. cyc = 1'b0;
  97. stb = 1'bx;
  98. adr = {awidth{1'bx}};
  99. dout = {dwidth{1'bx}};
  100. we = 1'hx;
  101. sel = {dwidth/8{1'bx}};
  102. end
  103. endtask
  104. // Wishbone read cycle
  105. task wb_read;
  106. input delay;
  107. integer delay;
  108. input [awidth -1:0] a;
  109. output [dwidth -1:0] d;
  110. begin
  111. // wait initial delay
  112. repeat(delay) @(posedge clk);
  113. // assert wishbone signals
  114. #1;
  115. adr = a;
  116. dout = {dwidth{1'bx}};
  117. cyc = 1'b1;
  118. stb = 1'b1;
  119. we = 1'b0;
  120. sel = {dwidth/8{1'b1}};
  121. @(posedge clk);
  122. // wait for acknowledge from slave
  123. while(~ack) @(posedge clk);
  124. // negate wishbone signals
  125. #1;
  126. cyc = 1'b0;
  127. stb = 1'bx;
  128. adr = {awidth{1'bx}};
  129. dout = {dwidth{1'bx}};
  130. we = 1'hx;
  131. sel = {dwidth/8{1'bx}};
  132. d = din;
  133. end
  134. endtask
  135. // Wishbone compare cycle (read data from location and compare with expected data)
  136. task wb_cmp;
  137. input delay;
  138. integer delay;
  139. input [awidth -1:0] a;
  140. input [dwidth -1:0] d_exp;
  141. begin
  142. wb_read (delay, a, q);
  143. if (d_exp !== q)
  144. $display("Data compare error. Received %h, expected %h at time %t", q, d_exp, $time);
  145. end
  146. endtask
  147. endmodule