Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ****************************************
- mailbox_assignment2.sv
- ****************************************
- include "transaction.sv";
- program mailbox_assignment2;
- // instatiating mailbox of of trasnsaction reference
- mailbox#(trasnsaction) myMailbox;
- int num_trans = 10;
- //like main in c
- initial begin
- myMailbox = new();
- $display($time,"join started");
- fork
- producer();
- consumer();
- join
- $display($time,"join ended");
- #700
- //join none
- $display($time,"join none start");
- fork
- producer();
- consumer();
- join_none
- $display($time,"join none ended");
- #1700;
- $display($time,"join any start");
- fork
- producer();
- consumer();
- join_any
- $display($time,"join any ended");
- #3700
- $finish();
- end
- task producer();
- trasnsaction tr;
- //using repeat instead of while
- repeat(10)
- begin
- #2
- tr = new();
- // using $random() to simplify transaction
- tr.data = $urandom;
- tr.compute_ref();
- myMailbox.put(tr);
- $display("@%0t:producer:%d!",$time,tr.data);
- end
- endtask
- task consumer();
- trasnsaction tr;
- repeat(10)
- begin
- #20
- // tr = new();
- if(myMailbox.num() > 0) begin
- myMailbox.get(tr);
- $display("@%0t:consumer:%d!",$time,tr.data);
- end
- else begin #2; end
- end
- endtask
- endprogram
- *********************************************
- do file
- ********************************************
- vlog -reportprogress 300 -work work transaction.sv
- vlog -reportprogress 300 -work work mailbox_assignment2.sv
- vsim work.mailbox_assignment2
- run -all
- ********************************************
- transaction.sv
- ********************************************
- class trasnsaction;
- rand bit [3:0] data;
- logic [7:0] reference;
- static bit [7:0] counter_value;
- function new;
- counter_value = 0;
- endfunction
- function [7:0] compute_ref;
- reference = counter_value+data;
- counter_value = counter_value+data;
- endfunction
- endclass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement