Created
September 5, 2022 20:29
-
-
Save rahulbhadani/28c847bc8155ac97eafcb38aa156d9ce to your computer and use it in GitHub Desktop.
Inverter logic in SystemC
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
#include<systemc> | |
#include<cstdlib> | |
#include<cstring> | |
using namespace std; | |
using namespace sc_core; | |
SC_MODULE(inverter) | |
{ | |
sc_in<bool> in; | |
sc_out<bool> out; | |
void invert() | |
{ | |
while(1) | |
{ | |
wait(); | |
out.write(! in.read() ); | |
} | |
} | |
SC_CTOR(inverter) | |
{ | |
SC_THREAD(invert); | |
sensitive << in; // sensitive to changes in the input | |
} | |
~inverter(){} | |
}; | |
int sc_main(int argc, char **argv) | |
{ | |
sc_signal<bool> signal_in; | |
sc_signal<bool> signal_out; | |
sc_trace_file *fp; | |
inverter I("1-bit-inverter"); | |
fp = sc_create_vcd_trace_file("trace_inverter"); | |
fp->set_time_unit(1.0, SC_NS); | |
I.in(signal_in); | |
I.out(signal_out); | |
bool input_sets[] = {true, false, false, true, true, true, false, true, false, false, false, true, true, false, false, true, true, false}; | |
int length = *(&input_sets + 1) - input_sets; | |
sc_trace(fp, signal_in, "inv_in"); | |
sc_trace(fp, signal_out, "inv_out"); | |
for(int i = 0; i < length; ++i) | |
{ | |
signal_in.write(input_sets[i]); | |
sc_start(2.0, SC_NS); | |
//Print time to console and display signal value | |
cout << sc_time_stamp().to_seconds() << " Input "<<signal_in.read()<<" Output "<< signal_out.read() << endl; | |
} | |
sc_stop(); | |
sc_close_vcd_trace_file(fp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment