Ejemplo n.º 1
0
int sc_main(int argc, char* argv[])
{
    sc_signal<sc_int<4> > ain, bin, sum;
    sc_signal<bool> ci,co,zflag,oflag;

    sc_clock clk("clk",10,SC_NS,0.5);

    adder4 DUT("addsub4");
    DUT.ain(ain);
    DUT.bin(bin);
    DUT.ci(ci); 
    DUT.sum(sum);
    DUT.co(co);
    DUT.zf(zflag);
    DUT.of(oflag);

    stim STIM("stimulus");
    STIM.clk(clk);
    STIM.ain(ain);
    STIM.bin(bin);
    STIM.ci(ci);

    check CHECK("checker");
    CHECK.clk(clk); 
    CHECK.ain(ain);
    CHECK.bin(bin);
    CHECK.ci(ci);
    CHECK.sum(sum);
    CHECK.co(co);
    CHECK.zflag(zflag);
    CHECK.oflag(oflag);

    sc_initialize();
    sc_trace_file *tf = sc_create_vcd_trace_file("trace");

    sc_trace(tf, ain, "ain"); 
    sc_trace(tf, bin, "bin");
    sc_trace(tf, ci, "add/sub"); 
    sc_trace(tf, sum, "sum");
    sc_trace(tf, co, "co");
    sc_trace(tf, clk, "clk");
    sc_trace(tf, zflag, "zero_flag");
    sc_trace(tf, oflag, "overflow_flag");

    sc_start(200, SC_NS);    
    sc_close_vcd_trace_file(tf);

    return 0;                           // Return OK, no errors.
}
Ejemplo n.º 2
0
int sc_main(int argc, char *argv[])
{
    sc_signal<bool> A;
    sc_signal<bool> B;
    sc_signal<bool> CI;
    sc_signal<bool> SUM;
    sc_signal<bool> CO;

    FA fa("FA");
    fa.A(A);
    fa.B(B);
    fa.CI(CI);
    fa.SUM(SUM);
    fa.CO(CO);

    /*sc_signal<bool> or_1;
    sc_signal<bool> or_2;
    sc_signal<bool> and_3;
    sc_signal<bool> and_4;
    sc_signal<bool> and_5;
    sc_signal<bool> and_6;
    sc_signal<bool> nor_7;

    OR2  or1("or1"), or8("or8");
    OR3  or2("or2");
    AND2 and3("and3"), and4("and4"), and5("and5");
    AND3 and6("and6");
    NOR2 nor7("nor7");
    INV  inv9("inv9");

    or1.a(A); or1.b(B); or1.o(or_1);
    or2.a(A); or2.b(B); or2.c(CI); or2.o(or_2);
    and3.a(or_1); and3.b(CI); and3.o(and_3);
    and4.a(A); and4.b(B); and4.o(and_4);
    and5.a(nor_7); and5.b(or_2); and5.o(and_5);
    and6.a(A); and6.b(B); and6.c(CI); and6.o(and_6);
    nor7.a(and_3); nor7.b(and_4); nor7.o(nor_7);
    or8.a(and_5); or8.b(and_6); or8.o(SUM);
    inv9.a(nor_7); inv9.o(CO); */

    sc_initialize();   // initialize the simulation engine
    // create the file to store simulation results
    sc_trace_file *tf = sc_create_vcd_trace_file("trace");
    // 4: specify the signals we’d like to record in the trace file
    sc_trace(tf, A, "A");
    sc_trace(tf, B, "B");
    sc_trace(tf, CI, "CI");
    sc_trace(tf, SUM, "SUM");
    sc_trace(tf, CO, "CO");
    // 5: put values on the input signals
    A=0;
    B=0;
    CI=0;                 // initialize the input values
    sc_start(10, SC_NS);
    for( int i = 0 ; i < 8 ; i++ )  // generate all input combinations
    {
        A  = ((i & 0x1) != 0);    // value of A is the bit0 of i
        B  = ((i & 0x2) != 0);    // value of B is the bit1 of i
        CI = ((i & 0x4) != 0);    // value of CI is the bit2 of i
        sc_start(10, SC_NS);          // evaluate
    }
    A  = 0;    // value of A is the bit0 of i
    B  = 0;    // value of B is the bit1 of i
    CI = 0;
    sc_start(10, SC_NS);
    sc_close_vcd_trace_file(tf);    // close file and we’re done
    return 0;
}
Ejemplo n.º 3
0
int sc_main (int argc, char *argv[]) {

    cout << "SYSTEMC_VERSION="<<dec<<SYSTEMC_VERSION<<endl;
    cout << "Compiled with pointer size "<<((sizeof(char*)==8) ? "-m64":"-m32")<<endl;

    // Timescale
#if (SYSTEMC_VERSION>=20070314)
    sc_set_time_resolution(100.0, SC_FS);
#elif (SYSTEMC_VERSION>20011000)
    sc_set_time_resolution(100.0, SC_FS);
    sc_set_default_time_unit(1.0, SC_NS);
    sc_report::make_warnings_errors(true);
#else
    sc_time dut(1.0, sc_ns);
    sc_set_default_time_unit(dut);
#endif // SYSTEMC_VERSION

#ifndef NC_SYSTEMC
    // Simulation logfile
    sp_log_file splog;
    splog.open ("sim.log");
    splog.redirect_cout();
#endif

    // Pins
#if SYSTEMC_VERSION >= 20060505
    sc_clock clk("clk",5,SC_NS);  // We want a non-integer half period to prove VCD works
#else
    sc_clock clk("clk",5);
#endif // SYSTEMC_VERSION

    ExBench* bench;
    SP_CELL (bench,ExBench);
    SP_PIN  (bench,clk,clk);
    bench->configure();	// Verify the #sp include worked

#ifndef NC_SYSTEMC
# if SYSTEMC_VERSION < 20060505
    sc_initialize();
# endif
#endif

    // Example enumeration usage
    MyENumClass enval = MyENumClass::ONE;
    cout << "Assigned to enumeration = "<<enval<<endl;	// Prints "ONE"
    cout << "Iterating an enumeration =";
    for (MyENumSimple::iterator it=MyENumSimple::begin();
	 it!=MyENumSimple::end(); ++it) {
	cout << " " << (*it).ascii();
    }
    cout << endl;

#ifndef NC_SYSTEMC
    // SystemC traces are flawed, you can't even trace ports
    sc_trace_file *tf = sc_create_vcd_trace_file("sim_sc" );
    sc_trace(tf, clk, "clk");

#if SYSTEMC_VERSION >= 20070314
    tf->set_time_unit(1, SC_NS);
#endif

    // SystemPerl traces
    SpTraceFile* stp = new SpTraceFile;
    bench->trace(stp,999);
    stp->open("sim_sp.vcd");

    // Alternative SystemPerl traces, allowing rollover
    // After running, concat the two files to make the vcd file.
    SpTraceFile* stp2 = new SpTraceFile;
    stp2->rolloverMB(1);	// Rollover logfiles when size > 1MB
    bench->trace(stp2,999);
    stp2->open("sim_sp2.vcd");
#endif // NC_SYSTEMC

    cout << "Starting\n";
#if SYSTEMC_VERSION >= 20060505
    sc_start();
#else
    sc_start(-1);
#endif // SYSTEMC_VERSION
    cout << "Done\n";

#ifndef NC_SYSTEMC
    sc_close_vcd_trace_file(tf);
    SpTraceVcd::flush_all();
#endif // NC_SYSTEMC

    // Coverage
    mkdir("logs", 0777);
    SpCoverage::write();  // Writes logs/coverage.pl

    return (0);
}