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 () |
#define configure_pin_available | ( | ) |
#define configure_pin_locked | ( | ) |
#define get_pin_available | ( | ) | 0 |
#define get_pin_locked | ( | ) | 0 |
#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_SAVE_RAM 0 |
Controls MMC/SD access buffering.
Set to 1 to save static RAM, but be aware that you will lose performance.
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.
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.
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 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) |
uint8_t sd_available | ( | ) |
Checks wether a memory card is located in the slot.
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.
[in] | info | A pointer to the structure into which to save the information. |
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 | ( | ) |
Initializes memory card communication.
Definition at line 170 of file sd_mmc.c.
References CMD_GO_IDLE_STATE, CMD_SEND_OP_COND, CMD_SET_BLOCKLEN, configure_pin_available, configure_pin_locked, R1_IDLE_STATE, raw_block, raw_block_address, raw_block_written, sd_available(), sd_read(), sd_send_command_r1(), spi_init(), spi_read_byte(), spi_set_maxspeed(), uart_putc(), and uart_puts().
Referenced by main().
uint8_t sd_locked | ( | ) |
Checks wether the memory card is locked for write access.
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.
[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. |
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.
This function only works if the following conditions are met:
[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. |
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.
[in] | command | The command to send. |
[in] | arg | The argument for command. |
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.
[in] | command | The command to send. |
[in] | arg | The argument for command. |
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.
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.
[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. |
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.
[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. |
Definition at line 707 of file sd_mmc.c.
References sd_write().
Referenced by main().