# avt_tlm2channel example

This example uses an avt_notify2analysis and an avt_tlm2channel adapter to connect a vmm_notifier_consumer and an ovm_passive_producer. The ovm_passive_producer gets notifier through avt_notify2analysis, then puts response on avt_tlm2channel back to consumer

../../../../examples/01_adapters/17_tlm2channel_passive_producer.sv

    `define OVM_ON_TOP

    `include "ovm_vmm_pkg.sv"

    `include "ovm_apb_rw.sv"
    `include "vmm_apb_rw.sv"
    `include "apb_rw_converters.sv"

    `include "ovm_producers.sv"
    `include "vmm_consumers.sv"
    `include "apb_scoreboard.sv"

    class my_apb_scoreboard extends apb_scoreboard;
      function new(string name = "my_apb_scoreboard",
                   ovm_component parent=null,
                   vmm_channel_typed #(vmm_apb_rw) vmm_fifo = null);
         super.new(name, parent, vmm_fifo);
      endfunction : new

      virtual task run();
        ovm_apb_rw o, v2o=new();
        vmm_apb_rw v;

        forever begin
          ovm_fifo.get(o);
          vmm_fifo.get(v);

          v2o = apb_rw_convert_vmm2ovm::convert(v);

          if(!o.compare(v2o)) begin
            ovm_report_error("mismatch",
                             {"OVM:\n", o.convert2string(),"\n",
                              "VMM:\n", v.psdisplay()});
            m_mismatches++;
          end
          else begin
            ovm_report_info("match",o.convert2string());
            m_matches++;
          end
        end
      endtask
    endclass

    class env extends ovm_component;

      `ovm_component_utils(env)

      ovm_passive_producer #(ovm_apb_rw)      o_prod;
      vmm_notifier_consumer #(vmm_apb_rw)      v_cons;
      apb_tlm2channel                 the_adapter0;
      apb_notify2analysis		  the_adapter1;
      my_apb_scoreboard                  comp;

      bit PASS  = 0;

      function new (string name="env",ovm_component parent=null);
        super.new(name,parent);
      endfunction

      virtual function void build();
        o_prod       = new("o_prod", this);
        v_cons       = new("v_cons",0);
        the_adapter0 = new("the_adapter0",this,v_cons.in_chan);
        the_adapter1 = new("the_adapter1",this,v_cons.notify, v_cons.GENERATED);
        comp         = new("Comparator", this, v_cons.out_chan);
      endfunction

      virtual function void connect();
        the_adapter0.blocking_get_peek_port.connect(o_prod.get_peek_export);
        the_adapter0.request_ap.connect(comp.ovm_in);
        the_adapter1.analysis_port.connect(o_prod.analysis_export);

      endfunction

      virtual task run();
        v_cons.start_xactor();
        @(v_cons.num_insts == 5);
        ovm_top.stop_request();
      endtask // run

      virtual function void check();
        if(comp.m_matches == 5 && comp.m_mismatches == 0)
          PASS  = 1;
      endfunction // check

      virtual function void report();
        `ovm_info("TEST_RESULT",((PASS==1)?"PASSED":"FAILED"), OVM_MEDIUM)
      endfunction // report

    endclass

    module example_17_tlm2channel_passive_producer;

      env e = new;

      initial run_test();

    endmodule