Microchip® Advanced Software Framework

nand_flash_ecc.h File Reference

ECC flash operation.

This file contains definitions and functions for ECC NAND Flash operation.

Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.

#include "nand_flash_raw.h"

Data Structures

struct  nand_flash_ecc
 NAND Flash ECC layer is called by upper layer, it will call the raw layer to do write/read operations, and do ECC check to the write/read result, it then will feedback the ECC check result to the upper layer. More...
 

Functions

uint32_t nand_flash_ecc_initialize (struct nand_flash_ecc *ecc, const struct nand_flash_model *model, uint32_t command_address, uint32_t address_address, uint32_t data_address)
 Initialize a nand_flash_ecc instance. More...
 
uint32_t nand_flash_ecc_read_page (const struct nand_flash_ecc *ecc, uint16_t block, uint16_t page, uint8_t *data, uint8_t *spare)
 Read the data and/or spare of a page of a NAND Flash chip, and verify that the data is valid using the ECC information contained in the spare. More...
 
uint32_t nand_flash_ecc_write_page (const struct nand_flash_ecc *ecc, uint16_t block, uint16_t page, uint8_t *data, uint8_t *spare)
 Write 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. More...
 

uint32_t nand_flash_ecc_initialize ( struct nand_flash_ecc ecc,
const struct nand_flash_model model,
uint32_t  command_address,
uint32_t  address_address,
uint32_t  data_address 
)

Initialize a nand_flash_ecc instance.

Parameters
eccPointer to an nand_flash_ecc instance.
modelPointer to the underlying NAND chip model. Can be 0.
command_addressAddress at which commands are sent.
address_addressAddress at which addresses are sent.
data_addressAddress at which data is sent.
Returns
0 if the initialization is done; or return the error code.

References nand_flash_raw_initialize(), and RAW.

uint32_t nand_flash_ecc_read_page ( const struct nand_flash_ecc ecc,
uint16_t  block,
uint16_t  page,
uint8_t *  data,
uint8_t *  spare 
)

Read the data and/or spare of a page of a NAND Flash chip, and verify that the data is valid using the ECC information contained in the spare.

If one buffer pointer is 0, the corresponding area is not saved.

Parameters
eccPointer to an nand_flash_ecc instance.
blockNumber of block to read from.
pageNumber of page to read inside given block.
dataData area buffer.
spareSpare area buffer.
Returns
0 if the data has been read and is valid; otherwise returns either NAND_COMMON_ERROR_CORRUPTEDDATA or ...

References HAMMING_ERROR_SINGLE_BIT, hamming_verify_256x(), MODEL, NAND_COMMON_ERROR_CORRUPTEDDATA, NAND_COMMON_MAX_PAGE_SPARE_SIZE, NAND_COMMON_MAX_SPARE_ECC_BYTES, nand_flash_model_get_page_data_size(), nand_flash_model_get_scheme(), nand_flash_raw_read_page(), nand_flash_spare_scheme_read_ecc(), RAW, and spare_buffer.

Referenced by main(), and run_test_software_ecc().

uint32_t nand_flash_ecc_write_page ( const struct nand_flash_ecc ecc,
uint16_t  block,
uint16_t  page,
uint8_t *  data,
uint8_t *  spare 
)

Write 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.

Parameters
eccPointer to an nand_flash_ecc instance.
blockNumber of block to read from.
pageNumber of page to read inside given block.
dataData area buffer.
spareSpare area buffer.
Returns
0 if successful; otherwise return the error code.

Compute ECC on the new data, if provided. If not provided, hamming code set to 0xFFFF.. to keep existing bytes.

References hamming_compute_256x(), MODEL, NAND_COMMON_MAX_PAGE_SPARE_SIZE, NAND_COMMON_MAX_SPARE_ECC_BYTES, nand_flash_model_get_page_data_size(), nand_flash_model_get_scheme(), nand_flash_raw_write_page(), nand_flash_spare_scheme_write_ecc(), RAW, and spare_buffer.

Referenced by main(), and run_test_software_ecc().