Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Generic/RegisterFile/RegisterFile_Multi_Banked/RegisterFile_Multi_Banked_Glue/SelfTest/src/main.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Generic/RegisterFile/RegisterFile_Multi_Banked/RegisterFile_Multi_Banked_Glue/SelfTest/src/main.cpp	(revision 10)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Generic/RegisterFile/RegisterFile_Multi_Banked/RegisterFile_Multi_Banked_Glue/SelfTest/src/main.cpp	(revision 15)
@@ -6,5 +6,5 @@
  */
 
-#include "Behavioural/Generic/RegisterFile_Multi_Banked/RegisterFile_Multi_Banked_Glue/SelfTest/include/test.h"
+#include "Behavioural/Generic/RegisterFile/RegisterFile_Multi_Banked/RegisterFile_Multi_Banked_Glue/SelfTest/include/test.h"
 
 #define NB_PARAMS 5
@@ -14,9 +14,12 @@
   cerr << "<Usage> " << argv[0] << " name_instance list_params" << endl
        << "list_params is :" << endl
-       << " - nb_port_read  (unsigned int)" << endl
-       << " - nb_port_write (unsigned int)" << endl
-       << " - size_address  (unsigned int)" << endl
-       << " - size_word     (unsigned int)" << endl
-       << " - nb_bank       (unsigned int)" << endl
+       << " - nb_port_read          (uint32_t   )" << endl
+       << " - nb_port_write         (uint32_t   )" << endl
+       << " - size_address          (uint32_t   )" << endl
+       << " - size_word             (uint32_t   )" << endl
+       << " - nb_bank               (uint32_t   )" << endl
+       << " - nb_port_read_by_bank  (uint32_t   )" << endl
+       << " - nb_port_write_by_bank (uint32_t   )" << endl
+       << " - crossbar              (Tcrossbar_t)" << endl
        << "" << endl;
 
@@ -37,19 +40,25 @@
     usage (argc, argv);
 
-  const string   name          = argv[1];
-  const uint32_t nb_port_read  = atoi(argv[2]);
-  const uint32_t nb_port_write = atoi(argv[3]);
-  const uint32_t size_address  = atoi(argv[4]);
-  const uint32_t size_word     = atoi(argv[5]);
-  const uint32_t nb_bank       = atoi(argv[6]);
+  const string      name                  =      argv[1];
+  const uint32_t    nb_port_read          = atoi(argv[2]);
+  const uint32_t    nb_port_write         = atoi(argv[3]);
+  const uint32_t    size_address          = atoi(argv[4]);
+  const uint32_t    size_word             = atoi(argv[5]);
+  const uint32_t    nb_bank               = atoi(argv[6]);
+  const uint32_t    nb_port_read_by_bank  = atoi(argv[7]);
+  const uint32_t    nb_port_write_by_bank = atoi(argv[8]);
+  const Tcrossbar_t crossbar              = fromString<Tcrossbar_t>(argv[9]);
 
   try 
     {
-      morpheo::behavioural::generic::registerfile_multi_banked::registerfile_multi_banked_glue::Parameters param (nb_port_read ,
-														  nb_port_write,
-														  size_address ,
-														  size_word    ,
-														  nb_bank      );
-      
+      morpheo::behavioural::generic::registerfile::registerfile_multi_banked::registerfile_multi_banked_glue::Parameters param (nb_port_read         ,
+																nb_port_write        ,
+																size_address         ,
+																size_word            ,
+																nb_bank              ,
+																nb_port_read_by_bank ,
+																nb_port_write_by_bank,
+																crossbar             );
+
       cout << param.print(1);
       
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Generic/RegisterFile/RegisterFile_Multi_Banked/RegisterFile_Multi_Banked_Glue/SelfTest/src/test.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Generic/RegisterFile/RegisterFile_Multi_Banked/RegisterFile_Multi_Banked_Glue/SelfTest/src/test.cpp	(revision 10)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Generic/RegisterFile/RegisterFile_Multi_Banked/RegisterFile_Multi_Banked_Glue/SelfTest/src/test.cpp	(revision 15)
@@ -7,11 +7,14 @@
  */
 
-#define NB_ITERATION 1
-
-#include "Behavioural/Generic/RegisterFile_Multi_Banked/RegisterFile_Multi_Banked_Glue/SelfTest/include/test.h"
+#define NB_ITERATION 16
+
+#define LABEL(str) do {cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} " << str << endl; _RegisterFile_Multi_Banked_Glue->vhdl_testbench_label(str);} while (0)
+
+#include "Behavioural/Generic/RegisterFile/RegisterFile_Multi_Banked/RegisterFile_Multi_Banked_Glue/SelfTest/include/test.h"
 #include "Include/Test.h"
+#include "Include/BitManipulation.h"
 
 void test (string name,
-	   morpheo::behavioural::generic::registerfile_multi_banked::registerfile_multi_banked_glue::Parameters _param)
+	   morpheo::behavioural::generic::registerfile::registerfile_multi_banked::registerfile_multi_banked_glue::Parameters _param)
 {
   cout << "<" << name << "> : Simulation SystemC" << endl;
@@ -19,7 +22,7 @@
   RegisterFile_Multi_Banked_Glue * _RegisterFile_Multi_Banked_Glue = new RegisterFile_Multi_Banked_Glue (name.c_str(),
 #ifdef STATISTICS
-					     morpheo::behavioural::Parameters_Statistics(5,50),
+													 morpheo::behavioural::Parameters_Statistics(5,50),
 #endif
-					     _param);
+													 _param);
   
 #ifdef SYSTEMC
