Index: trunk/kernel/fs/fatfs.c
===================================================================
--- trunk/kernel/fs/fatfs.c	(revision 407)
+++ trunk/kernel/fs/fatfs.c	(revision 435)
@@ -262,6 +262,10 @@
     "no FAT access required for first page\n");
 
-fatfs_dmsg("\n[DBG] %s : core[%x,%d] enters / first_cluster_id = %d / searched_index = %d\n",
-__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, first_cluster_id, searched_page_index );
+#if CONFIG_DEBUG_FATFS_GET_CLUSTER
+uint32_t cycle = (uint32_t)hal_get_cycles();
+if( CONFIG_DEBUG_FATFS_GET_CLUSTER < cycle )
+printk("\n[DBG] %s : thread %x enter / first_cluster_id %d / searched_index / cycle %d\n",
+__FUNCTION__, CURRENT_THREAD, first_cluster_id, searched_page_index, cycle );
+#endif
 
     // get number of FAT slots per page
@@ -289,8 +293,10 @@
         next_cluster_id = current_page_buffer[current_page_offset];
 
-fatfs_dmsg("\n[DBG] %s : core[%x,%d] traverse FAT / current_page_index = %d\n"
+#if (CONFIG_DEBUG_FATFS_GET_CLUSTER & 1)
+if( CONFIG_DEBUG_FATFS_GET_CLUSTER < cycle )
+printk("\n[DBG] %s : traverse FAT / current_page_index = %d\n"
 "current_page_offset = %d / next_cluster_id = %d\n",
-__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, current_page_index,
-current_page_offset , next_cluster_id );
+__FUNCTION__, current_page_index, current_page_offset , next_cluster_id );
+#endif
 
         // update loop variables
@@ -302,6 +308,10 @@
     if( next_cluster_id == 0xFFFFFFFF ) return EIO;
    
-fatfs_dmsg("\n[DBG] %s : core[%x;%d] exit / cluster_id = %d\n",
-__FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, next_cluster_id );
+#if CONFIG_DEBUG_FATFS_GET_CLUSTER
+cycle = (uint32_t)hal_get_cycles();
+if( CONFIG_DEBUG_FATFS_GET_CLUSTER < cycle )
+printk("\n[DBG] %s : thread %x exit / searched_cluster_id = %d / cycle %d\n",
+__FUNCTION__, CURRENT_THREAD, next_cluster_id / cycle );
+#endif
 
     *searched_cluster_id = next_cluster_id;
@@ -335,9 +345,13 @@
     uint8_t     * buffer;
 
-    fatfs_dmsg("\n[DBG] %s : enter for fatfs_ctx = %x\n",
-               __FUNCTION__ , fatfs_ctx );
+#if CONFIG_DEBUG_FATFS_INIT
+uint32_t cycle = (uint32_t)hal_get_cycles();
+if( CONFIG_DEBUG_FATFS_INIT < cycle )
+printk("\n[DBG] %s : thread %x enter for fatfs_ctx = %x / cycle %d\n",
+__FUNCTION__ , CURRENT_THREAD , fatfs_ctx , cycle );
+#endif
 
     assert( (fatfs_ctx != NULL) , __FUNCTION__ ,
-                   "cannot allocate memory for FATFS context\n" );
+    "cannot allocate memory for FATFS context\n" );
 
     // allocate a 512 bytes buffer to store the boot record
@@ -347,18 +361,15 @@
 
     assert( (buffer != NULL) , __FUNCTION__ ,
-                   "cannot allocate memory for 512 bytes buffer\n" );
+    "cannot allocate memory for 512 bytes buffer\n" );
      
-    fatfs_dmsg("\n[DBG] %s : allocated 512 bytes buffer\n", __FUNCTION__ );
-
     // load the boot record from device
     // using a synchronous access to IOC device  
     error = dev_ioc_sync_read( buffer , 0 , 1 );
 
-fatfs_dmsg("\n[DBG] %s : buffer loaded\n", __FUNCTION__ );
-
-    assert( (error == 0) , __FUNCTION__ , "cannot access boot record\n" );
-
-#if (CONFIG_FATFS_DEBUG & 0x1)
-if( hal_time_stamp() > CONFIG_FATFS_DEBUG )
+    assert( (error == 0) , __FUNCTION__ , 
+    "cannot access boot record\n" );
+
+#if (CONFIG_DEBUG_FATFS_INIT & 0x1)
+if( CONFIG_DEBUG_FATFS_INIT < cycle )
 {
     uint32_t   line;
@@ -389,5 +400,5 @@
 
     assert( (nb_sectors == 8) , __FUNCTION__ ,
-            "cluster size must be 8 sectors\n" );
+    "cluster size must be 8 sectors\n" );
 
     // check number of FAT copies from boot record
