/ovm-2.0.1/examples/tlm/producer_consumer/fifo.sv

http://camlet.googlecode.com/ · SystemVerilog · 144 lines · 67 code · 31 blank · 46 comment · 1 complexity · 3bd229fa9a26dc2438888428294302bb MD5 · raw file

  1. // $Id: //dvt/vtech/dev/main/ovm/examples/tlm/producer_consumer/fifo.sv#9 $
  2. //----------------------------------------------------------------------
  3. // Copyright 2007-2008 Mentor Graphics Corporation
  4. // Copyright 2007-2008 Cadence Design Systems, Inc.
  5. // All Rights Reserved Worldwide
  6. //
  7. // Licensed under the Apache License, Version 2.0 (the
  8. // "License"); you may not use this file except in
  9. // compliance with the License. You may obtain a copy of
  10. // the License at
  11. //
  12. // http://www.apache.org/licenses/LICENSE-2.0
  13. //
  14. // Unless required by applicable law or agreed to in
  15. // writing, software distributed under the License is
  16. // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  17. // CONDITIONS OF ANY KIND, either express or implied. See
  18. // the License for the specific language governing
  19. // permissions and limitations under the License.
  20. //----------------------------------------------------------------------
  21. /*
  22. About: producer_consumer
  23. this test is the basic simple to illustrates how to create a producer and consumer which are completely independent and connecting them using a tlm_fifo channel
  24. Walk through the test:
  25. two thrads *producer* and *consumer* will use ovm_blocking_put port and ovm_blocking_get port, to transfer an integer from the producer to the consumer through fifo exports at the connection function of an environment class
  26. */
  27. //----------------------------------------------------------------------
  28. // module top
  29. //----------------------------------------------------------------------
  30. module test;
  31. `ifdef INCA
  32. `include "ovm.svh"
  33. `else
  34. import ovm_pkg::*;
  35. `endif
  36. //----------------------------------------------------------------------
  37. // class producer
  38. //----------------------------------------------------------------------
  39. class producer extends ovm_component;
  40. ovm_blocking_put_port#(int) put_port;
  41. function new(string name, ovm_component p = null);
  42. super.new(name,p);
  43. put_port = new("put_port", this);
  44. endfunction
  45. task run;
  46. int randval;
  47. string s;
  48. for(int i = 0; i < 10; i++)
  49. begin
  50. randval = $random % 100;
  51. #10;
  52. $sformat(s, "sending %4d", randval);
  53. ovm_report_info("producer", s);
  54. put_port.put(randval);
  55. end
  56. endtask
  57. endclass : producer
  58. //----------------------------------------------------------------------
  59. // class consumer
  60. //----------------------------------------------------------------------
  61. class consumer extends ovm_component;
  62. ovm_blocking_get_port#(int) get_port;
  63. function new(string name, ovm_component p = null);
  64. super.new(name,p);
  65. get_port = new("get_port", this);
  66. endfunction
  67. task run;
  68. int val;
  69. string s;
  70. forever
  71. begin
  72. get_port.get(val);
  73. $sformat(s, "receiving %4d", val);
  74. ovm_report_info("consumer", s);
  75. end
  76. endtask
  77. endclass : consumer
  78. //----------------------------------------------------------------------
  79. // class env
  80. //----------------------------------------------------------------------
  81. class env extends ovm_env;
  82. producer p;
  83. consumer c;
  84. tlm_fifo #(int) f;
  85. function new(string name = "env");
  86. super.new(name);
  87. p = new("producer", this);
  88. c = new("consumer", this);
  89. f = new("fifo", this);
  90. $display("fifo put_export: %s", f.m_name);
  91. endfunction
  92. function void connect();
  93. p.put_port.connect(f.put_export);
  94. c.get_port.connect(f.get_export);
  95. endfunction
  96. task run();
  97. #1000 global_stop_request();
  98. endtask
  99. endclass
  100. // Main body of module top:
  101. env e;
  102. initial begin
  103. e = new();
  104. e.run_test();
  105. //$finish;
  106. end
  107. endmodule // test