X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fdrv%2Fsd.h;h=22a19d1e7d09322be23dc605caf16d58085fbe11;hb=23f95752ffe03a5f0c262b1f896211aedb185dda;hp=8be9c501749cb1f243e284ce3a586acf5c8827d2;hpb=1fb9b95e56d03933e5b38709a497b5f5f892ea23;p=bertos.git diff --git a/bertos/drv/sd.h b/bertos/drv/sd.h index 8be9c501..22a19d1e 100644 --- a/bertos/drv/sd.h +++ b/bertos/drv/sd.h @@ -31,83 +31,89 @@ * * \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. * - * \version $Id$ * \author Francesco Sacchi + * + * $WIZ$ module_name = "sd" + * $WIZ$ module_depends = "kfile", "timer", "kblock" + * $WIZ$ module_hw = "bertos/hw/hw_sd.h" + * $WIZ$ module_configuration = "bertos/cfg/cfg_sd.h" */ #ifndef DRV_SD_H #define DRV_SD_H +#include +#include + #include -#include -#include -bool sd_test(void); +#include "cfg/cfg_sd.h" /** - * Initializes the SD driver. - * - * \param _fd A pointer to a kfile where the SD will read/write to. - * \return true if initialization succeds, false otherwise. + * SD Card context structure. */ -bool sd_init(KFile *_fd); +typedef struct Sd +{ + KBlock b; ///< KBlock base class + KFile *ch; ///< SPI communication channel + 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; -#if CONFIG_FAT_DRIVES == 1 +bool sd_initUnbuf(Sd *sd, KFile *ch); +bool sd_initBuf(Sd *sd, KFile *ch); - /** - * Same as sd_disk_status. - * - * Card initialization must be done with sd_init. - */ - #define sd_disk_initialize disk_initialize +#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()." + #endif /** - * Return the status of the disk. + * Initializes the SD driver. * - * \param drv The number of the drive to initialize. Currently only drive 0 is allowed. - * \return RES_OK if the sd card was correctly initialized by a previous call to sd_init(), STA_NOINIT otherwise. - */ - #define sd_disk_status disk_status - /** - * Read \a count sectors from SD card. + * \param ch A pointer to a SPI channel where the SD will read/write to. * - * \param drv The drive number to read from. Only 0 is supported. - * \param buf A buffer to store read data. You can get sector size using sd_disk_ioctl. - * \param sector Start sector number. - * \param count The number of sectors to read. - * \return RES_OK if the function succeded, RES_ERROR if any error occurred, RES_NOTRDY if the disk is not initialized. + * \return true if initialization succeds, false otherwise. * - * \sa diskio.h + * \note This API is deprecated, disable CONFIG_SD_OLD_INIT and + * use the new one instead. + * + * \see CONFIG_SD_OLD_INIT. */ - #define sd_disk_read disk_read - - #if CONFIG_FAT_FS_READONLY == 0 - - /** - * Write \a count sectors to SD card. - * - * \param drv The drive number to read from. Only 0 is supported. - * \param buf The data to be written. - * \param sector Start sector number. - * \param count The number of sectors to write. - * \return RES_OK if the function succeded, RES_ERROR if any error occurred, RES_NOTRDY if the disk is not initialized. - * - * \sa diskio.h - */ - #define sd_disk_write disk_write - #endif + #define sd_init(ch) {static struct Sd sd; sd_initUnbuf(&sd, (ch));} + +#else /** - * Interface to send device independant commands to the device. + * Initializes the SD driver. * - * \sa diskio.h and related documentation for further explanations. + * \param sd The SD KBlock context. + * \param ch A pointer to a SPI channel where the SD will read/write to. + * \param buffered Set to true if you want the KBlock to be buffered, + * to false otherwise. The FatFs module does not require the device + * to be buffered because it has an internal cache. This will save + * 512 bytes of RAM in this case. + * + * \return true if initialization succeds, false otherwise. */ - #define sd_disk_ioctl disk_ioctl + #define sd_init(sd, ch, buffered) ((buffered) ? sd_initBuf((sd), (ch)) : sd_initUnbuf((sd), (ch))) + +#endif + + +#define KBT_SD MAKE_ID('S', 'D', 'B', 'K') + +bool sd_test(Sd *sd); +void sd_writeTest(Sd *sd); + +INLINE Sd *SD_CAST(KBlock *b) +{ + ASSERT(b->priv.type == KBT_SD); + return (Sd *)b; +} -#endif /* CONFIG_FAT_DRIVES == 1 */ #endif /* DRV_SD_H */