Jump to content

Recommended Posts

Posted
Quote

// All includes 
#include <systemc.h>

// Module defintion 
SC_MODULE (mux) {

    //inputs
    sc_in<bool> clk;
    sc_in<bool> reset;
    sc_in<bool> enable;
    sc_in<sc_uint<8> > in;

    //output ports
    sc_vector<sc_out<sc_uint<8> > > out;
     //sc_out<sc_uint<8> > out[8];


    //variable to hold # of o/p lines
     int lines = 8;

    void init(){
        out.init(lines);
        cout<<"@"<< sc_time_stamp() << "Initializing\n" <<endl;
    }
    void MUX_(){
        init();
        int value = in.read();
        if(value == -1){
            for(int i =0;i<lines;i++){
                out[i].write(1);
            }
        }else{
        out[value].write(1);
        cout<<"@"<< sc_time_stamp() << "Output =" << out[value].read()<<endl;
        }
    }

    //constructor
    SC_CTOR(mux) {

        SC_METHOD(MUX_);
            sensitive << clk.pos();
    }

};



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

    // Ports 

    sc_signal <bool> reset;
    sc_signal <bool> clock;
    sc_signal<sc_uint<8> > input;
    sc_vector<sc_signal<sc_uint<8>>> output;
    //sc_signal<sc_uint<8>> output[8];
    //instance and port binding
    mux bind("mux");

    bind.reset(reset);
    bind.clk(clock);
    bind.in(input);
    int i;
    for(i=0;i<8;i++){
        //bind.out[i](output[i]);
        //bind.out[i]( output[i] );
        //sc_assemble_vector( mux, &sub_module::out ).bind( output );
        }


    sc_start(0, SC_NS);
    // Open VCD file
    sc_trace_file *wf = sc_create_vcd_trace_file("mux");
    sc_trace(wf, bind.reset, "reset");
    sc_trace(wf, bind.clk, "clk");
    sc_trace(wf, bind.in, "input");
    for(int i =0;i<8;i++){
    sc_trace(wf, bind.out[i],"output");
    }
    

    for(int i = 0; i < 8; ++i){
        
        clock = 0;
        sc_start(1, SC_NS);
        clock = 1;
        sc_start(1, SC_NS);
        output[i].write(i);
       

    }
    //Test reset
    reset = 0;
    clock = 0;
    sc_start(1, SC_NS);
    reset = 1;
    clock = 1;
    sc_start(1, SC_NS);

    sc_close_vcd_trace_file(wf);
    return 0;
}

This is my code for a simple mux. I am not able to bind the vector of out with output signal vector. Both the methods dont seem to work. any suggstions?

      bind.out(output);
      
       sc_assemble_vector( mux, &sub_module::out ).bind( output );

 

Posted

You would do it like this:

