Index: trunk/modules/vci_synthetic_initator/caba/sources/src/vci_synthetic_initiator.cpp
===================================================================
--- trunk/modules/vci_synthetic_initator/caba/sources/src/vci_synthetic_initiator.cpp	(revision 127)
+++ trunk/modules/vci_synthetic_initator/caba/sources/src/vci_synthetic_initiator.cpp	(revision 128)
@@ -52,6 +52,5 @@
       const soclib::common::IntTab       &vci_index,
       const uint32_t length,    // Packet length (flit numbers)
-      const uint32_t rho,       // Packets ratio on the network
-    //  const float  rho,       // Packets ratio on the network
+      const uint32_t rho,       // Offered load * 1000
       const uint32_t depth,     // Fifo depth
       const uint32_t xmesh,	
@@ -82,18 +81,7 @@
     m_ymin(ymin),
     m_ymax(ymax),
-    m_date_fifo("m_date_fifo", depth),
-    r_count           ("r_count"),             
-    r_npackets        ("r_npackets"),		
-    r_start_latency1  ("r_start_latency1"),  
-    r_start_latency2  ("r_start_latency2"),    
-    r_latency1        ("r_latency1"),		 
-    r_latency2        ("r_latency2"),		 
-    r_address_to_send ("r_address_to_send"), 	 
-    r_local_seed      ("r_local_seed"),
-    r_id_to_send      ("r_id_to_send"),
-    r_start_latency_bc("r_start_latency_bc"),
-    r_latency_bc      ("r_latency_bc"),
-    r_nb_bc           ("r_nb_bc"),
-    r_cmd_fsm("r_cmd_fsm"),
+    r_date_fifo("r_date_fifo", depth),
+    r_type_fifo("r_type_fifo", depth),
+    r_cmd_fsm;        ("r_count"),             
     r_bc_rsp_fsm("r_bc_rsp_fsm"),
     r_index("r_index"),
@@ -161,7 +149,7 @@
 		  << " : state_cmd_fsm = " << state_cmd_str[r_cmd_fsm] 
 		  << " : state_rsp_fsm = " << state_bc_rsp_str[r_bc_rsp_fsm] 
-		  << " Adresse to send : " << std::hex << r_address_to_send.read()
+		  << " Adresse to send : " << std::hex << r_cmd_address.read()
 		  << " Number of broadcast to receive : " << std::dec << r_bc_nrsp.read() 
