Microchip® Advanced Software Framework

nand_flash_translation.h File Reference

NAND Flash Translation.

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

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

Data Structures

struct  nand_flash_map
 
struct  nand_flash_translation
 

Functions

void nand_flash_flush (void)
 Carry out all pending operations. More...
 
void nand_flash_get_version (uint32_t *minor_version, uint32_t *major_version)
 Get FTL version. More...
 
uint32_t nand_flash_read (uint32_t address, void *data, uint32_t length)
 Read data at the specified address of NAND Flash. More...
 
uint32_t nand_flash_translation_erase_all (struct nand_flash_translation *translated, uint32_t level)
 Erase all blocks in the translated area of NAND Flash. More...
 
uint32_t nand_flash_translation_flush (struct nand_flash_translation *translated)
 Terminate the current write operation by copying all the missing pages from the previous physical block. More...
 
uint16_t nand_flash_translation_get_device_size_in_block (const struct nand_flash_translation *translated)
 Return the number of available blocks in a translated NAND Flash. More...
 
uint64_t nand_flash_translation_get_device_size_in_byte (const struct nand_flash_translation *translated)
 Return the number of available data bytes in a translated NAND Flash. More...
 
uint32_t nand_flash_translation_get_device_size_in_page (const struct nand_flash_translation *translated)
 Return the number of available pages in a translated NAND Flash. More...
 
uint32_t nand_flash_translation_initialize (struct nand_flash_translation *translated, const struct nand_flash_model *model, uint32_t command_address, uint32_t address_address, uint32_t data_address, uint16_t base_block, uint16_t size_in_block, uint8_t *p_page_write_buffer, uint8_t *p_page_read_buffer)
 Initialize a nand_flash_translation instance. More...
 
uint32_t nand_flash_translation_read_page (const struct nand_flash_translation *translated, uint16_t block, uint16_t page, void *data, void *spare)
 Read the data and/or the spare area of a page on a translated NAND Flash. More...
 
uint32_t nand_flash_translation_save_logical_mapping (struct nand_flash_translation *translated)
 Allocate a free block to save the current logical mapping in it. More...
 
uint32_t nand_flash_translation_write_page (struct nand_flash_translation *translated, uint16_t block, uint16_t page, void *data, void *spare)
 Writes the data and/or spare area of a page on a translated NAND Flash. More...
 
uint32_t nand_flash_write (uint32_t address, const void *data, uint32_t length)
 Write a data buffer at the specified address to NAND Flash. More...
 

void nand_flash_flush ( void  )

Carry out all pending operations.

Referenced by nand_flash_test_unit_ready(), and nand_flash_unload().

void nand_flash_get_version ( uint32_t *  minor_version,
uint32_t *  major_version 
)

Get FTL version.

Parameters
minor_versionMinor version number.
major_versionMajor version number.
Returns
0 if successful; otherwise return the error code.
uint32_t nand_flash_read ( uint32_t  address,
void *  data,
uint32_t  length 
)

Read data at the specified address of NAND Flash.

Parameters
addressAddress at which the data shall be read.
dataData buffer.
lengthNumber of bytes to read.
Returns
0 if successful; otherwise return the error code.

Referenced by nand_flash_mem_2_ram(), and nand_flash_usb_read_10().

uint32_t nand_flash_translation_erase_all ( struct nand_flash_translation translated,
uint32_t  level 
)

Erase all blocks in the translated area of NAND Flash.

Parameters
translatedPointer to a nand_flash_translation instance.
levelErase level.
Returns
0 if successful; otherwise return the error code
uint32_t nand_flash_translation_flush ( struct nand_flash_translation translated)

Terminate the current write operation by copying all the missing pages from the previous physical block.

Parameters
translatedPointer to a nand_flash_translation instance.
Returns
0 if successful; otherwise return the error code
uint16_t nand_flash_translation_get_device_size_in_block ( const struct nand_flash_translation translated)

Return the number of available blocks in a translated NAND Flash.

Parameters
translatedPointer to a nand_flash_translation instance.
Returns
the number of available blocks in a translated NAND Flash.
uint64_t nand_flash_translation_get_device_size_in_byte ( const struct nand_flash_translation translated)

Return the number of available data bytes in a translated NAND Flash.

Parameters
translatedPointer to a nand_flash_translation instance.
Returns
the number of available data bytes in a translated NAND Flash.

Referenced by nand_flash_read_capacity().

uint32_t nand_flash_translation_get_device_size_in_page ( const struct nand_flash_translation translated)

Return the number of available pages in a translated NAND Flash.

Parameters
translatedPointer to a nand_flash_translation instance.
Returns
the number of available pages in a translated NAND Flash.
uint32_t nand_flash_translation_initialize ( struct nand_flash_translation translated,
const struct nand_flash_model model,
uint32_t  command_address,
uint32_t  address_address,
uint32_t  data_address,
uint16_t  base_block,
uint16_t  size_in_block,
uint8_t *  p_page_write_buffer,
uint8_t *  p_page_read_buffer 
)

Initialize a nand_flash_translation instance.

Parameters
translatedPointer to a nand_flash_translation 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.
base_blockBasic physical block address of mapped area.
size_in_blockNumber of blocks that is mapped.
p_page_write_bufferPointer to buffer for page write, must be allocated with the same size of the NAND Flash page size used.
p_page_read_bufferPointer to buffer for page read, must be allocated with the same size of the NAND Flash page size used.
Returns
0 if successful; otherwise return the error code.

Referenced by nand_flash_read_capacity(), and nand_flash_test_unit_ready().

uint32_t nand_flash_translation_read_page ( const struct nand_flash_translation translated,
uint16_t  block,
uint16_t  page,
void *  data,
void *  spare 
)

Read the data and/or the spare area of a page on a translated NAND Flash.

If the block is not currently mapped but could be (i.e. there are available physical blocks), then the data/spare is filled with 0xFF.

Parameters
translatedPointer to a nand_flash_translation instance.
blockLogical block number.
pageNumber of page to read inside logical block.
dataData area buffer, can be 0.
spareSpare area buffer, can be 0.
Returns
0 if successful; otherwise returns NAND_COMMON_ERROR_NOMOREBLOCKS
uint32_t nand_flash_translation_save_logical_mapping ( struct nand_flash_translation translated)

Allocate a free block to save the current logical mapping in it.

Parameters
translatedPointer to a nand_flash_translation instance.
Returns
0 if successful; otherwise return the error code.
uint32_t nand_flash_translation_write_page ( struct nand_flash_translation translated,
uint16_t  block,
uint16_t  page,
void *  data,
void *  spare 
)

Writes the data and/or spare area of a page on a translated NAND Flash.

Allocate block has needed to keep the wear even between all blocks.

Parameters
translatedPointer to a nand_flash_translation instance.
blockLogical block number.
pageNumber of page to read inside logical block.
dataData area buffer, can be 0.
spareSpare area buffer, can be 0.
Returns
0 if successful; otherwise return the error code
uint32_t nand_flash_write ( uint32_t  address,
const void *  data,
uint32_t  length 
)

Write a data buffer at the specified address to NAND Flash.

Parameters
addressAddress where the data shall be written.
dataData buffer.
lengthNumber of bytes to write.
Returns
0 if successful; otherwise return the error code.

Referenced by nand_flash_ram_2_mem(), and nand_flash_usb_write_10().