I would like to create an array of sc_out and sc_in in sc_module. I looked at the documentation of sc_vector, but I couldn't get it to work. I like to be able to read and write individual sc_out port.
I looked at the source code of System C, it seems to use std::vector. So I think there should be an easy way(may be one line of code) to create this vector of sc_out and use it.
https://forums.accellera.org/topic/1849-array-of-sc_vector-binding-and-assembling-help/
There are also people using sc_assemble_vector, is there any documented examples?
Thanks in advance.
I created the below sample code to show what I'm trying to do. I'm trying to create a size four vector there. sc_vector is a c++ class, so I constructed it in your_module constructor and saved its pointer in array_of_outputs.
#include <systemc.h>
class your_module : sc_module
{
private:
public:
sc_in_clk clk;
sc_vector < sc_out< unsigned > >* array_of_outputs; // <-------------------here is declaration
//Constructor
SC_CTOR(your_module) {
SC_CTHREAD(entry, clk.pos());
sc_vector<sc_out< unsigned >> array_outputs("vector_name", 4); // <-- size 4 array
array_of_outputs= &array_outputs; // <---------------------------save pointer
}
// Process functionality in member function below
void entry() {
while(true){
wait();
(*array_of_outputs)[0].write(2);
(*array_of_outputs)[1].write(4);
(*array_of_outputs)[2].write(8);
(*array_of_outputs)[3].write(10);
}
}
};
int sc_main(int, char* []) {
sc_clock clk("Clock", 1, SC_NS, 0.5, 0.0, SC_NS); // 1ns period, 0.5 duty cycle, start at 0ns
sc_vector<sc_signal<unsigned>> new_vector_wire("the_vector");
your_module YM("your_module");
(*YM.array_of_outputs)(new_vector_wire);
NCTRL.clk(clk);
sc_start(10000); // run forever
return 0;
}