Index: trunk/platforms/caba-vdspin-vci_synthetic_initiator/top.cpp
===================================================================
--- trunk/platforms/caba-vdspin-vci_synthetic_initiator/top.cpp	(revision 112)
+++ trunk/platforms/caba-vdspin-vci_synthetic_initiator/top.cpp	(revision 121)
@@ -16,6 +16,6 @@
 
 // MESH SIZE
-#define X_MAX           2
-#define Y_MAX           2
+#define X_MAX           16
+#define Y_MAX           16
 #define N_CLUSTERS      X_MAX*Y_MAX
 // FLIT_WIDTH
@@ -42,4 +42,12 @@
 #define TARGET_ADDR	0x00000000
 #define TARGET_SIZE	0x400
+// FIFO depth in the gateways
+#define DEPTH		2
+// LENGTH of packets
+#define PACKET_LENGTH	2
+// FIFO depth in the routers
+#define DSPIN_FIFO      4
+// DEBUG MODE : 0 OFF, 1 only the initiators and the targets, 2 only network
+#define DEBUG		0
 
 
@@ -65,5 +73,4 @@
 					wrplen_width> vci_param;
 
-	//soclib::common::Loader loader();
 	// Mapping table primary network
 	soclib::common::MappingTable maptab0(address_width, IntTab(soclib::common::uint32_log2(X_MAX)+soclib::common::uint32_log2(Y_MAX) ,srcid_width-soclib::common::uint32_log2(X_MAX)-soclib::common::uint32_log2(Y_MAX)),
@@ -83,6 +90,5 @@
 
 
-	std::cout << maptab0 << std::endl;
-	// Signals
+//	std::cout << maptab0 << std::endl;
 
 	sc_clock	signal_clk("clk");
@@ -95,10 +101,9 @@
 	//                  one level for Y length in the mesh, last level for each port of the router
 	///////////////////////////////////////////////////////////////
-	soclib::caba::DspinSignals<WIDTH_CMD> **** dspin_signals_cmd_c0 = soclib::common::alloc_elems<soclib::caba::DspinSignals<WIDTH_CMD> >("Dspin_cmd_signals_channel_0", 2, Y_MAX, X_MAX, 5 );
-	soclib::caba::DspinSignals<WIDTH_CMD> **** dspin_signals_cmd_c1 = soclib::common::alloc_elems<soclib::caba::DspinSignals<WIDTH_CMD> >("Dspin_cmd_signals_channel_1", 2, Y_MAX, X_MAX, 5 );
-	soclib::caba::DspinSignals<WIDTH_RSP> **** dspin_signals_rsp_c0 = soclib::common::alloc_elems<soclib::caba::DspinSignals<WIDTH_RSP> >("Dspin_rsp_signals_channel_0", 2, Y_MAX, X_MAX, 5 );
-	soclib::caba::DspinSignals<WIDTH_RSP> **** dspin_signals_rsp_c1 = soclib::common::alloc_elems<soclib::caba::DspinSignals<WIDTH_RSP> >("Dspin_rsp_signals_channel_2", 2, Y_MAX, X_MAX, 5 );
-
-	//soclib::caba::VciSignals<vci_param> * signal_vci_tgt_proc  = soclib::common::alloc_elems<soclib::caba::VciSignals<vci_param> >("signal_vci_tgt_proc",  N_CLUSTERS);
+	soclib::caba::DspinSignals<WIDTH_CMD> **** dspin_signals_cmd_c0 = soclib::common::alloc_elems<soclib::caba::DspinSignals<WIDTH_CMD> >("Dspin_cmd_signals_channel_0", 2, X_MAX, Y_MAX, 5 );
+	soclib::caba::DspinSignals<WIDTH_CMD> **** dspin_signals_cmd_c1 = soclib::common::alloc_elems<soclib::caba::DspinSignals<WIDTH_CMD> >("Dspin_cmd_signals_channel_1", 2, X_MAX, Y_MAX, 5 );
+	soclib::caba::DspinSignals<WIDTH_RSP> **** dspin_signals_rsp_c0 = soclib::common::alloc_elems<soclib::caba::DspinSignals<WIDTH_RSP> >("Dspin_rsp_signals_channel_0", 2, X_MAX, Y_MAX, 5 );
+	soclib::caba::DspinSignals<WIDTH_RSP> **** dspin_signals_rsp_c1 = soclib::common::alloc_elems<soclib::caba::DspinSignals<WIDTH_RSP> >("Dspin_rsp_signals_channel_2", 2, X_MAX, Y_MAX, 5 );
+
 
 	// N_CLUSTERS ring.
@@ -106,5 +111,4 @@
 	soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> * local_ring_c1 = (soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> *) malloc(sizeof(soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> ) * N_CLUSTERS) ;
 	for(int i = 0 ; i < N_CLUSTERS ; i++){                                                            // ringid, fifo, fifo, nb_init, nb_tgt
-		std::cout << "Passe " << i << " pour instanciation ring" << std::endl;
 		std::ostringstream	str0;
 		std::ostringstream	str1;
@@ -115,5 +119,5 @@
 													IntTab(i), 
 													2, 
-													18, 
+													DEPTH, 
 													1, 
 													1);
@@ -122,5 +126,5 @@
 													IntTab(i), 
 													2, 
-													18,
+													DEPTH,
 													1,
 													1);
@@ -135,11 +139,10 @@
 	  routers_rsp[i] = (soclib::caba::VirtualDspinRouter<WIDTH_RSP> * ) malloc(sizeof(soclib::caba::VirtualDspinRouter<WIDTH_RSP>) * Y_MAX);
 	  for(int j = 0; j < Y_MAX; j++){
-		  std::cout << "Passe " << i << j << " pour instanciation vdspin" << std::endl;
 		  std::ostringstream	str0;
 		  std::ostringstream	str1;
 		  str0 << "VDspinRouterCMD" << i << j;
 		  str1 << "VDspinRouterRSP" << i << j;
-		  new(&routers_cmd[i][j]) soclib::caba::VirtualDspinRouter<WIDTH_CMD> (str0.str().c_str(), i, j, soclib::common::uint32_log2(X_MAX), soclib::common::uint32_log2(Y_MAX), 4, 4);
-		  new(&routers_rsp[i][j]) soclib::caba::VirtualDspinRouter<WIDTH_RSP> (str1.str().c_str(), i, j, soclib::common::uint32_log2(X_MAX), soclib::common::uint32_log2(Y_MAX), 4, 4);
+		  new(&routers_cmd[i][j]) soclib::caba::VirtualDspinRouter<WIDTH_CMD> (str0.str().c_str(), i, j, soclib::common::uint32_log2(X_MAX), soclib::common::uint32_log2(Y_MAX), DSPIN_FIFO, DSPIN_FIFO);
+		  new(&routers_rsp[i][j]) soclib::caba::VirtualDspinRouter<WIDTH_RSP> (str1.str().c_str(), i, j, soclib::common::uint32_log2(X_MAX), soclib::common::uint32_log2(Y_MAX), DSPIN_FIFO, DSPIN_FIFO);
 	  }
 	}
