SystemC
 

1. 4 MS VISUAL STUDIO 2005

 

| | |

//-------------------------------------------------------------------------- not.h -----------------
#include "systemc.h"
SC_MODULE(not)
{
sc_in <bool> A;
sc_out <bool> F;
sc_event delay;
SC_CTOR(not)
{
SC_METHOD(do_delay);
sensitive << A;
SC_METHOD(do_not);
sensitive << delay;
}
void do_delay(){delay.notify(22, SC_NS);}
void do_not(){F.write(!A.read());}
};
//-------------------------------------------------------------------------- or2.h -----------------
#include "systemc.h"
SC_MODULE(or2)
{
sc_in <bool> A, B;
sc_out <bool> F;
sc_event delay;
SC_CTOR(or2)
{
SC_METHOD(do_delay);
sensitive << A << B;
SC_METHOD(do_or2);
sensitive << delay;
}
void do_delay(){delay.notify(22, SC_NS);}
void do_or2(){F.write( A.read() || B.read() );}
};
//-------------------------------------------------------------------------- and3.h ---------------
#include "systemc.h"
SC_MODULE(and3)
{
sc_in <bool> A, B, C;
sc_out <bool> F;
sc_event delay;
SC_CTOR(and3)
{
SC_THREAD(do_delay);
sensitive << A << B << C;
SC_THREAD(do_and3);
sensitive << delay;
}
void do_delay(){delay.notify(27, SC_NS);}
void do_and3(){F.write( A.read() && B.read() && C.read() );}
};
//-------------------------------------------------------------------------- stim.h ----------------
#include "systemc.h"
SC_MODULE(stim)
{
sc_out <bool> D0, D1, D2, D3, S0, S1;
sc_in <bool> Clk;
void do_stim()
{
wait();
D0.write(true);
D1.write(false);
D2.write(true);
D3.write(false);
wait();
while(1)
{
S0.write(false);
S1.write(false);
wait();
S0.write(false);
S1.write(true);
wait();
S0.write(true);
S1.write(false);
wait();
S0.write(true);
S1.write(true);
wait();
D0.write(true);
D1.write(true);
D2.write(false);
D3.write(true);
}
}
SC_CTOR(stim)
{
SC_THREAD(do_stim);
sensitive << Clk.neg();
}
};
//-------------------------------------------------------------------------- mux4.h ----------------
#include "systemc.h"
#include "not.h"
#include "and3.h"
#include "or2.h"
SC_MODULE(mux4)
{
sc_in <bool> D0, D1, D2, D3, S0, S1;
sc_out <bool> F;
sc_signal <bool> NS0, NS1, A1, A2, A3, A4, O1, O2;
not n1, n2;
and3 a1, a2, a3, a4;
or2 o1, o2, o3;
SC_CTOR(mux4) : n1("NOT1"), n2("NOT2"), a1("AND1"), a2("AND2"), a3("AND3"), a4("AND4"), o1("OR1"), o2("OR2"), o3("OR4")
{
n1 << S0 << NS0;
n2 << S1 << NS1;
a1 << D0 << NS0 << NS1 << A1;
a2 << D1 << S0 << NS1 << A2;
a3 << D2 << NS0 << S1 << A3;
a4 << D3 << S0 << S1 << A4;
o1 << A1 << A2 << O1;
o2 << A3 << A4 << O2;
o3 << O1 << O2 << F;
}
};
//-------------------------------------------------------------------------- main.cpp -------------
#include "systemc.h"
#include "mux4.h"
#include "stim.h"

int sc_main(int argc, char* argv[])
{
sc_report_handler::set_actions("/IEEE_Std_1666/deprecated",SC_DO_NOTHING);
sc_signal <bool> D0, D1, D2, D3, S0, S1, F;
sc_clock Clk("TestClock", 100, SC_NS, 0, 200, SC_NS);
stim Stim1("Stimulus");
Stim1.D0(D0);
Stim1.D1(D1);
Stim1.D2(D2);
Stim1.D3(D3);
Stim1.S0(S0);
Stim1.S1(S1);
Stim1.Clk(Clk);
mux4 Mux("Mux_4");
Mux.D0(D0);
Mux.D1(D1);
Mux.D2(D2);
Mux.D3(D3);
Mux.S0(S0);
Mux.S1(S1);
Mux.F(F);
sc_trace_file* Tf;
Tf = sc_create_vcd_trace_file("traces");
((vcd_trace_file*)Tf)->sc_set_vcd_time_unit(-9);
sc_trace(Tf, D3 , "D0" );
sc_trace(Tf, D2 , "D1" );
sc_trace(Tf, D1 , "D2" );
sc_trace(Tf, D0 , "D3" );
sc_trace(Tf, S1 , "S0" );
sc_trace(Tf, S0 , "S1" );
sc_trace(Tf, F , "F" );
sc_start(3000, SC_NS);
char v;
cin >> v;
sc_close_vcd_trace_file(Tf);
return 0;
}

| | |