# Backup Access: Overview

## Description

The backup device is connected to the SPI bus housed within a Nintendo DS Card. By conducting serial communication of commands through the IO register, you can perform operations such as state checks and data transfer. The type and limitations of the commands prepared depend on the device type and size, but there are features as listed below that are generally shared.

- All empty memory is divided depending on specific page sizes, and each page waits individually for the write count lifespan.
- If a write-related command is generated, the device goes into a busy state until it finishes.
- The amount of time it's in a busy state is proportionally longer than the write count accumulation, and it will never end within the given period of time.
- This does not depend on the write count and there is also a period of data maintenance for the whole device.

Device Types

The following are the main backup device types and their features supported by the current CARD library.

Device Types | Features
EEPROM | Standard feature, a relatively small amount of memory.
FLASH | Memory with large capacity but comparatively slow writing speed. For particularly large-capacity flash memory devices, the process of rewriting data can be somewhat complicated.

There is no way to automatically determine which type of backup device is housed in the DS Card, so the application must be aware of the device type that it will use and explicitly specify it with the `CARD_IdentifyBackup` function before any function call to backup access functions. You must follow the guidelines and make sure that ROM header information is determined in advance to prevent problems such as data being destroyed by carelessly accessing a DS Card whose details are uncertain. This is especially important for applications that are not started from a DS Card, such as in DS Download Play. Under those conditions, restrictions in the CARD library are applied automatically, and the card cannot be accessed as long as the `CARD_Enable` function is not called. The ROM header information for the inserted DS Card can be referenced with the `CARD_GetRomHeader` function.
As mentioned above, different types of flash devices can use different types of commands and have different restrictions. In particular, the `Write` command that performs a simple rewrite operation cannot be used with flash memory devices above a certain capacity. To perform a rewrite operation on such devices, you must use a combination of the `EraseSector` operation to erase data at the sector level, and the `Program` operation to write data to sectors after they have been erased.
The table below lists currently supported devices and their operating characteristics.

Device Types | EEPROM | FLASH
Size | 4 KB | 64 KB | 512 KB | 2 MB | 4 MB | 8 MB | 16 MB | 64 MB
Page Size | (Total Capacity) | 256 Bytes
Sector Size | (Total Capacity) | 65536 Bytes
Write (a direct write operation that does not require erasing) | Yes | Yes | No
Program (a write operation that takes place after erasures) | No | Yes
EraseSector (the sector-erase operation) | No | Yes

Flow of Access Functions

This is an explanation of the flow of operations after backup access functions are called.

1. Most device commands related to data transfer are limited to a unique size by pages or sectors, so the CARD library automatically divides content specified by the user into several appropriately sized commands.
2. The divided commands are each issued in order. Issuing of commands and the busy determination that follows need to be managed from beginning to end directly by the CPU, so this operation is mounted by a relatively low-priority thread on the ARM7 component side. Command issuance requests are notified one at a time from ARM9 through PXI.
3. When the command is finished in ARM7, ARM9 is notified of the result in the same way through PXI.
4. If there are any remaining divided commands, a command issuance request is notified from ARM9 again at this point. This is repeated until processing is complete, ends in failure, or has been canceled by the `CARD_CancelBackupAsync` function. Because waiting for completion or requesting re-issue here sometimes take a long time for operations such as copying memory, these processes are executed by an internal thread in the CARD library instead of with the PXI interrupt handler.
5. When the operation is complete, a notification is sent to the caller of the specified callback. The processing result can be referenced with the `CARD_GetResultCode` function as a `CARDResult` enumerated type.

## See Also

`CARD Function List
`

## Revision History

2009/04/10 Replaced symbols used in the tables with standard notation.
2008/11/27 Deleted `CARD_BACKUP_TYPE_FRAM_256KBITS` from the lineup of usable types.
2007/08/22 Added explanation about large-capacity FLASH devices and a table showing their characteristics.
2006/01/01 Initial version.

CONFIDENTIAL