@@ -33,6 +36,6 @@
   sc_signal<Taddress_t>                 ** READ_IN_ADDRESS   ;
   sc_signal<Tdata_t   >                 ** READ_IN_DATA      ;
-  sc_signal<Tcontrol_t>                 ** READ_SELECT_VAL   ;
-  sc_signal<Tcontrol_t>                 ** READ_SELECT_ACK   ;
+  sc_signal<Tcontrol_t>               **** READ_SELECT_VAL   ;
+  sc_signal<Tcontrol_t>               **** READ_SELECT_ACK   ;
   sc_signal<Tcontrol_t>                *** READ_OUT_VAL      ;
   sc_signal<Tcontrol_t>                *** READ_OUT_ACK      ;
@@ -41,8 +44,8 @@
   sc_signal<Tcontrol_t>                 ** WRITE_IN_VAL      ;
   sc_signal<Tcontrol_t>                 ** WRITE_IN_ACK      ;
-  sc_signal<Tcontrol_t>                 ** WRITE_SELECT_VAL  ;
-  sc_signal<Tcontrol_t>                 ** WRITE_SELECT_ACK  ;
   sc_signal<Taddress_t>                 ** WRITE_IN_ADDRESS  ;
   sc_signal<Tdata_t   >                 ** WRITE_IN_DATA     ;
+  sc_signal<Tcontrol_t>               **** WRITE_SELECT_VAL  ;
+  sc_signal<Tcontrol_t>               **** WRITE_SELECT_ACK  ;
   sc_signal<Tcontrol_t>                *** WRITE_OUT_VAL     ;
   sc_signal<Tcontrol_t>                *** WRITE_OUT_ACK     ;
@@ -58,6 +61,4 @@
   READ_IN_ADDRESS   = new sc_signal<Taddress_t>           * [_param._nb_port_read];
   READ_IN_DATA      = new sc_signal<Tdata_t   >           * [_param._nb_port_read];
-  READ_SELECT_VAL   = new sc_signal<Tcontrol_t>           * [_param._nb_port_read];
-  READ_SELECT_ACK   = new sc_signal<Tcontrol_t>           * [_param._nb_port_read];
 
   for (uint32_t i=0; i<_param._nb_port_read; i++)
@@ -71,9 +72,29 @@
       rename = "READ_IN_DATA_"+toString(i)+"     ";
       READ_IN_DATA      [i] = new sc_signal<Tdata_t   > (rename.c_str());
