c++systemc

Error: (E112) get interface failed: port is not bound - SystemC


My goal is to create an ALU that adds and subtracts with a barrelshifter

alu.h

#include "systemc.h"       

SC_MODULE(alu){
sc_in<bool> op;
sc_in<sc_int<8> > a;
sc_inout<sc_int<8> > b;
sc_out<sc_int<8> > output;

void alu_method();  

SC_CTOR(alu) {
    SC_METHOD(alu_method);
    dont_initialize();
    sensitive << a,b,op;
    }
};

alu.cpp

#include "alu.h"

void ALU::alu_method(){
if (op.read() == 0){
    //substract
    out.write(in.read() - in_bs.read());
}
else{
    //add
    out.write(in.read() + in_bs.read());
    }
}

barrelshift.h

    #include <systemc.h>       
    void make_barrel();

    SC_MODULE(barrel_shift) {
    sc_in<bool> clk;
    sc_in<bool> enable;
    sc_in<bool> left_right;
    sc_in<sc_uint<3> > shift_amt;
    sc_in<sc_int<8> > din;
    sc_inout<sc_int<8> > dout;

void barrel_method();   

    SC_CTOR(barrel_shift) {

    SC_METHOD(barrel_method);
dont_initialize();
    sensitive << clk.pos(); //edge sensitive
    }

};

barrelshift.cpp

    #include "barrelshift.h"

    void barrel_shift :: barrel_method(){

if(enable.read() == 1){
    if(left_right.read() == 0){ //shift left
                dout.write(din.read() << shift_amt.read()); 

    }else if(left_right.read() == 1){ // right shift
                dout.write(din.read() >> shift_amt.read());
    }
}
else 
        cout << "Not enabled "<<endl;
        dout <= din;    
}

sc_main.cpp

    #include <systemc.h>
    #include "alu.h"
    #include "barrelshift.h"

    int sc_main(int argc, char* argv[]){
sc_trace_file *tf; 

//Signals
sc_signal <bool> enable, op, l_r;
sc_signal <sc_int<8> > a, output,b, bin;
sc_signal < sc_uint<3> > shift_amt;

//Clock
sc_clock clk("clk",10,SC_PS,0.5);

alu myALU("myALU");
barrel_shift myShifter("myShifter");

myALU.a(a);
myALU.b(b);
myALU.output(output);
myALU.op(op);

myShifter.clk(clk);
myShifter.din(bin);
myShifter.enable(enable);
myShifter.left_right(l_r);
myShifter.shift_amt(shift_amt);
myShifter.dout(b);

tf = sc_create_vcd_trace_file("trace_file");
sc_trace(tf, clk, "clk");
sc_trace(tf, a, "a");
sc_trace(tf, bin, "BarrelShifter In");
sc_trace(tf, op, "op");
sc_trace(tf, shift_amt, "shift_amt");
sc_trace(tf, l_r, "left_right");
sc_trace(tf, enable, "enable");
sc_trace(tf, b, "b");
sc_trace(tf, output, "output");



sc_close_vcd_trace_file(tf);

cout << "The result from the ALU is: " << output.read();
}

There are no errors when I build it. But whenever I try to execute it, I get the following error:

Error: (E112) get interface failed: port is not bound: port 'myALU.port_0' (sc_in) In file: sc_port.cpp:231

What is causing this and how can I fix it?


Solution

  • The error message

    Error: (E112) get interface failed: port is not bound: port 'myALU.port_0' (sc_in)
    

    means that the port myALU.port_0 is not bound to a signal. But which port in the alu module corresponds to port_0?

    It is good practice to name all ports and signals -- regardless of the type of hardware description language you are using -- to make errors like this easier to diagnose.

    Name the ports in the alu constructor:

    SC_CTOR(alu) :
        op("op"),
        a("a"),
        b("b"),
        output("output")
    {
        // ...
    

    I couldn't reproduce the error you were seeing. I saw this error (after providing names for all ports and signals):

    Error: (E115) sc_signal<T> cannot have more than one driver:
     signal `signal_5' (sc_signal)
     first driver `myShifter.dout'  (sc_inout)
     second driver `myALU.b' (sc_inout)
    

    I noticed some other problems in your code: