c++systemc

SC_METHOD in custom constructor


In my custom constructor i want to use SC_METHOD:

class host_command : public sc_module, public bus_if {
public:
//  sc_out<packet_type> out_packet;
    sc_buffer<packet_type> out_packet;

    host_command(char *name, unsigned int limit) : sc_module(name) {
        SC_METHOD(write);
        sensitive << out_packet;
    }

private:
    void write(packet_type data) override {

    }
}

But if i compile it i get following error:

error: ‘SC_CURRENT_USER_MODULE’ has not been declared
         SC_METHOD(write);
         ^

How can i declare SC_CURRENT_USER_MODULE or cannot i use SC_METHOD in custom constructors at all?

If so, how can i achieve the same functionality?


Solution

  • When you declare a module without using the SC_MODULE macro, you must use the SC_HAS_PROCESS macro to indicate the current module for SC_THREADs and SC_METHODs:

    SC_HAS_PROCESS(host_command);
    host_command(char *name, unsigned int limit) : sc_module(name) {
        SC_METHOD(write);
        sensitive << out_packet;
    }