Passing parameters to a SystemC Module

This article describe how to pass parameters like a pointer into SystemC modules. Why do I need to pass parameters into a SystemC module?
Think of a SystemC testbench where a test sequence controls a transactor (TLM) the test sequence is also dumping golden responses into a FIFO that is connected to a respons checker. The response checker then picks the polden responses out of this FIFO and checks the Device Under Test’s (DUT) response against.

Many tutorials like the one from Esperan describe how a simple SystemC module is defined. Typically it uses a syntax like this:

SC_MODULE(nopar_test) {
   SC_CTOR(nopar_test) {
      cout << "This is a simple SystemC module" << endl;
   }
};

However, if you want to pass parameters to your module the SC_CTOR macro can no longer be used and you have to switch to a structure like the following one:

SC_MODULE(arg_test) {
   SC_HAS_PROCESS(arg_test);
   arg_test(sc_module_name nm, int parameter1) : sc_module(nm) {
      cout << "The parameter is: " << parameter1 << endl;
   }
};

This module can then be instantiated by the following code:

arg_test arg_test_U0("arg_test", 8);

Once you run your model you will be able to see the proper console output.

Note that the “SC_MODULE_EXPORT” macro may no longer work and result in a compiler error.

if you want to use SC_THREAD for task invocation the module looks something like this:

SC_MODULE(arg_test) {
   SC_HAS_PROCESS(arg_test);
   arg_test(sc_module_name nm, int parameter1) : sc_module(nm), main_parameter1(parameter1) {
	  cout << "The parameter is: " << parameter1 << endl;
	  SC_THREAD(main);
   }
   int main_parameter1;
   void main() {
      cout << "The THREAD parameter is: " << main_parameter1 << endl;
   }
};

Now let’s look at the case of a FIFO outline in the introduction. The FIFO is implemented as a templated class fifo with member functions like get() and put() to access the FIFO elements. For this case the SystemC code will look something like this:

SC_MODULE(arg_test) {
   SC_HAS_PROCESS(arg_test);
   arg_test(sc_module_name nm, fifo<T>* pfifo1) : sc_module(nm), _pfifo1(pfifo1) {
	  cout << "The parameter is: " << pfifo1->get() << endl;
	  SC_THREAD(main);
   }
   fifo<T> main_parameter1;
   void main() {
      cout << "The THREAD parameter is: " << _pfifo1->get() << endl;
   }
};

And the module can then be instantiated by the following code:

fifo<T> *pfifo1;
pfifo1 = new fifo<T>;
pfifo1->put(<T>);

arg_test *arg_test_U0;
arg_test_U0 = new ("arg_test", pfifo1);

Leave a Reply

Your email address will not be published. Required fields are marked *