no-OS
|
Implementation of SD card interface over SPI. More...
Macros | |
#define | BIT_CCS (1u<<30) |
#define | BIT_APPLICATION_CMD (1u<<7) |
#define | CMD(x) ((x) + 64) |
#define | ACMD(x) (CMD(x) | BIT_APPLICATION_CMD) |
#define | CMD0_RETRY_NUMBER (5u) |
#define | WAIT_RESP_TIMEOUT (1000u) |
#define | R1_READY_STATE (0x00u) |
#define | R1_IDLE_STATE (0x01u) |
#define | R1_ILLEGAL_COMMAND (0x04u) |
#define | R1_LEN (1u) |
#define | R2_LEN (2u) |
#define | R3_LEN (5u) |
#define | R7_LEN (5u) |
#define | CSD_LEN (18u) |
#define | CRC_LEN (2u) |
#define | CMD_LEN (8u) |
#define | STUFF_ARG (0x00000000u) |
#define | CMD8_ARG (0x000001AAu) |
#define | ACMD41_ARG (0x40000000u) |
#define | DATA_BLOCK_BITS (9u) |
#define | MASK_ADDR_IN_BLOCK (DATA_BLOCK_LEN - 1u) |
#define | MASK_BLOCK_NUMBER (~(uint64_t)MASK_ADDR_IN_BLOCK) |
#define | START_1_BLOCK_TOKEN (0xFEu) |
#define | START_N_BLOCK_TOKEN (0xFCu) |
#define | STOP_TRANSMISSION_TOKEN (0xFDu) |
#define | MASK_RESPONSE_TOKEN (0x0Eu) |
#define | MASK_ERROR_TOKEN (0xF0u) |
Functions | |
int32_t | sd_read (struct sd_desc *sd_desc, uint8_t *data, uint64_t address, uint64_t len) |
int32_t | sd_write (struct sd_desc *sd_desc, uint8_t *data, uint64_t address, uint64_t len) |
int32_t | sd_init (struct sd_desc **sd_desc, const struct sd_init_param *param) |
int32_t | sd_remove (struct sd_desc *desc) |
Implementation of SD card interface over SPI.
Copyright 2019(c) Analog Devices, Inc.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define ACMD | ( | x | ) | (CMD(x) | BIT_APPLICATION_CMD) |
#define ACMD41_ARG (0x40000000u) |
#define BIT_APPLICATION_CMD (1u<<7) |
#define BIT_CCS (1u<<30) |
#define CMD | ( | x | ) | ((x) + 64) |
#define CMD0_RETRY_NUMBER (5u) |
#define CMD8_ARG (0x000001AAu) |
#define CMD_LEN (8u) |
#define CRC_LEN (2u) |
#define CSD_LEN (18u) |
#define DATA_BLOCK_BITS (9u) |
#define MASK_ADDR_IN_BLOCK (DATA_BLOCK_LEN - 1u) |
#define MASK_BLOCK_NUMBER (~(uint64_t)MASK_ADDR_IN_BLOCK) |
#define MASK_ERROR_TOKEN (0xF0u) |
#define MASK_RESPONSE_TOKEN (0x0Eu) |
#define R1_IDLE_STATE (0x01u) |
#define R1_ILLEGAL_COMMAND (0x04u) |
#define R1_LEN (1u) |
#define R1_READY_STATE (0x00u) |
#define R2_LEN (2u) |
#define R3_LEN (5u) |
#define R7_LEN (5u) |
#define START_1_BLOCK_TOKEN (0xFEu) |
#define START_N_BLOCK_TOKEN (0xFCu) |
#define STOP_TRANSMISSION_TOKEN (0xFDu) |
#define STUFF_ARG (0x00000000u) |
#define WAIT_RESP_TIMEOUT (1000u) |
int32_t sd_init | ( | struct sd_desc ** | sd_desc, |
const struct sd_init_param * | param | ||
) |
Initialize an instance of SD card and stores it to the parameter desc
sd_desc | - Pointer where to store the instance of the SD |
param | - Contains an initialized SPI descriptor |
int32_t sd_read | ( | struct sd_desc * | sd_desc, |
uint8_t * | data, | ||
uint64_t | address, | ||
uint64_t | len | ||
) |
Read data of size len from the specified address and store it in data. This operation returns only when the read is complete
sd_desc | - Instance of the SD card |
data | - Where data will be read |
address | - Address in memory from where data will be read |
len | - Length in bytes of data to be read |
int32_t sd_remove | ( | struct sd_desc * | desc | ) |
Remove the initialize instance of SD card.
desc | - Instance of the SD card |
int32_t sd_write | ( | struct sd_desc * | sd_desc, |
uint8_t * | data, | ||
uint64_t | address, | ||
uint64_t | len | ||
) |
Write data of size len to the specified address This operation returns only when the write is complete
sd_desc | - Instance of the SD card |
data | - Data to write |
address | - Address in memory where data will be written |
len | - Length of data in bytes |