//Include SystemC library definitions
#include "systemc.h"
// NOT Gate Module
SC_MODULE(not_gate){
sc_in aIn; // Input of type bool
sc_out aOut; // Output of type bool
// Process(Funtionality of Invrter)
void not_gate_p(){
aOut = !aIn;
}
// Constructor for NOT Gate module
SC_CTOR(not_gate){
SC_METHOD(not_gate_p);
// Process sensitivity
sensitive << aIn;
}
};
// NOT Gate testbench
int sc_main(int argc, char* argv[]){
// testbench output signal
sc_signal aOut;
// testbench input as clock
sc_clock aIn("aIn", 5, SC_NS);
// Trace file pointer to store waveforms in VCD
sc_trace_file *tf;
// Module instantiation and name based connection
not_gate n1("not_gate_n1");
n1.aIn(aIn);
n1.aOut(aOut);
// Trace file name and timescale unit
tf = sc_create_vcd_trace_file("not_gate");
tf->set_time_unit(1, SC_NS);
// Trace file signals
sc_trace(tf, aIn, "aIn");
sc_trace(tf, aOut, "aOut");
//Start and run simulation for 100ns
sc_start(100, SC_NS);
// Close trace file
sc_close_vcd_trace_file(tf);
// Display end simulation time
cout << "Finished at time " << sc_time_stamp() << endl;
return 0;
}
Tuesday, 10 November 2015
Basic Gates using SystemC - Inverter
Labels:
SystemC