Index: /soft/giet_vm/giet_fat32/fat32.c
===================================================================
--- /soft/giet_vm/giet_fat32/fat32.c	(revision 568)
+++ /soft/giet_vm/giet_fat32/fat32.c	(revision 569)
@@ -5,5 +5,5 @@
 // Copyright (c) UPMC-LIP6
 //////////////////////////////////////////////////////////////////////////////////
-// The fat.h and fat_common.c files define a library of access functions
+// The fat32.h and fat32.c files define a library of access functions
 // to a FAT32 disk on a block device. It is intended to be used
 // by the GIET_VM nano-kernel for both the boot code and the kernel code.
@@ -14,6 +14,5 @@
 // 2. the "cluster" variable is actually a cluster index. A cluster contains
 //    typically 8 sectors (4K bytes) and the cluster index is a 32 bits word.
-// 3. This FAT32 library uses a FAT cache whose storage capacity is one
-//    sector (512 bytes = 128 cluster indexes in FAT)
+// 3. This FAT32 library uses a FAT cache whose storage capacity is one sector.
 //////////////////////////////////////////////////////////////////////////////////
 
@@ -38,12 +37,12 @@
 extern unsigned int _ptabs_vaddr[GIET_NB_VSPACE_MAX][X_SIZE][Y_SIZE];
   
-//////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////////
 // This function computes the memory buffer physical address, and calls 
-// the proper IOC driver depending on the subtype (BDV / HBA / SDC /RDK). 
+// the proper IOC driver depending on the subtype (BDV / HBA / SDC / SPI / RDK). 
 // The use_irq argument allows to activate the descheduling mode, if it 
 // supported by the IOC driver subtype
-//////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////////
 // Return 0 in case of success, return -1 in case of error
-//////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////////
 static
 int _fat_ioc_access( unsigned int use_irq,
@@ -66,9 +65,10 @@
     }
 
-#if (GIET_DEBUG_FAT > 1)
+#if GIET_DEBUG_FAT 
 unsigned int procid  = _get_procid();
 unsigned int x       = procid >> (Y_WIDTH + P_WIDTH);
 unsigned int y       = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1);
 unsigned int p       = procid & ((1<<P_WIDTH)-1);
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] P[%d,%d,%d] enters _fat_ioc_access() at cycle %d\n"
         "  to_mem = %d / vaddr = %x / paddr = %l / sectors = %d / lba = %x\n",
@@ -86,6 +86,8 @@
 #elif ( USE_IOC_HBA )
     return( _hba_access( use_irq , to_mem , lba , buf_paddr , count ) );
+#elif ( USE_IOC_SDC )
+    return( _sdc_access( use_irq , to_mem , lba , buf_paddr , count ) );
 #elif ( USE_IOC_SPI )
-    return( _sdc_access( use_irq , to_mem , lba , buf_paddr , count ) );
+    return( _spi_access( use_irq , to_mem , lba , buf_paddr , count ) );
 #elif ( USE_IOC_RDK )
     return( _rdk_access( use_irq , to_mem , lba , buf_paddr , count ) );
@@ -101,5 +103,5 @@
 // This function displays the content of the FAT cache
 //////////////////////////////////////////////////////////////////////////////////
-#if (GIET_DEBUG_FAT > 1)
+#if GIET_DEBUG_FAT 
 static
 void _display_fat_cache()
@@ -307,11 +309,13 @@
                                      _fat.fat_cache,
                                      1 );
-#if (GIET_DEBUG_FAT > 1)
+#if GIET_DEBUG_FAT 
 unsigned int procid  = _get_procid();
 unsigned int x       = procid >> (Y_WIDTH + P_WIDTH);
 unsigned int y       = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1);
 unsigned int p       = procid & ((1<<P_WIDTH)-1);
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] P[%d,%d,%d] in _get_next_cluster() :  next = %x\n",
         x , y , p , next );
+if ( (_get_proctime() > GIET_DEBUG_FAT) && (GIET_DEBUG_FAT & 0x1) )
 _display_fat_cache();
 #endif
@@ -725,4 +729,5 @@
 
 #if GIET_DEBUG_FAT
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] _update_fs_info()\n");
 #endif
@@ -773,4 +778,5 @@
 
 #if GIET_DEBUG_FAT
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] _update_fat() : cluster = %x / value = %x\n", 
         cluster, value );
@@ -839,4 +845,5 @@
 
 #if GIET_DEBUG_FAT
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] _fat_allocate() for fd = %d\n", fd_id );
 #endif
@@ -855,4 +862,5 @@
 
 #if GIET_DEBUG_FAT
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] cluster to update = %x / free cluster = %x / count = %d\n",
         last_cluster_file , free_cluster , cluster_to_allocate );
