From: batt Date: Thu, 8 Jul 2010 16:59:42 +0000 (+0000) Subject: Increase read/write performances; add some comments. X-Git-Tag: 2.6.0~301 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=9c7e10e5ff169a3ffb854b8023b103c9ef886ab8;p=bertos.git Increase read/write performances; add some comments. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4015 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/drv/sd.c b/bertos/drv/sd.c index 9880dfe1..2b462b7b 100644 --- a/bertos/drv/sd.c +++ b/bertos/drv/sd.c @@ -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) { diff --git a/bertos/drv/sd.h b/bertos/drv/sd.h index 368e0d4f..9845fcb4 100644 --- a/bertos/drv/sd.h +++ b/bertos/drv/sd.h @@ -31,13 +31,11 @@ * * \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 * * $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" */ @@ -53,12 +51,15 @@ #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);