Jump to content

Recommended Posts

Posted

Hi,

I am currently migrating from C++ to system C. I have nested functions in C++ and i need to replicate same behaviour in system C. how can i do that. Below is the mimic of the behavior of the model which i want to achieve. 

void check(int a, int b )

{ int x=10;

  int y=20;

  add_m(a,x);

  sub_m(b,y);

}

 

void add_m(int a, int x)

{

 cout<<a+x<<endl;

}

void sub_m(int b,int y)

{

cout<<b-y<<endl;

}

 

till know what i did is :-

 

sc_module(check) {

sc_ctor(check){

    sc_thread(run);

  }

};

void check::run(int a, int b )

{ int x=10;

  int y=20;

  add_m(a,x);

  sub_m(b,y);

}

 

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

check chk("chk");

}

 

Now how to declare add_m and sub_m. Can anybody help me out???

Posted

Your code for the module isn't correct, it should be a derived class of sc_module. Unless of course you don't know that C++ is a case sensitive language... So something like this would be closer



class check : public sc_module {
public:
 
  SC_CTOR(check){
    sc_thread(run);
  }

  void add_m(int a, int x)  
  {
     cout<<a+x<<endl;
  }
  void sub_m(int b,int y)
  {
    cout<<b-y<<endl;
  }
};

void check::run() // no arguments allowed on a static process
{ 
  int x=10;
  int y=20;
  add_m(a,x);
  sub_m(b,y);
}

After that it depends how you want to get a and b into the module. You could declare ports for a and b.

Also it's not clear to me if you want your run() thread to run repeatedly, or just once. If you need it to run repeatedly, then you need a while loop. And a wait statement. And possibly sensitivity, or a time delay.

 

regards

Alan

 

P.S. The other thing that's not clear to me is why you are migrating to SystemC. If your code works in C++, why change it?

Posted

Thanks for your reply. 

 

Actually i want to build a wrapper of systemC around my C++ code as my hardware tool does not support directly C++. 

.

As i have said in earlier post, it is just a mimic of the behavior which i need, so for run() thread, i have while loop and wait statement.

Can you suggest me some material/book where i can get the basic concepts of SystemC ?

 

Thanks in advance.

 

Lokesh  

Posted

Hi,

I am currently migrating from C++ to system C. I have nested functions in C++ and i need to replicate same behaviour in system C. how can i do that. Below is the mimic of the behavior of the model which i want to achieve. 

void check(int a, int b )

{ int x=10;

  int y=20;

  add_m(a,x);

  sub_m(b,y);

}

 

void add_m(int a, int x)

{

 cout<<a+x<<endl;

}

void sub_m(int b,int y)

{

cout<<b-y<<endl;

}

 

till know what i did is :-

 

sc_module(check) {

sc_ctor(check){

    sc_thread(run);

  }

};

void check::run(int a, int b )

{ int x=10;

  int y=20;

  add_m(a,x);

  sub_m(b,y);

}

 

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

check chk("chk");

}

 

Now how to declare add_m and sub_m. Can anybody help me out???

 

Hello Sir,

First of all, please note that SystemC is just a C++ library. It is

NOT a language on its own. Please look up any available

documentation on C++ to get started.

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