OpenOCD
at91sam9.c File Reference
Include dependency graph for at91sam9.c:

Go to the source code of this file.

Data Structures

struct  at91sam9_nand
 Private data for the controller that is stored in the NAND device structure. More...
 
struct  at91sam9_pin
 Representation of a pin on an AT91SAM9 chip. More...
 

Macros

#define AT91C_ECCX_CR   (0x00)
 Offset to ECC CR. More...
 
#define AT91C_ECCX_NPR   (0x10)
 Offset to ECC NPR. More...
 
#define AT91C_ECCX_PR   (0x0C)
 Offset to ECC PR. More...
 
#define AT91C_ECCX_SR   (0x08)
 Offset to ECC SR. More...
 
#define AT91C_PIOX_CODR   (0x34)
 Offset to PIO CODR. More...
 
#define AT91C_PIOX_PDSR   (0x3C)
 Offset to PIO PDSR. More...
 
#define AT91C_PIOX_SODR   (0x30)
 Offset to PIO SODR. More...
 

Functions

static int at91sam9_address (struct nand_device *nand, uint8_t address)
 Send an address to the NAND device attached to an AT91SAM9 NAND controller. More...
 
static int at91sam9_command (struct nand_device *nand, uint8_t command)
 Send a command to the NAND device. More...
 
static int at91sam9_disable (struct nand_device *nand)
 Disable NAND device attached to a controller. More...
 
static int at91sam9_ecc_init (struct target *target, struct at91sam9_nand *info)
 Initialize the ECC controller on the AT91SAM9. More...
 
static int at91sam9_enable (struct nand_device *nand)
 Enable NAND device attached to a controller. More...
 
static int at91sam9_halted (struct target *target, const char *label)
 Checks if the target is halted and prints an error message if it isn't. More...
 
static int at91sam9_init (struct nand_device *nand)
 Initialize the AT91SAM9 NAND controller. More...
 
static int at91sam9_nand_ready (struct nand_device *nand, int timeout)
 Determine if the NAND device is ready by looking at the ready/~busy pin. More...
 
static uint8_t * at91sam9_oob_init (struct nand_device *nand, uint8_t *oob, uint32_t *size)
 Initialize an area for the OOB based on whether a user is requesting the OOB data. More...
 
static int at91sam9_read_block_data (struct nand_device *nand, uint8_t *data, int size)
 Read a block of data from the NAND device attached to an AT91SAM9. More...
 
static int at91sam9_read_data (struct nand_device *nand, void *data)
 Read data directly from the NAND device attached to an AT91SAM9 NAND controller. More...
 
