Jump to content

get interface failed : port is not bound


TRAVIS

Recommended Posts

Hi I have a problem about using systemc.

I designed a simple and module, and it compiled well. 

But if I execute the file, it shows me the below error.

//////////////////////////////////////////////////////////////////////////////////////
        SystemC 2.3.3-Accellera --- Dec  7 2021 18:09:54
        Copyright (c) 1996-2018 by all Contributors,
        ALL RIGHTS RESERVED
0 sa :
Error: (E112) get interface failed: port is not bound: port 'and_inst.port_0' (sc_in)
In file: ../../../src/sysc/communication/sc_port.cpp:235

//////////////////////////////////////////////////////////////////////////////////////

 

The full source code is below. How can I fix the code?

 

//////////////////////////////////////////////////////////////////////////////////////

#include <systemc.h>


SC_MODULE(and2){
    sc_in< bool > a;
    sc_in< bool > b;
    sc_out< bool > f;

    void func(){
        f.write(a.read() & b.read() );
    }

    SC_CTOR(and2){
        SC_METHOD(func);
        sensitive << a << b; 
        std::cout << sc_time_stamp() << "a : " << a.read() << "b : " << b.read()
             << "f : " << f.read() << endl;
    }
};


int sc_main( int argc, char *argv[]){
    sc_signal< bool > a;
    sc_signal< bool > b;
    sc_signal< bool > f;

    and2 and_inst("and_inst");
    and_inst.a(a);
    and_inst.b(b);
    and_inst.f(f);

    a = 1;
    b = 0;

    sc_clock clk("clk",10,SC_NS,0.5,0.0,SC_NS,true);

 
    sc_start(50,SC_NS);

    b = 1;
    sc_start(50,SC_NS);
    return 0;
}

Link to comment
Share on other sites

REASON ->

When the code run, the first thing run is constructor and at the point your port's is not bound. Move that piece of code to end_of_elaboration() or start_of_simulation().

Then, it will work fine.

SUGGESTION =>

Use (->) operator instead of (.) operator like (a->read())

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include "systemc.h"
#include <bits/stdc++.h>
using namespace sc_core;
using namespace sc_dt;

SC_MODULE(and2){
    sc_in< bool > a;
    sc_in< bool > b;
    sc_out< bool > f;

    void func(){
        f.write(a->read() & b->read() );
        std::cout << sc_time_stamp() << "a : " << a->read() << "b : " << b.read() << "f : " << f->read() << endl;    
    }

    SC_CTOR(and2){
        SC_METHOD(func);
        sensitive << a << b;
          dont_initialize();
    }
};

int sc_main( int argc, char *argv[]){
    sc_signal< bool > a;
    sc_signal< bool > b;
    sc_signal< bool > f;

    and2 and_inst("and_inst");
    and_inst.a(a);
    and_inst.b(b);
    and_inst.f(f);

    a = 1;
    b = 0;

    sc_clock clk("clk",10,SC_NS,0.5,0,SC_NS,true);

 
    sc_start(50,SC_NS);

    b = 1;
    sc_start(50,SC_NS);
  
    b = 0;
    sc_start(50,SC_NS);
    return 0;
}

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...