@@ -926,11 +934,11 @@
                      unsigned int*  lba_dir_entry )  // lba of dir_entry
 {
-    char dir_entry[32];   // buffer to store a full directory_entry
-    char name_entry[14];  // buffer to store a 13 characters (partial) name
+    char dir_entry[32];       // buffer to store a full directory_entry
+    char name_entry[14];      // buffer to store a 13 characters (partial) name
 
     char sfn_string[12]    = {[0 ... 10] = ' ', '\0'};  // buffer Short File Name
     unsigned int  is_sfn   = is_short(file_name, sfn_string); // file_name is short
     unsigned int  offset   = 0;                         // byte offset in block
-    unsigned int  block_id = _fat.sectors_per_cluster;   // sector index 
+    unsigned int  block_id = _fat.sectors_per_cluster;  // sector index 
     unsigned int  lba      = cluster_to_lba(cluster);   // lba of cluster 
     unsigned int  attr     = 0;                         // dir entry attribute
@@ -945,5 +953,5 @@
 unsigned int y       = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1);
 unsigned int p       = procid & ((1<<P_WIDTH)-1);
-
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] _scan_directory() : P[%d,%d,%d] enters for %s\n",
       x, y, p, file_name );
@@ -968,5 +976,6 @@
     _fat.cache_lba = lba;
 
-#if ( GIET_DEBUG_FAT > 1 )
+#if GIET_DEBUG_FAT 
+if ( (_get_proctime() > GIET_DEBUG_FAT) && (GIET_DEBUG_FAT & 0x1) )
 _display_fat_cache();
 #endif
@@ -1095,4 +1104,5 @@
 
 #if GIET_DEBUG_FAT
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] _scan_directory() : P[%d,%d,%d] found %s"
         " : cluster = %x\n", x, y, p, file_name, searched_cluster );
@@ -1137,4 +1147,5 @@
 unsigned int y       = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1);
 unsigned int p       = procid & ((1<<P_WIDTH)-1);
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] P[%d,%d,%d] enters _fat_init\n",x,y,p);
 #endif
@@ -1160,5 +1171,7 @@
 
 #if GIET_DEBUG_FAT > 1
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] _fat_init() : Boot Sector Loaded\n");
+if ( (_get_proctime() > GIET_DEBUG_FAT) && (GIET_DEBUG_FAT & 0x1) )
 _display_fat_cache();
 #endif
@@ -1205,4 +1218,5 @@
 
 #if GIET_DEBUG_FAT
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] _fat_init() : FS_INFO Sector = %x\n", _fat.fs_info_lba );
 #endif
@@ -1224,4 +1238,5 @@
 
 #if GIET_DEBUG_FAT
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _fat_print();
 _printf("\n[DEBUG FAT] P[%d,%d,%d] exit _fat_init()\n", x,y,p );
@@ -1260,4 +1275,5 @@
 unsigned int y       = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1);
 unsigned int p       = procid & ((1<<P_WIDTH)-1);
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] _fat_open() : P[%d,%d,%d] enters for path %s\n",
         x, y, p, pathname );
@@ -1281,4 +1297,5 @@
 
 #if GIET_DEBUG_FAT
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] _fat_open() : P[%d,%d,%d] takes the FAT lock\n",
         x, y, p );
@@ -1298,4 +1315,5 @@
 
 #if GIET_DEBUG_FAT
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] _fat_open() : P[%d,%d,%d] search file/dir %s\n",
         x, y, p, name );
@@ -1306,5 +1324,5 @@
         {
             last_name   = 1;
-            dir_cluster = cluster;
+            dir_cluster = cluster;   // this is the lowest directory
         }
 
@@ -1325,4 +1343,5 @@
 
 #if GIET_DEBUG_FAT
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] P[%d,%d,%d] in _fat_open() : cluster for %s = %x\n",
        x, y, p, pathname, cluster );
@@ -1351,4 +1370,5 @@
 
 #if GIET_DEBUG_FAT
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] _fat_open() : P[%d,%d,%d] exit : fd = %d for file %s\n",
         x, y, p, fd_id, pathname );
@@ -1443,4 +1463,5 @@
 unsigned int y       = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1);
 unsigned int p       = procid & ((1<<P_WIDTH)-1);
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] _fat_read() : P[%d,%d,%d] enters for file %s\n"
         " - buffer vbase     = %x\n"
@@ -1478,4 +1499,5 @@
 
 #if GIET_DEBUG_FAT
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] _fat_read() : P[%d,%d,%d] makes an IOC read\n"
         "  cluster = %x / buffer = %x / lba = %x / sectors = %d\n",
@@ -1552,5 +1574,5 @@
 unsigned int y       = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1);
 unsigned int p       = procid & ((1<<P_WIDTH)-1);
-
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] _fat_write() : P[%d,%d,%d] enters for file %s\n"
         " - buffer vbase    = %x\n"
@@ -1597,4 +1619,5 @@
 
 #if GIET_DEBUG_FAT
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] _fat_write() : P[%d,%d,%d] get cluster %x\n",
         x, y, p, cluster );
@@ -1626,4 +1649,5 @@
 
 #if GIET_DEBUG_FAT
+if ( _get_proctime() > GIET_DEBUG_FAT )
 _printf("\n[DEBUG FAT] _fat_write() : P[%d,%d,%d] makes an IOC write"
         "  cluster = %x / buffer = %x / lba = %x / sectors = %d\n",
