Increase read/write performances; add some comments.
authorbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 8 Jul 2010 16:59:42 +0000 (16:59 +0000)
committerbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 8 Jul 2010 16:59:42 +0000 (16:59 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4015 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/drv/sd.c
bertos/drv/sd.h

index 9880dfe15cabde7e7c35b11d1b09f27349e3f088..2b462b7b4734ba8a800010c7ee005f841ba5ef73 100644 (file)
@@ -243,10 +243,14 @@ static size_t sd_readDirect(struct KBlock *b, block_idx_t idx, void *buf, size_t
        Sd *sd = SD_CAST(b);
        LOG_INFO("reading from block %ld, offset %d, size %d\n", idx, offset, size);
 
-       if ((sd->r1 = sd_setBlockLen(sd, size)))
+       if (sd->tranfer_len != size)
        {
-               LOG_ERR("setBlockLen failed: %04X\n", sd->r1);
-               return 0;
+               if ((sd->r1 = sd_setBlockLen(sd, size)))
+               {
+                       LOG_ERR("setBlockLen failed: %04X\n", sd->r1);
+                       return 0;
+               }
+               sd->tranfer_len = size;
        }
 
        SD_SELECT(sd);
@@ -280,10 +284,14 @@ static int sd_writeBlock(KBlock *b, block_idx_t idx, const void *buf)
        KFile *fd = sd->ch;
 
        LOG_INFO("writing block %ld\n", idx);
-       if ((sd->r1 = sd_setBlockLen(sd, SD_DEFAULT_BLOCKLEN)))
+       if (sd->tranfer_len != SD_DEFAULT_BLOCKLEN)
        {
-               LOG_ERR("setBlockLen failed: %04X\n", sd->r1);
-               return sd->r1;
+               if ((sd->r1 = sd_setBlockLen(sd, SD_DEFAULT_BLOCKLEN)))
+               {
+                       LOG_ERR("setBlockLen failed: %04X\n", sd->r1);
+                       return sd->r1;
+               }
+               sd->tranfer_len = SD_DEFAULT_BLOCKLEN;
        }
 
        SD_SELECT(sd);
@@ -461,6 +469,7 @@ static bool sd_blockInit(Sd *sd, KFile *ch)
        }
 
        sd->r1 = sd_setBlockLen(sd, SD_DEFAULT_BLOCKLEN);
+       sd->tranfer_len = SD_DEFAULT_BLOCKLEN;
 
        if (sd->r1)
        {
index 368e0d4fff975d6d375257004ed01c1f2f3e4fca..9845fcb4fcb489bb6a90835ba7cb692b93a0f8ef 100644 (file)
  *
  * \brief Function library for secure digital memory.
  *
- * Right now, the interface for these function is the one defined in diskio.h from
- * the FatFS module.
  *
  * \author Francesco Sacchi <batt@develer.com>
  *
  * $WIZ$ module_name = "sd"
- * $WIZ$ module_depends = "kfile", "timer"
+ * $WIZ$ module_depends = "kfile", "timer", "kblock"
  * $WIZ$ module_hw = "bertos/hw/hw_sd.h"
  * $WIZ$ module_configuration = "bertos/cfg/cfg_sd.h"
  */
 
 #include "cfg/cfg_sd.h"
 
-
+/**
+ * SD Card context structure.
+ */
 typedef struct Sd
 {
-       KBlock b;
+       KBlock b;   ///< KBlock base class
        KFile *ch;  ///< SPI communication channel
-       uint16_t r1;
+       uint16_t r1;  ///< Last status data received from SD
+       uint16_t tranfer_len; ///< Lenght for the read/write commands, cached in order to increase speed.
 } Sd;
 
 bool sd_initUnbuf(Sd *sd, KFile *ch);