MMC/SD card raw access

Collaboration diagram for MMC/SD card raw access:

Files

file  sd_mmc.c
file  sd_mmc.h
file  sd_mmc_config.h

Modules

 MMC/SD configuration

Data Structures

struct  sd_raw_info

Defines

#define SD_RAW_FORMAT_HARDDISK   0
#define SD_RAW_FORMAT_SUPERFLOPPY   1
#define SD_RAW_FORMAT_UNIVERSAL   2
#define SD_RAW_FORMAT_UNKNOWN   3
#define SD_RAW_WRITE_SUPPORT   1
#define SD_RAW_WRITE_BUFFERING   1
#define SD_RAW_SAVE_RAM   1
#define SD_RAW_SAVE_RAM   0
#define configure_pin_available()
#define configure_pin_locked()
#define get_pin_available()   0
#define get_pin_locked()   0

Typedefs

typedef uint8_t(* sd_raw_read_interval_handler_t )(uint8_t *buffer, uint32_t offset, void *p)
typedef uint16_t(* sd_raw_write_interval_handler_t )(uint8_t *buffer, uint32_t offset, void *p)

Functions

uint8_t sd_init ()
static uint8_t sd_send_command_r1 (uint8_t command, uint32_t arg)
static uint16_t sd_send_command_r2 (uint8_t command, uint32_t arg)
uint8_t sd_read (uint32_t offset, uint8_t *buffer, uint16_t length)
uint8_t sd_read_interval (uint32_t offset, uint8_t *buffer, uint16_t interval, uint16_t length, sd_raw_read_interval_handler_t callback, void *p)
uint8_t sd_write (uint32_t offset, const uint8_t *buffer, uint16_t length)
uint8_t sd_write_interval (uint32_t offset, uint8_t *buffer, uint16_t length, sd_raw_write_interval_handler_t callback, void *p)
uint8_t sd_sync ()
uint8_t sd_get_info (struct sd_raw_info *info)
uint8_t sd_available ()
uint8_t sd_locked ()

Detailed Description

This module implements read and write access to MMC and SD cards. It serves as a low-level driver for the higher level modules such as partition and file system access.

Define Documentation

 
#define configure_pin_available (  ) 

Definition at line 83 of file sd_mmc_config.h.

Referenced by sd_init().

 
#define configure_pin_locked (  ) 

Definition at line 84 of file sd_mmc_config.h.

Referenced by sd_init().

 
#define get_pin_available (  )     0

Definition at line 88 of file sd_mmc_config.h.

Referenced by sd_available().

 
#define get_pin_locked (  )     0

Definition at line 89 of file sd_mmc_config.h.

Referenced by sd_locked(), and sd_write().

#define SD_RAW_FORMAT_HARDDISK   0

The card's layout is harddisk-like, which means it contains a master boot record with a partition table.

Definition at line 40 of file sd_mmc.h.

#define SD_RAW_FORMAT_SUPERFLOPPY   1

The card contains a single filesystem and no partition table.

Definition at line 44 of file sd_mmc.h.

#define SD_RAW_FORMAT_UNIVERSAL   2

The card's layout follows the Universal File Format.

Definition at line 48 of file sd_mmc.h.

#define SD_RAW_FORMAT_UNKNOWN   3

The card's layout is unknown.

Definition at line 52 of file sd_mmc.h.

#define SD_RAW_SAVE_RAM   0

Controls MMC/SD access buffering.

Set to 1 to save static RAM, but be aware that you will lose performance.

Note:
When SD_RAW_WRITE_SUPPORT is 1, SD_RAW_SAVE_RAM will be reset to 0.

Definition at line 98 of file sd_mmc_config.h.

#define SD_RAW_SAVE_RAM   1

Controls MMC/SD access buffering.

Set to 1 to save static RAM, but be aware that you will lose performance.

Note:
When SD_RAW_WRITE_SUPPORT is 1, SD_RAW_SAVE_RAM will be reset to 0.

Definition at line 98 of file sd_mmc_config.h.

#define SD_RAW_WRITE_BUFFERING   1

Controls MMC/SD write buffering.

Set to 1 to buffer write accesses, set to 0 to disable it.

Note:
This option has no effect when SD_RAW_WRITE_SUPPORT is 0.

Definition at line 47 of file sd_mmc_config.h.

#define SD_RAW_WRITE_SUPPORT   1

Controls MMC/SD write support.

Set to 1 to enable MMC/SD write support, set to 0 to disable it.

Definition at line 37 of file sd_mmc_config.h.


Typedef Documentation

typedef uint8_t(* sd_raw_read_interval_handler_t)(uint8_t *buffer, uint32_t offset, void *p)

Definition at line 126 of file sd_mmc.h.

typedef uint16_t(* sd_raw_write_interval_handler_t)(uint8_t *buffer, uint32_t offset, void *p)

Definition at line 127 of file sd_mmc.h.


Function Documentation

uint8_t sd_available (  ) 

Checks wether a memory card is located in the slot.

Returns:
1 if the card is available, 0 if it is not.

Definition at line 285 of file sd_mmc.c.

References get_pin_available.

Referenced by sd_get_info(), and sd_init().

uint8_t sd_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] info A pointer to the structure into which to save the information.
Returns:
0 on failure, 1 on success.

Definition at line 787 of file sd_mmc.c.

References sd_raw_info::capacity, CMD_SEND_CID, CMD_SEND_CSD, sd_raw_info::flag_copy, sd_raw_info::flag_write_protect, sd_raw_info::flag_write_protect_temp, sd_raw_info::format, sd_raw_info::manufacturer, sd_raw_info::manufacturing_month, sd_raw_info::manufacturing_year, sd_raw_info::oem, sd_raw_info::product, sd_raw_info::revision, sd_available(), sd_send_command_r1(), sd_raw_info::serial, and spi_read_byte().

Referenced by print_disk_info().

uint8_t sd_init (  ) 

uint8_t sd_locked (  ) 

Checks wether the memory card is locked for write access.

Returns:
1 if the card is locked, 0 if it is not.

Definition at line 296 of file sd_mmc.c.

References get_pin_locked.

uint8_t sd_read ( uint32_t  offset,
uint8_t *  buffer,
uint16_t  length 
)

Reads raw data from the card.

Parameters:
[in] offset The offset from which to read.
[out] buffer The buffer into which to write the data.
[in] length The number of bytes to read.
Returns:
0 on failure, 1 on success.
See also:
sd_read_interval, sd_write, sd_write_interval

Definition at line 381 of file sd_mmc.c.

References CMD_READ_SINGLE_BLOCK, raw_block, raw_block_address, sd_send_command_r1(), sd_sync(), and spi_read_byte().

Referenced by main(), sd_init(), sd_read_interval(), and sd_write().

uint8_t sd_read_interval ( uint32_t  offset,
uint8_t *  buffer,
uint16_t  interval,
uint16_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] offset Offset from which to start reading.
[in] buffer Pointer to a buffer which is at least interval bytes in size.
[in] interval Number of bytes to read before calling the callback function.
[in] length Number of bytes to read altogether.
[in] callback The function to call every interval bytes.
[in] p An opaque pointer directly passed to the callback function.
Returns:
0 on failure, 1 on success
See also:
sd_write_interval, sd_read, sd_write

Definition at line 488 of file sd_mmc.c.

References CMD_READ_SINGLE_BLOCK, sd_read(), sd_send_command_r1(), and spi_read_byte().

Referenced by main().

uint8_t sd_send_command_r1 ( uint8_t  command,
uint32_t  arg 
) [static]

Send a command to the memory card which responses with a R1 response.

Parameters:
[in] command The command to send.
[in] arg The argument for command.
Returns:
The command answer.

Definition at line 309 of file sd_mmc.c.

References CMD_GO_IDLE_STATE, spi_read_byte(), and spi_write_byte().

Referenced by sd_get_info(), sd_init(), sd_read(), sd_read_interval(), and sd_write().

uint16_t sd_send_command_r2 ( uint8_t  command,
uint32_t  arg 
) [static]

Send a command to the memory card which responses with a R2 response.

Parameters:
[in] command The command to send.
[in] arg The argument for command.
Returns:
The command answer.

Definition at line 343 of file sd_mmc.c.

References CMD_GO_IDLE_STATE, spi_read_byte(), and spi_write_byte().

uint8_t sd_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

Definition at line 756 of file sd_mmc.c.

References raw_block, raw_block_address, raw_block_written, and sd_write().

Referenced by sd_read(), and sd_write().

uint8_t sd_write ( uint32_t  offset,
const uint8_t *  buffer,
uint16_t  length 
)

Writes raw data to the card.

Note:
If write buffering is enabled, you might have to call sd_sync() before disconnecting the card to ensure all remaining data has been written.
Parameters:
[in] offset The offset where to start writing.
[in] buffer The buffer containing the data to be written.
[in] length The number of bytes to write.
Returns:
0 on failure, 1 on success.
See also:
sd_write_interval, sd_read, sd_read_interval

Definition at line 596 of file sd_mmc.c.

References CMD_WRITE_SINGLE_BLOCK, get_pin_locked, raw_block, raw_block_address, raw_block_written, sd_read(), sd_send_command_r1(), sd_sync(), spi_read_byte(), and spi_write_byte().

Referenced by main(), sd_sync(), and sd_write_interval().

uint8_t sd_write_interval ( uint32_t  offset,
uint8_t *  buffer,
uint16_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] offset Offset where to start writing.
[in] buffer Pointer to a buffer which is used for the callback function.
[in] length Number of bytes to write in total. May be zero for endless writes.
[in] callback The function used to obtain the bytes to write.
[in] p An opaque pointer directly passed to the callback function.
Returns:
0 on failure, 1 on success
See also:
sd_read_interval, sd_write, sd_read

Definition at line 707 of file sd_mmc.c.

References sd_write().

Referenced by main().


Generated on Wed Sep 17 19:31:52 2008 for mptry by  doxygen 1.5.5