Microchip® Advanced Software Framework

nand_flash_raw.h File Reference

Raw flash operation.

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

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

#include "nand_flash_model.h"

Data Structures

struct  nand_flash_raw
 The raw NAND Flash layer drives hardware-specific Bus Read and Bus Write operations to communicate with the NAND Flash device. More...
 

Functions

uint32_t nand_flash_raw_copy_block (const struct nand_flash_raw *raw, uint16_t source_block, uint16_t dest_block)
 Copies the data of one whole block of a NAND Flash device to another block. More...
 
uint32_t nand_flash_raw_copy_page (const struct nand_flash_raw *raw, uint16_t source_block, uint16_t source_page, uint16_t dest_block, uint16_t dest_page)
 Copy the data in a page of the NAND Flash device to an other page on that same chip. More...
 
uint32_t nand_flash_raw_erase_block (const struct nand_flash_raw *raw, uint16_t block)
 Erase the specified block of the device, retrying several time if it fails. More...
 
uint32_t nand_flash_raw_initialize (struct nand_flash_raw *raw, const struct nand_flash_model *model, uint32_t command_address, uint32_t address_address, uint32_t data_address)
 Initializes a nand_flash_raw instance based on the given model and physical interface. More...
 
uint32_t nand_flash_raw_read_id (const struct nand_flash_raw *raw)
 Read and return the identifiers of a NAND Flash chip. More...
 
void nand_flash_raw_read_page (const struct nand_flash_raw *raw, uint16_t block, uint16_t page, uint8_t *data, uint8_t *spare)
 Read the data and/or the spare areas of a page of a NAND Flash into the provided buffers. More...
 
void nand_flash_raw_reset (const struct nand_flash_raw *raw)
 Reset a NAND Flash device. More...
 
uint32_t nand_flash_raw_write_page (const struct nand_flash_raw *raw, uint16_t block, uint16_t page, uint8_t *data, uint8_t *spare)
 Write the data and/or the spare areas of a page into a NAND Flash. More...
 

uint32_t nand_flash_raw_copy_block ( const struct nand_flash_raw raw,
uint16_t  source_block,
uint16_t  dest_block 
)

Copies the data of one whole block of a NAND Flash device to another block.

Parameters
rawPointer to a nand_flash_raw instance.
source_blockSource block number.
dest_blockDestination block number.
Returns
0 if successful; otherwise returns an NAND_COMMON_ERROR_BADBLOCK.
Note
Reference the Flash datasheet for the block address restriction.

References Assert, MODEL, NAND_COMMON_ERROR_BADBLOCK, nand_flash_model_get_block_size_in_pages(), and nand_flash_raw_copy_page().

uint32_t nand_flash_raw_copy_page ( const struct nand_flash_raw raw,
uint16_t  source_block,
uint16_t  source_page,
uint16_t  dest_block,
uint16_t  dest_page 
)

Copy the data in a page of the NAND Flash device to an other page on that same chip.

Parameters
rawPointer to a nand_flash_raw instance.
source_blockSource block number.
source_pageSource page number inside the source block.
dest_blockDestination block number.
dest_pageDestination page number inside the destination block.
Returns
0 if successful; otherwise returns an NAND_COMMON_ERROR_BADBLOCK.
Note
Reference the Flash datasheet for the block and page address restriction.

References copy_page(), and NAND_COMMON_ERROR_BADBLOCK.

Referenced by nand_flash_raw_copy_block().

uint32_t nand_flash_raw_erase_block ( const struct nand_flash_raw raw,
uint16_t  block 
)

Erase the specified block of the device, retrying several time if it fails.

Parameters
rawPointer to a nand_flash_raw instance.
blockNumber of the physical block to erase.
Returns
0 if successful; otherwise returns NAND_COMMON_ERROR_BADBLOCK.

References erase_block(), and NAND_COMMON_ERROR_BADBLOCK.

Referenced by main(), run_test_raw_read_write(), and run_test_software_ecc().

uint32_t nand_flash_raw_initialize ( struct nand_flash_raw raw,
const struct nand_flash_model model,
uint32_t  command_address,
uint32_t  address_address,
uint32_t  data_address 
)

Initializes a nand_flash_raw instance based on the given model and physical interface.

