ankit Posted March 11, 2014 Report Share Posted March 11, 2014 1) I will be thankful if i could get some support to resolve error in the attachment as i have tried to implement a pre-defined example. 2) for what time wait() statement is used in method tb_input 3) please guide me a bit about hierarchy ( module instantiation ) syntax part 4) how to view output in waveform #include "systemc.h" SC_MODULE (d_ff) { sc_in<bool> d; sc_in<bool> q; bool clk; SC_CTOR (d_ff) { SC_METHOD(flop); sensitive<<clk.pos(); } void flop() { q.write(d.read()); } }; // hierarchy SC_MODULE (d_ff_4) { sc_in<bool> d; sc_out<bool> q3; sc_signal<bool> q0,q1,q2; bool clk; d_ff d1,d2,d3,d4; SC_CTOR(d_ff_4) : d1("d1"), d2("d2"),d3("d3"),d4("d4") { d1.d(d); d1.clk(clk); d1.q(q0); d2.d(q0); d2.clk(clk); d2.q(q1); d3.d(q1); d3.clk(clk); d3.q(q2); d4.d(q2); d4.clk(clk); d4.q(q3); } }; //test bench SC_MODULE(tb) { sc_out<bool> d; bool clk; void tb_input() { d.write(false); wait(); d.write(true); wait(); sc_stop(); } SC_CTOR(tb) { SC_THREAD(tb_input); sensitive<<clk.pos(); } }; //top int sc_main(int argc, char* argv[]) { sc_clock testclk("testclock", 10, SC_NS,0.5); d_ff d_111("d_111"); d_mast.flop(); d_ff_4 d_112("d_112"); tb t1("t1"); t1.tb_input(); sc_start(); return (0); } Quote Link to comment Share on other sites More sharing options...
apfitch Posted March 11, 2014 Report Share Posted March 11, 2014 It would help to post the error message. However the error that stands out is q in your dff should be an output (sc_out<bool>), not an input, The wait() in tb_input waits until the rising edge of clk, which is every 10 ns. I'm not sure what you're asking about hierarchy. Have you seen this tutorial? http://www.doulos.com/knowhow/systemc/tutorial/ regards Alan Quote Link to comment Share on other sites More sharing options...
apfitch Posted March 11, 2014 Report Share Posted March 11, 2014 And the clock in your dff model should be declared sc_in<boo> clk; Alan Quote Link to comment Share on other sites More sharing options...
susharmas Posted July 14, 2016 Report Share Posted July 14, 2016 Hello Sir, Can you please help me to find out the error in this small code. I am newbie to the SystemC and not able to debug it. I am designing the D flip flop in SystemC. Here below is the code and error: ////////////////////////////////////////////////////////////////////// //dff.cpp ///////////////////////////////////////////////////////////////////// #include "systemc.h" SC_MODULE(dff){ sc_in<bool> din; sc_in<bool> clk; sc_out<bool> out; void func(); SC_CTOR(dff){ SC_THREAD(func); sensitive_pos<<clk; } }; void dff::func() { out.write(din.read()); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// AND BELOW IS THE TB FILE: dff_main.cpp /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include "systemc.h" #include "dff.cpp" int sc_main(int argc, char* argv[]){ sc_signal<bool> din; sc_signal<bool> out; sc_clock clk("clk", 10, 0.5, 0, true); dff inst("inst"); inst.din(din); inst.clk(clk); inst.out(out); sc_start(100, SC_NS); sc_trace_file *tf = sc_create_vcd_trace_file("inst"); sc_trace(tf, din, "din"); sc_trace(tf, clk, "clk"); sc_trace(tf, out, "out"); din.write(0); wait(5, SC_NS); din.write(1); wait(10, SC_NS); din.write(0); wait(15, SC_NS); din.write(1); wait(10, SC_NS); din.write(0); wait(20, SC_NS); din.write(1); wait(10, SC_NS); din.write(0); wait(8, SC_NS); sc_stop(); return (0); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// And the error is: ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// \dff.dir/objects.a(dff.cpp.obj):dff.cpp:(.text+0x0): multiple definition of `dff::func()' CMakeFiles\dff.dir/objects.a(dff_main.cpp.obj):dff_main.cpp:(.text+0x0): first defined here collect2.exe: error: ld returned 1 exit status Please help me how to remove this error. Regards Sunil S. Quote Link to comment Share on other sites More sharing options...
apfitch Posted July 14, 2016 Report Share Posted July 14, 2016 You need to separate your dff.cpp into two files, dff.h and dff.cpp. Put the class in dff.h, and put the function func() in dff.cpp. Change the main to include dff.h instead of dff.cpp, Alan 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.