Index: trunk/platforms/caba-vdspin-vci_synthetic_initiator/top.cpp
===================================================================
--- trunk/platforms/caba-vdspin-vci_synthetic_initiator/top.cpp	(revision 97)
+++ trunk/platforms/caba-vdspin-vci_synthetic_initiator/top.cpp	(revision 99)
@@ -8,9 +8,8 @@
 #include "mapping_table.h"
 #include "alloc_elems.h"
-#include "vci_simple_ram.h"
-#include "vci_multi_tty.h"
-#include "vci_local_ring_network.h"
-#include "vci_simple_ring_network.h"
-#include "virtual_dspin_network.h"
+//#include "vci_simple_ram.h"
+//#include "vci_multi_tty.h"
+#include "vci_local_ring_fast.h"
+#include "virtual_dspin_router.h"
 #include "vci_synthetic_initiator.h"
 
@@ -37,4 +36,6 @@
 	using soclib::common::Segment;
 
+	using soclib::common::uint32_log2;
+
 	// Define VCI parameters
 	typedef soclib::caba::VciParams<4,8,32,1,1,1,8,4,4,1> vci_param;
@@ -44,7 +45,4 @@
 	soclib::common::MappingTable maptab(32, IntTab(2,10), IntTab(2,3), 0x00C00000);
 
-	maptab.add(Segment("reset", RESET_BASE, RESET_SIZE, IntTab(2,1), true));
-	maptab.add(Segment("excep", EXCEP_BASE, EXCEP_SIZE, IntTab(2,1), true));
-	maptab.add(Segment("tty"  , TTY_BASE  , TTY_SIZE  , IntTab(3,1), false));
 
 	maptab.add(Segment("mc_r0" , MC0_R_BASE , MC0_R_SIZE , IntTab(0,0), false, true, IntTab(0,0)));
@@ -64,14 +62,26 @@
 	sc_signal<bool> signal_resetn("resetn");
    
-	soclib::caba::VciSignals<vci_param> * signal_vci_ini_synth = soclib::common::alloc_elems<soclib::caba::VciSignals<vci_param> >("signal_vci_ini_synth", N_CLUSTERS);
-	soclib::caba::DspinSignals<WIDTH_CMD> **** dspin_signals_cmd_c0 = soclib::common::alloc_elems<solib::caba::DspinSignals<WIDTH_CMD> >("Dspin_cmd_signals", 2, Y_MAX, X_MAX, 5 );
-	soclib::caba::DspinSignals<WIDTH_CMD> **** dspin_signals_cmd_c1 = soclib::common::alloc_elems<solib::caba::DspinSignals<WIDTH_CMD> >("Dspin_cmd_signals", 2, Y_MAX, X_MAX, 5 );
+	soclib::caba::VciSignals<vci_param> * signal_vci_ini_synth_c0 = soclib::common::alloc_elems<soclib::caba::VciSignals<vci_param> >("signal_vci_ini_synth", N_CLUSTERS);
+	soclib::caba::VciSignals<vci_param> * signal_vci_ini_synth_c1 = soclib::common::alloc_elems<soclib::caba::VciSignals<vci_param> >("signal_vci_ini_synth", N_CLUSTERS);
+	///////////////////////////////////////////////////////////////
+	// VDSPIN Signals : one level for in and out, one level for X length in the mesh, 
+	//                  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<solib::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<solib::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<solib::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<solib::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);
 
 	// N_CLUSTERS ring.
-	soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> * local_ring = (soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> *) malloc(sizeof(soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> ) * N_CLUSTERS) ;
+	soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> * local_ring_c0 = (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
-		new(&local_ring[i]) soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> ("cluster" + i,maptab, IntTab(i), 2, 18, 1, 1)
+		new(&local_ring_c0[i]) soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> ("cluster_c0" + i,maptab, IntTab(i), 2, 18, 1, 1)
+	}
+
+	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
+		new(&local_ring_c1[i]) soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> ("cluster_c1" + i,maptab, IntTab(i), 2, 18, 1, 1)
 	}
 
@@ -95,8 +105,13 @@
 
 	// N_CLUSTERS VCI Synthetic Initiator (1 initiator per cluster/network)
