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);
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);
}
sd->r1 = sd_setBlockLen(sd, SD_DEFAULT_BLOCKLEN);
+ sd->tranfer_len = SD_DEFAULT_BLOCKLEN;
if (sd->r1)
{
*
* \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);