Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Generic/RegisterFile/RegisterFile_Monolithic/SelfTest/src/test.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Generic/RegisterFile/RegisterFile_Monolithic/SelfTest/src/test.cpp	(revision 44)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Generic/RegisterFile/RegisterFile_Monolithic/SelfTest/src/test.cpp	(revision 50)
@@ -7,4 +7,6 @@
  */
 
+#define NB_ITERATION 32
+
 #include "Behavioural/Generic/RegisterFile/RegisterFile_Monolithic/SelfTest/include/test.h"
 #include "Common/include/Test.h"
@@ -31,9 +33,9 @@
     }
 
-  RegisterFile_Monolithic * registerfile = new RegisterFile_Monolithic (name.c_str(),
+  RegisterFile_Monolithic * registerfile = new RegisterFile_Monolithic (name.c_str()
 #ifdef STATISTICS
-									morpheo::behavioural::Parameters_Statistics(5,50),
+									,morpheo::behavioural::Parameters_Statistics(5,1000)
 #endif
-									param);
+									,param);
   
 #ifdef SYSTEMC
@@ -79,9 +81,11 @@
     }
   
+  cout << "<" << name << "> Start Simulation ............" << endl;
+  Time * _time = new Time();
+
   /********************************************************
    * Simulation - Begin
    ********************************************************/
 
-  cout << "<" << name << "> Start Simulation ............" << endl;
   // Initialisation
 
@@ -100,93 +104,106 @@
   NRESET.write(1);
 
