Last active
September 2, 2022 18:45
-
-
Save rahulbhadani/aa29c41337dfb5ab364299b6c513d5c4 to your computer and use it in GitHub Desktop.
Reader Writer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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