Advertisement
Guest User

Untitled

a guest
Oct 26th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ****************************************
  2. mailbox_assignment2.sv
  3. ****************************************
  4. include "transaction.sv";
  5.  
  6. program mailbox_assignment2;
  7. // instatiating mailbox of of trasnsaction reference
  8.   mailbox#(trasnsaction) myMailbox;
  9.  
  10. int num_trans = 10;
  11.  
  12. //like main in c
  13. initial begin
  14.      myMailbox = new();
  15.      $display($time,"join started");  
  16.     fork
  17.       producer();
  18.       consumer();
  19.     join
  20.     $display($time,"join ended");
  21.     #700
  22.     //join none
  23.     $display($time,"join none start");
  24.     fork
  25.        producer();
  26.        consumer();
  27.     join_none
  28.     $display($time,"join none ended");
  29.    
  30.     #1700;
  31.     $display($time,"join any start");
  32.     fork
  33.       producer();
  34.       consumer();
  35.     join_any
  36.     $display($time,"join any ended");
  37.     #3700
  38.  
  39.     $finish();
  40.    
  41. end
  42.  
  43. task producer();
  44.     trasnsaction tr;
  45.    
  46.     //using repeat instead of while
  47.     repeat(10)
  48.     begin
  49.         #2
  50.         tr = new();
  51.         // using $random() to simplify transaction
  52.         tr.data = $urandom;
  53.         tr.compute_ref();
  54.         myMailbox.put(tr);
  55.         $display("@%0t:producer:%d!",$time,tr.data);
  56.     end
  57. endtask
  58.  
  59. task consumer();
  60.     trasnsaction tr;
  61.     repeat(10)
  62.     begin
  63.         #20
  64.      //   tr = new();
  65.         if(myMailbox.num() > 0) begin
  66.             myMailbox.get(tr);
  67.             $display("@%0t:consumer:%d!",$time,tr.data);
  68.         end
  69.         else begin #2; end
  70.     end
  71. endtask
  72. endprogram
  73.  
  74. *********************************************
  75. do file
  76. ********************************************
  77. vlog -reportprogress 300 -work work transaction.sv
  78. vlog -reportprogress 300 -work work mailbox_assignment2.sv
  79. vsim work.mailbox_assignment2
  80. run -all
  81.  
  82. ********************************************
  83. transaction.sv
  84. ********************************************
  85. class trasnsaction;
  86. rand bit [3:0] data;
  87. logic [7:0] reference;
  88. static bit [7:0] counter_value;
  89. function new;
  90. counter_value = 0;
  91. endfunction
  92. function [7:0] compute_ref;
  93. reference = counter_value+data;
  94. counter_value = counter_value+data;
  95. endfunction
  96. endclass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement