sd-reader
Data Structures | Modules | Files | Defines | Functions
MMC/SD/SDHC card raw access

This module implements read and write access to MMC, SD and SDHC cards. More...

Data Structures

struct  sd_raw_info
 This struct is used by sd_raw_get_info() to return manufacturing and status information of the card. More...

Modules

 MMC/SD configuration
 

Preprocessor defines to configure the MMC/SD support.


Files

file  sd_raw.c
 

MMC/SD/SDHC raw access implementation (license: GPLv2 or LGPLv2.1)


file  sd_raw.h
 

MMC/SD/SDHC raw access header (license: GPLv2 or LGPLv2.1)


file  sd_raw_config.h
 

MMC/SD support configuration (license: GPLv2 or LGPLv2.1)


Defines

#define SD_RAW_FORMAT_HARDDISK
 The card's layout is harddisk-like, which means it contains a master boot record with a partition table.
#define SD_RAW_FORMAT_SUPERFLOPPY
 The card contains a single filesystem and no partition table.
#define SD_RAW_FORMAT_UNIVERSAL
 The card's layout follows the Universal File Format.
#define SD_RAW_FORMAT_UNKNOWN
 The card's layout is unknown.

Functions

uint8_t sd_raw_init ()
 Initializes memory card communication.
uint8_t sd_raw_available ()
 Checks wether a memory card is located in the slot.
uint8_t sd_raw_locked ()
 Checks wether the memory card is locked for write access.
uint8_t sd_raw_read (offset_t offset, uint8_t *buffer, uintptr_t length)
 Reads raw data from the card.
uint8_t sd_raw_read_interval (offset_t offset, uint8_t *buffer, uintptr_t interval, uintptr_t length, sd_raw_read_interval_handler_t callback, void *p)
 Continuously reads units of interval bytes and calls a callback function.
uint8_t sd_raw_write (offset_t offset, const uint8_t *buffer, uintptr_t length)
 Writes raw data to the card.
uint8_t sd_raw_write_interval (offset_t offset, uint8_t *buffer, uintptr_t length, sd_raw_write_interval_handler_t callback, void *p)
 Writes a continuous data stream obtained from a callback function.
uint8_t sd_raw_sync ()
 Writes the write buffer's content to the card.
uint8_t sd_raw_get_info (struct sd_raw_info *info)
 Reads informational data from the card.

Detailed Description

This module implements read and write access to MMC, SD and SDHC cards.

It serves as a low-level driver for the higher level modules such as partition and file system access.


Function Documentation

uint8_t sd_raw_available ( )

Checks wether a memory card is located in the slot.

Returns:
1 if the card is available, 0 if it is not.
uint8_t sd_raw_get_info ( struct sd_raw_info info)

Reads informational data from the card.

This function reads and returns the card's registers containing manufacturing and status information.

Note:
: The information retrieved by this function is not required in any way to operate on the card, but it might be nice to display some of the data to the user.
Parameters:
[in]infoA pointer to the structure into which to save the information.
Returns:
0 on failure, 1 on success.
uint8_t sd_raw_init ( )

Initializes memory card communication.

Returns:
0 on failure, 1 on success.
uint8_t sd_raw_locked ( )

Checks wether the memory card is locked for write access.

Returns:
1 if the card is locked, 0 if it is not.
uint8_t sd_raw_read ( offset_t  offset,
uint8_t *  buffer,
uintptr_t  length 
)

Reads raw data from the card.

Parameters:
[in]offsetThe offset from which to read.
[out]bufferThe buffer into which to write the data.
[in]lengthThe number of bytes to read.
Returns:
0 on failure, 1 on success.
See also:
sd_raw_read_interval, sd_raw_write, sd_raw_write_interval
uint8_t sd_raw_read_interval ( offset_t  offset,
uint8_t *  buffer,
uintptr_t  interval,
uintptr_t  length,
sd_raw_read_interval_handler_t  callback,
void *  p 
)

Continuously reads units of interval bytes and calls a callback function.

This function starts reading at the specified offset. Every interval bytes, it calls the callback function with the associated data buffer.

By returning zero, the callback may stop reading.

Note:
Within the callback function, you can not start another read or write operation.
This function only works if the following conditions are met:
  • (offset - (offset % 512)) % interval == 0
  • length % interval == 0
Parameters:
[in]offsetOffset from which to start reading.
[in]bufferPointer to a buffer which is at least interval bytes in size.
[in]intervalNumber of bytes to read before calling the callback function.
[in]lengthNumber of bytes to read altogether.
[in]callbackThe function to call every interval bytes.
[in]pAn opaque pointer directly passed to the callback function.
Returns:
0 on failure, 1 on success
See also:
sd_raw_write_interval, sd_raw_read, sd_raw_write
uint8_t sd_raw_sync ( )

Writes the write buffer's content to the card.

Note:
When write buffering is enabled, you should call this function before disconnecting the card to ensure all remaining data has been written.
Returns:
0 on failure, 1 on success.
See also:
sd_raw_write
uint8_t sd_raw_write ( offset_t  offset,
const uint8_t *  buffer,
uintptr_t  length 
)

Writes raw data to the card.

Note:
If write buffering is enabled, you might have to call sd_raw_sync() before disconnecting the card to ensure all remaining data has been written.
Parameters:
[in]offsetThe offset where to start writing.
[in]bufferThe buffer containing the data to be written.
[in]lengthThe number of bytes to write.
Returns:
0 on failure, 1 on success.
See also:
sd_raw_write_interval, sd_raw_read, sd_raw_read_interval
uint8_t sd_raw_write_interval ( offset_t  offset,
uint8_t *  buffer,
uintptr_t  length,
sd_raw_write_interval_handler_t  callback,
void *  p 
)

Writes a continuous data stream obtained from a callback function.

This function starts writing at the specified offset. To obtain the next bytes to write, it calls the callback function. The callback fills the provided data buffer and returns the number of bytes it has put into the buffer.

By returning zero, the callback may stop writing.

Parameters:
[in]offsetOffset where to start writing.
[in]bufferPointer to a buffer which is used for the callback function.
[in]lengthNumber of bytes to write in total. May be zero for endless writes.
[in]callbackThe function used to obtain the bytes to write.
[in]pAn opaque pointer directly passed to the callback function.
Returns:
0 on failure, 1 on success
See also:
sd_raw_read_interval, sd_raw_write, sd_raw_read