Jump to content

Recommended Posts

Posted

I have three files:

hello.h

#ifndef hello_h
#define hello_h
#include <systemc.h>

SC_MODULE(Hello)
{
  Hello(sc_core::sc_module_name nm); //< Constructor
  void end_of_elaboration(void); //< Processes
  void Hello_thread(void); //< Processes
  virtual ~Hello(); //< Destructor
};
#endif

hello.cc

#include "hello.h"
#include <systemc.h>

using namespace std;
using namespace sc_core;

// Constructor <<
Hello::Hello(sc_module_name nm)
: sc_module(nm)
{
  cout << "Constructing "
       << name() << endl;
  SC_HAS_PROCESS(Hello);
  SC_THREAD(Hello_thread);
}//endconstructor

void Hello::end_of_elaboration(void) { //< callback
  cout << "End of elaboration" << endl;
}

void Hello::Hello_thread(void) { //< Process
  cout << "Hello World!" << endl;
}

Hello::~Hello() { //< Destructor
  cout << "Destroy " << name() << endl;
}

main.cc

#include "hello.h"
#include <iostream>

using namespace std;
using namespace sc_core;

int sc_main(int argc, char *argv[]) 
{
  Hello top_i("top_i");
  cout << "Starting" << endl;
  sc_start();
  cout << "Exiting" << endl;
  return 0;
}//end main

When I run them using

Quote

g++    -c -o main.o main.cc
g++    -c -o hello.o hello.cc
cc -o hello main.o hello.o -lsystemc -lstdc++ -lm

I got this output:

Quote

Constructing top_i
Starting
End of elaboration
Hello World!
Exiting
Destroy top_i

I wonder how is the "end_of_elaboration" and what does the SC_HAS_PROCESS() does. I have tried to Google it but it seems like there is no any helpful answer.

 

Thank you.

Posted

You should consult the language reference manual IEEE1666-2011. It is explaned there...

SC_HAS_PROCESS declares that the module has some processes  - essential it defines a name to be use later.

end_of_elaboration is one of the simulation phases. The simulation kernel calls this function for each module to allow some setup, initialization and alike before starting a simulation. There are more of them, you will find the declaration in include/sysc/kernel/sc_module.h of your SystemC installation

Posted

To add a bit more to @Eyck:

SC_THREAD specifies the type and name of your SystemC process, but requires SC_HAS_PROCESS to provide a critical bit of information.

Alternately, you could have replaced those two lines with:

sc_core::sc_spawn( std::bind(&Hello::Hello_thread,this) );

For SC_METHOD style processes, the answer is similar, but more complicated when using sc_spawn.

Last, I recommend against include "systemc.h". You are better off using <systemc>.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...