-      rename = "READ_SELECT_VAL_"+toString(i)+"  ";
-      READ_SELECT_VAL       [i] = new sc_signal<Tcontrol_t> (rename.c_str());
-      rename = "READ_SELECT_ACK_"+toString(i)+"  ";
-      READ_SELECT_ACK       [i] = new sc_signal<Tcontrol_t> (rename.c_str());
-    }
+    }
+
+   READ_SELECT_VAL  = new sc_signal<Tcontrol_t> *** [_param._nb_bank];
+   READ_SELECT_ACK  = new sc_signal<Tcontrol_t> *** [_param._nb_bank];
+
+    for (uint32_t i=0; i<_param._nb_bank; i++)
+      {
+	READ_SELECT_VAL [i] = new sc_signal<Tcontrol_t>  ** [_param._nb_port_read_by_bank];
+	READ_SELECT_ACK [i] = new sc_signal<Tcontrol_t>  ** [_param._nb_port_read_by_bank];
+
+	 for (uint32_t j=0; j<_param._nb_port_read_by_bank; j++)
+	   {
+	     READ_SELECT_VAL [i][j] = new sc_signal<Tcontrol_t>   * [_param._nb_port_select_by_bank_read_port [j]];
+	     READ_SELECT_ACK [i][j] = new sc_signal<Tcontrol_t>   * [_param._nb_port_select_by_bank_read_port [j]];
+	     
+	     for (uint32_t k=0; k<_param._nb_port_select_by_bank_read_port [j]; k++)
+	       {
+		 rename="READ_SELECT_VAL_"+toString(i)+"_"+toString(j)+"_"+toString(k)+" ";
+		 READ_SELECT_VAL [i][j][k] = new sc_signal<Tcontrol_t> (rename.c_str());
+		 
+		 rename="READ_SELECT_ACK_"+toString(i)+"_"+toString(j)+"_"+toString(k)+" ";
+		 READ_SELECT_ACK [i][j][k] = new sc_signal<Tcontrol_t> (rename.c_str());
+	       }
+	   }
+      }
    						      
    READ_OUT_VAL      = new sc_signal<Tcontrol_t>          ** [_param._nb_bank];
@@ -106,7 +127,4 @@
    WRITE_IN_ADDRESS  = new sc_signal<Taddress_t>           * [_param._nb_port_write];
    WRITE_IN_DATA     = new sc_signal<Tdata_t   >           * [_param._nb_port_write];
-   WRITE_SELECT_VAL  = new sc_signal<Tcontrol_t>           * [_param._nb_port_write];
-   WRITE_SELECT_ACK  = new sc_signal<Tcontrol_t>           * [_param._nb_port_write];
-
    for (uint32_t i=0; i<_param._nb_port_write; i++)
      {
@@ -119,10 +137,29 @@
        rename = "WRITE_IN_DATA_"+toString(i)+"    ";
        WRITE_IN_DATA     [i] = new sc_signal<Tdata_t   > (rename.c_str());
-
-       rename = "WRITE_SELECT_VAL_"+toString(i)+" ";
-       WRITE_SELECT_VAL  [i] = new sc_signal<Tcontrol_t> (rename.c_str());
-       rename = "WRITE_SELECT_ACK_"+toString(i)+" ";
-       WRITE_SELECT_ACK  [i] = new sc_signal<Tcontrol_t> (rename.c_str());
-     }
+     }
+
+   WRITE_SELECT_VAL  = new sc_signal<Tcontrol_t> *** [_param._nb_bank];
+   WRITE_SELECT_ACK  = new sc_signal<Tcontrol_t> *** [_param._nb_bank];
+
+    for (uint32_t i=0; i<_param._nb_bank; i++)
+      {
+	WRITE_SELECT_VAL [i] = new sc_signal<Tcontrol_t>  ** [_param._nb_port_write_by_bank];
+	WRITE_SELECT_ACK [i] = new sc_signal<Tcontrol_t>  ** [_param._nb_port_write_by_bank];
+
+	 for (uint32_t j=0; j<_param._nb_port_write_by_bank; j++)
+	   {
+	     WRITE_SELECT_VAL [i][j] = new sc_signal<Tcontrol_t>   * [_param._nb_port_select_by_bank_write_port [j]];
+	     WRITE_SELECT_ACK [i][j] = new sc_signal<Tcontrol_t>   * [_param._nb_port_select_by_bank_write_port [j]];
+	     
+	     for (uint32_t k=0; k<_param._nb_port_select_by_bank_write_port [j]; k++)
+	       {
+		 rename="WRITE_SELECT_VAL_"+toString(i)+"_"+toString(j)+"_"+toString(k)+" ";
+		 WRITE_SELECT_VAL [i][j][k] = new sc_signal<Tcontrol_t> (rename.c_str());
+		 
+		 rename="WRITE_SELECT_ACK_"+toString(i)+"_"+toString(j)+"_"+toString(k)+" ";
+		 WRITE_SELECT_ACK [i][j][k] = new sc_signal<Tcontrol_t> (rename.c_str());
+	       }
+	   }
+      }
       
    WRITE_OUT_VAL     = new sc_signal<Tcontrol_t>          ** [_param._nb_bank];
