//---------------------------------------------------------------------- // Copyright 2008 Mentor Graphics Corporation // Dave Rich // // Licensed under the Apache License, Version 2.0 (the // "License"); you may not use this file except in // compliance with the License. You may obtain a copy of // the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in // writing, software distributed under the License is // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR // CONDITIONS OF ANY KIND, either express or implied. See // the License for the specific language governing // permissions and limitations under the License. //---------------------------------------------------------------------- package probe_pkg; class probe #(type T=int); protected T shadow; local event wr_e; local process p; function new(ref T sig); fork start(sig); join_none endfunction : new task start(ref T sig); p = process::self(); fork forever @sig shadow = sig; forever @wr_e sig = shadow; join endtask : start virtual function T read(); return shadow; endfunction : read virtual function void write(T sig); shadow = sig; ->wr_e; endfunction : write virtual function void stop; p.kill(); endfunction : stop endclass : probe endpackage : probe_pkg module top; reg a; byte b; import probe_pkg::*; class env; probe #(reg) m_x; probe #(byte) m_y; function new(probe #(reg) x,probe #(byte) y); m_x = x; m_y = y; endfunction task run; #1; m_x.write('z); m_y.write(1); #1 $display("%m m_x %d m_y %d",m_x.read(),m_y.read()); #1; a = 0; b = 2; #1 $display("%m m_x %d m_y %d",m_x.read(),m_y.read()); m_x.stop(); m_y.stop(); m_x.write(1); m_y.write(3); #1 $display("%m m_x %d m_y %d",m_x.read(),m_y.read()); endtask : run endclass : env probe #(reg) p_a; probe #(byte) p_b; env e; initial begin p_a = new(a); p_b = new(b); e = new(p_a,p_b); e.run(); #1 $finish; end initial $monitor("mon: %m a %d b %d", a,b); endmodule : top