int sc_main(int argc, char* argv[]) {
    // Ports 
    sc_signal <bool> reset;
    sc_signal <bool> clock;
    sc_signal<sc_uint<8> > input;
    sc_vector<sc_signal<sc_uint<8>>> output;
    //instance and port binding
    mux bind("mux");

    bind.reset(reset);
    bind.clk(clock);
    bind.in(input);
    bind.out(output);
    // Open VCD file
    sc_trace_file *wf = sc_create_vcd_trace_file("mux");
    ...
    ...

But you cannot call sc_start before opening the VCD database. sc_start initializes the VCD output so you cannot add things to trace.

When you write 'Both the methods dont seem to work' what is the problem you are seeing?

Posted
2 hours ago, Eyck said:

You would do it like this:


int sc_main(int argc, char* argv[]) {
    // Ports 
    sc_signal <bool> reset;
    sc_signal <bool> clock;
    sc_signal<sc_uint<8> > input;
    sc_vector<sc_signal<sc_uint<8>>> output;
    //instance and port binding
    mux bind("mux");

    bind.reset(reset);
    bind.clk(clock);
    bind.in(input);
    bind.out(output);
    // Open VCD file
    sc_trace_file *wf = sc_create_vcd_trace_file("mux");
    ...
    ...

But you cannot call sc_start before opening the VCD database. sc_start initializes the VCD output so you cannot add things to trace.

When you write 'Both the methods dont seem to work' what is the problem you are seeing?


 

 
Quote

 

Warning: (W807) sc_vector::bind called with empty range: target `mux.vector_0' (sc_vector) not initialised yet
In file: ../../../../src/sysc/utils/sc_vector.cpp:140

Error: (E109) complete binding failed: port not bound: port 'mux.port_2' (sc_in)
In file: ../../../../src/sysc/communication/sc_port.cpp:230

 

Thank you for your help. I tried binding it like you suggested and recieved the above error and a warning.
 

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


// Ports

 

sc_signal <bool> reset;

sc_signal <bool> clock;

sc_signal<sc_uint<8> > input;

sc_vector<sc_signal<sc_uint<8>>> output;

//sc_signal<sc_uint<8>> output[8];

//instance and port binding

mux bind("mux");

 

bind.reset(reset);

bind.clk(clock);

bind.in(input);

bind.out(output);

// Open VCD file

sc_trace_file *wf = sc_create_vcd_trace_file("mux");
Quote

When you write 'Both the methods dont seem to work' what is the problem you are seeing?

from the documentations, i tried two ways to bind, which I have mentioned.

 

Posted

As the error message says: you forgot to bind a port. Since the are no names given (which I always suggest to do) it is a generated name. Moreover the sc_vector is not initialized to a certain size.

So for your module do (C++11 assumed) it should look like:

// Module defintion 
SC_MODULE (mux) {

    //inputs
    sc_in<bool> clk{"clk"};
    sc_in<bool> reset{"reset"};
    sc_in<bool> enable{"enable"};
    sc_in<sc_uint<8> > in{"in"};

    //output ports
    sc_vector<sc_out<sc_uint<8> > > out{"out", 8};

and sc_main should look like

int sc_main(int argc, char* argv[]) {
    // Ports 
    sc_signal <bool> reset{"reset"};
    sc_signal <bool> clock{"clock"};
    sc_signal <bool> enable{"enable"};
    sc_signal<sc_uint<8> > input{"input"};
    sc_vector<sc_signal<sc_uint<8>>> output{"output", 8};
    //instance and port binding
    mux bind("mux");

    bind.reset(reset);
    bind.clk(clock);
    bind.enable(enable);
    bind.in(input);
    bind.out(output);
    // Open VCD file
    sc_trace_file *wf = sc_create_vcd_trace_file("mux");
    ...
    ...

 

  • 2 years later...
Posted
On 4/18/2020 at 10:17 PM, Eyck said:

As the error message says: you forgot to bind a port. Since the are no names given (which I always suggest to do) it is a generated name. Moreover the sc_vector is not initialized to a certain size.

So for your module do (C++11 assumed) it should look like:

// Module defintion 
SC_MODULE (mux) {

    //inputs
    sc_in<bool> clk{"clk"};
    sc_in<bool> reset{"reset"};
    sc_in<bool> enable{"enable"};
    sc_in<sc_uint<8> > in{"in"};

    //output ports
    sc_vector<sc_out<sc_uint<8> > > out{"out", 8};

and sc_main should look like

int sc_main(int argc, char* argv[]) {
    // Ports 
    sc_signal <bool> reset{"reset"};
    sc_signal <bool> clock{"clock"};
    sc_signal <bool> enable{"enable"};
    sc_signal<sc_uint<8> > input{"input"};
    sc_vector<sc_signal<sc_uint<8>>> output{"output", 8};
    //instance and port binding
    mux bind("mux");

    bind.reset(reset);
    bind.clk(clock);
    bind.enable(enable);
    bind.in(input);
    bind.out(output);
    // Open VCD file
    sc_trace_file *wf = sc_create_vcd_trace_file("mux");
    ...
    ...

 

Hi Eyck Sir,

To bind vector of output ports we need use for loop and at function present in sc_ vector class (.at(i) where i iterates vector size ).

This is my doubt please answer sir.

Posted

This is what sc_vector provides beyond a std::vector: it allows to bind a vector of ports to a vector of ports or a vector of signals.. Therefore you do not need an explicit loop. But this only works if the datatype of the ports/signals are the same.

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...