Index: soft/giet_vm/applications/display/main.c
===================================================================
--- soft/giet_vm/applications/display/main.c	(revision 432)
+++ soft/giet_vm/applications/display/main.c	(revision 444)
@@ -1,50 +1,100 @@
-#include "stdio.h"
-#include "hard_config.h"
+ ///////////////////////////////////////////////////////////////////////////////
+//  file   : main.c  (for display application)
+//  date   : may 2014
+//  author : Alain Greiner
+///////////////////////////////////////////////////////////////////////////////////////
+//  This file describes the single thread "display" application.
+//  It uses the external chained buffer DMA to display a stream
+//  of images on the frame buffer.  
+///////////////////////////////////////////////////////////////////////////////////////
 
-#define NBLOCKS 32   // (128 * 128) / 512
+#include <stdio.h>
+#include <hard_config.h>
 
-unsigned char buf[128*128] __attribute__((aligned(512)));
+#define FILENAME    "misc/images.raw"
+#define NPIXELS     128
+#define NLINES      128
+#define NIMAGES     10                    
+#define NBLOCKS     (NPIXELS*NLINES/512)   // number of blocks per image
 
+
+unsigned char buf0[NPIXELS*NLINES] __attribute__((aligned(512)));
+unsigned char buf1[NPIXELS*NLINES] __attribute__((aligned(512)));
+
+////////////////////////////////////////////
 __attribute__((constructor)) void main()
-{  
+////////////////////////////////////////////
+{
+    // get processor identifiers
+    unsigned int    x;
+    unsigned int    y; 
+    unsigned int    lpid;
+    giet_proc_xyp( &x, &y, &lpid );
+
     int             fd;
-    int             blocks;
-    unsigned int    ko;
-    unsigned int    blocks_to_skip = 8*NBLOCKS;
+    unsigned int    image = 0;
 
-    unsigned int    procid     = giet_procid();
-    unsigned int    cluster_xy = procid/NB_PROCS_MAX;
-    unsigned int    lpid       = procid%NB_PROCS_MAX;
-    unsigned int    x          = cluster_xy >> Y_WIDTH;
-    unsigned int    y          = cluster_xy & ((1<<Y_WIDTH)-1);
-
-    giet_tty_printf( "*** Starting task display on processor[%d,%d,%d] at cycle %d\n\n", 
-                      x, y, lpid, giet_proctime() );
-
-    ///////////////////////////////////////////
-    fd = giet_fat_open( "misc/images.raw", 0 );
-    if ( fd < 0 ) giet_exit("echec giet_fat_open for misc/images.raw");
-
-    giet_tty_printf("\ngiet_fat_open completed for misc/images.raw at cycle %d\n", 
-                    giet_proctime() );
-
-    /////////////////////////////////////////
-    while ( blocks_to_skip < (10 * NBLOCKS) )
+    // parameters checking
+    if ( (NPIXELS != FBUF_X_SIZE) || (NLINES != FBUF_Y_SIZE) )
     {
-        // lecture image sur le disque
-        giet_fat_read( fd, buf, NBLOCKS, blocks_to_skip );
-        
-        giet_tty_printf("\ngiet_fat_read for image %d completed at cycle %d \n", 
-                        (blocks_to_skip>>5), giet_proctime());
-
-        // transfert vers le frame buffer  
-        giet_fb_sync_write( 0, buf, 128 * 128 );
-
-        giet_tty_printf("\ndisplay completed for image %d at cycle %d \n", 
-                        (blocks_to_skip>>5), giet_proctime());
-
-        blocks_to_skip = blocks_to_skip + NBLOCKS;
+        giet_exit("[DISPLAY ERROR] Frame buffer size does not fit image size");
     }
 
-    giet_exit("completed");
+    giet_shr_printf("\n[DISPLAY] Processor[%d,%d,%d] starts at cycle %d\n",
+                    x, y, lpid, giet_proctime() );
+
+    // open file
+    fd = giet_fat_open( FILENAME , 0 );
+    if ( fd < 0 ) 
+    {
+        giet_exit("echec giet_fat_open for misc/images.raw");
+    }
+    else
+    {
+        giet_shr_printf("\n[DISPLAY] Proc[%d,%d,%d] open file %s at cycle %d\n", 
+                    x, y, lpid, FILENAME, giet_proctime() );
+    }
+
+    // get a Chained Buffer DMA channel
+    giet_fbf_cma_alloc();
+
+    // start Chained Buffer DMA channel
+    giet_fbf_cma_start( buf0, buf1, NPIXELS*NLINES );
+    
+    giet_shr_printf("\n[DISPLAY] Proc[%d,%d,%d] starts CMA at cycle %d\n", 
+                    x, y, lpid, giet_proctime() );
+
+    // Main loop (on images)
+    while ( image < NIMAGES )
+    {
+        giet_fat_read( fd, buf0, NBLOCKS, image*NBLOCKS );
+
+        giet_shr_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d to buf0 at cycle %d\n", 
+                        x, y, lpid, image, giet_proctime() );
+
+        giet_fbf_cma_display( 0 );
+
+        giet_shr_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d from buf0 at cycle %d\n", 
+                        x, y, lpid, image, giet_proctime() );
+
+        image++;
+
+        giet_fat_read( fd, buf1, NBLOCKS, image*NBLOCKS );
+
+        giet_shr_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d to buf1 at cycle %d\n", 
+                        x, y, lpid, image, giet_proctime() );
+
+        giet_fbf_cma_display( 1 );
+
+        giet_shr_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d from buf1 at cycle %d\n", 
+                        x, y, lpid, image, giet_proctime() );
+
+
+        image++;
+    }
+
+    // stop Chained buffer DMA channel
+    giet_fbf_cma_stop();
+
+    giet_exit("display completed");
 }
