libnds
Loading...
Searching...
No Matches
Functions
card.h File Reference

Slot-1 card commands. More...

#include <stddef.h>
#include <nds/ndstypes.h>

Functions

void cardEepromChipErase (void)
 Erase the entirety of a TYPE 3 (FLASH) card EEPROM.
 
u8 cardEepromCommand (u8 command)
 Send a command to the card EEPROM.
 
u32 cardEepromGetSize (void)
 Read the card EEPROM's size.
 
int cardEepromGetType (void)
 Read the card EEPROM's type.
 
u32 cardEepromReadID (void)
 Attempt to read the ID of the card EEPROM chip.
 
void cardEepromSectorErase (u32 address)
 Erase a single sector of a TYPE 3 (FLASH) card EEPROM.
 
void cardParamCommand (u8 command, u32 parameter, u32 flags, u32 *destination, u32 length)
 Write a ROM command of the following form, reading the response via polling (synchronously).
 
void cardPolledTransfer (u32 flags, u32 *destination, u32 length, const u8 *command)
 Write a ROM command, reading the response via polling (synchronously).
 
void cardRead (void *dest, size_t offset, size_t len, uint32_t flags)
 Read bytes from the card ROM.
 
void cardReadEeprom (u32 address, u8 *data, u32 length, u32 addrtype)
 Read from the card EEPROM.
 
void cardReadHeader (u8 *header)
 Read card header to the provided buffer.
 
u32 cardReadID (u32 flags)
 Read card ID.
 
void cardReset (void)
 Reset the card.
 
void cardStartTransfer (const u8 *command, u32 *destination, int channel, u32 flags)
 Perform a ROM command, reading the response via DMA (asynchronously).
 
uint32_t cardWriteAndRead (const u8 *command, u32 flags)
 Perform a ROM command, reading one word of response.
 
void cardWriteCommand (const u8 *command)
 Write a command to the card interface.
 
void cardWriteEeprom (u32 address, u8 *data, u32 length, u32 addrtype)
 Write to the card EEPROM.
 
void disableSlot1 (void)
 Disable Slot-1 in a DSi console.
 
static void eepromWaitBusy (void)
 Wait until an EEPROM command is done.
 
void enableSlot1 (void)
 Enable Slot-1 in a DSi console.
 

Detailed Description

Slot-1 card commands.

Function Documentation

◆ cardEepromCommand()

u8 cardEepromCommand ( u8  command)

Send a command to the card EEPROM.

Parameters
commandThe command to send.
Returns
The result, if any.

◆ cardEepromGetSize()

u32 cardEepromGetSize ( void  )

Read the card EEPROM's size.

Returns
The EEPROM's size, in bytes.

◆ cardEepromGetType()

int cardEepromGetType ( void  )

Read the card EEPROM's type.

Type | Description
-----+-------------------------------------------------------------
-1 | no card or no EEPROM
0 | unknown PassMe?
1 | TYPE 1 4Kbit(512Byte) EEPROM
2 | TYPE 2 64Kbit(8KByte)or 512kbit(64Kbyte) EEPROM
3 | TYPE 3 2Mbit(256KByte) FLASH MEMORY (some rare 4Mbit and 8Mbit chips also)
Returns
It returns the type.

◆ cardEepromReadID()

u32 cardEepromReadID ( void  )

Attempt to read the ID of the card EEPROM chip.

Doesn't work well; most chips return 0xFFFF.

Returns
The ID of the chip.

◆ cardEepromSectorErase()

void cardEepromSectorErase ( u32  address)

Erase a single sector of a TYPE 3 (FLASH) card EEPROM.

Parameters
addressThe address to erase at.

◆ cardParamCommand()

void cardParamCommand ( u8  command,
u32  parameter,
u32  flags,
u32 destination,
u32  length 
)

Write a ROM command of the following form, reading the response via polling (synchronously).

ccpppppppp000000

where cc is the command and pp is the parameter.

Parameters
commandThe command.
parameterThe parameter.
flagsThe ROM control flags to use for the transfer.
destinationThe response's destination buffer.
lengthThe length of the response, in bytes.

◆ cardPolledTransfer()

void cardPolledTransfer ( u32  flags,
u32 destination,
u32  length,
const u8 command 
)

Write a ROM command, reading the response via polling (synchronously).

Parameters
flagsThe ROM control flags to use for the transfer.
destinationThe response's destination buffer.
lengthThe length of the response, in bytes.
command8-byte command buffer, little endian.

◆ cardRead()

void cardRead ( void *  dest,
size_t  offset,
size_t  len,
uint32_t  flags 
)

Read bytes from the card ROM.

Parameters
destThe destination buffer.
offsetThe offset to read from, in bytes.
lenThe number of bytes to read.
flagsThe read flags.

◆ cardReadEeprom()

void cardReadEeprom ( u32  address,
u8 data,
u32  length,
u32  addrtype 
)

Read from the card EEPROM.

Parameters
addressThe address to read from.
dataThe data to write.
lengthThe length of data, in bytes.
addrtypeThe card EEPROM's type.
See also
cardEepromGetType

◆ cardReadHeader()

void cardReadHeader ( u8 header)

Read card header to the provided buffer.

This command requires the cart to not be initialized yet, which may mean the user needs to eject and reinsert the cart or they will return random data.

TODO: Is that correct?

Parameters
headerBuffer to store the data in.

◆ cardReadID()

u32 cardReadID ( u32  flags)

Read card ID.

This command requires the cart to not be initialized yet, which may mean the user needs to eject and reinsert the cart or they will return random data.

TODO: Is that correct?

Parameters
flagsThe ROM control flags to use for the transfer.
Returns
The card ID.

◆ cardReset()

void cardReset ( void  )

Reset the card.

This command requires the cart to not be initialized yet, which may mean the user needs to eject and reinsert the cart or they will return random data.

TODO: Is that correct?

◆ cardStartTransfer()

void cardStartTransfer ( const u8 command,
u32 destination,
int  channel,
u32  flags 
)

Perform a ROM command, reading the response via DMA (asynchronously).

Note that this function does not wait for the DMA to complete!

Parameters
command8-byte command buffer, little endian.
destinationThe response's destination buffer.
channelThe DMA channel to use for the transfer.
flagsThe ROM control flags to use for the transfer.

◆ cardWriteAndRead()

uint32_t cardWriteAndRead ( const u8 command,
u32  flags 
)

Perform a ROM command, reading one word of response.

Parameters
command8-byte command buffer, little endian.
flagsThe ROM control flags to use for the transfer.
Returns
uint32_t The response.

◆ cardWriteCommand()

void cardWriteCommand ( const u8 command)

Write a command to the card interface.

Parameters
command8-byte command buffer, little endian.

◆ cardWriteEeprom()

void cardWriteEeprom ( u32  address,
u8 data,
u32  length,
u32  addrtype 
)

Write to the card EEPROM.

Note that TYPE 3 (FLASH) EEPROM must be erased before writing.

Parameters
addressThe address to write to.
dataThe data to write.
lengthThe length of data, in bytes.
addrtypeThe card EEPROM's type.
See also
cardEepromGetType