static int at91sam9_read_page (struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
 Reads a page from an AT91SAM9 NAND controller and verifies using 1-bit ECC controller on chip. More...
 
static int at91sam9_reset (struct nand_device *nand)
 Reset the AT91SAM9 NAND controller. More...
 
static int at91sam9_write_block_data (struct nand_device *nand, uint8_t *data, int size)
 Write a block of data to a NAND device attached to an AT91SAM9. More...
 
static int at91sam9_write_data (struct nand_device *nand, uint16_t data)
 Write data directly to the NAND device attached to an AT91SAM9 NAND controller. More...
 
static int at91sam9_write_page (struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
 Write a page of data including 1-bit ECC information to a NAND device attached to an AT91SAM9 controller. More...
 
 COMMAND_HANDLER (handle_at91sam9_ale_command)
 Handle the AT91SAM9 ALE command for specifying the address line to use for writing addresses to the NAND device. More...
 
 COMMAND_HANDLER (handle_at91sam9_ce_command)
 Handle the AT91SAM9 CE command for specifying the pin that is used to enable or disable the NAND device. More...
 
 COMMAND_HANDLER (handle_at91sam9_cle_command)
 Handle the AT91SAM9 CLE command for specifying the address line to use for writing commands to a NAND device. More...
 
 COMMAND_HANDLER (handle_at91sam9_rdy_busy_command)
 Handle the AT91SAM9 RDY/~BUSY command for specifying the pin that watches the RDY/~BUSY line from the NAND device. More...
 
 NAND_DEVICE_COMMAND_HANDLER (at91sam9_nand_device_command)
 Handle the initial NAND device command for AT91SAM9 controllers. More...
 

Variables

static const struct command_registration at91sam9_command_handler []
 
struct nand_flash_controller at91sam9_nand_controller
 Structure representing the AT91SAM9 NAND controller. More...
 
static const struct command_registration at91sam9_sub_command_handlers []
 

Macro Definition Documentation

◆ AT91C_ECCX_CR

#define AT91C_ECCX_CR   (0x00)

Offset to ECC CR.

Definition at line 20 of file at91sam9.c.

◆ AT91C_ECCX_NPR

#define AT91C_ECCX_NPR   (0x10)

Offset to ECC NPR.

Definition at line 23 of file at91sam9.c.

◆ AT91C_ECCX_PR

#define AT91C_ECCX_PR   (0x0C)

Offset to ECC PR.

Definition at line 22 of file at91sam9.c.

◆ AT91C_ECCX_SR

#define AT91C_ECCX_SR   (0x08)

Offset to ECC SR.

Definition at line 21 of file at91sam9.c.

◆ AT91C_PIOX_CODR

#define AT91C_PIOX_CODR   (0x34)

Offset to PIO CODR.

Definition at line 18 of file at91sam9.c.

◆ AT91C_PIOX_PDSR

#define AT91C_PIOX_PDSR   (0x3C)

Offset to PIO PDSR.

Definition at line 19 of file at91sam9.c.

◆ AT91C_PIOX_SODR

#define AT91C_PIOX_SODR   (0x30)

Offset to PIO SODR.

Definition at line 17 of file at91sam9.c.

Function Documentation

◆ at91sam9_address()

static int at91sam9_address ( struct nand_device nand,
uint8_t  address 
)
static

Send an address to the NAND device attached to an AT91SAM9 NAND controller.

Parameters
nandNAND device to send the address to.
addressAddress to be sent.
Returns
Success or failure of sending the address.

Definition at line 163 of file at91sam9.c.

References at91sam9_halted(), nand_device::controller_priv, ERROR_NAND_OPERATION_FAILED, info, nand_device::target, and target_write_u8().

◆ at91sam9_command()

static int at91sam9_command ( struct nand_device nand,
uint8_t  command 
)
static

Send a command to the NAND device.

Parameters
nandNAND device to write the command to.
commandCommand to be written.
Returns
Success or failure of writing the command.

Definition at line 129 of file at91sam9.c.

References at91sam9_enable(), at91sam9_halted(), nand_device::controller_priv, ERROR_NAND_OPERATION_FAILED, info, nand_device::target, and target_write_u8().

◆ at91sam9_disable()

static int at91sam9_disable ( struct nand_device nand)
static

Disable NAND device attached to a controller.

Parameters
nandNAND controller information for controlling NAND device.
Returns
Success or failure of the disabling.

Definition at line 114 of file at91sam9.c.

References AT91C_PIOX_SODR, nand_device::controller_priv, info, nand_device::target, and target_write_u32().

Referenced by at91sam9_reset().

◆ at91sam9_ecc_init()

static int at91sam9_ecc_init ( struct target target,
struct at91sam9_nand info 
)
static

Initialize the ECC controller on the AT91SAM9.

Parameters
targetTarget to configure ECC on.
infoNAND controller information for where the ECC is.
Returns
Success or failure of initialization.

Definition at line 295 of file at91sam9.c.

References AT91C_ECCX_CR, ERROR_NAND_OPERATION_FAILED, info, LOG_ERROR, and target_write_u32().

Referenced by at91sam9_read_page(), and at91sam9_write_page().

◆ at91sam9_enable()

static int at91sam9_enable ( struct nand_device nand)
static

Enable NAND device attached to a controller.

Parameters
nandNAND controller information for controlling NAND device.
Returns
Success or failure of the enabling.

Definition at line 100 of file at91sam9.c.

References AT91C_PIOX_CODR, nand_device::controller_priv, info, nand_device::target, and target_write_u32().

Referenced by at91sam9_command().

◆ at91sam9_halted()

static int at91sam9_halted ( struct target target,
const char *  label 
)
static

Checks if the target is halted and prints an error message if it isn't.

Parameters
targetTarget to be checked.
labelString label for where function is called from.
Returns
True if the target is halted.

Definition at line 69 of file at91sam9.c.

References label, LOG_ERROR, target::state, and TARGET_HALTED.

Referenced by at91sam9_address(), at91sam9_command(), at91sam9_init(), at91sam9_nand_ready(), at91sam9_read_block_data(), at91sam9_read_data(), at91sam9_reset(), at91sam9_write_block_data(), and at91sam9_write_data().

◆ at91sam9_init()

static int at91sam9_init ( struct nand_device nand)
static

Initialize the AT91SAM9 NAND controller.

Parameters
nandNAND device the controller is attached to.
Returns
Success or failure of initialization.

Definition at line 84 of file at91sam9.c.

References at91sam9_halted(), ERROR_NAND_OPERATION_FAILED, ERROR_OK, and nand_device::target.

◆ at91sam9_nand_ready()

static int at91sam9_nand_ready ( struct nand_device nand,
int  timeout 
)
static

Determine if the NAND device is ready by looking at the ready/~busy pin.

Parameters
nandNAND device to check.
timeoutTime in milliseconds to wait for NAND to be ready.
Returns
True if the NAND is ready in the timeout period.

Definition at line 219 of file at91sam9.c.

References alive_sleep(), AT91C_PIOX_PDSR, at91sam9_halted(), nand_device::controller_priv, info, status, nand_device::target, and target_read_u32().

◆ at91sam9_oob_init()

static uint8_t* at91sam9_oob_init ( struct nand_device nand,
uint8_t *  oob,
uint32_t *  size 
)
static

Initialize an area for the OOB based on whether a user is requesting the OOB data.

This determines the size of the OOB and allocates the space in case the user has not requested the OOB data.

Parameters
nandNAND device we are creating an OOB for.
oobPointer to the user supplied OOB area.
sizeSize of the OOB.
Returns
Pointer to an area to store OOB data.

Definition at line 316 of file at91sam9.c.

References LOG_ERROR, NULL, nand_device::page_size, and size.

Referenced by at91sam9_read_page(), and at91sam9_write_page().

◆ at91sam9_read_block_data()

static int at91sam9_read_block_data ( struct nand_device nand,
uint8_t *  data,
int  size 
)
static

Read a block of data from the NAND device attached to an AT91SAM9.

This utilizes the ARM hosted NAND read function.

Parameters
nandNAND device to read from.
dataPointer to where the read data should be placed.
sizeSize of the data being read.
Returns
Success or failure of the hosted read.

Definition at line 249 of file at91sam9.c.

References arm_nandread(), at91sam9_halted(), arm_nand_data::chunk_size, nand_device::controller_priv, arm_nand_data::data, ERROR_NAND_OPERATION_FAILED, info, nand_device::page_size, size, status, and nand_device::target.

◆ at91sam9_read_data()

static int at91sam9_read_data ( struct nand_device nand,
void *  data 
)
static

Read data directly from the NAND device attached to an AT91SAM9 NAND controller.

Parameters
nandNAND device to read from.
dataPointer to where the data should be put.
Returns
Success or failure of reading the data.

Definition at line 182 of file at91sam9.c.

References at91sam9_halted(), nand_device::controller_priv, ERROR_NAND_OPERATION_FAILED, info, nand_device::target, and target_read_u8().

◆ at91sam9_read_page()

static int at91sam9_read_page ( struct nand_device nand,
uint32_t  page,
uint8_t *  data,
uint32_t  data_size,
uint8_t *  oob,
uint32_t  oob_size 
)
static

Reads a page from an AT91SAM9 NAND controller and verifies using 1-bit ECC controller on chip.

This makes an attempt to correct any errors that are encountered while reading the page of data.

Parameters
nandNAND device to read from
pagePage to be read.
dataPointer to where data should be read to.
data_sizeSize of the data to be read.
oobPointer to where OOB data should be read to.
oob_sizeSize of the OOB data to be read.
Returns
Success or failure of reading the NAND page.

Definition at line 350 of file at91sam9.c.

References AT91C_ECCX_PR, AT91C_ECCX_SR, at91sam9_ecc_init(), at91sam9_oob_init(), bit(), nand_device::controller_priv, ERROR_OK, info, LOG_ERROR, LOG_INFO, NAND_CMD_READ0, nand_page_command(), nand_read_data_page(), parity(), status, nand_device::target, and target_read_u32().

◆ at91sam9_reset()

static int at91sam9_reset ( struct nand_device nand)
static

Reset the AT91SAM9 NAND controller.

Parameters
nandNAND device to be reset.
Returns
Success or failure of reset.

Definition at line 148 of file at91sam9.c.

References at91sam9_disable(), at91sam9_halted(), ERROR_NAND_OPERATION_FAILED, and nand_device::target.

◆ at91sam9_write_block_data()

static int at91sam9_write_block_data ( struct nand_device nand,
uint8_t *  data,
int  size 
)
static

Write a block of data to a NAND device attached to an AT91SAM9.

This uses the ARM hosted write function to write the data.

Parameters
nandNAND device to write to.
dataData to be written to device.
sizeSize of the data being written.
Returns
Success or failure of the hosted write.

Definition at line 273 of file at91sam9.c.

References arm_nandwrite(), at91sam9_halted(), arm_nand_data::chunk_size, nand_device::controller_priv, arm_nand_data::data, ERROR_NAND_OPERATION_FAILED, info, nand_device::page_size, size, status, and nand_device::target.

◆ at91sam9_write_data()

static int at91sam9_write_data ( struct nand_device nand,
uint16_t  data 
)
static

Write data directly to the NAND device attached to an AT91SAM9 NAND controller.

Parameters
nandNAND device to be written to.
dataData to be written.
Returns
Success or failure of the data write.

Definition at line 201 of file at91sam9.c.

References at91sam9_halted(), nand_device::controller_priv, ERROR_NAND_OPERATION_FAILED, info, nand_device::target, and target_write_u8().

◆ at91sam9_write_page()

static int at91sam9_write_page ( struct nand_device nand,
uint32_t  page,
uint8_t *  data,
uint32_t  data_size,
uint8_t *  oob,
uint32_t  oob_size 
)
static

Write a page of data including 1-bit ECC information to a NAND device attached to an AT91SAM9 controller.

If there is OOB data to be written, this will ignore the computed ECC from the ECC controller.

Parameters
nandNAND device to write to.
pagePage to write.
dataPointer to data being written.
data_sizeSize of the data being written.
oobPointer to OOB data being written.
oob_sizeSize of the OOB data.
Returns
Success or failure of the page write.

Definition at line 425 of file at91sam9.c.

References AT91C_ECCX_NPR, AT91C_ECCX_PR, at91sam9_ecc_init(), at91sam9_oob_init(), nand_device::controller_priv, ERROR_OK, info, LOG_ERROR, NAND_CMD_SEQIN, nand_page_command(), nand_write_data_page(), nand_write_finish(), parity(), nand_device::target, and target_read_u32().

◆ COMMAND_HANDLER() [1/4]

COMMAND_HANDLER ( handle_at91sam9_ale_command  )

Handle the AT91SAM9 ALE command for specifying the address line to use for writing addresses to the NAND device.

Definition at line 562 of file at91sam9.c.

References CMD, CMD_ARGC, CMD_ARGV, COMMAND_PARSE_NUMBER, command_print(), nand_device::controller_priv, ERROR_COMMAND_ARGUMENT_INVALID, ERROR_COMMAND_SYNTAX_ERROR, ERROR_OK, get_nand_device_by_num(), info, and NULL.

◆ COMMAND_HANDLER() [2/4]

COMMAND_HANDLER ( handle_at91sam9_ce_command  )

Handle the AT91SAM9 CE command for specifying the pin that is used to enable or disable the NAND device.

Definition at line 621 of file at91sam9.c.

◆ COMMAND_HANDLER() [3/4]

COMMAND_HANDLER ( handle_at91sam9_cle_command  )

Handle the AT91SAM9 CLE command for specifying the address line to use for writing commands to a NAND device.

Definition at line 532 of file at91sam9.c.

References CMD, CMD_ARGC, CMD_ARGV, COMMAND_PARSE_NUMBER, command_print(), nand_device::controller_priv, ERROR_OK, get_nand_device_by_num(), info, and NULL.

◆ COMMAND_HANDLER() [4/4]

COMMAND_HANDLER ( handle_at91sam9_rdy_busy_command  )

Handle the AT91SAM9 RDY/~BUSY command for specifying the pin that watches the RDY/~BUSY line from the NAND device.

Definition at line 590 of file at91sam9.c.

References CMD, CMD_ARGC, CMD_ARGV, COMMAND_PARSE_NUMBER, command_print(), nand_device::controller_priv, ERROR_COMMAND_ARGUMENT_INVALID, ERROR_COMMAND_SYNTAX_ERROR, ERROR_OK, get_nand_device_by_num(), info, and NULL.

◆ NAND_DEVICE_COMMAND_HANDLER()

NAND_DEVICE_COMMAND_HANDLER ( at91sam9_nand_device_command  )

Handle the initial NAND device command for AT91SAM9 controllers.

This initializes much of the controller information struct to be ready for future reads and writes.

Definition at line 483 of file at91sam9.c.

References ARM_NAND_NONE, CMD_ARGC, CMD_ARGV, COMMAND_PARSE_NUMBER, ERROR_NAND_OPERATION_FAILED, ERROR_OK, info, LOG_DEBUG, LOG_ERROR, and NULL.

Variable Documentation

◆ at91sam9_command_handler

const struct command_registration at91sam9_command_handler[]
static
Initial value:
= {
{
.name = "at91sam9",
.mode = COMMAND_ANY,
.help = "AT91SAM9 NAND flash controller commands",
.usage = "",
},
}
static const struct command_registration at91sam9_sub_command_handlers[]
Definition: at91sam9.c:648
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:247
@ COMMAND_ANY
Definition: command.h:42

Definition at line 621 of file at91sam9.c.

◆ at91sam9_nand_controller

struct nand_flash_controller at91sam9_nand_controller
Initial value:
= {
.name = "at91sam9",
.nand_device_command = at91sam9_nand_device_command,
.init = at91sam9_init,
.command = at91sam9_command,
.reset = at91sam9_reset,
.address = at91sam9_address,
.read_data = at91sam9_read_data,
.write_data = at91sam9_write_data,
.nand_ready = at91sam9_nand_ready,
.read_block_data = at91sam9_read_block_data,
.write_block_data = at91sam9_write_block_data,
.read_page = at91sam9_read_page,
.write_page = at91sam9_write_page,
}
static int at91sam9_read_page(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
Reads a page from an AT91SAM9 NAND controller and verifies using 1-bit ECC controller on chip.
Definition: at91sam9.c:350
static int at91sam9_read_data(struct nand_device *nand, void *data)
Read data directly from the NAND device attached to an AT91SAM9 NAND controller.
Definition: at91sam9.c:182
static int at91sam9_nand_ready(struct nand_device *nand, int timeout)
Determine if the NAND device is ready by looking at the ready/~busy pin.
Definition: at91sam9.c:219
static int at91sam9_command(struct nand_device *nand, uint8_t command)
Send a command to the NAND device.
Definition: at91sam9.c:129
static int at91sam9_write_page(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
Write a page of data including 1-bit ECC information to a NAND device attached to an AT91SAM9 control...
Definition: at91sam9.c:425
static int at91sam9_read_block_data(struct nand_device *nand, uint8_t *data, int size)
Read a block of data from the NAND device attached to an AT91SAM9.
Definition: at91sam9.c:249
static int at91sam9_reset(struct nand_device *nand)
Reset the AT91SAM9 NAND controller.
Definition: at91sam9.c:148
static const struct command_registration at91sam9_command_handler[]
Definition: at91sam9.c:682
static int at91sam9_write_block_data(struct nand_device *nand, uint8_t *data, int size)
Write a block of data to a NAND device attached to an AT91SAM9.
Definition: at91sam9.c:273
static int at91sam9_write_data(struct nand_device *nand, uint16_t data)
Write data directly to the NAND device attached to an AT91SAM9 NAND controller.
Definition: at91sam9.c:201
static int at91sam9_address(struct nand_device *nand, uint8_t address)
Send an address to the NAND device attached to an AT91SAM9 NAND controller.
Definition: at91sam9.c:163
static int at91sam9_init(struct nand_device *nand)
Initialize the AT91SAM9 NAND controller.
Definition: at91sam9.c:84

Structure representing the AT91SAM9 NAND controller.

Definition at line 621 of file at91sam9.c.

◆ at91sam9_sub_command_handlers

const struct command_registration at91sam9_sub_command_handlers[]
static

Definition at line 621 of file at91sam9.c.