SAM3S8/SD8 Software Package: libraries/memories/nandflash/RawNandFlash.c File Reference

SAM3S8/SD8 Software Package 1.2
Defines | Functions | Variables

# RawNandFlash.c File Reference

`#include "memories.h"`
`#include <string.h>`
`#include <assert.h>`

Go to the source code of this file.

## Defines

#define | STATUS_READY (1 << 6)
#define | STATUS_ERROR (1 << 0)
#define | COMMAND_READ_1 0x00
#define | COMMAND_READ_2 0x30
#define | COMMAND_COPYBACK_READ_1 0x00
#define | COMMAND_COPYBACK_READ_2 0x35
#define | COMMAND_COPYBACK_PROGRAM_1 0x85
#define | COMMAND_COPYBACK_PROGRAM_2 0x10
#define | COMMAND_RANDOM_OUT 0x05
#define | COMMAND_RANDOM_OUT_2 0xE0
#define | COMMAND_RANDOM_IN 0x85
#define | COMMAND_READID 0x90
#define | COMMAND_WRITE_1 0x80
#define | COMMAND_WRITE_2 0x10
#define | COMMAND_ERASE_1 0x60
#define | COMMAND_ERASE_2 0xD0
#define | COMMAND_STATUS 0x70
#define | COMMAND_RESET 0xFF
#define | COMMAND_READ_A 0x00
#define | COMMAND_READ_C 0x50
#define | ENABLE_CE(raw) PIO_Clear(&(raw->pinChipEnable))
#define | DISABLE_CE(raw) PIO_Set(&(raw->pinChipEnable))
#define | WRITE_COMMAND(raw, command) {*((volatile unsigned char *) raw->commandAddress) = (unsigned char) command;}
#define | WRITE_COMMAND16(raw, command) {*((volatile unsigned short *) raw->commandAddress) = (unsigned short) command;}
#define | WRITE_ADDRESS(raw, address) {*((volatile unsigned char *) raw->addressAddress) = (unsigned char) address;}
#define | WRITE_ADDRESS16(raw, address) {*((volatile unsigned short *) raw->addressAddress) = (unsigned short) address;}
#define | WRITE_DATA8(raw, data) {*((volatile unsigned char *) raw->dataAddress) = (unsigned char) data;}
#define | READ_DATA8(raw) (*((volatile unsigned char *) raw->dataAddress))
#define | WRITE_DATA16(raw, data) {*((volatile unsigned short *) raw->dataAddress) = (unsigned short) data;}
#define | READ_DATA16(raw) (*((volatile unsigned short *) raw->dataAddress))
#define | MODEL(raw) ((struct NandFlashModel *) raw)
#define | NUMERASETRIES 2
#define | NUMWRITETRIES 2
#define | NUMCOPYTRIES 2

## Functions

unsigned char | RawNandFlash_Initialize (struct RawNandFlash *raw, const struct NandFlashModel *model, unsigned int commandAddress, unsigned int addressAddress, unsigned int dataAddress, const Pin pinChipEnable, const Pin pinReadyBusy)
| Initializes a RawNandFlash instance based on the given model and physical interface.
void | RawNandFlash_Reset (const struct RawNandFlash *raw)
| Resets a NandFlash device.
unsigned int | RawNandFlash_ReadId (const struct RawNandFlash *raw)
| Reads and returns the identifiers of a NandFlash chip.
unsigned char | RawNandFlash_EraseBlock (const struct RawNandFlash *raw, unsigned short block)
| Erases the specified block of the device, retrying several time if it fails.
unsigned char | RawNandFlash_ReadPage (const struct RawNandFlash *raw, unsigned short block, unsigned short page, void *data, void *spare)
| Reads the data and/or the spare areas of a page of a NandFlash into the provided buffers.
unsigned char | RawNandFlash_WritePage (const struct RawNandFlash *raw, unsigned short block, unsigned short page, void *data, void *spare)
| Writes the data and/or the spare areas of a page of a NandFlash into the provided buffers.
unsigned char | RawNandFlash_CopyPage (const struct RawNandFlash *raw, unsigned short sourceBlock, unsigned short sourcePage, unsigned short destBlock, unsigned short destPage)
| Copy the data in a page of the NandFlash device to an other page on that same chip.
unsigned char | RawNandFlash_CopyBlock (const struct RawNandFlash *raw, unsigned short sourceBlock, unsigned short destBlock)
| Copies the data of one whole block of a NandFlash device to another block.

## Variables

uint8_t | gdwNandFlashTempBuffer [NandCommon_MAXPAGEDATASIZE]

## Detailed Description

The RawNandFlash layer drives hardware-specific Bus Read and Bus Write operations to communicate with the NAND Flash device. It directly interacts with hardware's register to operate NAND Flash interface.The RawNandFlash layer code implement procedures to program basic NAND Flash operations. It takes care of issuing the correct sequences of write/read operations for each command. All functions in the layer are blocked i.e. they wait for the completion of an operation. RawNandFlash layer access NAND Flash device by SMC.

Definition in file RawNandFlash.c.

## Define Documentation

#define COMMAND_READ_1 0x00

Nand flash commands

Definition at line 61 of file RawNandFlash.c.

#define COMMAND_READ_A 0x00

Nand flash commands (small blocks)

Definition at line 80 of file RawNandFlash.c.

#define MODEL | ( |  | raw ) | ((struct NandFlashModel *) raw)

Internal cast macros

Definition at line 108 of file RawNandFlash.c.

