Index: branch/giet_vm_ioc_drivers/giet_drivers/sdc_driver.c
===================================================================
--- branch/giet_vm_ioc_drivers/giet_drivers/sdc_driver.c	(revision 283)
+++ branch/giet_vm_ioc_drivers/giet_drivers/sdc_driver.c	(revision 284)
@@ -1,10 +1,8 @@
-/**
- * \file    : sdc_driver.c
- * \date    : 30 August 2012
- * \author  : Cesar Fuguet
- *
- * This file defines the driver of a SD Card device using an SPI controller
- */
-
+///////////////////////////////////////////////////////////////////////////////////
+// File     : sdc_driver.c
+// Date     : 31/08/2012
+// Author   : cesar fuguet
+// Copyright (c) UPMC-LIP6
+///////////////////////////////////////////////////////////////////////////////////
 #include <sdc_driver.h>
 #include <utils.h>
@@ -16,9 +14,8 @@
 static struct spi_dev*   spi;
 
-/**
- * \return  void
- *
- * \brief   Enable SD Card select signal
- */
+///////////////////////////////////////////////////////////////////////////////
+//      _sdc_enable()
+// This function enables SD Card select signal
+///////////////////////////////////////////////////////////////////////////////
 static void _sdc_enable()
 {
@@ -26,9 +23,8 @@
 }
 
-/**
- * \return  void
- *
- * \brief   Disable SD Card select signal
- */
+///////////////////////////////////////////////////////////////////////////////
+//      _sdc_enable()
+// This function disables SD Card select signal
+///////////////////////////////////////////////////////////////////////////////
 static void _sdc_disable()
 {
@@ -36,12 +32,9 @@
 }
 
-/**
- * \param   tick_count: SD Card clock ticks number
- *
- * \return  void
- *
- * \brief   Enable SD Card clock
- *          The tick count is byte measured (1 tick, 8 clock)
- */
+///////////////////////////////////////////////////////////////////////////////
+//      _sdc_gen_tick()
+// This function writes on the SPI tx register to generate SD card clock ticks
+// - tick_count: number of ticks to generate (1 tick -> 8 clocks) 
+///////////////////////////////////////////////////////////////////////////////
 static void _sdc_gen_tick(unsigned int tick_count)
 {
@@ -50,14 +43,10 @@
 }
 
-/**
- * \param   lba : Position where the block device access
- *                pointer must be move
- *
- * \return  void
- *
- * \brief   Change block device access pointer position
- *  
- * The block device access pointer is relocated in terms of blocks
- */
+///////////////////////////////////////////////////////////////////////////////
+//      _sdc_lseek()
+// This function changes the SD card access pointer position in terms of
+// blocks
+// - lba: number of logical block to move the pointer
+///////////////////////////////////////////////////////////////////////////////
 void _sdc_lseek(unsigned int lba)
 {
@@ -65,9 +54,8 @@
 }
 
-/**
- * \return  char from the SD card
- *
- * \brief   Get a byte from the SD Card
- */
+///////////////////////////////////////////////////////////////////////////////
+//      _sdc_receive_char()
+// This function gets a byte from the SD card
+///////////////////////////////////////////////////////////////////////////////
 static unsigned char _sdc_receive_char()
 {
@@ -77,13 +65,10 @@
 }
 
-/**
- * \return  sdcard response
- *
- * \brief   Wait for a valid response after the send of a command
- *          This function can return if one of the next two conditions are true:
- *           1. Bit valid received
- *           2. Timeout (not valid bit received after SDCARD_COMMAND_TIMEOUT
- *              wait ticks)
- */
+///////////////////////////////////////////////////////////////////////////////
+//      _sdc_wait_response()
+// This function returns when a valid response from the SD card is received or
+// a timeout has been triggered
+// Returns the SD card response value
+///////////////////////////////////////////////////////////////////////////////
 static unsigned char _sdc_wait_response()
 {
@@ -105,9 +90,10 @@
 }
 
-/**
- * \return  void
- *
- * \brief   Wait data block start marker
- */
+///////////////////////////////////////////////////////////////////////////////
+//      _sdc_wait_data_block()
+// This function returns when a data block from the SD card is received (data
+// block start marker received).
+// It must be called after a read command
+///////////////////////////////////////////////////////////////////////////////
 static void _sdc_wait_data_block()
 {
@@ -115,14 +101,12 @@
 }
 
