Index: soft/giet_vm/applications/router/main.c
===================================================================
--- soft/giet_vm/applications/router/main.c	(revision 432)
+++ soft/giet_vm/applications/router/main.c	(revision 451)
@@ -1,2 +1,32 @@
+/////////////////////////////////////////////////////////////////////////////////////////////
+// File   : main.c   (for router application)
+// Date   : november 2014
+// author : Alain Greiner
+/////////////////////////////////////////////////////////////////////////////////////////////
+// This multi-threaded application emulates a packet routing communication application,
+// described as a TCG (Task and Communication Graph).
+// It contains 2 + N tasks : one "producer", one "consumer" and N "router")
+// It contains 2 MWMR channels : "fifo_in" and "fifo_out".
+// - The "producer" task writes NMAX token into "fifo_in".
+// - The N "router" tasks read token from "fifo_in" and write them into "fifo_out".
+// - The "consumer" task read token from "fifo_out" and displays instrumentation results.
+// Token are indexed (by the producer) from 0 to NMAX-1.
+// The router task contain a random delay emulating a variable processing time.
+//
+// This application is intended to run on a multi-processors, multi-clusters architecture,
+//  with one thread per processor. 
+//
+// It uses the he following hardware parameters, defined in the hard_config.h file:
+// - X_SIZE       : number of clusters in a row
+// - Y_SIZE       : number of clusters in a column
+// - NB_PROCS_MAX : number of processors per cluster
+// 
+// There is two global arrays (indexed by the token index) for insrumentation:
+// - The "router_tab" array is filled concurrently by all "router" tasks.
+//   Each entry contains the processor index that routed the token.
+// - The "consumer_tab" array is filled by the "consumer" task.
+//   Each entry contain the arrival order to the consumer task.
+/////////////////////////////////////////////////////////////////////////////////////////////
+
 #include "stdio.h"
 #include "mwmr_channel.h"
@@ -4,11 +34,19 @@
 #include "hard_config.h"
 
-#if NB_TTY_CHANNELS == 1
-#  define printf(...) giet_shr_printf(__VA_ARGS__)
-#else
-#  define printf(...) giet_tty_printf(__VA_ARGS__)
-#endif
 
-#define NMAX 50
+#define NMAX   50			// total number of token
+#define DEPTH  20           // MWMR channels depth
+
+//////////////// MWMR channels /////////////////////////////////////////////
+
+__attribute__((section (".data_in")))  mwmr_channel_t fifo_in;
+__attribute__((section (".data_out"))) mwmr_channel_t fifo_out;
+ 
+//////////////// Instrumentation Counters //////////////////////////////////
+
+__attribute__((section (".data_out")))  unsigned int consumer_tab[NMAX];
+__attribute__((section (".data_out")))  unsigned int router_tab[NMAX];
+
+
 
 /////////////////////////////////////////////
@@ -18,5 +56,4 @@
     unsigned int 	n;
     unsigned int 	buf;
-    mwmr_channel_t*	mwmr;
 
     // get processor identifiers
@@ -26,10 +63,9 @@
     giet_proc_xyp( &x, &y, &lpid );
 
-    printf( "*** Starting task producer on processor[%d,%d,%d] at cycle %d\n\n", 
-             x, y, lpid, giet_proctime() );
+    giet_shr_printf("\n*** Starting task producer on P[%d,%d,%d] at cycle %d\n", 
+                    x, y, lpid, giet_proctime() );
 
-    giet_vobj_get_vbase( "router" , 
-                         "mwmr_in", 
-                         (void*)&mwmr );
+    // initializes fifo_in
+    mwmr_init( &fifo_in, 1 , DEPTH );
 
     // main loop : display token value = source index
@@ -37,6 +73,5 @@
     { 
         buf = n;
-        mwmr_write( mwmr, &buf , 1 );
-        printf( "transmitted value : %d\n", buf);
+        mwmr_write( &fifo_in , &buf , 1 );
     }
 
@@ -50,5 +85,4 @@
     unsigned int 	n;
     unsigned int 	buf;
-    mwmr_channel_t*	mwmr;
 
     // get processor identifiers
@@ -58,16 +92,23 @@
     giet_proc_xyp( &x, &y, &lpid );
 
-    printf( "*** Starting task consumer on processor[%d,%d,%d] at cycle %d\n\n", 
-             x, y, lpid, giet_proctime() );
+    giet_shr_printf("\n*** Starting task consumer on P[%d,%d,%d] at cycle %d\n", 
+                    x, y, lpid, giet_proctime() );
 
-    giet_vobj_get_vbase( "router" , 
-                         "mwmr_out", 
-                         (void*)&mwmr );
+    // initializes fifo_out 
+    mwmr_init( &fifo_out, 1 , DEPTH );
 
-    // main loop : display token arrival index and value
-    for(n = 0 ; n < NMAX ; n++ ) 
+    // main loop : register token arrival index and value
+    for( n = 0 ; n < NMAX ; n++ ) 
     { 
-        mwmr_read( mwmr, &buf , 1 );
-        printf( "received token %d / value = %d\n", n  , buf);
+        mwmr_read( &fifo_out , &buf , 1 );
+        consumer_tab[n] = buf;
+    }
+
+    // instrumentation display
+    giet_shr_printf("\n");
+    for( n = 0 ; n < NMAX ; n++ )
+    {
+        giet_shr_printf("@@@ arrival = %d / value = %d / router = %x\n",
+                        n, consumer_tab[n], router_tab[n] );
     }
 
@@ -82,6 +123,4 @@
     unsigned int 	n;
     unsigned int	tempo;
-    mwmr_channel_t*	mwmr_in ;
-    mwmr_channel_t* mwmr_out ;
 
     // get processor identifiers
@@ -91,22 +130,21 @@
     giet_proc_xyp( &x, &y, &lpid );
 
-    printf( "*** Starting task router on processor[%d,%d,%d] at cycle %d\n\n", 
-             x, y, lpid, giet_proctime() );
+    giet_shr_printf("\n*** Starting task router on P[%d,%d,%d] at cycle %d\n", 
+                    x, y, lpid, giet_proctime() );
 
-    giet_vobj_get_vbase( "router" , 
-                         "mwmr_out", 
-                         (void*)&mwmr_out );
+    // waiting fifo_in and fifo_out initialisation
+    while( (fifo_in.depth == 0) || (fifo_out.depth == 0) ) asm volatile( "nop" ); 
 
-    giet_vobj_get_vbase( "router" , 
-                         "mwmr_in", 
-                         (void*)&mwmr_in );
     // main loop
     while(1)
     {
-        mwmr_read( mwmr_in , &buf , 1 );
-        tempo = giet_rand() >> 6;
-        for ( n = 0 ; n < tempo ; n++ ) asm volatile ("");
-        printf( "token value : %d / temporisation = %d\n", buf, tempo);
-        mwmr_write( mwmr_out, &buf , 1 );
+        mwmr_read( &fifo_in , &buf , 1 );
+
+        tempo = giet_rand();
+        for ( n = 0 ; n < tempo ; n++ ) asm volatile ( "nop" );
+
+        router_tab[buf] = (x<<(Y_WIDTH + P_WIDTH)) + (y<<P_WIDTH) + lpid;
+
+        mwmr_write( &fifo_out , &buf , 1 );
     }
-}
+} // end router