#define NUMCOPYTRIES 2

Number of tries for copying a block

Definition at line 115 of file RawNandFlash.c.

#define NUMERASETRIES 2

Number of tries for erasing a block

Definition at line 111 of file RawNandFlash.c.

#define NUMWRITETRIES 2

Number of tries for writing a block

Definition at line 113 of file RawNandFlash.c.

#define STATUS_READY (1 << 6)

Nand flash chip status codes

Definition at line 57 of file RawNandFlash.c.

## Function Documentation

unsigned char RawNandFlash_CopyBlock | ( | const struct RawNandFlash * | raw,
|  | unsigned short | sourceBlock,
|  | unsigned short | destBlock
| ) |  |

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

Parameters:

  raw | Pointer to a RawNandFlash instance.
  sourceBlock | Source block number.
  destBlock | Destination block number.

Returns:
  0 if successful; otherwise returns an NandCommon_ERROR_BADBLOCK.

Definition at line 786 of file RawNandFlash.c.

Here is the call graph for this function:

unsigned char RawNandFlash_CopyPage | ( | const struct RawNandFlash * | raw,
|  | unsigned short | sourceBlock,
|  | unsigned short | sourcePage,
|  | unsigned short | destBlock,
|  | unsigned short | destPage
| ) |  |

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

Parameters:

  raw | Pointer to a RawNandFlash instance.
  sourceBlock | Source block number.
  sourcePage | Source page number inside the source block.
  destBlock | Destination block number.
  destPage | Destination page number inside the destination block.

Returns:
  0 if successful; otherwise returns an NandCommon_ERROR_BADBLOCK.

Note:
  Both pages must have be even or odd; it is not possible to copy and even page to an odd page and vice-versa.

Definition at line 753 of file RawNandFlash.c.

unsigned char RawNandFlash_EraseBlock | ( | const struct RawNandFlash * | raw,
|  | unsigned short | block
| ) |  |

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

Parameters:

  raw | Pointer to a RawNandFlash instance.
  block | Number of the physical block to erase.

Returns:
  0 if successful; otherwise returns NandCommon_ERROR_UNKNOWNMODEL.

Definition at line 595 of file RawNandFlash.c.

unsigned char RawNandFlash_Initialize | ( | struct RawNandFlash * | raw,
|  | const struct NandFlashModel * | model,
|  | unsigned int | commandAddress,
|  | unsigned int | addressAddress,
|  | unsigned int | dataAddress,
|  | const Pin | pinChipEnable,
|  | const Pin | pinReadyBusy
| ) |  |

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

Parameters:

  raw | Pointer to a RawNandFlash instance.
  model | Pointer to the underlying nand chip model. Can be 0.
  commandAddress | Address at which commands are sent.
  addressAddress | Address at which addresses are sent.
  dataAddress | Address at which data is sent.
  pinChipEnable | Pin controlling the CE signal of the NandFlash.
  pinReadyBusy | Pin used to monitor the ready/busy signal of the Nand.

Returns:
  0 if successful; otherwise returns NandCommon_ERROR_UNKNOWNMODEL.

Definition at line 502 of file RawNandFlash.c.

Here is the call graph for this function:

unsigned int RawNandFlash_ReadId | ( | const struct RawNandFlash * | raw ) |

Reads and returns the identifiers of a NandFlash chip.

Parameters:

  raw | Pointer to a RawNandFlash instance.

Returns:
  id1|(id2<<8)|(id3<<16)|(id4<<24)

Definition at line 568 of file RawNandFlash.c.

unsigned char RawNandFlash_ReadPage | ( | const struct RawNandFlash * | raw,
|  | unsigned short | block,
|  | unsigned short | page,
|  | void * | data,
|  | void * | spare
| ) |  |

Reads the data and/or the spare areas of a page of a NandFlash into the provided buffers.

Parameters:

  raw | Pointer to a RawNandFlash instance.
  block | Number of the physical block to read.
  page | Number of the page to read inside the given block.
  data | Buffer where the data area will be read.
  spare | Buffer where the spare area will be read.

Returns:
  0 if successful; otherwise returns 1.

Note:
  If one of the buffer pointer is 0, the corresponding area is not read.

Definition at line 632 of file RawNandFlash.c.

Here is the call graph for this function:

void RawNandFlash_Reset | ( | const struct RawNandFlash * | raw ) |

Resets a NandFlash device.

Parameters:

  raw | Pointer to a RawNandFlash instance.

Definition at line 551 of file RawNandFlash.c.

unsigned char RawNandFlash_WritePage | ( | const struct RawNandFlash * | raw,
|  | unsigned short | block,
|  | unsigned short | page,
|  | void * | data,
|  | void * | spare
| ) |  |

Writes the data and/or the spare areas of a page of a NandFlash into the provided buffers.

Parameters:

  raw | Pointer to a RawNandFlash instance.
  block | Number of the physical block to write resides.
  page | Number of the page to write inside the given block.
  data | Buffer where the data area will be stored.
  spare | Buffer where the spare area will be stored.

Returns:
  0 if successful; otherwise returns NandCommon_ERROR_BADBLOCK.

Note:
  If one of the buffer pointer is 0, the corresponding area is not written.

Definition at line 717 of file RawNandFlash.c.

## Variable Documentation

uint8_t gdwNandFlashTempBuffer[NandCommon_MAXPAGEDATASIZE]

Global nand flash temp buffer

Definition at line 121 of file RawNandFlash.c.

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines