Skip to content

Instantly share code, notes, and snippets.

@rahulbhadani
Last active September 2, 2022 18:45
Show Gist options
  • Save rahulbhadani/aa29c41337dfb5ab364299b6c513d5c4 to your computer and use it in GitHub Desktop.
Save rahulbhadani/aa29c41337dfb5ab364299b6c513d5c4 to your computer and use it in GitHub Desktop.
Reader Writer
#ifndef READWRITE_H
#define READWRITE_H
#include <systemc>
using namespace std;
using namespace sc_core;
SC_MODULE(Read)
{
/*Declare i/o ports*/
sc_in<bool> clk;
sc_in<unsigned int> in;
unsigned int input;
void reader()
{
while(1)
{
/*Sync with an external Clock*/
wait();
input = in.read();
cout<<name()<<" Read"<<input << endl;
}
}
/*Constructor*/
SC_CTOR(Read):input(0)
{
SC_CTHREAD(reader, clk.pos());
/*Declare/assign thread*/
}
/*Destructor*/
~Read(){}
};
SC_MODULE(Write)
{
sc_in<bool> clk;
sc_out<unsigned int> out;
unsigned int output;
/*Production op thread*/
void writer()
{
while(1)
{
/*Sync with an external Clock*/
wait();
output = ((unsigned int)(10.0*drand48()));
out.write(output);
cout<< name () <<" Wrote "<<output<<endl;
}
}
/*Constructor*/
SC_CTOR(Write):output(0)
{
SC_CTHREAD(writer, clk.pos()); /*declare/assign thread*/
}
/*Destructor*/
~Write()
{
}
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment