X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fdrv%2Fnand.h;h=87faf65e3e985fcac249499bda9900ad44caacee;hb=15810459b8f5fb09b12cef6f8e4d4e64d167087b;hp=821fa004ac1c3bffb77bdf7fdcd52cadff838103;hpb=bd20c479c3668f2a6a109aad6059228126964c9b;p=bertos.git diff --git a/bertos/drv/nand.h b/bertos/drv/nand.h index 821fa004..87faf65e 100644 --- a/bertos/drv/nand.h +++ b/bertos/drv/nand.h @@ -29,20 +29,20 @@ * Copyright 2011 Develer S.r.l. (http://www.develer.com/) * --> * -* \brief NAND driver +* \brief ONFI 1.0 compliant NAND kblock driver * * \author Stefano Fedrigo * * $WIZ$ module_name = "nand" * $WIZ$ module_depends = "timer", "kblock", "heap" * $WIZ$ module_configuration = "bertos/cfg/cfg_nand.h" +* */ #ifndef DRV_NAND_H #define DRV_NAND_H #include "cfg/cfg_nand.h" -#include #include @@ -61,12 +61,6 @@ #define NAND_ERR_ECC BV(5) ///< Unrecoverable ECC error /** \} */ -#define NAND_PAGE_SIZE (CONFIG_NAND_DATA_SIZE + CONFIG_NAND_SPARE_SIZE) -#define NAND_BLOCK_SIZE (CONFIG_NAND_DATA_SIZE * CONFIG_NAND_PAGES_PER_BLOCK) - -// Number of usable blocks, and index of first remapping block -#define NAND_NUM_USER_BLOCKS (CONFIG_NAND_NUM_BLOCK - CONFIG_NAND_NUM_REMAP_BLOCKS) - // NAND commands #define NAND_CMD_READ_1 0x00 @@ -87,18 +81,10 @@ #define NAND_CMD_RESET 0xFF -// Get block from page -#define PAGE(blk) ((blk) * CONFIG_NAND_PAGES_PER_BLOCK) - -// Page from block and page in block -#define BLOCK(page) ((uint16_t)((page) / CONFIG_NAND_PAGES_PER_BLOCK)) -#define PAGE_IN_BLOCK(page) ((uint16_t)((page) % CONFIG_NAND_PAGES_PER_BLOCK)) - - /** * NAND context. */ -typedef struct Mt29f +typedef struct Nand { KBlock fd; // KBlock descriptor @@ -107,7 +93,7 @@ typedef struct Mt29f uint16_t *block_map; // For bad blocks remapping uint16_t remap_start; // First unused remap block -} Mt29f; +} Nand; /* * Kblock id. @@ -117,36 +103,36 @@ typedef struct Mt29f /** * Convert + ASSERT from generic KBlock to NAND context. */ -INLINE Mt29f *NAND_CAST(KBlock *kb) +INLINE Nand *NAND_CAST(KBlock *kb) { ASSERT(kb->priv.type == KBT_NAND); - return (Mt29f *)kb; + return (Nand *)kb; } struct Heap; // Kblock interface -bool nand_init(Mt29f *chip, struct Heap *heap, unsigned chip_select); -bool nand_initUnbuffered(Mt29f *chip, struct Heap *heap, unsigned chip_select); +bool nand_init(Nand *chip, struct Heap *heap, unsigned chip_select); +bool nand_initUnbuffered(Nand *chip, struct Heap *heap, unsigned chip_select); // NAND specific functions -bool nand_getDevId(Mt29f *chip, uint8_t dev_id[5]); -int nand_blockErase(Mt29f *chip, uint16_t block); -void nand_format(Mt29f *chip); +bool nand_getDevId(Nand *chip, uint8_t dev_id[5]); +int nand_blockErase(Nand *chip, uint16_t block); +void nand_format(Nand *chip); #ifdef _DEBUG -void nand_ruinSomeBlocks(Mt29f *chip); +void nand_ruinSomeBlocks(Nand *chip); #endif // Hardware specific functions, implemented by cpu specific module -bool nand_waitReadyBusy(Mt29f *chip, time_t timeout); -bool nand_waitTransferComplete(Mt29f *chip, time_t timeout); -void nand_sendCommand(Mt29f *chip, uint32_t cmd1, uint32_t cmd2, +bool nand_waitReadyBusy(Nand *chip, time_t timeout); +bool nand_waitTransferComplete(Nand *chip, time_t timeout); +void nand_sendCommand(Nand *chip, uint32_t cmd1, uint32_t cmd2, int num_cycles, uint32_t cycle0, uint32_t cycle1234); -uint8_t nand_getChipStatus(Mt29f *chip); -void *nand_dataBuffer(Mt29f *chip); -bool nand_checkEcc(Mt29f *chip); -void nand_computeEcc(Mt29f *chip, const void *buf, size_t size, uint32_t *ecc, size_t ecc_size); -void nand_hwInit(Mt29f *chip); +uint8_t nand_getChipStatus(Nand *chip); +void *nand_dataBuffer(Nand *chip); +bool nand_checkEcc(Nand *chip); +void nand_computeEcc(Nand *chip, const void *buf, size_t size, uint32_t *ecc, size_t ecc_size); +void nand_hwInit(Nand *chip); #endif /* DRV_NAND_H */