-		  << " Number of packets sent : " << std::dec << r_npackets.read() << " " << r_id_to_send.read() << std::endl;
+		  << " Number of packets sent : " << std::dec << r_nb_single.read() << " " << r_id_to_send.read() << std::endl;
 	for(int i = 0; i < (1<<vci_param::T) ; i++){
 	  std::cout << "ID : " << i << " " << (uint64_t)(r_req_id[i][0].read()) << " " << (uint64_t)(r_req_id[i][1].read()) << std::endl;
@@ -173,6 +161,6 @@
   //////////////////////////////////
   {
-  	std::cout << name() << " : "<< std::dec << m_cpt_cycles << " cycles, " << r_npackets.read() << " packets sent" << std::endl;
-	std::cout << ((double)r_latency1.read()/(double)r_npackets.read()) << " | " << ((double)r_latency2.read()/(double)r_npackets.read()) << std::endl;
+  	std::cout << name() << " : "<< std::dec << m_cpt_cycles << " cycles, " << r_nb_single.read() << " packets sent" << std::endl;
+	std::cout << ((double)r_latency1.read()/(double)r_nb_single.read()) << " | " << ((double)r_latency2.read()/(double)r_nb_single.read()) << std::endl;
 	if(m_bc_period)
 	  std::cout << ((double)r_latency_bc.read()/(double)r_nb_bc.read()) << std::endl;
@@ -184,6 +172,8 @@
   {
     //  RESET          
-    if ( ! p_resetn.read() ) {
+    if ( ! p_resetn.read() ) 
+    {
       // Initializing seed for random numbers generation
+
 #ifndef DETERMINISTIC
       srand(time(NULL));
@@ -192,111 +182,101 @@
       // Initializing FSMs
       r_cmd_fsm = VCI_IDLE;
-
-      r_bc_rsp_fsm = BC_RSP_IDLE;
+      r_bc_fsm = BC_RSP_IDLE;
+      for(size_t i=0 ; i<m_tab_size ; i++) r_pending_fsm[i] = false;
 
       // Initializing FIFOs 
-      m_date_fifo.init();
-
-      // Initializing the stats
-      r_latency1 = 0 ;
-      r_latency2 = 0 ;
-      // Activity counters
-      m_cpt_cycles		= 0;
+      r_date_fifo.init();
+      r_bc_fifo.init();
+
+      // Initializing the instrumentation registers
+      r_latency_single 		= 0 ;
+      r_nb_single		= 0;
+      r_latency_bc 		= 0 ;
+      r_nb_bc			= 0;
+      r_cpt_cycles		= 0;
+      r_cpt_period		= 0;
       
-      r_start_latency_bc	= 0;
-      r_latency_bc		= 0;
-      r_nb_bc			= 0;
-      r_id_to_send		= -1;
-
-      r_broadcast_req		= false;
-
-      r_broadcast_rsp		= false;
-
-      r_bc_nrsp			= 0;
-      r_count            	= 0;        
-      r_npackets         	= 0;	  
-      r_start_latency1   	= 0;        
-      r_start_latency2   	= 0;        
-      r_address_to_send  	= 0; 	  
-      r_local_seed       	= (uint32_t)m_srcid;
-
-      r_latency_bc       	= 0;
-
-      for(int i = 0; i < tab_size; i++){
-   	r_req_id[i][0] = 0;
-   	r_req_id[i][1] = 0;
-      }
+      r_cmd_seed       	= (uint32_t)m_srcid;
 
       return;
     }
 
-    bool    date_fifo_put = false;
-    bool    date_fifo_get = false;
+    bool    fifo_put = false;
+    bool    fifo_get = false;
+    bool    fifo_bc;
 
     uint32_t m_local_seed ;
 
-
-    // FSM controling effective requests send
+    //////////////////
+    // VCI CMD FSM 
+    //////////////////
     switch ( r_cmd_fsm.read() ) {
-      //////////////////
       case VCI_IDLE:
         {
-	  if (m_date_fifo.rok()){
-	    if (r_broadcast_req.read() && !r_broadcast_rsp.read()){
-	      r_address_to_send = 0x3 | (0x7c1f << vci_param::N-20) ;
+	  if (r_date_fifo.rok())
+          {
+	    if ( r_bc_fifo() = true )	// its a broadcast request
+            {
+	      if ( r_bc_fsm.read() = false )	// no current broadcast
+              {
 	      r_cmd_fsm = VCI_BC_SEND ;
-	    } else {
-	      r_id_to_send = -1;
+	      r_cmd_address = 0x3 | (0x7c1f << vci_param::N-20) ;
+              }
+            }
+            else			// its a single request
+            {
+	      int id = -1;
 	      for(int i = 0; i < tab_size; i++){
-	        if(r_req_id[i][0].read() == 0){
-		  r_id_to_send = i;
+	        if(r_pending_fsm[i].read() == false)
+                {
+		  id = i;
 		  break;
 		}
 	      }
-	      if(r_id_to_send.read() == -1){
-	        r_cmd_fsm = VCI_IDLE ;
-		break;
-	      } else {
+	      if(id != -1){
 	        r_cmd_fsm = VCI_SINGLE_SEND ;
+	        r_cmd_count = 0;
+                r_cmd_trdid = id;
 	      }
 #ifdef DETERMINISTIC
-	      m_local_seed = r_local_seed.read();
-	      r_address_to_send = destAdress(&m_local_seed) << (vci_param::N)-(soclib::common::uint32_log2((uint32_t)m_xmesh)+soclib::common::uint32_log2((uint32_t)m_ymesh));
-	      r_local_seed = m_local_seed;
+	      m_local_seed = r_cmd_seed.read();
+	      r_cmd_address = destAdress(&m_local_seed) << (vci_param::N)-(soclib::common::uint32_log2((uint32_t)m_xmesh)+soclib::common::uint32_log2((uint32_t)m_ymesh));
+	      r_cmd_seed = m_local_seed;
 #else
-	      r_address_to_send = destAdress() << (vci_param::N)-(soclib::common::uint32_log2((uint32_t)m_xmesh)+soclib::common::uint32_log2((uint32_t)m_ymesh));
+	      r_cmd_address = destAdress() << (vci_param::N)-(soclib::common::uint32_log2((uint32_t)m_xmesh)+soclib::common::uint32_log2((uint32_t)m_ymesh));
 #endif
-	      r_count = 0;
 	    }
 	  }
           break;
         }
-        //////////////////
       case VCI_SINGLE_SEND:
         {
-	  if (p_vci.cmdack.read()){
-	    if (r_count.read() == m_length-1) {
-	      r_req_id[r_id_to_send.read()][0] = (uint64_t)(m_date_fifo.read());
-	      r_req_id[r_id_to_send.read()][1] = m_cpt_cycles;
-	      //std::cout << name () << " FIFO " << m_date_fifo.read() << std::endl;
-	      date_fifo_get = true;
-	      r_npackets = r_npackets.read() + 1;
-	      r_cmd_fsm = VCI_IDLE ;
-	    } else {
-	      r_cmd_fsm = VCI_SINGLE_SEND ;
-	      r_count = r_count.read() + 1;
+	  if ( p_vci.cmdack.read())
+          {
+	    r_count = r_count.read() + 1;
+	    if (r_cmd_count.read() == m_length-1) 
+            {
+	      r_nb_single = r_nb_single.read() + 1;
+	      r_cmd_fsm = VCI_SINGLE_REGISTER ;
 	    }
 	  }
           break;
         }
-      ///////////////////
+      case VCI_SINGLE_REGISTER:
+        {
+	  r_pending_date[r_cmd_trdid.read()] = (uint64_t)(m_date_fifo.read());
+          r_pending_fsm[r_cmd_trdid.read()] = true;
+          fifo_get = true;
+	  r_cmd_fsm = VCI_IDLE;
+        }
       case VCI_BC_SEND:
         {
-	  if (p_vci.rspval.read()) {
+	  if (p_vci.cmdack.read()) 
+          {
+	    r_bc_fsm = true;
 	    r_bc_nrsp = (m_xmax - m_xmin) * (m_ymax - m_ymin) ;
-	    r_start_latency_bc = m_cpt_cycles;
-	    r_broadcast_rsp = true;
-	    date_fifo_get = true;
-	    r_bc_rsp_fsm = VCI_IDLE;
+	    r_bc_date = (uint64_t)(m_date_fifo.read());
+	    fifo_get = true;
+	    r_cmd_fsm = VCI_IDLE;
             break;
 	  }
@@ -304,68 +284,71 @@
     } // end switch vci_fsm
 
-    switch(r_bc_rsp_fsm.read()){
-      ///////////////////
-      case BC_RSP_IDLE:
-        {
-	  if (p_vci.rspval.read() && r_broadcast_rsp.read()) {
-	    r_bc_rsp_fsm = BC_RSP_WAIT_RSP;
-            break;
-	  }
-        }
-      ////////////////////
-      case BC_RSP_WAIT_RSP:
-        {
-	  if (p_vci.rspval.read() && (p_vci.rpktid.read() == 1)){
-	    if (r_bc_nrsp == 1) {
-	      r_broadcast_req = false;
-	      r_broadcast_rsp = false;
-	      //r_address_to_send.read() = 0;
-	      r_latency_bc = r_latency_bc.read() + (m_cpt_cycles - r_start_latency_bc.read());
-	      r_nb_bc = r_nb_bc.read() + 1;
-	      r_bc_rsp_fsm = BC_RSP_IDLE ;
-	    } else {
-	      r_bc_nrsp = r_bc_nrsp.read() - 1;;
-	      r_bc_rsp_fsm = BC_RSP_WAIT_RSP ;
-	    }
-	  }
-          break;
-        }    
-    }
-
-    if(p_vci.rspval.read()){
-      if((int)(p_vci.pktid.read()) == 0){
-	r_latency1 = r_latency1.read() + (m_cpt_cycles - r_req_id[(int)(p_vci.rtrdid.read())][0].read());
-	r_latency2 = r_latency2.read() + (m_cpt_cycles - r_req_id[(int)(p_vci.rtrdid.read())][1].read());
-        r_req_id[(int)(p_vci.rtrdid.read())][0] = 0;
-        r_req_id[(int)(p_vci.rtrdid.read())][1] = 0;
-	//std::cout << name() << " bla bla " << p_vci.rtrdid.read() << std::endl;
+    /////////////////////
+    // BC_FSM
+    /////////////////////
+    if ( r_bc_fsm.read() && p_vci.rspval.read() ) 
+    {
+      if ( p_vci.rpktid.read() == 1 ) r_bc_nrsp = r_bc_nrsp.read() - 1; 
+      if (r_bc_nrsp == 1)
+      {
+	r_bc_fsm = false;
+        r_latency_bc = r_latency_bc.read() + (r_cpt_cycle.read() - r_bc_date.read());
       }
     }
 
-    /////////////////// Filling fifo
-    if( ( (uint64_t)(m_rho*m_cpt_cycles) > (uint64_t)(m_length*r_npackets.read()*1000)) ){
-      if (m_date_fifo.wok()){
-        date_fifo_put = true ;
-      } 
-      if (m_bc_period){
-	      if (!r_broadcast_req.read() && (m_cpt_cycles % m_bc_period)){
-		      r_broadcast_req = true;
-	      }
+    ///////////////////
+    // PENDING FSMs
+    //////////////////
+    if(p_vci.rspval.read())i
+    {
+      if((int)(p_vci.pktid.read()) == 0)	// not a broadcast
+      {
+        assert( ( r_pending_fsm[(int)p_vci.rtrdid.read()] == true ) && 
+                "illegal single response received")
+        r_pending_fsm[p_vci.rtrdid.read()] = false;
+	r_latency_single = r_latency_single.read() + 
+                           (r_cpt_cycles.read() - r_pending_date[(int)p_vci.rtrdid.read()].read());
       }
     }
 
+    ////////////////////////
+    //  traffic regulator
+    ////////////////////////
+    if ( m_bc_period && (r_cpt_period.read() > m_bc_period) )
+    { 
+      fifo_put = true ;
+      fifo_bc  = true;
+      if (r_date_fifo.wok())   r_nb_bc = r_nb_bc.read() + 1;
+    }
+    else if( ( (uint64_t)(m_rho*r_cpt_cycles.read()) > (uint64_t)(m_length*r_nb_single.read()*1000)) )
+    {
+      fifo_put = true ;
+      fifo_bc  = false;
+      if (r_date_fifo.wok())   r_nb_single = r_nb_single.read() + 1;
+    }
+
+    ////////////////////////
+    //  update fifos
+    ////////////////////////
     if (date_fifo_put){
       if (date_fifo_get){
-        m_date_fifo.put_and_get(m_cpt_cycles);
+        r_date_fifo.put_and_get(r_cpt_cycles.read());
+        r_bc_fifo.put_and_get(fifo_bc);
       } else {
-        m_date_fifo.simple_put(m_cpt_cycles);
+        r_date_fifo.simple_put(m_cpt_cycles);
+        r_bc_fifo.simple_put(fifo_bc);
       }
     } else {
       if (date_fifo_get){
-        m_date_fifo.simple_get();
+        r_date_fifo.simple_get();
+        r_bc_fifo.simple_get();
       }
     }
    
-    m_cpt_cycles++;
+    ///////////////////////////
+    //  increment local time
+    ///////////////////////////
+    r_cpt_cycles = r_cpt_cycles.read() + 1;
+    r_cpt_period = r_cpt_period.read() + 1;
 
     return;
@@ -375,5 +358,5 @@
   /////////////////////////////
   tmpl(void)::genMoore()
-    /////////////////////////////
+  /////////////////////////////
   {
     ////////////////////////////////////////////////////////////
@@ -409,5 +392,5 @@
         {
 	  p_vci.cmdval  = true;                 
-	  p_vci.address = (addr_t)(r_address_to_send.read() + (r_count.read()*4)); 
+	  p_vci.address = (addr_t)(r_cmd_address.read() + (r_count.read()*4)); 
 	  p_vci.plen    = m_length*4;                                         
 	  p_vci.wdata   = 0;                                       
@@ -424,5 +407,5 @@
         {
        	  p_vci.cmdval  = true;                 
-	  p_vci.address = (addr_t) r_address_to_send.read(); 
+	  p_vci.address = (addr_t) r_cmd_address.read(); 
 	  p_vci.plen    = 4;                                         
 	  p_vci.wdata   = 0;                                       