-	soclib::caba::VciSyntheticInitiator<vci_param> * initiator = (soclib::caba::VciSyntheticInitiator<vci_param> *) malloc(sizeof(soclib::caba::VciSyntheticInitiator<vci_param> )* N_CLUSTERS);
+	soclib::caba::VciSyntheticInitiator<vci_param> * initiator_c0 = (soclib::caba::VciSyntheticInitiator<vci_param> *) malloc(sizeof(soclib::caba::VciSyntheticInitiator<vci_param> )* N_CLUSTERS);
 	for(int i = 0 ; i < Y_MAX; i++)
 		for(int j = 0 ; j < Y_MAX ; j++)
-			new(&initiator[Y_MAX*i+j]) soclib::caba::VciSyntheticInitiator<vci_param> ("Initiator" + (Y_MAX*i+j), Y_MAX*i+j, maptab, IntTab(i,j),);
+			new(&initiator_c0[Y_MAX*i+j]) soclib::caba::VciSyntheticInitiator<vci_param> ("Initiator_c0" + (i*X_MAX+j), i*X_MAX+j, maptab, IntTab(i,j),16, 0.5, 2, X_MAX, Y_MAX);
+
+	soclib::caba::VciSyntheticInitiator<vci_param> * initiator_c1 = (soclib::caba::VciSyntheticInitiator<vci_param> *) malloc(sizeof(soclib::caba::VciSyntheticInitiator<vci_param> )* N_CLUSTERS);
+	for(int i = 0 ; i < Y_MAX; i++)
+		for(int j = 0 ; j < Y_MAX ; j++)
+			new(&initiator_c1[Y_MAX*i+j]) soclib::caba::VciSyntheticInitiator<vci_param> ("Initiator_c1" + (i*X_MAX+j), i*X_MAX+j, maptab, IntTab(i,j),16, 0.5, 2, X_MAX, Y_MAX);
 
 	///////////////////////////////////////////////////////////////
@@ -104,14 +119,21 @@
 	///////////////////////////////////////////////////////////////
 	for(int i = 0 ; i < N_CLUSTERS ; i++){
-	  local_ring[i].p_clk(signal_clk);
-	  local_ring[i].p_resetn(signal_resetn);
-	  local_ring[i].p_to_initiator[0](signal_vci_ini_synth[i]);
-	  initiator[i].p_clk(signal_clk);
-	  initiator[i].p_resetn(signal_resetn);
-	  initiator[i].p_vci(signal_vci_ini_synth[i]);
+	  local_ring_c0[i].p_clk(signal_clk);
+	  local_ring_c0[i].p_resetn(signal_resetn);
+	  local_ring_c0[i].p_to_initiator[0](signal_vci_ini_synt_c0h[i]);
+	  initiator_c0[i].p_clk(signal_clk);
+	  initiator_c0[i].p_resetn(signal_resetn);
+	  initiator_c0[i].p_vci(signal_vci_ini_synth_c0[i]);
+	  local_ring_c1[i].p_clk(signal_clk);
+	  local_ring_c1[i].p_resetn(signal_resetn);
+	  local_ring_c1[i].p_to_initiator[0](signal_vci_ini_synth_c1[i]);
+	  initiator_c1[i].p_clk(signal_clk);
+	  initiator_c1[i].p_resetn(signal_resetn);
+	  initiator_c1[i].p_vci(signal_vci_ini_synth_c1[i]);
 	}
 	
 	///////////////////////////////////////////////////////////////
