Rahul_111 Posted April 14, 2023 Report Posted April 14, 2023 Hi. I have taken this example from a book and tried to execute it,But i got few errors. I am not able to find a right solution for this one. Can someone please help me out with this. I have posted the code below Thank you. //main.cpp #include "systemc" #include "testbench.cpp" #include "adder.cpp" int sc_main(int argc, char *argv[]) { sc_core::sc_fifo<int> fifo(10); testbench tb("test"); tb.TB_a(fifo); tb.TB_b(fifo); tb.TB_OUT(fifo); adder ad("adder"); ad.a(fifo); ad.b(fifo); ad.out(fifo); sc_start(60, sc_core::SC_NS); return 0; } //testbench.cpp #include "systemc" SC_MODULE(testbench) { sc_core::sc_fifo_out<int> TB_a, TB_b; sc_core::sc_fifo_in<int> TB_OUT; void adder() // Testbench { wait(0, sc_core::SC_NS); TB_a = 0; TB_b = 0; wait(5, sc_core::SC_NS); TB_a = 5; TB_b = 0; wait(3, sc_core::SC_NS); TB_a = 5; TB_b = 10; wait(7, sc_core::SC_NS); TB_a = 5; TB_b = 1; } void output() { std::cout << sc_core::sc_time_stamp() << " : "; std::cout << "A= " << TB_a.read() << " B= " << TB_b.read(); std::cout << " OUT= " << TB_OUT << std::endl; } SC_CTOR(testbench) { SC_METHOD(output); sensitive << TB_OUT; SC_THREAD(adder); } }; //adder.cpp #include "systemc" SC_MODULE(adder) { sc_core::sc_fifo_in<int> a, b; sc_core::sc_fifo_out<int> out; void add_input() { out.write(a.read() + b.read()); } SC_CTOR(adder) { SC_METHOD(add_input); sensitive << a << b; } }; Quote
David Black Posted April 14, 2023 Report Posted April 14, 2023 What errors? You cannot just assign to sc_fifo. You need to use an appropriate write() method or read() to get the values back. Do you have an adequate training in C++. What book had this code? Quote
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.