SystemC
 

2. MS VISUAL STUDIO 2005

 

| | |

and2.h, or2.h and3.h 1.
//-------------------------------------------------------------------------- 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_METHOD(do_delay);
sensitive << A << B << C;
SC_METHOD(do_and3);
sensitive << delay;
}
void do_delay(){delay.notify(27, SC_NS);}
void do_and3(){F.write( A.read() && B.read() && C.read() );}
};
//-------------------------------------------------------------------------- jk.h ----------------
#include "systemc.h"
SC_MODULE(jk)
{
sc_in <bool> J, K, Clock, Reset;
sc_out <bool> F, NF;
bool fall;
sc_event trigger_switch;
SC_CTOR(jk)
{
SC_METHOD(do_reset);
sensitive << Reset;
SC_METHOD(do_jk);
sensitive << Clock.neg();
SC_METHOD(do_switch);
sensitive << trigger_switch;
}
void do_switch()
{
if(fall){F.write(true);NF.write(false);}
else {F.write(false);NF.write(true);}
}
void do_jk()
{
if(F.read() || NF.read())
{
if(J.read() == true && K.read() == true)
{
if(F.read())
{
fall = false;
trigger_switch.notify(25, SC_NS);
}
else
{
fall = true;
trigger_switch.notify(40, SC_NS);
}
}
if(J.read() == true && K.read() == false)
{
if(!F.read())fall = true;
trigger_switch.notify(40, SC_NS);
}
if(J.read() == false && K.read() == true)
{
if(F.read())fall = false;
trigger_switch.notify(25, SC_NS);
}
}
}
void do_reset()
{
fall = false;
trigger_switch.notify(25, SC_NS);
}
};
//-------------------------------------------------------------------------- stim.h -------------
#include "systemc.h"
SC_MODULE(stim)
{
sc_out <bool> M, R;
sc_in <bool> Clk;
void do_stim()
{
M.write(false);
wait();
R.write(false);
wait();
R.write(true);
wait();
R.write(false);
wait();
for(int i = 0; i < 15; i++)
{
wait();
}
M.write(true);

for(int j = 0; j < 15; j++)
{
wait();
}
sc_stop();
}
SC_CTOR(stim)
{
SC_THREAD(do_stim);
sensitive << Clk.pos();
}
};
//--------------------------------------------------------- Jonson_02468310.h -------------
#include "systemc.h"
#include "and2.h"
#include "and3.h"
#include "or2.h"
#include "not.h"
#include "jk.h"
SC_MODULE(Jonson_02468310)
{
sc_in <bool> M, R, C;
sc_out <bool> Q0, Q1, Q2, Q3, NQ0, NQ1, NQ2, NQ3;
sc_signal <bool> J[4], K[4], NR, NM;
sc_signal <bool> I[16];

and2 A2_0, A2_1, A2_2, A2_3, A2_4, A2_5, A2_6, A2_7, A2_8;
and3 A3_0, A3_1, A3_2, A3_3, A3_4, A3_5;
or2 O2_0, O2_1, O2_2, O2_3, O2_4, O2_5, O2_6, O2_7, O2_8;
not N_0, N_1;
jk JK_0, JK_1, JK_2, JK_3;

SC_CTOR(Jonson_02468310) : A2_0("AND2_0"), A2_1("AND2_1"), A2_2("AND2_2"), A2_3("AND2_3"), A2_4("AND2_4"),
A2_5("AND2_5"), A2_6("AND2_6"), A2_7("AND2_7"), A2_8("AND2_8"), O2_0("OR2_0"), O2_1("OR2_1"), O2_2("OR2_2"), O2_3("OR2_3"), O2_4("OR2_4"),
O2_5("OR2_5"), O2_6("OR2_6"), O2_7("OR2_7"), O2_8("OR2_8"), A3_0("AND3_0"), A3_1("AND3_1"), A3_2("AND3_2"), A3_3("AND3_3"), A3_4("AND3_4"),
A3_5("AND3_5"), N_0("N_0"), N_1("N_1"), JK_0("JK_0"), JK_1("JK_1"), JK_2("JK_2"), JK_3("JK_3")
{
N_0 << R << NR;N_1 << M << NM;
A2_0 << NM << NQ3 << I[0];A3_0 << M << Q3 << NQ1 << I[1];
O2_0 << I[0] << I[1] << J[0];A2_1 << M << NQ1 << I[2];
O2_1 << Q3 << I[2] << K[0];A3_1 << NM << Q1 << Q2 << I[3];
A3_2 << Q2 << Q1 << NQ0 << I[4];O2_2 << I[3] << I[4] << J[3];
A2_2 << NQ2 << NQ1 << I[5];A2_3 << M << NQ1 << I[6];
O2_3 << I[5] << I[6] << K[3];A3_3 << M << NQ1 << NQ0 << I[7];
A3_4 << NM << Q0 << NQ3 << I[8];O2_4 << I[7] << I[8] << J[1];
A2_4 << NQ0 << Q3 << I[9];O2_5 << M << I[9] << K[1];
A2_5 << NM << Q1 << I[10];A3_5 << Q1 << NQ0 << NQ3 << I[11];
O2_6 << I[10] << I[11] << J[2];A2_6 << NM << NQ1 << I[12];
A2_7 << M << Q1 << I[13];O2_7 << I[12] << I[13] << I[14];
A2_8 << M << Q3 << I[15];O2_8 << I[14] << I[15] << K[2];
JK_0 << J[0] << K[0] << C << NR << Q0 << NQ0;
JK_1 << J[1] << K[1] << C << NR << Q1 << NQ1;
JK_2 << J[2] << K[2] << C << NR << Q2 << NQ2;
JK_3 << J[3] << K[3] << C << NR << Q3 << NQ3;
}
};
//-------------------------------------------------------------------------- main.h -------------
#include "systemc.h"
#include "Jonson_02468310.h"
#include "stim.h"
int sc_main(int argc, char* argv[])
{
sc_signal <bool> M, R, Q0, Q1, Q2, Q3, NQ0, NQ1, NQ2, NQ3;
sc_clock Clk("TestClock", 150, SC_NS, 0.5, 1, SC_NS);
stim Stim1("Stimulus");
Stim1(M, R, Clk);
Jonson_02468310 AA("Jonson_02468310");
AA(M, Clk, R, Q0, Q1, Q2, Q3, NQ0, NQ1, NQ2,NQ3);
sc_trace_file* Tf;
Tf = sc_create_vcd_trace_file("traces");
((vcd_trace_file*)Tf)->sc_set_vcd_time_unit(-9);
sc_trace(Tf, M , "M" );
sc_trace(Tf, Clk , "C" );
sc_trace(Tf, R , "R" );
sc_trace(Tf, Q0 , "Q0" );
sc_trace(Tf, Q1 , "Q1" );
sc_trace(Tf, Q2 , "Q2" );
sc_trace(Tf, Q3 , "Q3" );
sc_start();
sc_close_vcd_trace_file(Tf);
return 0;

}

| | |