mirror of
https://github.com/apache/nuttx.git
synced 2026-05-23 14:58:13 +08:00
MTD NAND: Beginning of software ECC logic
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/mtd/hamming.h
|
||||
*
|
||||
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* This logic was taken directly from Atmel sample code with only
|
||||
* modifications for better integration with NuttX. The Atmel sample
|
||||
* code has a BSD compatibile license that requires this copyright notice:
|
||||
*
|
||||
* Copyright (c) 2011, Atmel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the names NuttX nor Atmel nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_HAMMING_H
|
||||
#define __INCLUDE_NUTTX_HAMMING_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#include <nuttx/mtd/mtd.h>
|
||||
#include <nuttx/mtd/nand_raw.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
/* These are the possible errors when trying to verify a block of data
|
||||
* encoded using a Hamming code:
|
||||
*
|
||||
* HAMMING_SUCCESS - Block verified without errors
|
||||
* HAMMING_ERROR_SINGLEBIT - A single bit was incorrect but has been
|
||||
* recovered
|
||||
* HAMMING_ERROR_ECC - The original code has been corrupted
|
||||
* HAMMING_ERROR_MULTIPLEBITS - Multiple bits are incorrect in the data
|
||||
* and they cannot be corrected
|
||||
*/
|
||||
|
||||
#define HAMMING_SUCCESS 0
|
||||
#define HAMMING_ERROR_SINGLEBIT 1
|
||||
#define HAMMING_ERROR_ECC 2
|
||||
#define HAMMING_ERROR_MULTIPLEBITS 3
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __INCLUDE_NUTTX_HAMMING_H */
|
||||
@@ -81,8 +81,10 @@ extern "C"
|
||||
* Name: nandecc_readpage
|
||||
*
|
||||
* Description:
|
||||
* Reads the data and/or the spare areas of a page of a NAND FLASH into the
|
||||
* provided buffers.
|
||||
* Reads the data and/or spare areas of a page of a NAND FLASH chip and
|
||||
* verifies that the data is valid using the ECC information contained in
|
||||
* the spare area. If a buffer pointer is NULL, then the corresponding area
|
||||
* is not saved.
|
||||
*
|
||||
* Input parameters:
|
||||
* nand - Upper-half, NAND FLASH interface
|
||||
@@ -103,14 +105,18 @@ int nandecc_readpage(FAR struct nand_dev_s *nand, off_t block,
|
||||
* Name: nandecc_writepage
|
||||
*
|
||||
* Description:
|
||||
* Writes the data and/or the spare area of a page on a NAND FLASH chip.
|
||||
* Writes the data and/or spare area of a NAND FLASH page after
|
||||
* calculating an ECC for the data area and storing it in the spare. If no
|
||||
* data buffer is provided, the ECC is read from the existing page spare.
|
||||
* If no spare buffer is provided, the spare area is still written with the
|
||||
* ECC information calculated on the data buffer.
|
||||
*
|
||||
* Input parameters:
|
||||
* nand - Upper-half, NAND FLASH interface
|
||||
* block - Number of the block where the page to write resides.
|
||||
* page - Number of the page to write inside the given block.
|
||||
* data - Buffer containing the data to be writting
|
||||
* spare - Buffer conatining the spare data to be written.
|
||||
* spare - Buffer containing the spare data to be written.
|
||||
*
|
||||
* Returned value.
|
||||
* OK is returned in success; a negated errno value is returned on failure.
|
||||
@@ -118,8 +124,8 @@ int nandecc_readpage(FAR struct nand_dev_s *nand, off_t block,
|
||||
****************************************************************************/
|
||||
|
||||
int nandecc_writepage(FAR struct nand_dev_s *nand, off_t block,
|
||||
unsigned int page, FAR const void *data,
|
||||
FAR const void *spare);
|
||||
unsigned int page, FAR const void *data,
|
||||
FAR void *spare);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -81,6 +81,19 @@
|
||||
#define COMMAND_READ_A 0x00
|
||||
#define COMMAND_READ_C 0x50
|
||||
|
||||
/* Type of ECC to be performed (must be enabled in the configuration)
|
||||
* NANDECC_NONE No ECC, only raw NAND FLASH accesses
|
||||
* NANDECC_SWECC Software ECC. Handled by the common MTD logic.
|
||||
* NANDECC_HWECC Values >= 2 are various hardware ECC implementations
|
||||
* all handled by the lower-half, raw NAND FLASH driver.
|
||||
* These hardware ECC types may be extended beginning
|
||||
* with the value NANDECC_HWECC.
|
||||
*/
|
||||
|
||||
#define NANDECC_NONE 0
|
||||
#define NANDECC_SWECC 1
|
||||
#define NANDECC_HWECC 2
|
||||
|
||||
/* NAND access macros */
|
||||
|
||||
#define WRITE_COMMAND8(raw, command) \
|
||||
@@ -151,7 +164,7 @@
|
||||
* block - Number of the block where the page to write resides.
|
||||
* page - Number of the page to write inside the given block.
|
||||
* data - Buffer containing the data to be writting
|
||||
* spare - Buffer conatining the spare data to be written.
|
||||
* spare - Buffer containing the spare data to be written.
|
||||
*
|
||||
* Returned value.
|
||||
* OK is returned in succes; a negated errno value is returned on failure.
|
||||
@@ -171,13 +184,19 @@
|
||||
|
||||
struct nand_raw_s
|
||||
{
|
||||
/* NAND data */
|
||||
/* NAND data description */
|
||||
|
||||
struct nand_model_s model; /* The NAND model storage */
|
||||
uintptr_t cmdaddr; /* NAND command address base */
|
||||
uintptr_t addraddr; /* NAND address address base */
|
||||
uintptr_t dataaddr; /* NAND data address */
|
||||
|
||||
#ifdef CONFIG_MTD_NAND_BLOCKCHECK
|
||||
/* ECC */
|
||||
|
||||
uint8_t ecc; /* See enum nand_ecc_e */
|
||||
#endif
|
||||
|
||||
/* NAND operations */
|
||||
|
||||
CODE int (*eraseblock)(FAR struct nand_raw_s *raw, off_t block);
|
||||
@@ -206,22 +225,6 @@ extern "C"
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nand_chipid
|
||||
*
|
||||
* Description:
|
||||
* Reads and returns the identifiers of a NAND FLASH chip
|
||||
*
|
||||
* Input Parameters:
|
||||
* raw - Pointer to a struct nand_raw_s instance.
|
||||
*
|
||||
* Returned Value:
|
||||
* id1|(id2<<8)|(id3<<16)|(id4<<24)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint32_t nand_chipid(FAR struct nand_raw_s *raw);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user