Search the Community
Showing results for tags 'sc_port'.
-
I have an SC_MODULE that contains two types(probably multiple types in the future) of sc_out ports. I want to store a reference(or pointer) of the port in a std::map, so that I can later get the right port through lookup of strings and access the write method of it. Following post helped me understand the topic better but for me it is still unclear how I can achieve my goal. I don't understand how I should cast my stored reference. Small example for showing how I want to use it. #pragma once #include <systemc.h> #include <map> //typedef std::map<std::string, sc_interface*> Map0; //typedef std::map<std::string, sc_object*> Map0; typedef std::map<std::string, (????)*> Map0; // what type should I use since sc_out<T> varies on type T class stimulator: public sc_module { public: sc_out<bool> POWER_ON; sc_out<sc_uint<2>> T01_SBIT_mil_stub; private: Map0 dict; public: void stimulator::stimulus_generator() { std::string key0; for(int i=0; i<=1; i++) { if(i==0) key0 = "VOLTAGE"; else key0 = "T01_SBIT_mil_stub"; dict::iterator it0 = dict.find(key0); if (it0 == dict.end()) cout << "Map lookup key not found." << endl; // How to cast it? Type Erasure? if(i==0) it0->second->write(true); //write method not available else it0->second->write(1); //write method not available } } public: SC_CTOR(stimulator): POWER_ON("POWER_ON"), T01_SBIT_mil_stub("T01_SBIT_mil_stub") { // if type of map is sc_object* use get_parent() instead of get_interface() dict.insert( std::make_pair("VOLTAGE", POWER_ON.get_interface()) ); dict.insert( std::make_pair("T01_SBIT_mil_stub", T01_SBIT_mil_stub.get_interface()) ); SC_THREAD(stimulus_generator); // runs one time at creation, which is sufficient to demonstrate } } Is an sc_object* the best way to do it? If yes how do I cast it back to the right sc_out<T>? I know that I could solve my problem with a different approach, like defining enums and each enum indicates a port and thus I know which port I should write to. But that would involve more lines of code that is not really flexible. I prefer the generic way and would like to understand the SystemC framework better. Thanks for any help or guidance in advance 🙂
-
Hi all, I created two modules with interfaces as below: M1 : sc_port<sc_fifo_out_if<T>, 0> a M2 : sc_port<sc_fifo_in_if<T>, 0> a2; I have a third module which is also my top module i.e M3 and tried binding M1 output to M2 input to create a communication channel. I have tried using sc_fifo<T> but it doesn't work. How do I bind M1 output to M2 input inside M3 module? Please not that T is a struct. Thanks