X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fdrv%2Fsd.h;h=3e6ca6f373d5b56a17a34bd30146047bea8a7503;hb=2f50401ce6fac0fef325bfb851ef32193ee32dc8;hp=813e65a7124c15416be948b25f15d1533cf285b3;hpb=5579f0a02cd782e3df7849e2f84640bd1160e232;p=bertos.git diff --git a/bertos/drv/sd.h b/bertos/drv/sd.h index 813e65a7..3e6ca6f3 100644 --- a/bertos/drv/sd.h +++ b/bertos/drv/sd.h @@ -35,7 +35,7 @@ * \author Francesco Sacchi * * $WIZ$ module_name = "sd" - * $WIZ$ module_depends = "kfile", "timer", "kblock" + * $WIZ$ module_depends = "kfile", "timer", "kblock", "sd_spi" * $WIZ$ module_hw = "bertos/hw/hw_sd.h" * $WIZ$ module_configuration = "bertos/cfg/cfg_sd.h" */ @@ -99,6 +99,18 @@ typedef struct SDssr #endif +#define SD_START_DELAY 10 +#define SD_INIT_TIMEOUT ms_to_ticks(2000) +#define SD_IDLE_RETRIES 4 +#define SD_DEFAULT_BLOCKLEN 512 + +/** + * $WIZ$ sd_mode = "SD_SDMMC_MODE", "SD_SPI_MODE" + * \{ + */ +#define SD_SDMMC_MODE 0 +#define SD_SPI_MODE 1 +/** \} */ #define SD_UNBUFFERED BV(0) ///< Open SD memory disabling page caching, no modification and partial write are allowed. @@ -123,9 +135,11 @@ typedef struct Sd } Sd; -bool sd_initUnbuf(Sd *sd, KFile *ch); -bool sd_initBuf(Sd *sd, KFile *ch); +bool sd_hw_initUnbuf(Sd *sd, KFile *ch); +bool sd_hw_initBuf(Sd *sd, KFile *ch); +bool sd_spi_initUnbuf(Sd *sd, KFile *ch); +bool sd_spi_initBuf(Sd *sd, KFile *ch); #if CPU_CM3_SAM3X8 @@ -135,8 +149,8 @@ void sd_dumpSsr(Sd *sd); void sd_sendInit(void); void sd_goIdle(void); -int sd_sendIfCond(void); -int sd_sendAppOpCond(void); +int sd_sendIfCond(Sd *sd); +int sd_sendAppOpCond(Sd *sd); int sd_getCid(Sd *sd, uint32_t addr, uint8_t flag); int sd_getCsd(Sd *sd); @@ -153,6 +167,7 @@ int sd_setBusWidth(Sd *sd, size_t len); int sd_set_BlockLen(Sd *sd, size_t len); void sd_setHightSpeed(Sd *sd); int sd_readSingleBlock(Sd *sd, size_t index, uint32_t *buf, size_t words); +int sd_writeSingleBlock(Sd *sd, size_t index, uint32_t *buf, size_t words); INLINE int sd_setBus4bit(Sd *sd) @@ -167,8 +182,14 @@ INLINE int sd_setBus1bit(Sd *sd) #endif +// For old compatibility. +#ifndef CONFIG_SD_MODE + #define CONFIG_SD_MODE SD_SPI_MODE + #define SD_INCLUDE_SPI_SOURCE +#endif #if CONFIG_SD_OLD_INIT + #if !(ARCH & ARCH_NIGHTTEST) #warning "Deprecated: this API will be removed in the next major release," #warning "please disable CONFIG_SD_OLD_INIT and pass explicitly the SD context to sd_init()." @@ -186,7 +207,11 @@ INLINE int sd_setBus1bit(Sd *sd) * * \see CONFIG_SD_OLD_INIT. */ - #define sd_init(ch) {static struct Sd sd; sd_initUnbuf(&sd, (ch));} + #if CONFIG_SD_MODE == SD_SPI_MODE + #define sd_init(ch) {static struct Sd sd; sd_spi_initUnbuf(&sd, (ch));} + #else + #define sd_init(ch) {static struct Sd sd; sd_hw_initUnbuf(&sd, (ch));} + #endif #else @@ -202,7 +227,11 @@ INLINE int sd_setBus1bit(Sd *sd) * * \return true if initialization succeds, false otherwise. */ - #define sd_init(sd, ch, buffered) ((buffered & SD_UNBUFFERED) ? sd_initUnbuf((sd), (ch)) : sd_initBuf((sd), (ch))) + #if CONFIG_SD_MODE == SD_SPI_MODE + #define sd_init(sd, ch, buffered) ((buffered & SD_UNBUFFERED) ? sd_spi_initUnbuf((sd), (ch)) : sd_spi_initBuf((sd), (ch))) + #else + #define sd_init(sd, ch, buffered) ((buffered & SD_UNBUFFERED) ? sd_hw_initUnbuf((sd), (ch)) : sd_hw_initBuf((sd), (ch))) + #endif #endif