killer89 Posted May 26, 2014 Report Share Posted May 26, 2014 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??? Quote Link to comment Share on other sites More sharing options...
apfitch Posted May 26, 2014 Report Share Posted May 26, 2014 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? Quote Link to comment Share on other sites More sharing options...
killer89 Posted May 26, 2014 Author Report Share Posted May 26, 2014 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 Quote Link to comment Share on other sites More sharing options...
dakupoto Posted May 27, 2014 Report Share Posted May 27, 2014 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. Quote Link to comment Share on other sites More sharing options...
apfitch Posted May 27, 2014 Report Share Posted May 27, 2014 Hi Lokesh, there's a basic tutorial on the Doulos website, http://www.doulos.com/knowhow/systemc Probably the best book is "SystemC from the Ground Up" by David Black et al regards Alan killer89 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.