@@ -155,16 +158,15 @@
 	for(int i = 0 ; i < X_MAX; i++)
 		for(int j = 0 ; j < Y_MAX ; j++){
-			std::cout << "Passe " << i << j << " pour instanciation synthetic_init" << std::endl;
 			std::ostringstream	str0;
 			std::ostringstream	str1;
 			str0 << "Initiator_c0_" << (i*Y_MAX+j) ;
 			str1 << "Initiator_c1_" << (i*Y_MAX+j) ;
-			if( (i == X_MAX-1) && (j == Y_MAX-1)){
-				new(&initiator_c0[Y_MAX*i+j]) soclib::caba::VciSyntheticInitiator<vci_param> (str0.str().c_str() , maptab0, IntTab((i*Y_MAX+j) ,0), 16, 900, 2, X_MAX, Y_MAX, 25, 0, X_MAX, 0, Y_MAX); //, 0, 0, 0, 0, 0);
-				new(&initiator_c1[Y_MAX*i+j]) soclib::caba::VciSyntheticInitiator<vci_param> (str1.str().c_str() , maptab1, IntTab((i*Y_MAX+j) ,0), 16, 900, 2, X_MAX, Y_MAX, 25, 0, X_MAX, 0, Y_MAX); //, 0, 0, 0, 0, 0);
-			} else {
-				new(&initiator_c0[Y_MAX*i+j]) soclib::caba::VciSyntheticInitiator<vci_param> (str0.str().c_str() , maptab0, IntTab((i*Y_MAX+j),0), 16, 500, 2, X_MAX, Y_MAX); //, 0, 0, 0, 0, 0);
-				new(&initiator_c1[Y_MAX*i+j]) soclib::caba::VciSyntheticInitiator<vci_param> (str1.str().c_str() , maptab1, IntTab((i*Y_MAX+j),0), 16, 500, 2, X_MAX, Y_MAX); //, 0, 0, 0, 0, 0);
-			}
+			//if( (i == X_MAX-1) && (j == Y_MAX-1)){
+				new(&initiator_c0[Y_MAX*i+j]) soclib::caba::VciSyntheticInitiator<vci_param> (str0.str().c_str() , maptab0, IntTab((i*Y_MAX+j) ,0), PACKET_LENGTH, 40, 8, X_MAX, Y_MAX); //, 250, 0, X_MAX, 0, Y_MAX); 
+				new(&initiator_c1[Y_MAX*i+j]) soclib::caba::VciSyntheticInitiator<vci_param> (str1.str().c_str() , maptab1, IntTab((i*Y_MAX+j) ,0), PACKET_LENGTH, 40, 8, X_MAX, Y_MAX); //, 250, 0, X_MAX, 0, Y_MAX); 
+			//} else {
+			//	new(&initiator_c0[Y_MAX*i+j]) soclib::caba::VciSyntheticInitiator<vci_param> (str0.str().c_str() , maptab0, IntTab((i*Y_MAX+j),0), 16, 50, 2, X_MAX, Y_MAX); //, 0, 0, 0, 0, 0);
+			//	new(&initiator_c1[Y_MAX*i+j]) soclib::caba::VciSyntheticInitiator<vci_param> (str1.str().c_str() , maptab1, IntTab((i*Y_MAX+j),0), 16, 50, 2, X_MAX, Y_MAX); //, 0, 0, 0, 0, 0);
+			//}
 		}
 
