Hello systemc community,
I want to model a network on chip for my research and systemc proved to be my choice as it meets most of my requirements .In my attempt to try it ,I created two nodes that send simple data to each other using a simple generator and testnode modules as shown in the code below .
The generator generates numbers but the code hangs on the statements to write to the fifos .Can anyone help hint out what can be done to make this work?I am quite new to systemc so ,sorry if this is obvious.
Thanks.
Dan.
#include <systemc.h> #include <iostream> using namespace std; SC_MODULE(Generator) { sc_out<int> hanze; sc_event event1; int value; SC_HAS_PROCESS(Generator); Generator(sc_module_name name); void generateMethod(); void eventTriggerThread(); }; Generator::Generator(sc_module_name name) :sc_module(name) { value=0; SC_THREAD(eventTriggerThread); SC_METHOD(generateMethod); dont_initialize(); sensitive << event1; } void Generator::eventTriggerThread() { for(;;) { wait(1,SC_NS); event1.notify(); } } void Generator::generateMethod() { value++; hanze.write(value); cout<<name()<<"@ "<<sc_time_stamp() << " wrote "<<value << " to the terminal"<< endl; } SC_MODULE(testNode) { //GENERATOR PORTS sc_in <int> dataToSend; sc_port < sc_fifo_out_if <int> > out_port; sc_port < sc_fifo_in_if <int> > in_port; SC_HAS_PROCESS(testNode); testNode(sc_module_name name); void method1(); void method2 (); }; testNode::testNode(sc_module_name name) :sc_module(name) { SC_THREAD(method1); dont_initialize(); sensitive << dataToSend; SC_THREAD(method2); dont_initialize(); sensitive << dataToSend; } void testNode::method1() { for( ; ;) { wait(); int availableData; availableData=dataToSend.read(); out_port->write(availableData); std::cout << "At time "<< sc_time_stamp() <<" Method1 Wrote a piece of data to the output port :"<<std::endl; wait(1, SC_NS); } } void testNode::method2 () { for( ; ;) { wait(); int availableData; availableData=dataToSend.read(); out_port->write(availableData); std::cout <<"At time "<< sc_time_stamp() << " Method2 Wrote a piece of data to the output port :"<<std::endl; wait(1, SC_NS); } } int sc_main(int argc,char *argv[]) { sc_time sim_time( 10, SC_NS); //CREATE THE NODE testNode mNode1("node1"); testNode mNode2("node2"); //CREATE THE SIGNALS sc_signal<int> dataToSend1; sc_signal<int> dataToSend2; sc_fifo<int> connect1To2(1); sc_fifo<int> connect2To1(1); //CREATE THE GENERATOR Generator gen1("gen1"); Generator gen2("gen2"); //CONNECT THE GENERATOR gen1.hanze(dataToSend1); gen2.hanze(dataToSend2); //CONNECT THE SIGNALS mNode1.dataToSend(dataToSend1); mNode1.in_port(connect2To1); mNode1.out_port(connect1To2); mNode2.dataToSend(dataToSend2); mNode2.in_port(connect1To2); mNode2.out_port(connect2To1); //START THE SIMULATION sc_start(sim_time); return 1; }