-  cout << "<" << name << "> Write the RegisterFile (no read)" << endl;
-
-  uint32_t grain = 0;
-  //uint32_t grain = static_cast<uint32_t>(time(NULL));
-  
-  srand(grain);
-  
-  Tdata_t    data, data_wait;
-  Taddress_t address = 0;
-
-  while (address < param._nb_word)
-    {
-      uint32_t num_port = 0;
-      
-      cout << "cycle : " << static_cast<uint32_t> (sc_simulation_time()) << endl;
-
-      while (num_port<param._nb_port_write)
+
+  for (uint32_t nb_iteration=0; nb_iteration < NB_ITERATION; nb_iteration ++)
+    {
+      cout << "<" << name << "> 1) Write the RegisterFile (no read)" << endl;
+
+      // random init
+      uint32_t grain = 0;
+      //uint32_t grain = static_cast<uint32_t>(time(NULL));
+      
+      srand(grain);
+
+      Tdata_t tab [param._nb_word];
+      
+      for (uint32_t i=0; i<param._nb_word; i++)
+	tab[i]= rand()%(1<<(param._size_word-1));
+      
+      Taddress_t address_next = 0;
+      Taddress_t nb_ack = 0;
+      
+      while (nb_ack < param._nb_word)
 	{
-	  data = rand()%(1<<(param._size_word-1));
-
-	  cout << "(" << num_port << ") [" << address << "] <= " << data << endl;
-	  WRITE_VAL  [num_port] .write(1);
-	  WRITE_DATA    [num_port] .write(data);
-	  WRITE_ADDRESS [num_port] .write(address);
-
-	  address  ++;
-	  num_port ++;
-	  // Address can be not a multiple of nb_port_write
-	  if (address >= param._nb_word)
-	    break;
+	  cout << "cycle : " << static_cast<uint32_t> (sc_simulation_time()) << endl;
+
+	  for (uint32_t num_port=0; num_port < param._nb_port_write; num_port ++)
+	    {
+	      if ((address_next < param._nb_word) and
+		  (WRITE_VAL [num_port].read() == 0))
+		{
+		  cout << "(" << num_port << ") [" << address_next << "] <= " << tab[address_next] << endl;
+		  
+		  WRITE_VAL     [num_port] .write(1);
+		  WRITE_DATA    [num_port] .write(tab[address_next]);
+		  WRITE_ADDRESS [num_port] .write(address_next++);
+		  
+		  // Address can be not a multiple of nb_port_write
+		  if (address_next >= param._nb_word)
+		    break;
+		}
+	    }
+	  
+	  sc_start(1);
+
+	  // reset write_val port
+	  for (uint32_t num_port=0; num_port < param._nb_port_write; num_port ++)
+	    {
+	      if ((WRITE_ACK [num_port].read() == 1) and
+		  (WRITE_VAL [num_port].read() == 1))
+		{
+		  WRITE_VAL  [num_port] .write(0);
+		  nb_ack ++;
+		}
+	    }
+
+	  sc_start(0);
 	}
-
-      while (num_port<param._nb_port_write)
+      
+      address_next = 0;
+      nb_ack       = 0;
+
+      cout << "<" << name << "> 2) Read the RegisterFile (no write)" << endl;
+      
+      Tdata_t read_address [param._nb_port_read];
+
+      while (nb_ack < param._nb_word)
 	{
-	  WRITE_VAL  [num_port] .write(0);
-	  num_port ++;
+	  cout << "cycle : " << static_cast<uint32_t> (sc_simulation_time()) << endl;
+	  
+	  for (uint32_t num_port=0; num_port < param._nb_port_read; num_port ++)
+	    {
+	      if ((address_next < param._nb_word) and
+		  (READ_VAL [num_port].read() == 0))
+		{
+		  read_address [num_port] = address_next++;
+
+		  READ_VAL     [num_port].write(1);
+		  READ_ADDRESS [num_port].write(read_address [num_port]);
+
+		  if (address_next >= param._nb_word)
+		    break;
+		}
+	    }
+
+	  sc_start(1);
+
+	  // reset write_val port
+	  for (uint32_t num_port=0; num_port < param._nb_port_read; num_port ++)
+	    {
+	      if ((READ_ACK [num_port].read() == 1) and
+		  (READ_VAL [num_port].read() == 1))
+		{
+		  READ_VAL  [num_port] .write(0);
+
+		  cout << "(" << num_port << ") [" << read_address [num_port] << "] => " << READ_DATA [num_port].read() << endl;
+
+		  TEST(Tdata_t,READ_DATA [num_port].read(), tab[read_address [num_port]]);
+		  nb_ack ++;
+		}
+	    }
+
+	  sc_start(0);
 	}
-
-      sc_start(1);
-    }
-  cout << "<" << name << "> Read the RegisterFile (no write)" << endl;
-
-  srand(grain);
-
-  for (uint32_t i=0; i<param._nb_port_write; i++)
-    WRITE_VAL [i] .write (0);
-
-  sc_start(1);
-
-  address  = 0;
-  while (address < param._nb_word)
-    {
-      uint32_t num_port = 0;
-
-      cout << "cycle : " << static_cast<uint32_t> (sc_simulation_time()) << endl;
-      
-      while (num_port<param._nb_port_read)
-	{
-	  READ_VAL  [num_port] .write(1);
-	  READ_ADDRESS [num_port] .write(address);
-
-	  sc_start(0); // evaluation
-
-	  data_wait = rand()%(1<<(param._size_word-1));
-	  data      = READ_DATA    [num_port] .read();
-
-	  cout << "(" << num_port << ") [" << address << "] => " << data << endl;
-
-	  TEST(Tdata_t,data,data_wait);
-
-	  address  ++;
-	  num_port ++;
-	  if (address >= param._nb_word)
-	    break;
-	}
-
-      while (num_port<param._nb_port_read)
-	{
-	  READ_VAL  [num_port] .write(0);
-	  num_port ++;
-	}
-
-      sc_start(1);
-    }
-
-  for (uint32_t i=0; i<param._nb_port_read; i++)
-    READ_VAL  [i] .write (0);
-
-  sc_start(1);
+    }
 
   /********************************************************
@@ -194,4 +211,6 @@
    ********************************************************/
 
+  TEST_STR(bool,true,true, "End of Simulation");
+  delete _time;
   cout << "<" << name << "> ............ Stop Simulation" << endl;
 