@@ -165,7 +202,14 @@
        (*(_RegisterFile_Multi_Banked_Glue-> in_READ_IN_ADDRESS   [i]))       (*(READ_IN_ADDRESS   [i]));
        (*(_RegisterFile_Multi_Banked_Glue->out_READ_IN_DATA      [i]))       (*(READ_IN_DATA      [i]));
-       (*(_RegisterFile_Multi_Banked_Glue-> in_READ_SELECT_VAL   [i]))       (*(READ_SELECT_VAL   [i]));
-       (*(_RegisterFile_Multi_Banked_Glue->out_READ_SELECT_ACK   [i]))       (*(READ_SELECT_ACK   [i]));
-     }
+     }
+
+   for (uint32_t i=0; i<_param._nb_bank; i++)
+     for (uint32_t j=0; j<_param._nb_port_read_by_bank; j++)
+       for (uint32_t k=0; k<_param._nb_port_select_by_bank_read_port[j]; k++)
+	 {
+	   (*(_RegisterFile_Multi_Banked_Glue->out_READ_SELECT_VAL [i][j][k])) (*(READ_SELECT_VAL [i][j][k]));
+	   (*(_RegisterFile_Multi_Banked_Glue-> in_READ_SELECT_ACK [i][j][k])) (*(READ_SELECT_ACK [i][j][k]));
+	 }
+
    for (uint32_t i=0; i<_param._nb_bank; i++)
        for (uint32_t j=0; j<_param._nb_port_read_by_bank; j++)
@@ -183,7 +227,13 @@
        (*(_RegisterFile_Multi_Banked_Glue-> in_WRITE_IN_ADDRESS  [i]))       (*(WRITE_IN_ADDRESS  [i]));
        (*(_RegisterFile_Multi_Banked_Glue-> in_WRITE_IN_DATA     [i]))       (*(WRITE_IN_DATA     [i]));
-       (*(_RegisterFile_Multi_Banked_Glue-> in_WRITE_SELECT_VAL  [i]))       (*(WRITE_SELECT_VAL  [i]));
-       (*(_RegisterFile_Multi_Banked_Glue->out_WRITE_SELECT_ACK  [i]))       (*(WRITE_SELECT_ACK  [i]));
-     }
+     }
+
+   for (uint32_t i=0; i<_param._nb_bank; i++)
+     for (uint32_t j=0; j<_param._nb_port_write_by_bank; j++)
+       for (uint32_t k=0; k<_param._nb_port_select_by_bank_write_port[j]; k++)
+	 {
+	   (*(_RegisterFile_Multi_Banked_Glue->out_WRITE_SELECT_VAL [i][j][k])) (*(WRITE_SELECT_VAL [i][j][k]));
+	   (*(_RegisterFile_Multi_Banked_Glue-> in_WRITE_SELECT_ACK [i][j][k])) (*(WRITE_SELECT_ACK [i][j][k]));
+	 }
 
    for (uint32_t i=0; i<_param._nb_bank; i++)
@@ -197,9 +247,10 @@
 
 
+  cout << "<" << name << "> Start Simulation ............" << endl;
+  
   /********************************************************
    * Simulation - Begin
    ********************************************************/
 
-  cout << "<" << name << "> Start Simulation ............" << endl;
   // Initialisation
 
@@ -210,16 +261,104 @@
 
   sc_start(0);
-  _RegisterFile_Multi_Banked_Glue->vhdl_testbench_label("Initialisation");
-  cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Initialisation" << endl;
-
-
-  _RegisterFile_Multi_Banked_Glue->vhdl_testbench_label("Loop of Test");
-  cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Loop of Test" << endl;
+
+  LABEL("Initialisation");
+
+  uint32_t   read_in_num_bank [_param._nb_port_read]; // Number of bank
+//Tcontrol_t read_in_valid    [_param._nb_port_read];
+  Tcontrol_t read_in_ack      [_param._nb_port_read]; // to test
+  Tdata_t    read_in_data     [_param._nb_port_read]; // to test
+  Tcontrol_t read_out_val     [_param._nb_bank][_param._nb_port_read_by_bank];  
+  Tcontrol_t read_out_ack     [_param._nb_bank][_param._nb_port_read_by_bank];  
+  Taddress_t read_out_address [_param._nb_bank][_param._nb_port_read_by_bank];  
+  Tcontrol_t read_is_busy     [_param._nb_port_read];
+  Tcontrol_t read_select_val  [_param._nb_bank][_param._nb_port_read        ];
+  Tcontrol_t read_select_ack  [_param._nb_bank][_param._nb_port_read        ];
+
+  LABEL("Loop of Test");
 
   for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++)
     {
-      _RegisterFile_Multi_Banked_Glue->vhdl_testbench_label("Iteration "+toString(iteration));
-
+      LABEL("Iteration "+toString(iteration));
+      
+      LABEL("Test read_in");
+      
+      // Write in interface "read_in"
+      for (uint32_t i=0; i<_param._nb_port_read; i++)
+	{
+	  read_in_num_bank  [i] =  rand() % _param._nb_bank;
+	  Tcontrol_t read_in_valid = (rand() % 2) != 0;
+
+	  Taddress_t address    = (read_in_num_bank[i] << _param._shift_address) | (gen_mask<Taddress_t>(_param._size_address-_param._shift_address) & i);
+
+	  read_is_busy      [i] = (read_in_valid == 0);
+	  read_in_ack       [i] = 0;
+	  read_in_data      [i] = 0;
+	  READ_IN_VAL       [i]->write(read_in_valid);
+	  READ_IN_ADDRESS   [i]->write(address);
+
+	  for (uint32_t j=0; j<_param._nb_bank; j++)
+	    read_select_ack [j][i] = 0;
+	}
+
+      for (uint32_t i=0; i<_param._nb_bank; i++)
+	for (uint32_t j=0; j<_param._nb_port_read_by_bank; j++)
+	  {
+	    read_out_ack      [i][j] = (rand() % 2) != 0;
+	    READ_OUT_ACK      [i][j]->write(read_out_ack      [i][j]);
+	    READ_OUT_DATA     [i][j]->write((j<<1)|1); // (j<<1)|1 afin de n'avoir jamais 0
+	  }
+      
+      // compute the good read_select
+      for (uint32_t i=0; i<_param._nb_bank; i++)
+	for (uint32_t j=0; j<_param._nb_port_read_by_bank; j++)
+	  {
+	    bool find = false; // have find a port_in to link with this port_out
+	    for (uint32_t k=0; k<_param._nb_port_select_by_bank_read_port[j]; k++)
+	      {
+
+		uint32_t num_port; // number of port
+		
+		// compute the good number of port
+		if (_param._crossbar == FULL_CROSSBAR)
+		  num_port = k;
+		else
+		  num_port = _param._link_port_read [i];
+
+		read_select_val [i][num_port] = read_out_ack [i][j] && not read_is_busy [num_port];
+		
+		if ((read_out_ack [i][j] == 0) || find)
+		  read_select_ack [i][num_port] = 0; // read_out is busy or already find
+		else
+		  {
+		    // find a busy port?
+		    find = not read_is_busy [num_port];
+		    read_is_busy       [num_port]|= find;
+		    read_select_ack [i][num_port] = find;
+
+		    if (find)
+		      {
+			read_in_ack      [num_port] = 1;
+			read_in_data     [num_port] = ((j<<1)|1);
+			read_out_val     [i][j]     = 1;
+			read_out_address [i][j]     = (read_in_num_bank[i] << _param._shift_address) | (gen_mask<Taddress_t>(_param._size_address-_param._shift_address) & i);
+		      }
+		  }
+		
+		READ_SELECT_ACK [i][j][k]->write(read_select_ack [i][num_port]);
+	      }
+	  }
+
+      // next cycle
       sc_start(1);
+
+//       // lot of test
+//   public    : SC_OUT(Tcontrol_t)           ** out_READ_IN_ACK       ;
+//   public    : SC_OUT(Tdata_t   )           ** out_READ_IN_DATA      ;
+
+//   public    : SC_OUT(Tcontrol_t)         **** out_READ_SELECT_VAL   ;
+
+//   public    : SC_OUT(Tcontrol_t)          *** out_READ_OUT_VAL      ;
+//   public    : SC_OUT(Taddress_t)          *** out_READ_OUT_ADDRESS  ;
+
     }
 
@@ -238,6 +377,4 @@
       delete READ_IN_ADDRESS   [i];
       delete READ_IN_DATA      [i];
-      delete READ_SELECT_VAL   [i];
-      delete READ_SELECT_ACK   [i];
     }
   						      
@@ -246,6 +383,22 @@
   delete READ_IN_ADDRESS;
   delete READ_IN_DATA   ;
-  delete READ_SELECT_VAL;
-  delete READ_SELECT_ACK;
+
+   for (uint32_t i=0; i<_param._nb_bank; i++)
+     {
+       for (uint32_t j=0; j<_param._nb_port_read_by_bank; j++)
+	 {
+	   for (uint32_t k=0; k<_param._nb_port_select_by_bank_read_port[j]; k++)
+	     {
+	       delete READ_SELECT_VAL [i][j][k];
+	       delete READ_SELECT_ACK [i][j][k];
+	     }
+	   delete READ_SELECT_VAL [i][j];
+	   delete READ_SELECT_ACK [i][j];
+	 }
+       delete READ_SELECT_VAL [i];
+       delete READ_SELECT_ACK [i];
+     }
+   delete READ_SELECT_VAL;
+   delete READ_SELECT_ACK;
 
    for (uint32_t i=0; i<_param._nb_bank; i++)
@@ -276,6 +429,4 @@
       delete WRITE_IN_ADDRESS  [i];
       delete WRITE_IN_DATA     [i];
-      delete WRITE_SELECT_VAL  [i];
-      delete WRITE_SELECT_ACK  [i];
     }
 
@@ -284,4 +435,20 @@
   delete WRITE_IN_ADDRESS;
   delete WRITE_IN_DATA   ;
+
+  for (uint32_t i=0; i<_param._nb_bank; i++)
+    {
+      for (uint32_t j=0; j<_param._nb_port_write_by_bank; j++)
+	{
+	  for (uint32_t k=0; k<_param._nb_port_select_by_bank_write_port[j]; k++)
+	    {
+	      delete WRITE_SELECT_VAL [i][j][k];
+	      delete WRITE_SELECT_ACK [i][j][k];
+	    }
+	  delete WRITE_SELECT_VAL [i][j];
+	  delete WRITE_SELECT_ACK [i][j];
+	}
+      delete WRITE_SELECT_VAL [i];
+      delete WRITE_SELECT_ACK [i];
+    }
   delete WRITE_SELECT_VAL;
   delete WRITE_SELECT_ACK;
