Secure Digital (SD) Driver.
The SD driver is designed to serve as an interface to perform basic transfers directly to the SD card.
This section will cover driver usage.
Get total capacity of an SD card:
Refer to the Driver's Configuration section for driver configuration information.
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | SD_Params |
SD Parameters. More... | |
struct | SD_FxnTable |
The definition of a SD function table that contains the required set of functions to control a specific SD driver implementation. More... | |
struct | SD_Config_ |
SD Global configuration. More... | |
Macros | |
#define | SD_CMD_RESERVED (32) |
#define | SD_STATUS_RESERVED (-32) |
#define | SD_STATUS_SUCCESS (0) |
Successful status code returned by SD_control(). More... | |
#define | SD_STATUS_ERROR (-1) |
Generic error status code returned by SD_control(). More... | |
#define | SD_STATUS_UNDEFINEDCMD (-2) |
An error status code returned by SD_control() for undefined command codes. More... | |
Typedefs | |
typedef struct SD_Config_ * | SD_Handle |
A handle that is returned from a SD_open() call. More... | |
typedef void(* | SD_CloseFxn) (SD_Handle handle) |
A function pointer to a driver specific implementation of SD_CloseFxn(). More... | |
typedef int_fast16_t(* | SD_ControlFxn) (SD_Handle handle, uint_fast16_t cmd, void *arg) |
A function pointer to a driver specific implementation of SD_controlFxn(). More... | |
typedef uint_fast32_t(* | SD_getNumSectorsFxn) (SD_Handle handle) |
A function pointer to a driver specific implementation of SD_getNumSectorsFxn(). More... | |
typedef uint_fast32_t(* | SD_getSectorSizeFxn) (SD_Handle handle) |
A function pointer to a driver specific implementation of SD_getSectorSizeFxn(). More... | |
typedef void(* | SD_InitFxn) (SD_Handle handle) |
A function pointer to a driver specific implementation of SD_InitFxn(). More... | |
typedef int_fast16_t(* | SD_InitializeFxn) (SD_Handle handle) |
A function pointer to a driver specific implementation of SD_initializeFxn(). More... | |
typedef SD_Handle(* | SD_OpenFxn) (SD_Handle handle, SD_Params *params) |
A function pointer to a driver specific implementation of SD_OpenFxn(). More... | |
typedef int_fast16_t(* | SD_ReadFxn) (SD_Handle handle, void *buf, int_fast32_t sector, uint_fast32_t secCount) |
A function pointer to a driver specific implementation of SD_readFxn(). More... | |
typedef int_fast16_t(* | SD_WriteFxn) (SD_Handle handle, const void *buf, int_fast32_t sector, uint_fast32_t secCount) |
A function pointer to a driver specific implementation of SD_writeFxn(). More... | |
typedef struct SD_Config_ | SD_Config |
SD Global configuration. More... | |
Enumerations | |
enum | SD_CardType { SD_NOCARD = 0, SD_MMC = 1, SD_SDSC = 2, SD_SDHC = 3 } |
SD Card type inserted. More... | |
Functions | |
void | SD_close (SD_Handle handle) |
Function to close a SD peripheral specified by the SD handle. More... | |
int_fast16_t | SD_control (SD_Handle handle, uint_fast16_t cmd, void *arg) |
Function performs implementation specific features on a given SD_Handle. More... | |
uint_fast32_t | SD_getNumSectors (SD_Handle handle) |
A function pointer to a driver specific implementation of SD_getNumSectors(). Note: Total Card capacity is the (NumberOfSectors * SectorSize). More... | |
uint_fast32_t | SD_getSectorSize (SD_Handle handle) |
Function to obtain the sector size used to access the SD card. More... | |
void | SD_init (void) |
This function initializes the SD driver. More... | |
void | SD_Params_init (SD_Params *params) |
Function to initialize the SD_Params struct to its defaults. More... | |
int_fast16_t | SD_initialize (SD_Handle handle) |
A function pointer to a driver specific implementation of SD_initialize(). More... | |
SD_Handle | SD_open (uint_least8_t index, SD_Params *params) |
A function pointer to a driver specific implementation of SD_open(). More... | |
int_fast16_t | SD_read (SD_Handle handle, void *buf, int_fast32_t sector, uint_fast32_t secCount) |
A function pointer to a driver specific implementation of SD_read(). More... | |
int_fast16_t | SD_write (SD_Handle handle, const void *buf, int_fast32_t sector, uint_fast32_t secCount) |
A function pointer to a driver specific implementation of SD_write(). More... | |
typedef struct SD_Config_* SD_Handle |
A handle that is returned from a SD_open() call.
typedef void(* SD_CloseFxn) (SD_Handle handle) |
A function pointer to a driver specific implementation of SD_CloseFxn().
typedef int_fast16_t(* SD_ControlFxn) (SD_Handle handle, uint_fast16_t cmd, void *arg) |
A function pointer to a driver specific implementation of SD_controlFxn().
typedef uint_fast32_t(* SD_getNumSectorsFxn) (SD_Handle handle) |
A function pointer to a driver specific implementation of SD_getNumSectorsFxn().
typedef uint_fast32_t(* SD_getSectorSizeFxn) (SD_Handle handle) |
A function pointer to a driver specific implementation of SD_getSectorSizeFxn().
typedef void(* SD_InitFxn) (SD_Handle handle) |
A function pointer to a driver specific implementation of SD_InitFxn().
typedef int_fast16_t(* SD_InitializeFxn) (SD_Handle handle) |
A function pointer to a driver specific implementation of SD_initializeFxn().
A function pointer to a driver specific implementation of SD_OpenFxn().
typedef int_fast16_t(* SD_ReadFxn) (SD_Handle handle, void *buf, int_fast32_t sector, uint_fast32_t secCount) |
A function pointer to a driver specific implementation of SD_readFxn().
typedef int_fast16_t(* SD_WriteFxn) (SD_Handle handle, const void *buf, int_fast32_t sector, uint_fast32_t secCount) |
A function pointer to a driver specific implementation of SD_writeFxn().
typedef struct SD_Config_ SD_Config |
enum SD_CardType |
void SD_close | ( | SD_Handle | handle | ) |
int_fast16_t SD_control | ( | SD_Handle | handle, |
uint_fast16_t | cmd, | ||
void * | arg | ||
) |
Function performs implementation specific features on a given SD_Handle.
Commands for SD_control can originate from SD.h or from implementation specific SD*.h files. While commands from SD.h are API portable across driver implementations, not all implementations may support all these commands. Conversely, commands from driver implementation specific SD*.h files add unique driver capabilities but are not API portable across all SD driver implementations.
Commands supported by SD.h follow a SD*_CMD naming convention.
Commands supported by SD*.h follow a SD*_CMD naming convention. Each control command defines arg differently. The types of arg are documented with each command.
See SD_control command codes for command codes.
See SD_control return status codes for status codes.
handle | A SD_Handle returned from SD_open(). |
cmd | SD.h or SD*.h commands. |
arg | An optional R/W (read/write) command argument accompanied with cmd. |
uint_fast32_t SD_getNumSectors | ( | SD_Handle | handle | ) |
A function pointer to a driver specific implementation of SD_getNumSectors(). Note: Total Card capacity is the (NumberOfSectors * SectorSize).
uint_fast32_t SD_getSectorSize | ( | SD_Handle | handle | ) |
Function to obtain the sector size used to access the SD card.
void SD_init | ( | void | ) |
This function initializes the SD driver.
void SD_Params_init | ( | SD_Params * | params | ) |
int_fast16_t SD_initialize | ( | SD_Handle | handle | ) |
A function pointer to a driver specific implementation of SD_initialize().
A function pointer to a driver specific implementation of SD_open().
index | Logical peripheral number for the SD indexed into the SD_config[] table. |
params | Pointer to a parameter block, if NULL it will use default values. All the fields in this structure are RO (read-only). |
int_fast16_t SD_read | ( | SD_Handle | handle, |
void * | buf, | ||
int_fast32_t | sector, | ||
uint_fast32_t | secCount | ||
) |
A function pointer to a driver specific implementation of SD_read().
handle | A SD_Handle returned from SD_open(). |
buf | Pointer to a buffer to read data into. |
sector | Starting sector on the disk to read from. |
secCount | Number of sectors to be read. |
int_fast16_t SD_write | ( | SD_Handle | handle, |
const void * | buf, | ||
int_fast32_t | sector, | ||
uint_fast32_t | secCount | ||
) |
A function pointer to a driver specific implementation of SD_write().
handle | A SD_Handle returned from SD_open(). |
buf | Pointer to a buffer containing data to write to disk. |
sector | Starting sector on the disk to write to. |
secCount | Number of sectors to be written. |