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 122)
+++ trunk/modules/vci_synthetic_initator/caba/sources/src/vci_synthetic_initiator.cpp	(revision 123)
@@ -1,7 +1,9 @@
+
 /* -*- c++ -*-
- * File 	: vci_traffic_generator.cpp
- * Date 	: 26/08/2010
+ * File 	: vci_synthetic_initiator.cpp
+ * Date 	: 23/12/2010
  * Copyright 	: UPMC / LIP6
  * Authors 	: Christophe Choichillon
+ * Version	: 2.0
  *
  * SOCLIB_LGPL_HEADER_BEGIN
@@ -82,7 +84,11 @@
     m_date_fifo("m_date_fifo", depth),
     m_local_seed(m_srcid),
-    r_vci_fsm("r_vci_fsm")
+    r_cmd_fsm("r_cmd_fsm")
     {
 
+      r_req_id = new sc_signal<uint64_t>*[tab_size];
+      for(int i = 0; i < tab_size ; i++){
+        r_req_id[i] = new sc_signal<uint64_t>[2];
+      }
 
       SC_METHOD(transition);
@@ -123,15 +129,21 @@
   //////////////////////////////////
   {
-  	const char* state_str[] = { "IDLE",
-				     "SINGLE_SEND",
-				     "SINGLE_RECEIVE",
-				     "BC_SEND",
-				     "BC_RECEIVE" };
+  	const char* state_cmd_str[] = { "IDLE",
+				        "SINGLE_SEND",
+					"BC_SEND"};
+
+	const char* state_bc_rsp_str[] = {"IDLE",
+					  "WAIT_RSP"};
 
 	std::cout << "Vci_Synthetic_Initiator " << name()
 		  << " : " << std::dec << m_cpt_cycles << " cycles " 
-		  << " : state = " << state_str[r_vci_fsm] 
+		  << " : 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 << m_address_to_send 
-		  << " Number of broadcast to receive : " << std::dec << m_bc_nrsp << std::endl;
+		  << " Number of broadcast to receive : " << std::dec << r_bc_nrsp.read() 
+		  << " Number of packets sent : " << std::dec << m_npackets << m_id_to_send << std::endl;
+	for(int i = 0; i < (1<<vci_param::T) ; i++){
+	  std::cout << "ID : " << i << " " << r_req_id[i][0].read() << " " << r_req_id[i][0].read() << std::endl;
+	}
   }
 
@@ -158,5 +170,7 @@
 
       // Initializing FSMs
-      r_vci_fsm = VCI_IDLE;
+      r_cmd_fsm = VCI_IDLE;
+
+      r_bc_rsp_fsm = BC_RSP_IDLE;
 
       // Initializing FIFOs 
@@ -173,6 +187,17 @@
       m_latency_bc		= 0;
       m_nb_bc			= 0;
+      m_id_to_send		= -1;
 
       r_broadcast_req		= false;
+
+      r_broadcast_rsp		= false;
+
+      r_bc_nrsp			= 0;
+
+      for(int i = 0; i < tab_size; i++){
+   	r_req_id[i][0] = 0;
+   	r_req_id[i][1] = 0;
+	//std::cout << name() << " bla bla " << i << std::endl;
+      }
 
       return;
@@ -184,17 +209,28 @@
 
 
-    switch ( r_vci_fsm.read() ) {
-
-  	std::cout << m_cpt_cycles << " cycles, " << m_npackets << " packets sent" << std::endl;
-      //printStats();
+    // FSM controling effective requests send
+    switch ( r_cmd_fsm.read() ) {
       //////////////////
       case VCI_IDLE:
         {
 	  if (m_date_fifo.rok()){
-	    if (r_broadcast_req.read()){
+	    if (r_broadcast_req.read() && !r_broadcast_rsp.read()){
 	      m_address_to_send = 0x3 | (0x7c1f << vci_param::N-20) ;
-	      r_vci_fsm = VCI_BC_SEND ;
+	      r_cmd_fsm = VCI_BC_SEND ;
 	    } else {
-	      r_vci_fsm = VCI_SINGLE_SEND ;
+	      for(int i = 0; i < tab_size; i++){
+	        if(r_req_id[i][0] == 0){
+		  m_id_to_send = i;
+		  break;
+		}else{
+		  m_id_to_send = -1;
+		}
+	      }
+	      if(m_id_to_send == -1){
+	        r_cmd_fsm = VCI_IDLE ;
+		break;
+	      } else {
+	        r_cmd_fsm = VCI_SINGLE_SEND ;
+	      }
 #ifdef DETERMINISTIC
 	      m_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));
@@ -212,9 +248,10 @@
 	  if (p_vci.cmdack.read()){
 	    if (m_count == m_length-1) {
-	      m_start_latency1 = m_date_fifo.read();
-	      m_start_latency2 = m_cpt_cycles;
-	      r_vci_fsm = VCI_SINGLE_RECEIVE ;
+	      r_req_id[(int)m_id_to_send][0] = m_date_fifo.read();
+	      r_req_id[m_id_to_send][1] = m_cpt_cycles;
+	      date_fifo_get = true;
+	      r_cmd_fsm = VCI_IDLE ;
 	    } else {
-	      r_vci_fsm = VCI_SINGLE_SEND ;
+	      r_cmd_fsm = VCI_SINGLE_SEND ;
 	      m_count++;
 	    }
@@ -222,47 +259,57 @@
           break;
         }
-        //////////////////////
-      case VCI_SINGLE_RECEIVE:
+      ///////////////////
+      case VCI_BC_SEND:
         {
 	  if (p_vci.rspval.read()) {
-	    m_latency1 = m_latency1 + (m_cpt_cycles - m_start_latency1);
-	    m_latency2 = m_latency2 + (m_cpt_cycles - m_start_latency2);
-	    m_npackets++;
+	    r_bc_nrsp = (m_xmax - m_xmin) * (m_ymax - m_ymin) ;
+	    m_start_latency_bc = m_cpt_cycles;
 	    date_fifo_get = true;
-	    m_address_to_send = 0;
-	    r_vci_fsm = VCI_IDLE ;
-	  }
-          break;
-        }
-        ///////////////////
-      case VCI_BC_SEND:
-        {
-	  if (p_vci.cmdack.read()) {
-	    m_bc_nrsp = (m_xmax - m_xmin) * (m_ymax - m_ymin) ;
-	    m_start_latency_bc = m_cpt_cycles;
-	    r_vci_fsm = VCI_BC_RECEIVE;
+	    r_broadcast_rsp = true;
+	    r_bc_rsp_fsm = VCI_IDLE;
             break;
 	  }
         }
-        ////////////////////
-      case VCI_BC_RECEIVE:
-        {
-	  if (p_vci.rspval.read()){
-	    if (m_bc_nrsp == 1) {
+
+    } // 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;
 	      m_address_to_send = 0;
-	      date_fifo_get = true;
 	      m_latency_bc = m_latency_bc + (m_cpt_cycles - m_start_latency_bc);
 	      m_nb_bc++;
-	      r_vci_fsm = VCI_IDLE ;
+	      r_bc_rsp_fsm = BC_RSP_IDLE ;
 	    } else {
-	      m_bc_nrsp--;
-	      r_vci_fsm = VCI_BC_RECEIVE ;
+	      r_bc_nrsp = r_bc_nrsp.read() - 1;;
+	      r_bc_rsp_fsm = BC_RSP_WAIT_RSP ;
 	    }
 	  }
           break;
-        }
-    } // end switch vci_fsm
-
+        }    
+    }
+
+    if(p_vci.rspval.read()){
+      if((int)(p_vci.pktid.read()) == 0){
+	m_latency1 = m_latency1 + (m_cpt_cycles - r_req_id[(int)(p_vci.trdid.read())][0]);
+	m_latency2 = m_latency2 + (m_cpt_cycles - r_req_id[(int)(p_vci.trdid.read())][1]);
+	m_npackets++;
+        r_req_id[(int)(p_vci.trdid.read())][0] = 0;
+        r_req_id[(int)(p_vci.trdid.read())][1] = 0;
+      }
+    }
 
     /////////////////// Filling fifo
@@ -305,6 +352,6 @@
      p_vci.cmd        = vci_param::CMD_WRITE;   
      p_vci.be         = 0xF;                             
+     p_vci.srcid      = m_srcid;   
      p_vci.pktid      = 0;      
-     p_vci.srcid      = m_srcid;   
      p_vci.cons       = false;        
      p_vci.wrap       = false;       
@@ -312,7 +359,8 @@
      p_vci.clen       = 0;         
      p_vci.cfixed     = false;           
-
-
-    switch ( r_vci_fsm.read() ) {
+     p_vci.rspack     = true;
+
+
+    switch ( r_cmd_fsm.read() ) {
 
       //////////////////
@@ -325,5 +373,4 @@
 	  p_vci.trdid   = 0;                  
 	  p_vci.eop     = false;                                   
-	  p_vci.rspack  = false;
           break;
         }
@@ -335,5 +382,5 @@
 	  p_vci.plen    = m_length*4;                                         
 	  p_vci.wdata   = 0;                                       
-	  p_vci.trdid   = 0;                  
+	  p_vci.trdid   = m_id_to_send;                  
 	  if (m_count == m_length - 1 ) {
 	    p_vci.eop     = true;                                   
@@ -341,18 +388,5 @@
 	    p_vci.eop     = false;                                   
 	  }
-	  p_vci.rspack  = false;
-          break;
-        }
-        //////////////////////
-      case VCI_SINGLE_RECEIVE:
-        {
-       	  p_vci.cmdval  = false;                 
-	  p_vci.address = 0; 
-	  p_vci.plen    = 0;                                         
-	  p_vci.wdata   = 0;                                       
-	  p_vci.trdid   = 0;                  
-	  p_vci.eop     = false;                                   
-	  p_vci.rspack  = true;
-   	  break;
+          break;
         }
         ///////////////////
@@ -363,22 +397,10 @@
 	  p_vci.plen    = 4;                                         
 	  p_vci.wdata   = 0;                                       
+          p_vci.pktid   = 1;      
 	  p_vci.trdid   = 0;                  
 	  p_vci.eop     = true;                                   
-	  p_vci.rspack  = false;
-          break;
-        }
-        ////////////////////
-      case VCI_BC_RECEIVE:
-        {
-       	  p_vci.cmdval  = false;                 
-	  p_vci.address = 0; 
-	  p_vci.plen    = 0;                                         
-	  p_vci.wdata   = 0;                                       
-	  p_vci.trdid   = 0;                  
-	  p_vci.eop     = false;                                   
-	  p_vci.rspack  = true;
-          break;
-        }
-    } // end switch vci_fsm
+          break;
+        }
+    } // end switch vci_cmd_fsm
 
   } // end genMoore()