-/**
- * \param   index   : SD card CMD index
- * \param   app     : Type of command, 0 for normal command or 1 for
- *                    application specific
- * \param   args    : SD card CMD arguments
- *
- * \return  response first byte
- *
- * \brief   Send command to the SD card
- */
+///////////////////////////////////////////////////////////////////////////////
+//      _sdc_send_command()
+// This function sends a command to the SD card
+// - index: CMD index
+// - app: type of command
+// - args: CMD arguments vector
+// - crc7: CRC (7 bits) to send
+///////////////////////////////////////////////////////////////////////////////
 static int _sdc_send_command ( int      index,
                                int      app  ,
@@ -137,10 +121,10 @@
     if (app == SDCARD_ACMD)
     {
-        spi_put_tx(sdcard.spi, 0x40 | 55         , 0 );/* CMD and START bit */
-        spi_put_tx(sdcard.spi, 0x00              , 0 );/* Argument[0]       */
-        spi_put_tx(sdcard.spi, 0x00              , 0 );/* Argument[1]       */
-        spi_put_tx(sdcard.spi, 0x00              , 0 );/* Argument[2]       */
-        spi_put_tx(sdcard.spi, 0x00              , 0 );/* Argument[3]       */
-        spi_put_tx(sdcard.spi, 0x01 | (crc7 << 1), 0 );/* END bit           */
+        spi_put_tx(sdcard.spi, 0x40 | 55         , 0 );// CMD and START bit
+        spi_put_tx(sdcard.spi, 0x00              , 0 );// Argument[0]
+        spi_put_tx(sdcard.spi, 0x00              , 0 );// Argument[1]
+        spi_put_tx(sdcard.spi, 0x00              , 0 );// Argument[2]
+        spi_put_tx(sdcard.spi, 0x00              , 0 );// Argument[3]
+        spi_put_tx(sdcard.spi, 0x01 | (crc7 << 1), 0 );// END bit
 
         sdcard_rsp = _sdc_wait_response();
@@ -165,4 +149,10 @@
 }
 
+///////////////////////////////////////////////////////////////////////////////
+//      _sdc_open()
+// This function initializes the SD card (reset procedure)
+// - channel: channel index (only channel 0 is supported)
+// Returns 0 if success, other value if failure
+///////////////////////////////////////////////////////////////////////////////
 static int _sdc_open( unsigned int channel )
 {
@@ -174,14 +164,10 @@
 	sdcard.slave_id = channel;
 
-	/* 
-	* Supply SD card ramp up time (min 74 cycles)
-	*/
+	// supply SD card ramp up time (min 74 cycles)
 	_sdc_gen_tick(10);
 
-	/* 
-	* Assert slave select signal
-	* Send CMD0 (Reset Command)
-	* Deassert slave select signal
-	*/
+	// Assert slave select signal
+	// Send CMD0 (Reset Command)
+	// Deassert slave select signal
 	_sdc_enable();
 
@@ -199,8 +185,7 @@
 
 	_sdc_disable();
-	/*
-	 * send CMD8. If card is pre-v2, It will reply with illegal command.
-	 * Otherwise we announce sdhc support.
-	 */
+
+	// send CMD8. If card is pre-v2, It will reply with illegal command.
+	// Otherwise we announce sdhc support.
 	_sdc_enable();
 	args[0] = 0;
@@ -209,10 +194,12 @@
 	args[3] = 0x01;
 	sdcard_rsp = _sdc_send_command(8, SDCARD_CMD, args, 0x63);
-	if (!SDCARD_CHECK_R1_VALID(sdcard_rsp)) {
+	if (!SDCARD_CHECK_R1_VALID(sdcard_rsp))
+    {
 		_puts("card CMD8 failed ");
 		return sdcard_rsp;
 	}
-	if (!SDCARD_CHECK_R1_ERROR(sdcard_rsp)) {
-		/* no error, command accepted. get whole reply */
+	if (!SDCARD_CHECK_R1_ERROR(sdcard_rsp))
+    {
+		// no error, command accepted. get whole reply
 		ersp = _sdc_receive_char();
 		ersp = (ersp << 8) | _sdc_receive_char();
@@ -220,5 +207,5 @@
 		ersp = (ersp << 8) | _sdc_receive_char();
 		if ((ersp & 0xffff) != 0x0101) {
-			/* voltage mismatch */
+			// voltage mismatch
 			_puts("card CMD8 mismatch: ");
 			_putx(ersp);
@@ -227,13 +214,18 @@
 		_puts("v2 or later ");
 		sdcard.sdhc = 1;
-	} else if ((sdcard_rsp & SDCARD_R1_ILLEGAL_CMD) == 0) {
-		/* other error */
+	}
+    else if ((sdcard_rsp & SDCARD_R1_ILLEGAL_CMD) == 0)
+    {
+		// other error
 		_puts("card CMD8 error ");
 		return sdcard_rsp;
-	} else {
+	}
+    else
+    {
 		sdcard.sdhc = 0;
 	}
 	_sdc_disable();
-	/* send CMD41, enabling the card */
+
+	// send CMD41, enabling the card
 	_sdc_enable();
 	args[0] = sdcard.sdhc ? 0x40: 0;
@@ -255,10 +247,12 @@
 
 	_sdc_disable();
-	if (sdcard_rsp) {
+	if (sdcard_rsp)
+    {
 		_puts("SD ACMD41 failed ");
 		return sdcard_rsp;
 	}
-	if (sdcard.sdhc != 0) {
-		/* get the card capacity to see if it's really HC */
+	if (sdcard.sdhc != 0)
+    {
+		// get the card capacity to see if it's really HC
 		_sdc_enable();
 		args[0] = sdcard.sdhc ? 0x40: 0;
@@ -267,5 +261,6 @@
 		args[3] = 0;
         sdcard_rsp = _sdc_send_command(58, SDCARD_CMD, args, 0x00);
-		if (sdcard_rsp) {
+		if (sdcard_rsp)
+        {
 			_puts("SD CMD58 failed ");
 			return sdcard_rsp;
@@ -275,7 +270,9 @@
 		ersp = (ersp << 8) | _sdc_receive_char();
 		ersp = (ersp << 8) | _sdc_receive_char();
-		if (ersp & 0x40000000) {
+		if (ersp & 0x40000000)
+        {
 			_puts("SDHC ");
-		} else {
+		} else
+        {
 			sdcard.sdhc = 0;
 		}
@@ -286,4 +283,10 @@
 }
 
+///////////////////////////////////////////////////////////////////////////////
+//      _sdc_set_block_size()
+// This function sets the block size in bytes of the SD card
+// - len: block size in bytes (only 512 bytes supported)
+// Returns 0 if success, other value if failure
+///////////////////////////////////////////////////////////////////////////////
 static unsigned int _sdc_set_block_size(unsigned int len)
 {
@@ -292,13 +295,9 @@
     register int i;
 
-    /*
-     * For now, supported block size is 512 bytes
-     */
+    // For now, supported block size is 512 bytes
     if (len != 512) return 1;
 
-    /*
-     * When using high capacity SDCARD, the block_length is not a number of bytes
-     * but a number of blocks (transfer unit)
-     */
+    // When using high capacity SDCARD, the block_length is not a number of bytes
+    // but a number of blocks (transfer unit)
     if (sdcard.sdhc)
     {
@@ -328,11 +327,16 @@
 }
 
+///////////////////////////////////////////////////////////////////////////////
+//      _sdc_init()
+// This function initializes the SPI controller and call sdc_open to
+// initializes SD card
+// - channel: channel to initialize (only channel 0 supported)
+// Returns 0 if success, other value if failure
+///////////////////////////////////////////////////////////////////////////////
 unsigned int _sdc_init( unsigned int channel )
 {
     spi = (struct spi_dev*) &seg_ioc_base;
 
-    /**
-     * Initializing the SPI controller
-     */
+    // initializing the SPI controller
     _spi_init (
         spi           ,
@@ -344,7 +348,5 @@
     );
 
-    /**
-     * Initializing the SD Card
-     */
+    // initializing the SD Card
     unsigned int iter = 0;
     unsigned char sdcard_rsp;
@@ -376,7 +378,5 @@
     }
 
-    /**
-     * Set the block length of the SD Card
-     */
+    // set the block length of the SD Card
     sdcard_rsp = _sdc_set_block_size(512);
     if (sdcard_rsp)
@@ -386,12 +386,10 @@
     }
 
-    /**
-     * Incrementing SDCARD clock frequency for normal function
-     */
+    // incrementing SDCARD clock frequency for normal function
     _spi_init (
         spi         ,
-        10000000    , /**< SPI_clk 10 Mhz */
-        SYSCLK_FREQ , /**< Sys_clk        */
-        -1          , /**< Charlen: 8     */
+        10000000    , // SPI_clk 10 Mhz
+        SYSCLK_FREQ , // Sys_clk
+        -1          , // Charlen: 8
         -1          ,
         -1
@@ -450,7 +448,5 @@
         }
 
-        /*
-         * Get the CRC16 (comes at the end of the data block)
-         */
+        // Get the CRC16 (comes at the end of the data block)
         _sdc_receive_char(); // first byte
         _sdc_receive_char(); // second byte
@@ -464,4 +460,13 @@
 }
 
+///////////////////////////////////////////////////////////////////////////////
+//     _sdc_write() (not supported for now)
+// Transfer data from memory buffer to SD card device. 
+// - mode     : BOOT / KERNEL / USER
+// - lba      : destination first block index on the SD card
+// - buffer   : base address of the memory buffer (must be word aligned)
+// - count    : number of blocks to be transfered.
+// Returns 0 if success, > 0 if error.
+///////////////////////////////////////////////////////////////////////////////
 unsigned int _sdc_write( unsigned int mode,
                          unsigned int lba,
@@ -472,10 +477,23 @@
 }
 
+///////////////////////////////////////////////////////////////////////////////
+//     _sdc_get_status()
+// Transfer data from memory buffer to SD card device. 
+// - channel: channel index
+// - status: this pointer is used to transmit the status value to caller. 
+// Returns 0 if success, > 0 if error.
+///////////////////////////////////////////////////////////////////////////////
 unsigned int _sdc_get_status( unsigned int channel ,
                               unsigned int* status )
 {
-    return BLOCK_DEVICE_IDLE;
-}
-
+    *status = BLOCK_DEVICE_IDLE;
+
+    return 0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+//     _sdc_get_block_size()
+// Returns the block size in bytes of the SD card
+///////////////////////////////////////////////////////////////////////////////
 unsigned int _sdc_get_block_size()
 {
@@ -484,7 +502,9 @@
 }
 
-
-
-/*
- * vim: tabstop=4 : shiftwidth=4 : expandtab : softtabstop=4
- */
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