-	// Connection of each VDspin Router to each local ring 
+	// Connection of each VDspin Router to each local ring and 
+	// neighbors VDspin Router
 	///////////////////////////////////////////////////////////////
 	for(int i = 0; i < Y_MAX ; i++){
@@ -119,4 +141,14 @@
 	    routers_cmd[i][j].p_clk(signal_clk);
 	    routers_cmd[i][j].p_resetn(signal_resetn);
+	    routers_rsp[i][j].p_clk(signal_clk);
+	    routers_rsp[i][j].p_resetn(signal_resetn);
+	    local_ring_c0[i*X_MAX+j].p_gate_cmd_in( dspin_signals_cmd_c0[0][i][j][LOCAL]);
+	    local_ring_c0[i*X_MAX+j].p_gate_cmd_out(dspin_signals_cmd_c0[1][i][j][LOCAL] );
+	    local_ring_c0[i*X_MAX+j].p_gate_rsp_in( dspin_signals_rsp_c0[0][i][j][LOCAL]);
+	    local_ring_c0[i*X_MAX+j].p_gate_rsp_out(dspin_signals_rsp_c0[1][i][j][LOCAL] );
+	    local_ring_c1[i*X_MAX+j].p_gate_cmd_in( dspin_signals_cmd_c1[0][i][j][LOCAL]);
+	    local_ring_c1[i*X_MAX+j].p_gate_cmd_out(dspin_signals_cmd_c1[1][i][j][LOCAL] );
+	    local_ring_c1[i*X_MAX+j].p_gate_rsp_in( dspin_signals_rsp_c1[0][i][j][LOCAL]);
+	    local_ring_c1[i*X_MAX+j].p_gate_rsp_out(dspin_signals_rsp_c1[1][i][j][LOCAL] );
 	    for(k = 0; k < 5; k++){
 	      if(i == 0){
@@ -126,13 +158,69 @@
 		  routers_cmd[i][j].p_in[0][k](dspin_signals_cmd_c0[1][i][j][k]);
 		  routers_cmd[i][j].p_in[1][k](dspin_signals_cmd_c1[1][i][j][k]);
-		  routers_rsp[i][j].p_out[0][k](dspin_signals_cmd_c0[0][i][j][k]);
-		  routers_rsp[i][j].p_out[1][k](dspin_signals_cmd_c1[0][i][j][k]);
-		  routers_rsp[i][j].p_in[0][k](dspin_signals_cmd_c0[1][i][j][k]);
-		  routers_rsp[i][j].p_in[1][k](dspin_signals_cmd_c1[1][i][j][k]);
+		  routers_rsp[i][j].p_out[0][k](dspin_signals_rsp_c0[0][i][j][k]);
+		  routers_rsp[i][j].p_out[1][k](dspin_signals_rsp_c1[0][i][j][k]);
+		  routers_rsp[i][j].p_in[0][k](dspin_signals_rsp_c0[1][i][j][k]);
+		  routers_rsp[i][j].p_in[1][k](dspin_signals_rsp_c1[1][i][j][k]);
 		} else {
-		  
+		  if(k == WEST){
+		 	routers_cmd[i][j].p_out[0][k](dspin_signals_cmd_c0[1][i][j-1][EAST]);
+		 	routers_cmd[i][j].p_out[1][k](dspin_signals_cmd_c1[1][i][j-1][EAST]);
+		 	routers_cmd[i][j].p_in[0][k](dspin_signals_cmd_c0[0][i][j-1][EAST]);
+		 	routers_cmd[i][j].p_in[1][k](dspin_signals_cmd_c1[0][i][j-1][EAST]);
+		 	routers_rsp[i][j].p_out[0][k](dspin_signals_rsp_c0[1][i][j-1][EAST]);
+		 	routers_rsp[i][j].p_out[1][k](dspin_signals_rsp_c1[1][i][j-1][EAST]);
+		 	routers_rsp[i][j].p_in[0][k](dspin_signals_rsp_c0[0][i][j-1][EAST]);
+		 	routers_rsp[i][j].p_in[1][k](dspin_signals_rsp_c1[0][i][j-1][EAST]);
+		  } else {
+		 	routers_cmd[i][j].p_out[0][k](dspin_signals_cmd_c0[0][i][j][k]);
+		 	routers_cmd[i][j].p_out[1][k](dspin_signals_cmd_c1[0][i][j][k]);
+		 	routers_cmd[i][j].p_in[0][k](dspin_signals_cmd_c0[1][i][j][k]);
+		 	routers_cmd[i][j].p_in[1][k](dspin_signals_cmd_c1[1][i][j][k]);
+		 	routers_rsp[i][j].p_out[0][k](dspin_signals_rsp_c0[0][i][j][k]);
+		 	routers_rsp[i][j].p_out[1][k](dspin_signals_rsp_c1[0][i][j][k]);
+		 	routers_rsp[i][j].p_in[0][k](dspin_signals_rsp_c0[1][i][j][k]);
+		 	routers_rsp[i][j].p_in[1][k](dspin_signals_rsp_c1[1][i][j][k]);
+		  }
 		}
 	      } else {
-	      
+		if(k == SOUTH){
+		 	routers_cmd[i][j].p_out[0][k](dspin_signals_cmd_c0[1][i-1][j][NORTH]);
+		 	routers_cmd[i][j].p_out[1][k](dspin_signals_cmd_c1[1][i-1][j][NORTH]);
+		 	routers_cmd[i][j].p_in[0][k](dspin_signals_cmd_c0[0][i-1][j][NORTH]);
+		 	routers_cmd[i][j].p_in[1][k](dspin_signals_cmd_c1[0][i-1][j][NORTH]);
+		 	routers_rsp[i][j].p_out[0][k](dspin_signals_rsp_c0[1][i-1][j][NORTH]);
+		 	routers_rsp[i][j].p_out[1][k](dspin_signals_rsp_c1[1][i-1][j][NORTH]);
+		 	routers_rsp[i][j].p_in[0][k](dspin_signals_rsp_c0[0][i-1][j][NORTH]);
+		 	routers_rsp[i][j].p_in[1][k](dspin_signals_rsp_c1[0][i-1][j][NORTH]);
+		} else if(k == WEST){
+		   if(j == 0){
+		 	routers_cmd[i][j].p_out[0][k](dspin_signals_cmd_c0[0][i][j][k]);
+		 	routers_cmd[i][j].p_out[1][k](dspin_signals_cmd_c1[0][i][j][k]);
+		 	routers_cmd[i][j].p_in[0][k](dspin_signals_cmd_c0[1][i][j][k]);
+		 	routers_cmd[i][j].p_in[1][k](dspin_signals_cmd_c1[1][i][j][k]);
+		 	routers_rsp[i][j].p_out[0][k](dspin_signals_rsp_c0[0][i][j][k]);
+		 	routers_rsp[i][j].p_out[1][k](dspin_signals_rsp_c1[0][i][j][k]);
+		 	routers_rsp[i][j].p_in[0][k](dspin_signals_rsp_c0[1][i][j][k]);
+		 	routers_rsp[i][j].p_in[1][k](dspin_signals_rsp_c1[1][i][j][k]);
+		   } else {
+		 	routers_cmd[i][j].p_out[0][k](dspin_signals_cmd_c0[1][i][j-1][EAST]);
+		 	routers_cmd[i][j].p_out[1][k](dspin_signals_cmd_c1[1][i][j-1][EAST]);
+		 	routers_cmd[i][j].p_in[0][k](dspin_signals_cmd_c0[0][i][j-1][EAST]);
+		 	routers_cmd[i][j].p_in[1][k](dspin_signals_cmd_c1[0][i][j-1][EAST]);
+		 	routers_rsp[i][j].p_out[0][k](dspin_signals_rsp_c0[1][i][j-1][EAST]);
+		 	routers_rsp[i][j].p_out[1][k](dspin_signals_rsp_c1[1][i][j-1][EAST]);
+		 	routers_rsp[i][j].p_in[0][k](dspin_signals_rsp_c0[0][i][j-1][EAST]);
+		 	routers_rsp[i][j].p_in[1][k](dspin_signals_rsp_c1[0][i][j-1][EAST]);
+		   }
+		} else {
+		 	routers_cmd[i][j].p_out[0][k](dspin_signals_cmd_c0[0][i][j][k]);
+		 	routers_cmd[i][j].p_out[1][k](dspin_signals_cmd_c1[0][i][j][k]);
+		 	routers_cmd[i][j].p_in[0][k](dspin_signals_cmd_c0[1][i][j][k]);
+		 	routers_cmd[i][j].p_in[1][k](dspin_signals_cmd_c1[1][i][j][k]);
+		 	routers_rsp[i][j].p_out[0][k](dspin_signals_rsp_c0[0][i][j][k]);
+		 	routers_rsp[i][j].p_out[1][k](dspin_signals_rsp_c1[0][i][j][k]);
+		 	routers_rsp[i][j].p_in[0][k](dspin_signals_rsp_c0[1][i][j][k]);
+		 	routers_rsp[i][j].p_in[1][k](dspin_signals_rsp_c1[1][i][j][k]);
+		}
 	      }
 	    }
