VFS driver for accessing SD cards over the SCIF or SCI port
More...
|
file | sd.h |
| Block-level access to an SD card attached to the SCI or SCIF port.
|
|
VFS driver for accessing SD cards over the SCIF or SCI port
◆ sd_interface_t
SD card interface type.
Enumerator |
---|
SD_IF_SCIF | Use SCIF interface.
|
SD_IF_SCI | Use SCI interface.
|
◆ sd_blockdev_for_device()
Get a block device for the SD card.
This function creates a block device descriptor for the attached SD card. This block device is used to interface with various filesystems on the device.
- Parameters
-
rv | Used to return the block device. Must be non-NULL. |
- Return values
-
0 | On success. |
-1 | On error, errno will be set as appropriate. |
- Error Conditions:
- ENXIO - SD card support was not initialized EFAULT - rv was NULL ENOMEM - out of memory
◆ sd_blockdev_for_partition()
Get a block device for a given partition on the SD card.
This function creates a block device descriptor for the given partition on the attached SD card. This block device is used to interface with various filesystems on the device.
- Parameters
-
partition | The partition number (0-3) to use. |
rv | Used to return the block device. Must be non-NULL. |
partition_type | Used to return the partition type. Must be non-NULL. |
- Return values
-
0 | On success. |
-1 | On error, errno will be set as appropriate. |
- Error Conditions:
- ENXIO - SD card support was not initialized
EIO - an I/O error occurred in reading data
EINVAL - invalid partition number was given
EFAULT - rv or partition_type was NULL
ENOENT - no MBR found
ENOENT - no partition at the specified position
ENOMEM - out of memory
- Note
- This interface currently only supports MBR-formatted SD cards. There is currently no support for GPT partition tables.
◆ sd_crc7()
Calculate a SD/MMC-style CRC over a block of data.
This function calculates a 7-bit CRC over a given block of data. The polynomial of this CRC is x^7 + x^3 + 1. The CRC is shifted into the upper 7 bits of the return value, so bit 0 should always be 0.
- Parameters
-
data | The block of data to calculate the CRC over. |
size | The number of bytes in the block of data. |
crc | The starting value of the calculation. If you're passing in a full block, this will probably be 0. |
- Returns
- The calculated CRC.
◆ sd_get_size()
Retrieve the size of the SD card.
This function reads the size of the SD card from the card's CSD register. This is the raw size of the card, not its formatted capacity. To get the number of blocks from this, divide by 512.
- Returns
- On success, the raw size of the SD card in bytes. On error, (uint64)-1.
- Error Conditions:
- EIO - an I/O error occurred in reading data
ENXIO - SD card support was not initialized
◆ sd_init()
Initialize the SD card for use.
This function initializes the SD card for first use using default parameters (SCIF interface and CRC checking enabled).
- Return values
-
0 | On success. |
-1 | On failure. This could indicate any number of problems, but probably means that no SD card was detected. |
◆ sd_init_ex()
Initialize the SD card with extended parameters.
This function initializes the SD card with specified parameters. This includes all steps of the basic initialization sequence for SPI mode, as documented in the SD card spec and at http://elm-chan.org/docs/mmc/mmc_e.html.
- Parameters
-
params | Pointer to initialization parameters. |
- Return values
-
0 | On success. |
-1 | On failure. This could indicate any number of problems, but probably means that no SD card was detected. |
◆ sd_read_blocks()
int sd_read_blocks |
( |
uint32 | block, |
|
|
size_t | count, |
|
|
uint8 * | buf ) |
Read one or more blocks from the SD card.
This function reads the specified number of blocks from the SD card from the beginning block specified into the buffer passed in. It is your responsibility to allocate the buffer properly for the number of bytes that is to be read (512 * the number of blocks requested).
- Parameters
-
block | The starting block number to read from. |
count | The number of 512 byte blocks of data to read. |
buf | The buffer to read into. |
- Return values
-
0 | On success. |
-1 | On error, errno will be set as appropriate. |
- Error Conditions:
- EIO - an I/O error occurred in reading data
ENXIO - SD card support was not initialized
◆ sd_shutdown()
Shut down SD card support.
This function shuts down SD card support, and cleans up anything that the sd_init() function set up.
- Return values
-
0 | On success. |
-1 | On failure. The only currently defined error is if the card was never initialized to start with. |
◆ sd_write_blocks()
int sd_write_blocks |
( |
uint32 | block, |
|
|
size_t | count, |
|
|
const uint8 * | buf ) |
Write one or more blocks to the SD card.
This function writes the specified number of blocks to the SD card at the beginning block specified from the buffer passed in. Each block is 512 bytes in length, and you must write at least one block at a time. You cannot write partial blocks.
If this function returns an error, you have quite possibly corrupted something on the card or have a damaged card in general (unless errno is ENXIO).
- Parameters
-
block | The starting block number to write to. |
count | The number of 512 byte blocks of data to write. |
buf | The buffer to write from. |
- Return values
-
0 | On success. |
-1 | On error, errno will be set as appropriate. |
- Error Conditions:
- EIO - an I/O error occurred in reading data
ENXIO - SD card support was not initialized