Parameters
rawPointer to a nand_flash_raw 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 successful; otherwise returns NAND_COMMON_ERROR_UNKNOWNMODEL.

References nand_flash_raw::address_address, ATPASTE2, BOARD_NAND_CS, nand_flash_raw::command_address, CONF_NF_BUSWIDTH, CONF_NF_CYCLE_TIMING, CONF_NF_PULSE_TIMING, CONF_NF_SETUP_TIMING, nand_flash_raw::data_address, data_address, delay_ms, gpio_configure_pin, IOPORT_DIR_INPUT, IOPORT_MODE_PULLUP, ioport_set_pin_dir(), ioport_set_pin_mode(), nand_flash_raw::model, NAND_COMMON_ERROR_UNKNOWNMODEL, nand_flash_model_find(), nand_flash_model_list, NAND_FLASH_MODEL_LIST_SIZE, nand_flash_raw_read_id(), nand_flash_raw_reset(), NF_WP_PIN, PIN_NF_CE_IDX, PIN_NF_RB_IDX, pmc_enable_periph_clk(), smc_set_cycle_timing(), smc_set_mode(), smc_set_pulse_timing(), smc_set_setup_timing(), and sysclk_get_cpu_hz().

Referenced by main(), nand_flash_ecc_initialize(), and run_test_initialization().

uint32_t nand_flash_raw_read_id ( const struct nand_flash_raw raw)

Read and return the identifiers of a NAND Flash chip.

Parameters
rawPointer to a nand_flash_raw instance.
Returns
id1|(id2<<8)|(id3<<16)|(id4<<24)

References delay_us, DISABLE_CE, ENABLE_CE, NAND_COMMAND_READID, READ_DATA8, WRITE_ADDRESS, and WRITE_COMMAND.

Referenced by nand_flash_raw_initialize(), and run_test_initialization().

void nand_flash_raw_read_page ( const struct nand_flash_raw raw,
uint16_t  block,
uint16_t  page,
uint8_t *  data,
uint8_t *  spare 
)

Read the data and/or the spare areas of a page of a NAND Flash into the provided buffers.

Parameters
rawPointer to a nand_flash_raw instance.
blockNumber of the physical block to read.
pageNumber of the page to read inside the given block.
dataBuffer where the data area will be read.
spareBuffer where the spare area will be read.
Note
If one of the buffer pointer is 0, the corresponding area is not read.

References delay_us, DISABLE_CE, ENABLE_CE, MODEL, NAND_COMMAND_READ_1, NAND_COMMAND_READ_2, NAND_COMMAND_READ_A, NAND_COMMAND_READ_C, nand_flash_model_get_block_size_in_pages(), nand_flash_model_get_page_data_size(), nand_flash_model_get_page_spare_size(), nand_flash_model_small_block(), read_data(), wait_ready(), write_column_address(), WRITE_COMMAND, and write_row_address().

Referenced by copy_page(), main(), nand_flash_ecc_read_page(), run_test_raw_read_write(), and run_test_software_ecc().

void nand_flash_raw_reset ( const struct nand_flash_raw raw)

Reset a NAND Flash device.

Parameters
rawPointer to a nand_flash_raw instance.

References DISABLE_CE, ENABLE_CE, NAND_COMMAND_RESET, wait_ready(), and WRITE_COMMAND.

Referenced by nand_flash_raw_initialize().

uint32_t nand_flash_raw_write_page ( const struct nand_flash_raw raw,
uint16_t  block,
uint16_t  page,
uint8_t *  data,
uint8_t *  spare 
)

Write the data and/or the spare areas of a page into a NAND Flash.

Parameters
rawPointer to a nand_flash_raw instance.
blockNumber of the physical block to write resides.
pageNumber of the page to write inside the given block.
dataBuffer where the data area will be stored.
spareBuffer where the spare area will be stored.
Returns
0 if successful; otherwise returns NAND_COMMON_ERROR_BADBLOCK.
Note
If one of the buffer pointer is 0, the corresponding area is not written.

References NAND_COMMON_ERROR_BADBLOCK, and write_page().

Referenced by copy_page(), main(), nand_flash_ecc_write_page(), and run_test_raw_read_write().