and_2 And_Gate1, And_Gate2, And_Gate3;
or_2 Or_Gate1, Or_Gate2;
sc_signal<bool> NotSel, A_AND_B,
A_AND_NotSel, B_AND_Sel,
A_AND_NotSel_OR_A_AND_B, Mux_Out;
void Mux(void);
SC_CTOR(Mux_2): And_Gate1("And_Gate1"),
And_Gate2("And_Gate2"),
And_Gate3("And_Gate3"),
Or_Gate1("Or_Gate1"), Or_Gate2("Or_Gate2")
{
NotSel = !(Mux_2_Sel.read());
And_Gate1.And_A(Mux_2_In1);
And_Gate1.And_B(Mux_2_In2);
And_Gate1.And_Output(A_AND_B);
And_Gate2.And_A(Mux_2_In1);
And_Gate2.And_B(NotSel);
And_Gate2.And_Output(A_AND_NotSel);
And_Gate3.And_A(Mux_2_In2);
And_Gate3.And_B(NotSel);
And_Gate3.And_Output(B_AND_Sel);
Or_Gate1.Or_A(A_AND_B);
Or_Gate1.Or_B(A_AND_NotSel);
Or_Gate1.Or_Output(A_AND_NotSel_OR_A_AND_B);
Or_Gate2.Or_A(A_AND_NotSel_OR_A_AND_B);
Or_Gate2.Or_B(B_AND_Sel);
Or_Gate2.Or_Output(Mux_Out);
SC_METHOD(Mux);
sensitive << Mux_2_Sel <<
Mux_2_In1 << Mux_2_In2;
}
};
//
FILE:tb.h
#include <systemc.h>
#include <iostream>
SC_MODULE(tb) {
sc_out<bool> A, B, sel;
//sc_signal<bool> A,B,sel;
void testcases(void);
SC_CTOR(tb) {
SC_THREAD(testcases);
}
};
//
FILE:or_2.cpp
#include "or_2.h"
#include <iostream>
void or_2::do_or(void) {
Or_Output.write( Or_A.read() ||
Or_B.read() );
std::cout << "Time:" <<
sc_time_stamp()<< endl <<" Fisrt
Input:" << Or_A << endl <<
" Second Input" << Or_B << endl
<< " Output : " << Or_Output
<< endl ;
}
//
FILE:AND_2.cpp
#include "and_2.h"
#include <iostream>
void and_2::do_and(void) {
And_Output.write(And_A.read() &&
And_B.read());
std::cout << "Time:" <<
sc_time_stamp()<< endl <<" Fisrt
Input:" << And_A << endl
<< " Second Input" << And_B
<< endl << " Output : " <<
And_Output << endl ;
}
//
FILE:MUX_2.cpp
#include <iostream>
#include "Mux_2.h"
void Mux_2::Mux(void){
Mux_2_Output = Mux_Out;
std::cout << "Time:" <<
sc_time_stamp()<< endl <<" First
Input:" << Mux_2_In1 << endl
<< " Second Input" << Mux_2_In2
<< endl << " Select Line"
<< Mux_2_Sel << endl << "
Output : " << Mux_2_Output <<
endl ;
}
#include "Mux_2.h"
#include "tb.h"
#include "tstbnsh.h"
#include <iostream>
int sc_main(int argc, char* argv[]) {
sc_signal<bool> in1, in2, sel;
tb my_tb("my_tb");
Mux_2 my_mux_2("my_mux_2");
my_mux_2.Mux_2_In1(in1);
my_mux_2.Mux_2_In2(in2);
my_mux_2.Mux_2_Sel(sel);