X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fdrv%2Fmt29f.h;h=e6c8ad7d9b8859d196caaaec2370112efd6f819f;hb=a003d4c2a077f7c60ab84a6894bcb9c423ec09a7;hp=b5c466656c327289af8e6801c85325eb227779ad;hpb=ecbc38a94d767a547fb44ee30faef2bccc20c775;p=bertos.git diff --git a/bertos/drv/mt29f.h b/bertos/drv/mt29f.h index b5c46665..e6c8ad7d 100644 --- a/bertos/drv/mt29f.h +++ b/bertos/drv/mt29f.h @@ -33,29 +33,11 @@ * * This module allows read/write access to Micron MT29F serial * NANDs. -* It is a block device, so it must be accessed using the KBlock -* interface functions (see kblock.h). -* -* Once you have opened the flash for writing, you may want to use -* kblock_trim() to avoid overwriting data on other flash banks. -* -* Example usage: -* \code -* Flash fls; -* flash_init(&fls, 0); -* // enable access only on desired blocks -* // start block = 50, num blocks = 20 -* kblock_trim(&fls.blk, 50, 20); -* // ... -* // now write to the flash -* // block number is automatically converted -* kblock_write(&fls.blk, 0, buf, 0, 128); -* \endcode * * \author Stefano Fedrigo * * $WIZ$ module_name = "mt29f" -* $WIZ$ module_depends = "kfile", "kfile_block", "kblock" +* $WIZ$ module_depends = "timer", "kblock", "heap" * $WIZ$ module_configuration = "bertos/cfg/cfg_mt29f.h" */ @@ -63,43 +45,59 @@ #define DRV_MT29F_H #include "cfg/cfg_mt29f.h" - #include -#include - #include -#include -#include -#include +/** + * \name Error codes. + * \{ + */ +#define MT29F_ERR_ERASE BV(1) ///< Error erasing a block +#define MT29F_ERR_WRITE BV(2) ///< Error writing a page +#define MT29F_ERR_RD_TMOUT BV(3) ///< Read timeout +#define MT29F_ERR_WR_TMOUT BV(4) ///< Write timeout +#define MT29F_ERR_ECC BV(5) ///< Unrecoverable ECC error +/** \} */ -struct Mt29fHardware; /** - * MT29F KBlock context structure. + * MT29F context. */ typedef struct Mt29f { - KBlock blk; ///< KBlock context - struct Mt29fHardware *hw; + KBlock kblock; + + uint8_t chip_select; + uint8_t status; + + uint16_t *block_map; // For bad blocks remapping + uint16_t remap_start; // First unused remap block } Mt29f; /* - * Kblock type ID. + * Kblock id. */ -#define KBT_MT29F MAKE_ID('M', 'T', '2', '9') +#define KBT_NAND MAKE_ID('N', 'A', 'N', 'D') /** - * Convert + ASSERT from generic KBlock to Flash. - */ -INLINE Mt29f *FLASH_CAST(KBlock *fls) +* Convert + ASSERT from generic KBlock to NAND context. +*/ +INLINE Mt29f *MT29F_CAST(KBlock *kb) { - ASSERT(fls->priv.type == KBT_MT29F); - return (Mt29f *)fls; + ASSERT(kb->priv.type == KBT_NAND); + return (Mt29f *)kb; } -void mt29f_hw_init(Mt29f *fls); -void mt29f_hw_initUnbuffered(Mt29f *fls); +struct Heap; + +// Kblock interface +bool mt29f_init(Mt29f *chip, struct Heap *heap, unsigned chip_select); +bool mt29f_initUnbuffered(Mt29f *chip, struct Heap *heap, unsigned chip_select); + +// Private functions: use at your own risk, could change in any moment +bool mt29f_getDevId(Mt29f *chip, uint8_t dev_id[5]); +int mt29f_blockErase(Mt29f *chip, uint16_t block); + #endif /* DRV_MT29F_H */