gabriel123 Posted October 30, 2020 Report Posted October 30, 2020 Hi, im new to systemC. I want to know how to create a specific amount of sc_fifos<int> depending on an argument. Usually something like this is done with a vector in c++. That is why i thought that an sc_vector is appropriate here. My original code (static). I would have to write new fifos depending on how much i need: sc_fifo<int> *fifos1; sc_fifo<int> *fifos2; sc_fifo<int> *fifos3; fifos1 = new sc_fifo<int>(50000); fifos2 = new sc_fifo<int>(50000); fifos3 = new sc_fifo<int>(50000); The approach with vectors: sc_vector< sc_fifo<int> > fifos; fifos(outputs) for (int i = 0; i < outputs; i++) { fifos[i] = new sc_fifo<int>(50000); } The above code doesn't work. How am i supposed to initialize the vector and add new sc_fifos? Quote
David Black Posted October 30, 2020 Report Posted October 30, 2020 SystemC FIFO's represent hardware and as such may only be created during construction of a model. After elaboration closes, you are not allowed to add more fifos. None of your code examples above are complete, so it is fairly hard to give you a complete answer. Perhaps you could put your design on https://edaplayground.com and share a link with us. For details on phases of SystemC (e.g. elaboration) see IEEE-1666-2011.pdf, which you can obtain through Accellera.org. gabriel123 1 Quote
gabriel123 Posted October 30, 2020 Author Report Posted October 30, 2020 This is all in the constructor so they are created during construction if i understand correctly. I want to know how to add members to my sc_vector. In C++ the method push_back would be used. If it isnt possible does that mean if i need 1000 fifos i would have to write the below code 1000 times? sc_fifo<int> *fifos1; fifos1 = new sc_fifo<int>(50000); Quote
Eyck Posted October 31, 2020 Report Posted October 31, 2020 In the constructor list you would provide a creator function. This is a functor(a function pointer, a std::function object, a Functor classinstance, a lambda function, ...) which accepts a char const* and a size_type and returns a constructed object. In your case it would look like (C++11): class example: public sc_core::sc_module { public: sc_core::sc_vector<sc_core::sc_fifo<unsigned>> fifos; example(sc_core::sc_module_name nm, unsigned outputs) : sc_core::sc_module(nm) , fifos("fifos", outputs, [](char const* name, unsigned i)->sc_core::sc_fifo<unsigned> { return new sc_core::sc_fifo<unsigned>(5000); } { // some construction code } } gabriel123 1 Quote
gabriel123 Posted November 3, 2020 Author Report Posted November 3, 2020 Thanks @eyck the solution worked Quote
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.