ElliottCB Posted January 1, 2013 Report Share Posted January 1, 2013 Hey Everyone, I'm very new to SystemC so this might sound like a pretty trivial question, but I'm not really sure what specifically to look for in order to resolve this issue. I have a simple module with 2 input ports and an SC_THREAD method which is sensitive to these inputs. The function assigned to this SC_THREAD is : void test() { while(true) { wait(); cout<<"received"<<endl; } } In sc_main where I instantiate this module, I attach 2 signals (laneA and laneB) to its 2 input ports and execute the following : sc_start(); laneA.write(testA); laneB.write(testB); My assumption was that the output printed in test() would be called twice (once for each of the writes). Unfortunately, it is only printed once. I'm sure there must be some underlying misunderstanding here, but hopefully it is something trivial. Another clue that I've misunderstood something is that if I print the contents of both the ports within the while(true){} block, both of the values written in sc_main appear. So, what exactly am I missing about the overall flow of execution? Any help would be greatly apprecaited. Thanks in advance! Elliott Quote Link to comment Share on other sites More sharing options...
apfitch Posted January 1, 2013 Report Share Posted January 1, 2013 I'm a bit confused by your code - if you do the calls to write *after* returning from sc_start(), I wouldn't expect either write to work as once the simulation has returned from sc_start(), it is either finished or paused. Regarding your main question - the two events created by assigning signals in the same delta will only result in the process running once. Have a look at our (Doulos's - I work for Doulos) little tutorial here: http://www.doulos.com/knowhow/systemc/tutorial/ and see if that helps, regards Alan P.S. An interesting experiment would be to put dont_initialize() ; after the sensitivity of your SC_THREAD and see what happens. All SystemC processes run at time zero without being triggered - by adding dont_initialize(), you will be able to see if your writes are really what is causing the process to run. maehne 1 Quote Link to comment Share on other sites More sharing options...
dakupoto Posted January 2, 2013 Report Share Posted January 2, 2013 Hello Sir, May we have some more source code to look at ? The producer-consumer model is tricky to implement correctly, especially the synchronization part. Consumer 'consumes' only after producer 'produces' and producer does not 'produce' unless consumer has 'consumed'. Quote Link to comment Share on other sites More sharing options...
david.wcc Posted January 2, 2013 Report Share Posted January 2, 2013 Custom-Made IP Quote Link to comment Share on other sites More sharing options...
ElliottCB Posted January 2, 2013 Author Report Share Posted January 2, 2013 Thanks everyone for the quick responses. I believe my confusion arises from what should be done in sc_main() in regards to providing stimulus for a module. Currently my sc_main() simply consists of instantiating a module and attacing sc_signals to each of its ports. My hope was that I could write to these ports to see how the module reacts. How I (incorrectly) did this was shown in my initial post. Is it a requirement to create a separate module which creates and issues stimulus to the my module being tested as shown in the tutorial that Alan posted, or is there a way to provide stimulus to my module directly within sc_main()? Again, very sorry for these uninformed questions. Moving from C++ to SystemC has been a rather large paradigm shift Thanks for everyone's help. Quote Link to comment Share on other sites More sharing options...
apfitch Posted January 2, 2013 Report Share Posted January 2, 2013 You could provide stimulus in sc_main, but you need to call sc_start for a limited amount of time, e.g. sc_start(1, SC_NS); // assign some signals sc_start(1, SC_NS); and so on. At least I think that will work - I always write a separate stimulus module :-) Alan maehne 1 Quote Link to comment Share on other sites More sharing options...
david.wcc Posted January 3, 2013 Report Share Posted January 3, 2013 Hi : ElliottCB : You can refer and modify the following example as your template, actually it was modified by using SystemC example (pipe project as i remember). Due to the version of SystemC, some descriptions indicated in old documents can not work properly at this moment. That will be a major problem for you as a beginner. It works after referring many documents and examples about SystemC. Good Luck to make it happen #define DISPLAY_H // display.h #include "systemc.h" class display : public sc_module { public: sc_in<bool> inPort0; sc_in<bool> inPort1; sc_in<bool> cin; // input port 1 sc_in<bool> sum; sc_in<bool> clk; // clock void print_result(); // method to display input port values //Constructor SC_CTOR( display ) { SC_METHOD( print_result ); // declare print_result as SC_METHOD and dont_initialize(); sensitive << clk.pos(); // make it sensitive to positive clock edge } }; #endif #include "systemc.h" class driver : public sc_module{ public: sc_out<bool> outPort_a; sc_out<bool> outPort_b; // output port sc_in<bool> clk; void prc_driver(); // Constructor SC_CTOR(driver) { SC_METHOD(prc_driver); // Method process to print data dont_initialize(); sensitive << clk.pos(); //make it sensitive to positive clock edge } }; #ifndef HALFADDER_H #define HALFADDER_H #include "systemc.h" class halfadder : public sc_module{ public: sc_in<bool> inPort_0,inPort_1; //input 1 sc_out<bool> sum,carry; //output 1 sc_in<bool> clk; //halfadder():sc void prc_half_adder(); //method implementing functionality //Counstructor SC_CTOR(halfadder) { SC_METHOD(prc_half_adder); //Declare addsub as SC_METHOD and //sensitive << a<<b ; //make it sensitive to positive clock edge dont_initialize(); sensitive << clk.pos(); //make it sensitive to positive clock edge } }; #endif #include "waveform.h" #include "halfadder.h" #include "monitor.h" int sc_main(int argc, char* argv[]) { sc_signal<bool> in1; // initial signals for the system sc_signal<bool> in2; sc_signal<bool> t_cin; sc_signal<bool> t_sum; sc_signal<bool> clk; WaveForm wave("waveforms"); //instance of `waveform' module wave(in1,in2,clk); HalfAdder h1("halfadder"); //instance of `halfadder' module h1.inPort_0(in1); h1.inPort_1(in2); h1.carry(t_cin); h1.sum(t_sum); h1.clk(clk); Monitor m("monitor"); //instance of `monitor' module m(in1,in2,t_cin,t_sum,clk); //Positional port binding cout<<"start waveform :"<<endl; sc_start(0, SC_NS); //Initialize simulation for(int i = 0; i < 50; i++){ clk.write(1); sc_start( 10, SC_NS ); clk.write(0); sc_start( 10, SC_NS ); } system("Pause"); return 0; } Diagram of Example Quote Link to comment Share on other sites More sharing options...
ravi_stylish Posted January 3, 2013 Report Share Posted January 3, 2013 Hi Elliott, I am not able to understand what exactly ur doubt is? It would be better if u display ur code in the post and then ask questions so that i can help u. With Regards, Ravi. Quote Link to comment Share on other sites More sharing options...
ElliottCB Posted January 3, 2013 Author Report Share Posted January 3, 2013 Thanks everyone for the replies. I ended up following Alan's tutorial and simply made a separate module which generates stimulus as having such a module seemed like an inevitability. Everything is working as I expect now. Thanks again! 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.