Jump to content

Error in sc_fifo example


Rahul_111

Recommended Posts

  •  

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;
  }
};

 

Link to comment
Share on other sites

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