@@ -395,5 +406,5 @@
 
     assert( (nb_fats == 1) , __FUNCTION__ ,
-            "number of FAT copies must be 1\n" );
+    "number of FAT copies must be 1\n" );
 
     // get & check number of sectors in FAT from boot record
@@ -401,5 +412,5 @@
 
     assert( ((fat_sectors & 0xF) == 0) , __FUNCTION__ ,
-            "FAT not multiple of 16 sectors\n");
+    "FAT not multiple of 16 sectors\n");
 
     // get and check root cluster from boot record
@@ -407,5 +418,5 @@
 
     assert( (root_cluster == 2) , __FUNCTION__ ,
-            "root cluster index must be  2\n");
+    "root cluster index must be  2\n");
 
     // get FAT lba from boot record
@@ -417,11 +428,9 @@
     kmem_free( &req );
 
-    fatfs_dmsg("\n[DBG] %s : boot record read & released\n",
-               __FUNCTION__ );
-
     // allocate a mapper for the FAT itself
     mapper_t * fat_mapper = mapper_create( FS_TYPE_FATFS );
 
-    assert( (fat_mapper != NULL) , __FUNCTION__ , "no memory for FAT mapper" );
+    assert( (fat_mapper != NULL) , __FUNCTION__ ,
+    "no memory for FAT mapper" );
 
     // WARNING : the inode field MUST be NULL for the FAT mapper
@@ -439,5 +448,10 @@
     fatfs_ctx->fat_mapper_xp         = XPTR( local_cxy , fat_mapper );
 
-fatfs_dmsg("\n[DBG] %s : exit for fatfs_ctx = %x\n", __FUNCTION__ , fatfs_ctx );
+#if CONFIG_DEBUG_FATFS_INIT
+cycle = (uint32_t)hal_get_cycles();
+if( CONFIG_DEBUG_FATFS_INIT < cycle )
+printk("\n[DBG] %s : thread %x exit for fatfs_ctx = %x / cycle %d\n",
+__FUNCTION__ , CURRENT_THREAD , fatfs_ctx , cycle );
+#endif
 
 }  // end fatfs_ctx_init()
@@ -472,6 +486,10 @@
     inode = mapper->inode;
 
-fatfs_dmsg("\n[DBG] %s : core[%x,%d] enter for page %d / inode %x / mapper %x\n",
-__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , index , inode , mapper );
+#if CONFIG_DEBUG_FATFS_MOVE
+uint32_t cycle = (uint32_t)hal_get_cycles();
+if( CONFIG_DEBUG_FATFS_MOVE < cycle )
+printk("\n[DBG] %s : thread %x enter / page %d / inode %x / mapper %x / cycle %d\n",
+__FUNCTION__ , CURRENT_THREAD , index , inode , mapper , cycle );
+#endif
 
     // get page base address
@@ -489,6 +507,8 @@
         lba = fatfs_ctx->fat_begin_lba + (count * index);
  
-fatfs_dmsg("\n[DBG] %s : core[%x,%d] access FAT on device / lba = %d\n",
-__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , lba );
+#if (CONFIG_DEBUG_FATFS_MOVE & 0x1)
+if( CONFIG_DEBUG_FATFS_MOVE < cycle )
+printk("\n[DBG] %s : access FAT on device / lba = %d\n", __FUNCTION__ , lba );
+#endif
 
         // access device
@@ -521,9 +541,10 @@
             {
 
-fatfs_dmsg("\n[DBG] %s : core[%x,%d] access local FAT mapper\n"
+#if (CONFIG_DEBUG_FATFS_MOVE & 0x1)
+if( CONFIG_DEBUG_FATFS_MOVE < cycle )
+print("\n[DBG] %s : access local FAT mapper\n"
 "fat_mapper_cxy = %x / fat_mapper_ptr = %x / first_cluster_id = %d / index = %d\n",
-__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid ,
-fat_mapper_cxy , fat_mapper_ptr , first_cluster_id , index );
-
+__FUNCTION__ , fat_mapper_cxy , fat_mapper_ptr , first_cluster_id , index );
+#endif
                 error = fatfs_get_cluster( fat_mapper_ptr,
                                            first_cluster_id,
@@ -534,9 +555,10 @@
             {
 
-fatfs_dmsg("\n[DBG] %s : core[%x,%d] access remote FAT mapper\n"
+#if (CONFIG_DEBUG_FATFS_MOVE & 0x1)
+if( CONFIG_DEBUG_FATFS_MOVE < cycle )
+printk("\n[DBG] %s : access remote FAT mapper\n"
 "fat_mapper_cxy = %x / fat_mapper_ptr = %x / first_cluster_id = %d / index = %d\n",
-__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid ,
-fat_mapper_cxy , fat_mapper_ptr , first_cluster_id , index );
-
+__FUNCTION__ , fat_mapper_cxy , fat_mapper_ptr , first_cluster_id , index );
+#endif
                 rpc_fatfs_get_cluster_client( fat_mapper_cxy,
                                               fat_mapper_ptr,
@@ -550,6 +572,9 @@
         }
 
-fatfs_dmsg("\n[DBG] %s : core[%x,%d] access device for inode %x / cluster_id %d\n",
-__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , inode , searched_cluster_id );
+#if (CONFIG_DEBUG_FATFS_MOVE & 0x1)
+if( CONFIG_DEBUG_FATFS_MOVE < cycle )
+printk("\n[DBG] %s : access device for inode %x / cluster_id %d\n",
+__FUNCTION__ , inode , searched_cluster_id );
+#endif
 
         // get lba from cluster_id
@@ -563,9 +588,13 @@
     }
 
-fatfs_dmsg("\n[DBG] %s : core[%x,%d] exit for page %d / inode %x / mapper %x\n",
-__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , index , inode , mapper );
-
-#if (CONFIG_FATFS_DEBUG & 0x1)
-if( hal_time_stamp() > CONFIG_FATFS_DEBUG )
+#if CONFIG_DEBUG_FATFS_MOVE
+cycle = (uint32_t)hal_get_cycles();
+if( CONFIG_DEBUG_FATFS_MOVE < cycle )
+printk("\n[DBG] %s : thread %x exit / page %d / inode %x / mapper %x / cycle %d\n",
+__FUNCTION__ , CURRENT_THREAD , index , inode , mapper , cycle );
+#endif
+
+#if (CONFIG_DEBUG_FATFS_MOVE & 0x1)
+if( CONFIG_DEBUG_FATFS_MOVE < cycle )
 {
     uint32_t * tab = (uint32_t *)buffer;
@@ -594,6 +623,10 @@
     // - scan the directory entries in each 4 Kbytes page
 
-fatfs_dmsg("\n[DBG] %s : enter for child <%s> in parent inode %l\n",
-__FUNCTION__ , name , XPTR( local_cxy , parent_inode ) );
+#if CONFIG_DEBUG_FATFS_LOAD
+uint32_t cycle = (uint32_t)hal_get_cycles();
+if( CONFIG_DEBUG_FATFS_LOAD < cycle )
+printk("\n[DBG] %s : thread %x enter for child <%s> in parent inode %x / cycle %d\n",
+__FUNCTION__ , CURRENT_THREAD , name , parent_inode , cycle );
+#endif
 
     mapper_t * mapper = parent_inode->mapper;
@@ -632,6 +665,6 @@
         base = (uint8_t *)GET_PTR( base_xp );
 
-#if (CONFIG_FATFS_DEBUG & 0x1)
-if( hal_time_stamp() > CONFIG_FATFS_DEBUG )
+#if (CONFIG_DEBUG_FATFS_LOAD & 0x1)
+if( CONFIG_DEBUG_FATFS_LOAD < cycle )
 {
     uint32_t * buf = (uint32_t *)base;
@@ -716,6 +749,10 @@
     {
 
-fatfs_dmsg("\n[DBG] %s : exit / child <%s> not found in parent inode %l\n",
-__FUNCTION__ , name , XPTR( local_cxy , parent_inode ) );
+#if CONFIG_DEBUG_FATFS_LOAD
+cycle = (uint32_t)hal_get_cycles();
+if( CONFIG_DEBUG_FATFS_LOAD < cycle )
+printk("\n[DBG] %s : thread %x exit / child <%s> not found / cycle %d\n",
+__FUNCTION__ , CURRENT_THREAD, name, cycle );
+#endif
 
         return ENOENT;
@@ -734,6 +771,10 @@
         hal_remote_sw( XPTR( child_cxy , &child_ptr->extend ) , cluster );
 
-fatfs_dmsg("\n[DBG] %s : exit / child <%s> found in parent inode %l\n",
-__FUNCTION__ , name , XPTR( local_cxy , parent_inode ) );
+#if CONFIG_DEBUG_FATFS_LOAD
+cycle = (uint32_t)hal_get_cycles();
+if( CONFIG_DEBUG_FATFS_LOAD < cycle )
+printk("\n[DBG] %s : thread %x exit / child <%s> loaded / cycle %d\n",
+__FUNCTION__ , CURRENT_THREAD, name, cycle );
+#endif
 
         return 0;
