Jump to content

how to connect modules inside another module


Recommended Posts

i have a module called dispenser, which is my top hierarchy module and it has tow sub modules inside (module1 and module2). how can i connect them inside my main module ?

i have tried something like this and it is failing. know that it is possible to do it using Pointers, but i am trying in this way. how can i do it? 

SC_MODULE(dispenser){

sc_in<bool> input1; 

sc_in<bool>input2; 

sc_out<bool>out1;

sc_signal<bool> s1;

 

SC_CTOR(dispenser){

 

module1 m1("module1");

m1.in1(input1);

m1.in2(input2)

m1.outA(s1);

 

module2 m2 ("module2");

m2.input1(input1);

m2.input2(s1);

m2.out(out1);

      }

 

}

Link to post
Share on other sites

You declare your modules as local variables in the constructor. Leaving the constructor they are destroyed. Something like this should work:

SC_MODULE(dispenser){
    sc_in<bool> input1; 
    sc_in<bool>input2; 
    sc_out<bool>out1;
    sc_signal<bool> s1;
    module1 m1;
    module2 m2;

    SC_CTOR(dispenser): input1("input1"), input2("input2"), out1("out1"), s1("s1"), m1("module1"), m2("module2") {
      m1.in1(input1);
      m1.in2(input2)
      m1.outA(s1);
      m2.input1(input1);
      m2.input2(s1);
      m2.out(out1);
    }
};

I highly advice to name all signals and ports. If you start debugging this will ease you live. If you are using newer versions of SystemC you can write it like:

SC_MODULE(dispenser){
    sc_in<bool> input1; 
    sc_in<bool>input2; 
    sc_out<bool>out1;
    sc_signal<bool> s1;
    module1 m1;
    module2 m2;

    SC_CTOR(dispenser): SC_NAMED(input1), SC_NAMED(input2), SC_NAMED(out1), SC_NAMED(s1), SC_NAMED(m1), SC_NAMED(m2) {
      m1.in1(input1);
      m1.in2(input2)
      m1.outA(s1);
      m2.input1(input1);
      m2.input2(s1);
      m2.out(out1);
    }
};

If you compile using C++11 you can also doing it like this:

SC_MODULE(dispenser){
    sc_in<bool> input1{"input1"}; 
    sc_in<bool>input2{"input2"}; 
    sc_out<bool>out1{"out1"};
    sc_signal<bool> s1{"s1"};
    module1 m1{"m1"};
    module2 m2{"m2"};

    SC_CTOR(dispenser){
      m1.in1(input1);
      m1.in2(input2)
      m1.outA(s1);
      m2.input1(input1);
      m2.input2(s1);
      m2.out(out1);
    }
};

 

Link to post
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...