0

Using the following code from doulos tutorial on SystemC

#include "systemc.h"
#include 
SC_MODULE(mon)
{
    sc_in<bool> A,B,F;
    sc_in<bool> Clk;

  void monitor()
  {
    cout << setw(10) << "Time";
    cout << setw(2) << "A" ;
    cout << setw(2) << "B";
    cout << setw(2) << "F" << endl;
    while (true)
    {
      cout << setw(10) << sc_time_stamp();
      cout << setw(2) << A.read();
      cout << setw(2) << B.read();
      cout << setw(2) << F.read() << endl;
      wait();    // wait for 1 clock cycle
    }
  }

  SC_CTOR(mon)
  {
    SC_THREAD(monitor);
    sensitive << Clk.pos();
  }
};

and a clock declaration sc_clock TestClk("TestClock", 10, SC_NS,0.5); in the sc_main the output contains results from time 0
but when the positive edge of the clock is delayed for 1 ns (i.e. sc_clock TestClk("TestClock", 10, SC_NS,0.5, 1, SC_NS);) the output starts from time 1 ns.
This is logical as the first trigger of the process is delayed until 1 ns.
The question is isn't the simulation kernel supposed to run all the processes once at time zero!
According to this the results are supposed to start from time 0 in both cases. what am I missing here?

1 Answers1

2

I just compiled and ran the following code (I added a simple sc_main to your example) against System 2.3.1:

#include <iostream>
#include <iomanip>
#include "systemc.h"

using namespace std;

SC_MODULE(mon)
{
    sc_in<bool> A,B,F;
    sc_in<bool> Clk;

  void monitor()
  {
    cout << setw(10) << "Time";
    cout << setw(2) << "A" ;
    cout << setw(2) << "B";
    cout << setw(2) << "F" << endl;
    while (true)
    {
      cout << setw(10) << sc_time_stamp();
      cout << setw(2) << A.read();
      cout << setw(2) << B.read();
      cout << setw(2) << F.read() << endl;
      wait();    // wait for 1 clock cycle
    }
  }

  SC_CTOR(mon)
  {
    SC_THREAD(monitor);
    sensitive << Clk.pos();
  }
};

int sc_main(int argc, char **argv) {
    mon m("m");

    sc_signal<bool> A,B,F;
    sc_clock TestClk("TestClock", 10, SC_NS, 0.5, 1, SC_NS);

    m.A(A);
    m.B(B);
    m.F(F);
    m.Clk(TestClk);

    sc_start(50, SC_NS);

    return 0;
}

and saw this output:

    SystemC 2.3.1-Accellera --- Nov 29 2014 15:29:06
    Copyright (c) 1996-2014 by all Contributors,
    ALL RIGHTS RESERVED
  Time A B F
   0 s 0 0 0
  1 ns 0 0 0
 11 ns 0 0 0
 21 ns 0 0 0
 31 ns 0 0 0
 41 ns 0 0 0

There is output at time 0, as you were expecting. I'm not sure why you aren't seeing that. Perhaps there is typo in your code. Maybe try again with the example code I included above?

DarrylLawson
  • 136
  • 2
  • you are right I have just run the code now. I wrote the question according to what was written in the tutorial. looks like the tutorial was for older version. Thank you. – Abdo Saied Anwar Sep 22 '16 at 14:37