Jump to content

fifo example


veeresh k

Recommended Posts

Hi.

I have taken this example from a book and tried to execute it,But i got few errors.

I have compared this code with std 2011 and made changes according to that like using namspace sc_core .

I am not able to find a right solution for this one.

Can someone plese help me out with this.I have posted the code below along with the error,check it out.

Thank you.

 

 

//error//////////

In file included from testbench.cpp:6:0:
head1.h: In member function 'void www::woperation()':
head1.h:16:9: error: 'class sc_core::sc_port<sc_core::sc_fifo_out_if<int> >' has no member named 'write'
In file included from testbench.cpp:7:0:
head2.h: In member function 'void rrr::roperation()':
head2.h:17:9: error: 'class sc_core::sc_port<sc_core::sc_fifo_in_if<int> >' has no member named 'read'

 

 

 

////////code/////

#include<systemc.h>
#include"Head1.h"
#include"Head2.h"

int sc_main(int argc, char* argv[])
{

    sc_fifo<int> fifo(10);

    writer w("writer");
    reader r("reader");
    w.out(fifo);
    r.in(fifo);

    sc_start(-1);

    return 0;

}

//header1
#include<systemc.h>
SC_MODULE(reader) {

    sc_port<sc_fifo_in_if<int> > in;

    void roperation()
    {

        int val;

        while (true)
        {
            wait(10, SC_NS)
                for (int i = 0; i <= 15; i++)
                {

                    in.read(val);

                    cout << val << endl;

                }
        }

        cout << "Availaible : " << in.num availaible() << endl;

    }

   SC_CTOR(writer)
    {
        SC_THREAD(woperation);

    }

};

 


//header2
#include<systemc.h>

SC_MODULE(writer)
{
    sc_port<sc_fifo_out_if<int> > out;

    void woperation()
    {

        int val = 0;
        while (true)
        {
            wait(10, SC_NS);
            for (int i = 0; i <= 20; i++)
            {
                out.write(val++);

            }
        }

    }

    SC_CTOR(writer)
    {
        SC_THREAD(woperation);

    }
};

Link to comment
Share on other sites

Hello @veeresh k,

There are multiple issues in the sample code provided by you.

Here are the heavily modified version:

// main.cpp
#include<systemc>    //< Notice not systemc.h
#include"head1.h"
#include"head2.h"

int sc_main(int argc, char* argv[])
{

  sc_core::sc_fifo<int> fifo(10); //< sc_core namespace specifier

  writer w("writer");
  reader r("reader");
  w.out(fifo);
  r.in(fifo);

  sc_start(1000, sc_core::SC_NS); //< Run simulation for a limited time since no stopping condition are provided upfront. Also time is also specified in sc_core namespace.

  return 0;

}
//head1.h
// Notice the HEADER GUARD
#ifndef HEAD1_H_
#define HEAD1_H_

// Changed the header file to systemc instead of systemc.h
#include<systemc>

SC_MODULE(reader) {
  // sc_fifo_in_if is a abstract class from which you cannot create an object.
  // sc_fifo_in is derived from the above class which actually implements the read method.
  sc_core::sc_fifo_in<int> in; 

  void roperation()
  {

    int val;

    while (true)
    {
      wait(10, sc_core::SC_NS); // Time unit is defined in sc_core namespace.
      for (int i = 0; i <= 15; i++)
      {

        in.read(val);

        std::cout << val << std::endl; //< when using the systemc header you need to specify the std namespace.
        // Or you can use the statement after including all the header files:
        // using namespace std

      }
    }

    std::cout << "Availaible : " << in.num_available() << std::endl; //< Instead of num available it is num_available
    //< when using the systemc header you need to specify the std namespace.
    // Or you can use the statement after including all the header files:
    // using namespace std

  }

  SC_CTOR(reader) //< Your code mentions here writer the constructor name should be same as the class name.
  {
    SC_THREAD(roperation); //< Your code mentions woperation

  }

};

#endif // HEAD1_H_

 

//head2.h
// Refer the head1.h for similar details
#ifndef HEAD2_H_
#define HEAD2_H_


#include<systemc>

SC_MODULE(writer)
{
  // Refer the head1.h for similar details
  sc_core::sc_fifo_out<int> out;

  void woperation()
  {

    int val = 0;
    while (true)
    {
      wait(10, sc_core::SC_NS);
      for (int i = 0; i <= 20; i++)
      {
        out.write(val++);

      }
    }

  }

  SC_CTOR(writer)
  {
    SC_THREAD(woperation);

  }
};
#endif // HEAD2_H_

Here is a minimal makefile for building the example:

CC=gcc
CXX=g++

CXX_FLAGS= -g3 -Wall -c

all: main.exe

main.exe: main.o
  ${CXX} $< -o $@ -L${SYSTEMC_HOME}/lib-linux64 -L${SYSTEMC_HOME}/lib -lsystemc

main.o: main.cpp head1.h head2.h
  ${CXX} ${CXX_FLAGS} -I${SYSTEMC_HOME}/include -o $@ $<

clean:
  rm -rf main.o main.exe

Note:

  • For reference of the sc_fifo_in/out_if classes see here.

For more details you can also refer to the SystemC LRM.

Hope it helps.

Regards,
Ameya Vikram Singh

Link to comment
Share on other sites

Hey ameya,

Thanks for taking out your time n helping me out by modifying code. ?

By seeing the developed code of yours,i can understand now that they had clearly mentioned the error while i was executing,but i dint get it.

And one more thing,I am trying to trace out the wave for the input and the output.

I have tried for different ways,but not getting the desired results.

One of the way was,i created 2 same signals with diff. name in testbench file and tried to trace ,but i was not successful in doing so.

Any suggestions to do? 

Thank you.:-)

 

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