@@ -173,5 +175,4 @@
 	for(int i = 0 ; i < X_MAX ; i++)
 		for(int j = 0 ; j < Y_MAX ; j++){
-			std::cout << "Passe " << i << j << " pour instanciation Ram" << std::endl;
 			std::ostringstream	str0;
 			std::ostringstream	str1;
@@ -226,5 +227,4 @@
 	    local_ring_c0[i*Y_MAX+j].p_gate_rsp_out(dspin_signals_rsp_c0[1][i][j][LOCAL]);
 	    local_ring_c1[i*Y_MAX+j].p_gate_rsp_out(dspin_signals_rsp_c1[1][i][j][LOCAL]);
-	    std::cout << "Ring to DSPIN Connection done" << std::endl;
 	    for(int k = 0; k < 5; k++){
 	     	if(j == 0){
@@ -304,8 +304,21 @@
 	}
 
-	////////////////////////////////////////////////////////
-	for(int i = 0; i < Y_MAX ; i++){
+	////////////////////////////////////////////////
+	//             Simulation Loop                //
+	////////////////////////////////////////////////
+	int ncycles;
+
+
+	if(argc == 2){
+	  ncycles = std::atoi(argv[1]);
+	} else {
+	  exit(1);
+	}
+	sc_start(sc_core::sc_time(0, SC_NS));
+	signal_resetn = false;
+
+	for(int i = 0; i < X_MAX ; i++){
 		for(int j = 0; j < Y_MAX ; j++){
-			if(i == 0){
+			if(j == 0){
 			  	dspin_signals_cmd_c0[0][i][j][SOUTH].read = true   ;
 			  	dspin_signals_cmd_c0[1][i][j][SOUTH].write = false ;
@@ -317,5 +330,5 @@
 			  	dspin_signals_rsp_c1[1][i][j][SOUTH].write = false ;
 			} 
-			if(i == Y_MAX-1){
+			if(j == Y_MAX-1){
 			  	dspin_signals_cmd_c0[0][i][j][NORTH].read = true   ;
 			  	dspin_signals_cmd_c0[1][i][j][NORTH].write = false ;
@@ -327,5 +340,5 @@
 			  	dspin_signals_rsp_c1[1][i][j][NORTH].write = false ;
 			} 
-			if(j == 0){
+			if(i == 0){
 				dspin_signals_cmd_c0[0][i][j][WEST].read = true   ;
 				dspin_signals_cmd_c0[1][i][j][WEST].write = false ;
@@ -337,5 +350,5 @@
 				dspin_signals_rsp_c1[1][i][j][WEST].write = false ;
 			} 
-			if(j == X_MAX-1){
+			if(i == X_MAX-1){
 				dspin_signals_cmd_c0[0][i][j][EAST].read = true   ;
 				dspin_signals_cmd_c0[1][i][j][EAST].write = false ;
@@ -348,95 +361,65 @@
 			}
 		}
-	}
-
-
-
-	////////////////////////////////////////////////
-	//             Simulation Loop                //
-	////////////////////////////////////////////////
-	//int ncycles;
-
-	sc_start(sc_core::sc_time(0, SC_NS));
-	signal_resetn = false;
+	} 
 
 	sc_start(sc_core::sc_time(1, SC_NS));
 	signal_resetn = true;
 
-	while(1) {
+	for(int t = 0; t < ncycles; t++){
 		sc_start(sc_time(1, SC_NS));
-		std::cout << "Synthetic initiators signals ------------------------------" << std::endl;
-		for(int i = 0 ; i < N_CLUSTERS ; i++){
-			initiator_c0[i].print_trace();
-			std::cout << std::hex;
-			std::cout << "synt_cmdval  = " << signal_vci_ini_synth_c0[0][i].cmdval.read() << std::endl;
-			std::cout << "synt_address = " << signal_vci_ini_synth_c0[0][i].address.read() << std::endl;
-			std::cout << "synt_cmd     = " << signal_vci_ini_synth_c0[0][i].cmd.read() << std::endl;
-			std::cout << "synt_srcid   = " << signal_vci_ini_synth_c0[0][i].srcid.read() << std::endl;
-			std::cout << "synt_plen    = " << signal_vci_ini_synth_c0[0][i].plen.read() << std::endl;
-			std::cout << "synt_eop     = " << signal_vci_ini_synth_c0[0][i].eop.read() << std::endl;
-			std::cout << "synt_rspval  = " << signal_vci_ini_synth_c0[0][i].rspval.read() << std::endl;
-			std::cout << "synt_rerror  = " << signal_vci_ini_synth_c0[0][i].rerror.read() << std::endl;
-			std::cout << "synt_reop    = " << signal_vci_ini_synth_c0[0][i].reop.read() << std::endl;
-		}
-		std::cout << "RAM signals -----------------------------------------------" << std::endl;
-		for(int i = 0 ; i < N_CLUSTERS ; i++){
-			ram_c0[i].print_trace();
-			std::cout << std::hex;
-			std::cout << "ram_cmdval  = " << signal_vci_ini_synth_c0[1][i].cmdval.read() << std::endl;
-			std::cout << "ram_address = " << signal_vci_ini_synth_c0[1][i].address.read() << std::endl;
-			std::cout << "ram_cmd     = " << signal_vci_ini_synth_c0[1][i].cmd.read() << std::endl;
-			std::cout << "ram_srcid   = " << signal_vci_ini_synth_c0[1][i].srcid.read() << std::endl;
-			std::cout << "ram_plen    = " << signal_vci_ini_synth_c0[1][i].plen.read() << std::endl;
-			std::cout << "ram_eop     = " << signal_vci_ini_synth_c0[1][i].eop.read() << std::endl;
-			std::cout << "ram_rspval  = " << signal_vci_ini_synth_c0[1][i].rspval.read() << std::endl;
-			std::cout << "ram_rsrcid  = " << signal_vci_ini_synth_c0[1][i].rsrcid.read() << std::endl;
-			std::cout << "ram_rerror  = " << signal_vci_ini_synth_c0[1][i].rerror.read() << std::endl;
-			std::cout << "ram_reop    = " << signal_vci_ini_synth_c0[1][i].reop.read() << std::endl;
-		}
-		std::cout << "Local_ring ------------------------------------------------" << std::endl;
-		for(int i = 0 ; i < N_CLUSTERS ; i++){
-			local_ring_c0[i].print_trace();
-		}
-		std::cout << "Routers CMD -----------------------------------------------" << std::endl;
+#if defined(DEBUG) 
 		for(int i = 0 ; i < Y_MAX ; i++){
 			for(int j = 0 ; j < X_MAX ; j++){
-				routers_cmd[i][j].printTrace(0);
+#endif
+#if DEBUG==1
+				initiator_c0[i*Y_MAX+j].print_trace();
+				std::cout << std::hex;
+				std::cout << "synt_cmdval  = " << signal_vci_ini_synth_c0[0][i*Y_MAX+j].cmdval.read() << std::endl;
+				std::cout << "synt_cmdack  = " << signal_vci_ini_synth_c0[0][i*Y_MAX+j].cmdack.read() << std::endl;
+				std::cout << "synt_address = " << signal_vci_ini_synth_c0[0][i*Y_MAX+j].address.read() << std::endl;
+				std::cout << "synt_cmd     = " << signal_vci_ini_synth_c0[0][i*Y_MAX+j].cmd.read() << std::endl;
+				std::cout << "synt_srcid   = " << signal_vci_ini_synth_c0[0][i*Y_MAX+j].srcid.read() << std::endl;
+				std::cout << "synt_plen    = " << signal_vci_ini_synth_c0[0][i*Y_MAX+j].plen.read() << std::endl;
+				std::cout << "synt_eop     = " << signal_vci_ini_synth_c0[0][i*Y_MAX+j].eop.read() << std::endl;
+				std::cout << "synt_rspval  = " << signal_vci_ini_synth_c0[0][i*Y_MAX+j].rspval.read() << std::endl;
+				std::cout << "synt_rerror  = " << signal_vci_ini_synth_c0[0][i*Y_MAX+j].rerror.read() << std::endl;
+				std::cout << "synt_reop    = " << signal_vci_ini_synth_c0[0][i*Y_MAX+j].reop.read() << std::endl;
+				ram_c0[i*Y_MAX+j].print_trace();
+				std::cout << std::hex;
+				std::cout << "ram_cmdval  = " << signal_vci_ini_synth_c0[1][i*Y_MAX+j].cmdval.read() << std::endl;
+				std::cout << "ram_address = " << signal_vci_ini_synth_c0[1][i*Y_MAX+j].address.read() << std::endl;
+				std::cout << "ram_cmd     = " << signal_vci_ini_synth_c0[1][i*Y_MAX+j].cmd.read() << std::endl;
+				std::cout << "ram_srcid   = " << signal_vci_ini_synth_c0[1][i*Y_MAX+j].srcid.read() << std::endl;
+				std::cout << "ram_plen    = " << signal_vci_ini_synth_c0[1][i*Y_MAX+j].plen.read() << std::endl;
+				std::cout << "ram_eop     = " << signal_vci_ini_synth_c0[1][i*Y_MAX+j].eop.read() << std::endl;
+				std::cout << "ram_rspval  = " << signal_vci_ini_synth_c0[1][i*Y_MAX+j].rspval.read() << std::endl;
+				std::cout << "ram_rspack  = " << signal_vci_ini_synth_c0[1][i*Y_MAX+j].rspack.read() << std::endl;
+				std::cout << "ram_rsrcid  = " << signal_vci_ini_synth_c0[1][i*Y_MAX+j].rsrcid.read() << std::endl;
+				std::cout << "ram_rerror  = " << signal_vci_ini_synth_c0[1][i*Y_MAX+j].rerror.read() << std::endl;
+				std::cout << "ram_reop    = " << signal_vci_ini_synth_c0[1][i*Y_MAX+j].reop.read() << std::endl;
+#endif
+#if DEBUG==2
+				local_ring_c0[i*Y_MAX+j].print_trace();
+				routers_cmd[i][j].print_trace(0);
+				std::cout << std::dec << t << " ns" << std::endl;
+				routers_rsp[i][j].print_trace(0);
+#endif
+#ifdef DEBUG
 			}
 		}
-		std::cout << "Routers RSP -----------------------------------------------" << std::endl;
-		for(int i = 0 ; i < Y_MAX ; i++){
-			for(int j = 0 ; j < X_MAX ; j++){
-				routers_rsp[i][j].printTrace(0);
-			}
-		}
-
-		//for(int i = 0; i< N_CLUSTERS; i++){
-		//	initiator_c1[i].print_trace();
-		//	std::cout << std::hex;
-		//	std::cout << "synt_cmdval  = " << signal_vci_ini_synth_c1[0][i].cmdval.read() << std::endl;
-		//	std::cout << "synt_address = " << signal_vci_ini_synth_c1[0][i].address.read() << std::endl;
-		//	std::cout << "synt_cmd     = " << signal_vci_ini_synth_c1[0][i].cmd.read() << std::endl;
-		//	std::cout << "synt_srcid   = " << signal_vci_ini_synth_c1[0][i].srcid.read() << std::endl;
-		//	std::cout << "synt_plen    = " << signal_vci_ini_synth_c1[0][i].plen.read() << std::endl;
-		//	std::cout << "synt_eop     = " << signal_vci_ini_synth_c1[0][i].eop.read() << std::endl;
-		//	std::cout << "synt_rspval  = " << signal_vci_ini_synth_c1[0][i].rspval.read() << std::endl;
-		//	std::cout << "synt_rerror  = " << signal_vci_ini_synth_c1[0][i].rerror.read() << std::endl;
-		//	std::cout << "synt_reop    = " << signal_vci_ini_synth_c1[0][i].reop.read() << std::endl;
-		//}
-		//for(int i = 0 ; i < N_CLUSTERS ; i++){
-		//	ram_c1[i].print_trace();
-		//	std::cout << std::hex;
-		//	std::cout << "ram_cmdval  = " << signal_vci_ini_synth_c0[1][i].cmdval.read() << std::endl;
-		//	std::cout << "ram_address = " << signal_vci_ini_synth_c0[1][i].address.read() << std::endl;
-		//	std::cout << "ram_cmd     = " << signal_vci_ini_synth_c0[1][i].cmd.read() << std::endl;
-		//	std::cout << "ram_srcid   = " << signal_vci_ini_synth_c0[1][i].srcid.read() << std::endl;
-		//	std::cout << "ram_plen    = " << signal_vci_ini_synth_c0[1][i].plen.read() << std::endl;
-		//	std::cout << "ram_eop     = " << signal_vci_ini_synth_c0[1][i].eop.read() << std::endl;
-		//	std::cout << "ram_rspval  = " << signal_vci_ini_synth_c0[1][i].rspval.read() << std::endl;
-		//	std::cout << "ram_rerror  = " << signal_vci_ini_synth_c0[1][i].rerror.read() << std::endl;
-		//	std::cout << "ram_reop    = " << signal_vci_ini_synth_c0[1][i].reop.read() << std::endl;
-		//}
+#endif
 		
 	}
+
+	std::cout << "Results : " << std::endl;
+	for(int i = 0 ; i < Y_MAX ; i++){
+		for(int j = 0 ; j < X_MAX ; j++){
+			initiator_c0[i*Y_MAX+j].printStats();
+		}
+	}
+
+
+	std::cout << "Simulation Ends" << std::endl;
+
 
 	return EXIT_SUCCESS;
@@ -455,2 +438,3 @@
 	return 1;
 }
+
