1

I have a SystemC module that implements a hardware block, where an input is directed as-is to the output (think for example about a non-inverting buffer). Say I defined:

sc_in<bool>  ip;
sc_out<bool> op;

Can I forward the input to the output with just an sc_signal object (i.e., do not create a method with a sensitivity list for the input)?

sc_signal<bool> net;
....

// in the constructor:
ip(net);
op(net);
ysap
  • 7,723
  • 7
  • 59
  • 122

3 Answers3

3

You can, but you should not, because in general ports should be bound outside of a module. This is not enforced, but is a common coding convention. That way a user of your module always knows what to expect: "I should bind every port of module instance to some signal"

Binding ports hierarchically (i.e. input to sub-module input) is considered OK. Since top level module still holds a contract that it's ports must be bound to "outside" signals.

Consider your buffer for example:

template <typename T>
SC_MODULE(buffer) {
    sc_in <int>       ip{"ip"};
    sc_out <int>      op{"out"};

    SC_CTOR(buffer) { ip(tmp_sig); op(tmp_sig); }

private:
    sc_signal <int>   tmp_sig{"sig"};
};

Suppose I want to write a test-bench for this module:

int sc_main(int argc, char * argv[] ) {
    sc_signal<int> in_signal{"in_signal"};
    sc_signal<int> out_signal{"out_signal"};

    buffer buffer1{"buffer1"};

    // Error ! **ip** is already bound to tmp_sig!!
    buffer1.ip(in_signal);

    // How can I write to **in** ??
    buffer1.ip = 1; // Error! Writing to input port is not defined

    sc_start();
    return 0;
}

As you can see, buffer written this way is pretty useless!

Please note that connecting input port to output port directly, as Rahul suggested, is also a bad idea:

SC_MODULE(buffer) {
    sc_in <int>       ip{"ip"};
    sc_out <int>      op{"op"};

    SC_CTOR(buffer) { ip(op);  }
};


int sc_main(int argc, char * argv[] ) {
    sc_signal<int> in_signal{"in_signal"};
    sc_signal<int> out_signal{"out_signal"};
    buffer buffer1{"buffer1"};

    buffer1.ip(in_signal);

    // Error, **op** is already bound to in_signal !
    buffer1.op(out_signal);

    sc_start();
    return 0;
}
random
  • 3,868
  • 3
  • 22
  • 39
0

Yes you can , if you want you can connect op(in) directly.

Rahul Menon
  • 792
  • 7
  • 12
  • Thanks, Rahul. In my model that signal was connected to the inputs of submodules as well. I got an error saying that I exceeded the number of allowed binds for the port. I had to use a method with explicit assignment of the values upon input change in order to get rid of that error. – ysap Jun 24 '16 at 11:01
0

I think a method with a sensitivity list for the input is your best option for this situation.

DarrylLawson
  • 732
  • 3
  • 9