AnandRamesh Posted May 25, 2016 Report Share Posted May 25, 2016 Hi, I'm a newbie with systemc and using it for design. I want to implement a class representing a generic register file which requires a mandatory parameter NUM_REGS in its constructor. I want to then contain this register file inside sc_signal<> to allow event handling. The reg_files header looks something like this (simplified version): #include<systemc.h> class reg_file { private: sc_uint<8> *reg_set; public: unsigned REG_NUMS; reg_file(const unsigned numberOfRegs) { REG_NUMS = numberOfRegs; reg_set = new sc_uint<8> [REG_NUMS]; } ~reg_file() { delete reg_set; } }; I want to contain the objects of this class in sc_signal by passing numberOfRegs as as a parameter during a creation of the the signal like this: sc_signal<reg_file> tmr_regs; // Where to pass numberOfRegs? Quote Link to comment Share on other sites More sharing options...
Roman Popov Posted May 25, 2016 Report Share Posted May 25, 2016 Hello, you can pass reg_file constructor parameter as second parameter to sc_signal constructor: For example: sc_signal<reg_file> tmr_regs {"tmr_regs", number_of_regs}; However your code won't compile anyway, because sc_signal requires operator =, operator <<, operator == and sc_trace method to be defined in user-defined data type. Check here for example: https://www.doulos.com/knowhow/systemc/faq/#q1 Also, please note that your modeling style is not common in SystemC world. For regfile modeling you should probably create a dedicated SC_MODULE (reg_file) or use array of sc_signals directly : sc_signal<sc_uint<8>> tmr_regs[REG_NUMS]; //You can also use sc_vector for that purpose. AnandRamesh 1 Quote Link to comment Share on other sites More sharing options...
AnandRamesh Posted May 27, 2016 Author Report Share Posted May 27, 2016 Thank you @Roman. The version of the header file shown above does not have the overloads as its simplified. I do have them all overloaded. I like the SC_MODULE(reg_file) idea. Essentially I want to model a module with a bunch of registers whose SC_CTHREAD and SC_MODULE is sensitive to the these its own register file. How do I implement the SC_MODULE? Quote Link to comment Share on other sites More sharing options...
Roman Popov Posted May 27, 2016 Report Share Posted May 27, 2016 How about something like this: template <int REG_NUMS> SC_MODULE(reg_file) { sc_signal<sc_uint<8> > reg_set[REG_NUMS]; SC_CTOR(reg_file) { SC_METHOD(some_method); for (int i = 0; i < REG_NUMS; ++i) { sensitive << reg_set[i]; } } void some_method() { /***/} }; I don't know what your final goal is, but if I want to implement some parameterizable module I always use templates instead of constructor parameters. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.