Modules | |
Compiler abstraction layer and code utilities | |
Compiler abstraction layer and code utilities for AT91SAM. | |
Preprocessor - Token Paste | |
Preprocessor - Stringize | |
Preprocessor - Macro Repeat | |
Global interrupt management | |
This is a driver for global enabling and disabling of interrupts. | |
Data Structures | |
struct | sd_mmc_card |
SD/MMC card information structure. More... | |
Files | |
file | compiler.h |
Commonly used includes, types and macros. | |
file | interrupt.h |
Global interrupt management for 8- and 32-bit AVR. | |
file | parts.h |
Atmel part identification macros. | |
file | parts.h |
Atmel part identification macros. | |
file | pmc.h |
Power Management Controller (PMC) driver for SAM. | |
file | tpaste.h |
Preprocessor token pasting utils. | |
Enumerations | |
enum | card_state { SD_MMC_CARD_STATE_READY = 0, SD_MMC_CARD_STATE_DEBOUNCE = 1, SD_MMC_CARD_STATE_INIT = 2, SD_MMC_CARD_STATE_UNUSABLE = 3, SD_MMC_CARD_STATE_NO_CARD = 4 } |
SD/MMC card states. More... | |
Functions | |
sd_mmc_err_t | sd_mmc_check (uint8_t slot) |
Performs a card checks. More... | |
uint32_t | sd_mmc_get_capacity (uint8_t slot) |
Get the memory capacity. More... | |
card_type_t | sd_mmc_get_type (uint8_t slot) |
Get the card type. More... | |
card_version_t | sd_mmc_get_version (uint8_t slot) |
Get the card version. More... | |
sd_mmc_err_t | sd_mmc_init_read_blocks (uint8_t slot, uint32_t start, uint16_t nb_block) |
Initialize the read blocks of data from the card. More... | |
sd_mmc_err_t | sd_mmc_init_write_blocks (uint8_t slot, uint32_t start, uint16_t nb_block) |
Initialize the write blocks of data. More... | |
bool | sd_mmc_is_write_protected (uint8_t slot) |
Get the card write protection status. More... | |
uint8_t | sd_mmc_nb_slot (void) |
Return the number of slot available. More... | |
sd_mmc_err_t | sd_mmc_start_read_blocks (void *dest, uint16_t nb_block) |
Start the read blocks of data from the card. More... | |
sd_mmc_err_t | sd_mmc_start_write_blocks (const void *src, uint16_t nb_block) |
Start the write blocks of data. More... | |
sd_mmc_err_t | sd_mmc_wait_end_of_read_blocks (bool abort) |
Wait the end of read blocks of data from the card. More... | |
sd_mmc_err_t | sd_mmc_wait_end_of_write_blocks (bool abort) |
Wait the end of write blocks of data. More... | |
sd_mmc_err_t | sdio_read_direct (uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t *dest) |
Read one byte from SDIO using RW_DIRECT command. More... | |
sd_mmc_err_t | sdio_read_extended (uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t inc_addr, uint8_t *dest, uint16_t size) |
Read bytes from SDIO using RW_EXTENDED command. More... | |
sd_mmc_err_t | sdio_write_direct (uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t data) |
Write one byte to SDIO using RW_DIRECT command. More... | |
sd_mmc_err_t | sdio_write_extended (uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t inc_addr, uint8_t *src, uint16_t size) |
Write bytes to SDIO using RW_EXTENDED command. More... | |
Variables | |
const uint32_t | mmc_trans_multipliers [16] |
MMC transfer multiplier factor codes (1/10) list. More... | |
static struct sd_mmc_card * | sd_mmc_card |
Pointer on current slot configurated. More... | |
static struct sd_mmc_card | sd_mmc_cards [SD_MMC_MEM_CNT] |
SD/MMC card list Note: Initialize card detect pin fields if present. More... | |
static uint16_t | sd_mmc_nb_block_remaining = 0 |
Number of block remaining to read or write on the current transfer. More... | |
static uint16_t | sd_mmc_nb_block_to_tranfer = 0 |
Number of block to read or write on the current transfer. More... | |
static uint8_t | sd_mmc_slot_sel |
Index of current slot configurated. More... | |
const uint32_t | sd_mmc_trans_units [7] |
SD/MMC transfer rate unit codes (10K) list. More... | |
const uint32_t | sd_trans_multipliers [16] |
SD transfer multiplier factor codes (1/10) list. More... | |
MMC, SD and SDIO commands process | |
static bool | mmc_spi_op_cond (void) |
Sends operation condition command and read OCR (SPI only) More... | |
static bool | mmc_mci_op_cond (void) |
Sends operation condition command and read OCR (MCI only) More... | |
static bool | sd_spi_op_cond (uint8_t v2) |
Ask to all cards to send their operations conditions (SPI only). More... | |
static bool | sd_mci_op_cond (uint8_t v2) |
Ask to all cards to send their operations conditions (MCI only). More... | |
static bool | sdio_op_cond (void) |
Try to get the SDIO card's operating condition. More... | |
static bool | sdio_get_max_speed (void) |
Get SDIO max transfer speed in Hz. More... | |
static bool | sdio_cmd52_set_bus_width (void) |
CMD52 for SDIO - Switches the bus width mode to 4. More... | |
static bool | sdio_cmd52_set_high_speed (void) |
CMD52 for SDIO - Enable the high speed mode. More... | |
static bool | sd_cm6_set_high_speed (void) |
CMD6 for SD - Switch card in high speed mode. More... | |
static bool | mmc_cmd6_set_bus_width (uint8_t bus_width) |
CMD6 for MMC - Switches the bus width mode. More... | |
static bool | mmc_cmd6_set_high_speed (void) |
CMD6 for MMC - Switches in high speed mode. More... | |
static bool | sd_cmd8 (uint8_t *v2) |
CMD8 for SD card - Send Interface Condition Command. More... | |
static bool | mmc_cmd8 (uint8_t *b_authorize_high_speed) |
CMD8 - The card sends its EXT_CSD register as a block of data. More... | |
static bool | sd_mmc_cmd9_spi (void) |
CMD9: Addressed card sends its card-specific data (CSD) on the CMD line spi. More... | |
static bool | sd_mmc_cmd9_mci (void) |
CMD9: Addressed card sends its card-specific data (CSD) on the CMD line mci. More... | |
static void | mmc_decode_csd (void) |
Decodes MMC CSD register. More... | |
static void | sd_decode_csd (void) |
Decodes SD CSD register. More... | |
static bool | sd_mmc_cmd13 (void) |
CMD13 - Addressed card sends its status register. More... | |
static bool | sdio_cmd52 (uint8_t rw_flag, uint8_t func_nb, uint32_t reg_addr, uint8_t rd_after_wr, uint8_t *io_data) |
CMD52 - SDIO IO_RW_DIRECT command. More... | |
static bool | sdio_cmd53 (uint8_t rw_flag, uint8_t func_nb, uint32_t reg_addr, uint8_t inc_addr, uint32_t size, bool access_block) |
CMD53 - SDIO IO_RW_EXTENDED command This implementation support only the SDIO multi-byte transfer mode which is similar to the single block transfer on memory. More... | |
static bool | sd_acmd6 (void) |
ACMD6 - Define the data bus width to 4 bits bus. More... | |
static bool | sd_acmd51 (void) |
ACMD51 - Read the SD Configuration Register. More... | |
Internal function to process the initialization and install | |
static sd_mmc_err_t | sd_mmc_select_slot (uint8_t slot) |
Select a card slot and initialize the associated driver. More... | |
static void | sd_mmc_configure_slot (void) |
Configures the driver with the selected card configuration. More... | |
static void | sd_mmc_deselect_slot (void) |
Deselect the current card slot. More... | |
static bool | sd_mmc_spi_card_init (void) |
Initialize the SD card in SPI mode. More... | |
static bool | sd_mmc_mci_card_init (void) |
Initialize the SD card in MCI mode. More... | |
static bool | sd_mmc_spi_install_mmc (void) |
Initialize the MMC card in SPI mode. More... | |
static bool | sd_mmc_mci_install_mmc (void) |
Initialize the MMC card in MCI mode. More... | |
Internal functions to manage a large timeout after a card insertion | |
static t_cpu_time | timer |
static bool | sd_mmc_sam_systick_used |
#define | SD_MMC_START_TIMEOUT() delay_ms(SD_MMC_DEBOUNCE_TIMEOUT) |
#define | SD_MMC_IS_TIMEOUT() true |
#define | SD_MMC_STOP_TIMEOUT() |
#define | SD_MMC_DEBOUNCE_TIMEOUT 1000 |
#define | SD_MMC_START_TIMEOUT() cpu_set_timeout(cpu_ms_2_cy(SD_MMC_DEBOUNCE_TIMEOUT, sysclk_get_cpu_hz()), &timer) |
#define | SD_MMC_IS_TIMEOUT() cpu_is_timeout(&timer) |
#define | SD_MMC_STOP_TIMEOUT() |
In this use case, the PMC module is configured for a variety of system clock sources and speeds. A LED is used to visually indicate the current clock speed as the source is switched.
The following function needs to be added to the user application, to flash a board LED a variable number of times at a rate given in CPU ticks.
Add to application C-file:
In this use case, the PMC module is configured to start the Slow Clock from an attached 32KHz crystal, and start one of the Programmable Clock modules sourced from the Slow Clock divided down with a prescale factor of 64.
The following code must be added to the user application:
The generated PCK1 clock output can be viewed on an oscilloscope attached to the correct pin of the microcontroller.
Add to application C-file:
#define driver hsmci |
Referenced by mmc_cmd8(), sd_acmd51(), sd_cm6_set_high_speed(), sd_mmc_cmd9_spi(), sd_mmc_init_read_blocks(), sd_mmc_init_write_blocks(), and sdio_cmd53().
Referenced by sd_mmc_wait_end_of_read_blocks(), and sd_mmc_wait_end_of_write_blocks().
Referenced by sd_mmc_deselect_slot().
Referenced by sd_mmc_mci_card_init(), and sd_mmc_mci_install_mmc().
Referenced by mmc_cmd6_set_bus_width(), mmc_cmd6_set_high_speed(), mmc_mci_op_cond(), mmc_spi_op_cond(), sd_cm6_set_high_speed(), sd_cmd8(), sd_mci_op_cond(), sd_mmc_cmd13(), sd_mmc_init_read_blocks(), sd_mmc_init_write_blocks(), sd_mmc_mci_card_init(), sd_spi_op_cond(), sdio_cmd52(), and sdio_op_cond().
Referenced by sd_mmc_cmd9_mci().
Referenced by sd_mmc_mci_card_init(), and sd_mmc_mci_install_mmc().
Referenced by mmc_cmd8().
Referenced by sd_mmc_configure_slot().
Referenced by sd_cm6_set_high_speed(), sd_mmc_mci_card_init(), and sd_mmc_spi_card_init().
Referenced by mmc_cmd6_set_bus_width(), mmc_cmd6_set_high_speed(), mmc_mci_op_cond(), mmc_spi_op_cond(), sd_acmd51(), sd_acmd6(), sd_cmd8(), sd_mci_op_cond(), sd_mmc_cmd13(), sd_mmc_cmd9_mci(), sd_mmc_mci_card_init(), sd_mmc_mci_install_mmc(), sd_mmc_spi_card_init(), sd_mmc_spi_install_mmc(), sd_spi_op_cond(), sdio_cmd52(), and sdio_op_cond().
Referenced by sd_acmd51(), sd_cm6_set_high_speed(), sd_mmc_cmd9_spi(), sd_mmc_start_read_blocks(), and sdio_read_extended().
Referenced by sd_mmc_start_write_blocks(), and sdio_write_extended().
Referenced by sd_acmd51(), sd_cm6_set_high_speed(), sd_mmc_cmd9_spi(), sd_mmc_wait_end_of_read_blocks(), and sdio_read_extended().
Referenced by sd_mmc_wait_end_of_write_blocks(), and sdio_write_extended().
#define IS_SDIO | ( | ) | (sd_mmc_card->type & CARD_TYPE_SDIO) |
Referenced by sd_mmc_mci_card_init(), and sd_mmc_spi_card_init().
#define SD_MMC_DEBOUNCE_TIMEOUT 1000 |
#define sd_mmc_debug | ( | ... | ) |
Referenced by mmc_cmd6_set_bus_width(), mmc_cmd6_set_high_speed(), mmc_mci_op_cond(), mmc_spi_op_cond(), sd_acmd6(), sd_cm6_set_high_speed(), sd_cmd8(), sd_mci_op_cond(), sd_mmc_check(), sd_mmc_cmd13(), sd_mmc_init_read_blocks(), sd_mmc_init_write_blocks(), sd_mmc_mci_card_init(), sd_mmc_spi_card_init(), sd_spi_op_cond(), sdio_cmd52_set_bus_width(), and sdio_op_cond().
#define sd_mmc_is_mci | ( | ) | (!sd_mmc_is_spi()) |
Referenced by sd_mmc_init_read_blocks(), sd_mmc_init_write_blocks(), and sd_mmc_wait_end_of_write_blocks().
#define sd_mmc_is_spi | ( | ) | false |
Referenced by sd_mmc_check(), and sd_mmc_cmd13().
Referenced by sd_mmc_select_slot().
#define SD_MMC_IS_TIMEOUT | ( | ) | cpu_is_timeout(&timer) |
#define SD_MMC_MCI_MEM_CNT 0 |
#define SD_MMC_MEM_CNT SD_MMC_HSMCI_MEM_CNT |
Referenced by sd_mmc_deselect_slot(), sd_mmc_nb_slot(), and sd_mmc_select_slot().
#define SD_MMC_SPI_MEM_CNT 0 |
|
inline |
Referenced by sd_mmc_select_slot().
#define SD_MMC_START_TIMEOUT | ( | ) | cpu_set_timeout(cpu_ms_2_cy(SD_MMC_DEBOUNCE_TIMEOUT, sysclk_get_cpu_hz()), &timer) |
|
inline |
Referenced by sd_mmc_select_slot().
#define SD_MMC_STOP_TIMEOUT | ( | ) |
#define SD_MMC_VOLTAGE_SUPPORT |
This SD MMC stack supports only the high voltage.
Referenced by mmc_mci_op_cond(), sd_mci_op_cond(), and sdio_op_cond().
enum card_state |
|
static |
CMD6 for MMC - Switches the bus width mode.
bus_width | Bus width to set |
References sd_mmc_card::bus_width, CARD_STATUS_SWITCH_ERROR, driver_get_response, driver_send_cmd, MMC_CMD6_ACCESS_SET_BITS, MMC_CMD6_INDEX_BUS_WIDTH, MMC_CMD6_SWITCH, MMC_CMD6_VALUE_BUS_WIDTH_1BIT, MMC_CMD6_VALUE_BUS_WIDTH_4BIT, MMC_CMD6_VALUE_BUS_WIDTH_8BIT, and sd_mmc_debug.
Referenced by sd_mmc_mci_install_mmc().
|
static |
CMD6 for MMC - Switches in high speed mode.
References CARD_STATUS_SWITCH_ERROR, sd_mmc_card::clock, driver_get_response, driver_send_cmd, sd_mmc_card::high_speed, MMC_CMD6_ACCESS_WRITE_BYTE, MMC_CMD6_INDEX_HS_TIMING, MMC_CMD6_SWITCH, MMC_CMD6_VALUE_HS_TIMING_ENABLE, and sd_mmc_debug.
Referenced by sd_mmc_mci_install_mmc().
|
static |
CMD8 - The card sends its EXT_CSD register as a block of data.
b_authorize_high_speed | Pointer to update with the high speed support information |
References sd_mmc_card::capacity, sd_mmc_card::csd, driver_adtc_start, driver_read_word, EXT_CSD_BSIZE, EXT_CSD_CARD_TYPE_INDEX, EXT_CSD_SEC_COUNT_INDEX, MMC_CMD8_SEND_EXT_CSD, MMC_CSD_C_SIZE, and MMC_CTYPE_52MHZ.
Referenced by sd_mmc_mci_install_mmc(), and sd_mmc_spi_install_mmc().
|
static |
Decodes MMC CSD register.
References sd_mmc_card::capacity, CARD_VER_MMC_1_2, CARD_VER_MMC_1_4, CARD_VER_MMC_2_2, CARD_VER_MMC_3, CARD_VER_MMC_4, sd_mmc_card::clock, sd_mmc_card::csd, CSD_TRAN_SPEED, MMC_CSD_C_SIZE, MMC_CSD_C_SIZE_MULT, MMC_CSD_READ_BL_LEN, MMC_CSD_SPEC_VERS, mmc_trans_multipliers, sd_mmc_trans_units, and sd_mmc_card::version.
Referenced by sd_mmc_mci_install_mmc(), and sd_mmc_spi_install_mmc().
|
static |
Sends operation condition command and read OCR (MCI only)
References CARD_TYPE_HC, driver_get_response, driver_send_cmd, MMC_MCI_CMD1_SEND_OP_COND, OCR_ACCESS_MODE_MASK, OCR_ACCESS_MODE_SECTOR, OCR_POWER_UP_BUSY, sd_mmc_debug, SD_MMC_VOLTAGE_SUPPORT, and sd_mmc_card::type.
Referenced by sd_mmc_mci_install_mmc().
|
static |
Sends operation condition command and read OCR (SPI only)
References CARD_TYPE_HC, driver_get_response, driver_send_cmd, MMC_SPI_CMD1_SEND_OP_COND, OCR_ACCESS_MODE_MASK, OCR_ACCESS_MODE_SECTOR, R1_SPI_IDLE, sd_mmc_debug, SDMMC_SPI_CMD58_READ_OCR, and sd_mmc_card::type.
Referenced by sd_mmc_spi_install_mmc().
|
static |
ACMD51 - Read the SD Configuration Register.
References CARD_VER_SD_1_0, CARD_VER_SD_1_10, CARD_VER_SD_2_0, CARD_VER_SD_3_0, driver_adtc_start, driver_send_cmd, driver_start_read_blocks, driver_wait_end_of_read_blocks, sd_mmc_card::rca, SD_ACMD51_SEND_SCR, SD_SCR_REG_BSIZE, SD_SCR_SD_SPEC, SD_SCR_SD_SPEC3, SD_SCR_SD_SPEC_1_0_01, SD_SCR_SD_SPEC_1_10, SD_SCR_SD_SPEC_2_00, SD_SCR_SD_SPEC_3_00, SDMMC_CMD55_APP_CMD, and sd_mmc_card::version.
Referenced by sd_mmc_mci_card_init(), and sd_mmc_spi_card_init().
|
static |
ACMD6 - Define the data bus width to 4 bits bus.
References sd_mmc_card::bus_width, driver_send_cmd, sd_mmc_card::rca, SD_ACMD6_SET_BUS_WIDTH, sd_mmc_debug, and SDMMC_CMD55_APP_CMD.
Referenced by sd_mmc_mci_card_init().
|
static |
CMD6 for SD - Switch card in high speed mode.
References CARD_STATUS_SWITCH_ERROR, sd_mmc_card::clock, driver_adtc_start, driver_get_response, driver_send_clock, driver_start_read_blocks, driver_wait_end_of_read_blocks, sd_mmc_card::high_speed, SD_CMD6_GRP1_HIGH_SPEED, SD_CMD6_GRP2_DEFAULT, SD_CMD6_GRP3_NO_INFLUENCE, SD_CMD6_GRP4_NO_INFLUENCE, SD_CMD6_GRP5_NO_INFLUENCE, SD_CMD6_GRP6_NO_INFLUENCE, SD_CMD6_MODE_SWITCH, SD_CMD6_SWITCH_FUNC, sd_mmc_debug, SD_SW_STATUS_BSIZE, SD_SW_STATUS_FUN_GRP1_BUSY, SD_SW_STATUS_FUN_GRP1_RC, and SD_SW_STATUS_FUN_GRP_RC_ERROR.
Referenced by sd_mmc_mci_card_init().
|
static |
CMD8 for SD card - Send Interface Condition Command.
v2 | Pointer to v2 flag to update |
References driver_get_response, driver_send_cmd, SD_CMD8_HIGH_VOLTAGE, SD_CMD8_MASK_PATTERN, SD_CMD8_MASK_VOLTAGE, SD_CMD8_PATTERN, SD_CMD8_SEND_IF_COND, and sd_mmc_debug.
Referenced by sd_mmc_mci_card_init(), and sd_mmc_spi_card_init().
|
static |
Decodes SD CSD register.
References sd_mmc_card::capacity, sd_mmc_card::clock, sd_mmc_card::csd, CSD_STRUCTURE_VERSION, CSD_TRAN_SPEED, SD_CSD_1_0_C_SIZE, SD_CSD_1_0_C_SIZE_MULT, SD_CSD_1_0_READ_BL_LEN, SD_CSD_2_0_C_SIZE, SD_CSD_VER_2_0, sd_mmc_trans_units, and sd_trans_multipliers.
Referenced by sd_mmc_mci_card_init(), and sd_mmc_spi_card_init().
|
static |
Ask to all cards to send their operations conditions (MCI only).
v2 | Shall be 1 if it is a SD card V2 |
References CARD_TYPE_HC, driver_get_response, driver_send_cmd, OCR_CCS, OCR_POWER_UP_BUSY, SD_ACMD41_HCS, SD_MCI_ACMD41_SD_SEND_OP_COND, sd_mmc_debug, SD_MMC_VOLTAGE_SUPPORT, SDMMC_CMD55_APP_CMD, and sd_mmc_card::type.
Referenced by sd_mmc_mci_card_init().
sd_mmc_err_t sd_mmc_check | ( | uint8_t | slot | ) |
Performs a card checks.
slot | Card slot to use |
SD_MMC_OK | Card ready |
SD_MMC_INIT_ONGOING | Initialization on going |
SD_MMC_ERR_NO_CARD | Card not present in slot |
Other | value for error cases, see sd_mmc_err_t |
References SD_MMC_CARD_STATE_READY, SD_MMC_CARD_STATE_UNUSABLE, sd_mmc_debug, sd_mmc_deselect_slot(), SD_MMC_ERR_UNUSABLE, SD_MMC_INIT_ONGOING, sd_mmc_is_spi, sd_mmc_mci_card_init(), sd_mmc_select_slot(), sd_mmc_spi_card_init(), and sd_mmc_card::state.
Referenced by main(), and sd_mmc_test_unit_ready().
|
static |
CMD13 - Addressed card sends its status register.
This function waits the clear of the busy flag
References CARD_STATUS_READY_FOR_DATA, driver_get_response, driver_send_cmd, sd_mmc_card::rca, sd_mmc_debug, sd_mmc_is_spi, SDMMC_MCI_CMD13_SEND_STATUS, and SDMMC_SPI_CMD13_SEND_STATUS.
Referenced by sd_mmc_init_read_blocks(), sd_mmc_spi_card_init(), and sd_mmc_spi_install_mmc().
|
static |
CMD9: Addressed card sends its card-specific data (CSD) on the CMD line mci.
References sd_mmc_card::csd, driver_get_response_128, driver_send_cmd, sd_mmc_card::rca, and SDMMC_MCI_CMD9_SEND_CSD.
Referenced by sd_mmc_mci_card_init(), and sd_mmc_mci_install_mmc().
|
static |
CMD9: Addressed card sends its card-specific data (CSD) on the CMD line spi.
References sd_mmc_card::csd, CSD_REG_BSIZE, driver_adtc_start, driver_start_read_blocks, driver_wait_end_of_read_blocks, sd_mmc_card::rca, and SDMMC_SPI_CMD9_SEND_CSD.
Referenced by sd_mmc_spi_card_init(), and sd_mmc_spi_install_mmc().
|
static |
Configures the driver with the selected card configuration.
References sd_mmc_card::bus_width, sd_mmc_card::clock, driver_select_device, sd_mmc_card::high_speed, and sd_mmc_slot_sel.
Referenced by sd_mmc_mci_card_init(), sd_mmc_mci_install_mmc(), sd_mmc_select_slot(), sd_mmc_spi_card_init(), and sd_mmc_spi_install_mmc().
|
static |
Deselect the current card slot.
References driver_deselect_device, SD_MMC_MEM_CNT, and sd_mmc_slot_sel.
Referenced by sd_mmc_check(), sd_mmc_get_capacity(), sd_mmc_get_type(), sd_mmc_get_version(), sd_mmc_init_read_blocks(), sd_mmc_init_write_blocks(), sd_mmc_wait_end_of_read_blocks(), sd_mmc_wait_end_of_write_blocks(), sdio_read_direct(), sdio_read_extended(), sdio_write_direct(), and sdio_write_extended().
uint32_t sd_mmc_get_capacity | ( | uint8_t | slot | ) |
Get the memory capacity.
slot | Card slot |
References sd_mmc_card::capacity, sd_mmc_deselect_slot(), SD_MMC_OK, and sd_mmc_select_slot().
Referenced by sd_mmc_read_capacity().
card_type_t sd_mmc_get_type | ( | uint8_t | slot | ) |
Get the card type.
slot | Card slot |
References CARD_TYPE_UNKNOWN, sd_mmc_deselect_slot(), SD_MMC_OK, sd_mmc_select_slot(), and sd_mmc_card::type.
Referenced by sd_mmc_test_unit_ready().
card_version_t sd_mmc_get_version | ( | uint8_t | slot | ) |
Get the card version.
slot | Card slot |
References CARD_VER_UNKNOWN, sd_mmc_deselect_slot(), SD_MMC_OK, sd_mmc_select_slot(), and sd_mmc_card::version.
sd_mmc_err_t sd_mmc_init_read_blocks | ( | uint8_t | slot, |
uint32_t | start, | ||
uint16_t | nb_block | ||
) |
Initialize the read blocks of data from the card.
slot | Card slot to use |
start | Start block number to to read. |
nb_block | Total number of blocks to be read. |
References CARD_STATUS_ERR_RD_WR, CARD_TYPE_HC, driver_adtc_start, driver_get_response, SD_MMC_BLOCK_SIZE, sd_mmc_cmd13(), sd_mmc_debug, sd_mmc_deselect_slot(), SD_MMC_ERR_COMM, sd_mmc_is_mci, sd_mmc_nb_block_remaining, sd_mmc_nb_block_to_tranfer, SD_MMC_OK, sd_mmc_select_slot(), SDMMC_CMD17_READ_SINGLE_BLOCK, SDMMC_CMD18_READ_MULTIPLE_BLOCK, SDMMC_CMD_GET_INDEX, and sd_mmc_card::type.
Referenced by sd_mmc_mem_2_ram().
sd_mmc_err_t sd_mmc_init_write_blocks | ( | uint8_t | slot, |
uint32_t | start, | ||
uint16_t | nb_block | ||
) |
Initialize the write blocks of data.
slot | Card slot to use |
start | Start block number to be written. |
nb_block | Total number of blocks to be written. |
References CARD_STATUS_ERR_RD_WR, CARD_TYPE_HC, driver_adtc_start, driver_get_response, SD_MMC_BLOCK_SIZE, sd_mmc_debug, sd_mmc_deselect_slot(), SD_MMC_ERR_COMM, SD_MMC_ERR_WP, sd_mmc_is_mci, sd_mmc_is_write_protected(), sd_mmc_nb_block_remaining, sd_mmc_nb_block_to_tranfer, SD_MMC_OK, sd_mmc_select_slot(), SDMMC_CMD24_WRITE_BLOCK, SDMMC_CMD25_WRITE_MULTIPLE_BLOCK, SDMMC_CMD_GET_INDEX, and sd_mmc_card::type.
Referenced by sd_mmc_ram_2_mem().
bool sd_mmc_is_write_protected | ( | uint8_t | slot | ) |
Get the card write protection status.
slot | Card slot |
References ioport_get_pin_level(), sd_mmc_cards, and UNUSED.
Referenced by sd_mmc_init_write_blocks(), and sd_mmc_wr_protect().
|
static |
Initialize the SD card in MCI mode.
References CARD_TYPE_MMC, CARD_TYPE_SD, CARD_VER_SD_1_0, CARD_VER_UNKNOWN, driver_get_bus_width, driver_get_response, driver_is_high_speed_capable, driver_send_clock, driver_send_cmd, IS_SDIO, sd_mmc_card::rca, sd_acmd51(), sd_acmd6(), sd_cm6_set_high_speed(), SD_CMD3_SEND_RELATIVE_ADDR, sd_cmd8(), sd_decode_csd(), sd_mci_op_cond(), SD_MMC_BLOCK_SIZE, sd_mmc_cmd9_mci(), sd_mmc_configure_slot(), sd_mmc_debug, sd_mmc_mci_install_mmc(), sd_mmc_slot_sel, SDIO_CCCR_IOA, SDIO_CIA, sdio_cmd52(), sdio_cmd52_set_bus_width(), sdio_cmd52_set_high_speed(), SDIO_CMD52_WRITE_FLAG, sdio_get_max_speed(), sdio_op_cond(), SDMMC_CMD16_SET_BLOCKLEN, SDMMC_CMD2_ALL_SEND_CID, SDMMC_CMD7_SELECT_CARD_CMD, SDMMC_MCI_CMD0_GO_IDLE_STATE, sd_mmc_card::type, and sd_mmc_card::version.
Referenced by sd_mmc_check().
|
static |
Initialize the MMC card in MCI mode.
References CARD_VER_MMC_4, driver_get_bus_width, driver_is_high_speed_capable, driver_send_cmd, MMC_CMD3_SET_RELATIVE_ADDR, mmc_cmd6_set_bus_width(), mmc_cmd6_set_high_speed(), mmc_cmd8(), mmc_decode_csd(), mmc_mci_op_cond(), sd_mmc_card::rca, SD_MMC_BLOCK_SIZE, sd_mmc_cmd9_mci(), sd_mmc_configure_slot(), sd_mmc_slot_sel, SDMMC_CMD16_SET_BLOCKLEN, SDMMC_CMD2_ALL_SEND_CID, SDMMC_CMD7_SELECT_CARD_CMD, SDMMC_MCI_CMD0_GO_IDLE_STATE, and sd_mmc_card::version.
Referenced by sd_mmc_mci_card_init().
uint8_t sd_mmc_nb_slot | ( | void | ) |
Return the number of slot available.
References SD_MMC_MEM_CNT.
|
static |
Select a card slot and initialize the associated driver.
slot | Card slot number |
SD_MMC_ERR_SLOT | Wrong slot number |
SD_MMC_ERR_NO_CARD | No card present on slot |
SD_MMC_ERR_UNUSABLE | Unusable card |
SD_MMC_INIT_ONGOING | Card initialization requested |
SD_MMC_OK | Card present |
Card Detect pins
References Assert, sd_mmc_card::bus_width, sd_mmc_card::cd_gpio, sd_mmc_card::clock, sd_mmc_card::high_speed, ioport_get_pin_level(), SD_MMC_0_CD_DETECT_VALUE, SD_MMC_CARD_STATE_DEBOUNCE, SD_MMC_CARD_STATE_INIT, SD_MMC_CARD_STATE_NO_CARD, SD_MMC_CARD_STATE_UNUSABLE, sd_mmc_cards, sd_mmc_configure_slot(), SD_MMC_ERR_NO_CARD, SD_MMC_ERR_SLOT, SD_MMC_ERR_UNUSABLE, SD_MMC_INIT_ONGOING, SD_MMC_IS_TIMEOUT, SD_MMC_MEM_CNT, sd_mmc_nb_block_remaining, SD_MMC_OK, sd_mmc_slot_sel, SD_MMC_START_TIMEOUT, SD_MMC_STOP_TIMEOUT, SDMMC_CLOCK_INIT, and sd_mmc_card::state.
Referenced by sd_mmc_check(), sd_mmc_get_capacity(), sd_mmc_get_type(), sd_mmc_get_version(), sd_mmc_init_read_blocks(), sd_mmc_init_write_blocks(), sdio_read_direct(), sdio_read_extended(), sdio_write_direct(), and sdio_write_extended().
|
static |
Initialize the SD card in SPI mode.
References CARD_TYPE_HC, CARD_TYPE_MMC, CARD_TYPE_SD, CARD_VER_UNKNOWN, driver_send_clock, driver_send_cmd, IS_SDIO, sd_mmc_card::rca, sd_acmd51(), sd_cmd8(), sd_decode_csd(), SD_MMC_BLOCK_SIZE, sd_mmc_cmd13(), sd_mmc_cmd9_spi(), sd_mmc_configure_slot(), sd_mmc_debug, sd_mmc_spi_install_mmc(), sd_spi_op_cond(), sdio_get_max_speed(), sdio_op_cond(), SDMMC_CMD16_SET_BLOCKLEN, SDMMC_SPI_CMD0_GO_IDLE_STATE, SDMMC_SPI_CMD59_CRC_ON_OFF, sd_mmc_card::type, and sd_mmc_card::version.
Referenced by sd_mmc_check().
|
static |
Initialize the MMC card in SPI mode.
References CARD_VER_MMC_4, driver_send_cmd, mmc_cmd8(), mmc_decode_csd(), mmc_spi_op_cond(), SD_MMC_BLOCK_SIZE, sd_mmc_cmd13(), sd_mmc_cmd9_spi(), sd_mmc_configure_slot(), SDMMC_CMD16_SET_BLOCKLEN, SDMMC_SPI_CMD0_GO_IDLE_STATE, SDMMC_SPI_CMD59_CRC_ON_OFF, and sd_mmc_card::version.
Referenced by sd_mmc_spi_card_init().
sd_mmc_err_t sd_mmc_start_read_blocks | ( | void * | dest, |
uint16_t | nb_block | ||
) |
Start the read blocks of data from the card.
dest | Pointer to read buffer. |
nb_block | Number of blocks to be read. |
References Assert, driver_start_read_blocks, SD_MMC_ERR_COMM, sd_mmc_nb_block_remaining, and SD_MMC_OK.
Referenced by sd_mmc_mem_2_ram().
sd_mmc_err_t sd_mmc_start_write_blocks | ( | const void * | src, |
uint16_t | nb_block | ||
) |
Start the write blocks of data.
src | Pointer to write buffer. |
nb_block | Number of blocks to be written. |
References Assert, driver_start_write_blocks, SD_MMC_ERR_COMM, sd_mmc_nb_block_remaining, and SD_MMC_OK.
Referenced by sd_mmc_ram_2_mem().
sd_mmc_err_t sd_mmc_wait_end_of_read_blocks | ( | bool | abort | ) |
Wait the end of read blocks of data from the card.
abort | Abort reading process initialized by sd_mmc_init_read_blocks() after the reading issued by sd_mmc_start_read_blocks() is done |
References driver_adtc_stop, driver_wait_end_of_read_blocks, sd_mmc_deselect_slot(), SD_MMC_ERR_COMM, sd_mmc_nb_block_remaining, sd_mmc_nb_block_to_tranfer, SD_MMC_OK, and SDMMC_CMD12_STOP_TRANSMISSION.
Referenced by sd_mmc_mem_2_ram().
sd_mmc_err_t sd_mmc_wait_end_of_write_blocks | ( | bool | abort | ) |
Wait the end of write blocks of data.
abort | Abort writing process initialized by sd_mmc_init_write_blocks() after the writing issued by sd_mmc_start_write_blocks() is done |
References driver_adtc_stop, driver_wait_end_of_write_blocks, sd_mmc_deselect_slot(), SD_MMC_ERR_COMM, sd_mmc_is_mci, sd_mmc_nb_block_remaining, sd_mmc_nb_block_to_tranfer, SD_MMC_OK, and SDMMC_CMD12_STOP_TRANSMISSION.
Referenced by sd_mmc_ram_2_mem().
|
static |
Ask to all cards to send their operations conditions (SPI only).
v2 | Shall be 1 if it is a SD card V2 |
References CARD_TYPE_HC, driver_get_response, driver_send_cmd, OCR_CCS, R1_SPI_IDLE, SD_ACMD41_HCS, sd_mmc_debug, SD_SPI_ACMD41_SD_SEND_OP_COND, SDMMC_CMD55_APP_CMD, SDMMC_SPI_CMD58_READ_OCR, and sd_mmc_card::type.
Referenced by sd_mmc_spi_card_init().
|
static |
CMD52 - SDIO IO_RW_DIRECT command.
rw_flag | Direction, 1:write, 0:read. |
func_nb | Number of the function. |
rd_after_wr | Read after Write flag. |
reg_addr | register address. |
io_data | Pointer to input argument and response buffer. |
References Assert, driver_get_response, driver_send_cmd, SDIO_CMD52_FUNCTION_NUM, SDIO_CMD52_IO_RW_DIRECT, SDIO_CMD52_RAW_FLAG, SDIO_CMD52_REG_ADRR, SDIO_CMD52_RW_FLAG, and SDIO_CMD52_WR_DATA.
Referenced by sd_mmc_mci_card_init(), sdio_cmd52_set_bus_width(), sdio_cmd52_set_high_speed(), sdio_get_max_speed(), sdio_read_direct(), and sdio_write_direct().
|
static |
CMD52 for SDIO - Switches the bus width mode to 4.
A SD memory card always supports bus 4bit A SD COMBO card always supports bus 4bit A SDIO Full-Speed alone always supports 4bit A SDIO Low-Speed alone can supports 4bit (Optional)
References sd_mmc_card::bus_width, sd_mmc_debug, SDIO_BUSWIDTH_4B, SDIO_CAP_4BLS, SDIO_CCCR_BUS_CTRL, SDIO_CCCR_CAP, SDIO_CIA, sdio_cmd52(), SDIO_CMD52_READ_FLAG, and SDIO_CMD52_WRITE_FLAG.
Referenced by sd_mmc_mci_card_init().
|
static |
CMD52 for SDIO - Enable the high speed mode.
References sd_mmc_card::clock, sd_mmc_card::high_speed, SDIO_CCCR_HS, SDIO_CIA, sdio_cmd52(), SDIO_CMD52_READ_FLAG, SDIO_CMD52_WRITE_FLAG, SDIO_EHS, and SDIO_SHS.
Referenced by sd_mmc_mci_card_init().
|
static |
CMD53 - SDIO IO_RW_EXTENDED command This implementation support only the SDIO multi-byte transfer mode which is similar to the single block transfer on memory.
Note: The SDIO block transfer mode is optional for SDIO card.
rw_flag | Direction, 1:write, 0:read. |
func_nb | Number of the function. |
reg_addr | Register address. |
inc_addr | 1:Incrementing address, 0: fixed. |
size | Transfer data size. |
access_block | true, if the block access (DMA) is used |
References Assert, driver_adtc_start, SDIO_CMD53_BLOCK_MODE, SDIO_CMD53_COUNT, SDIO_CMD53_FUNCTION_NUM, SDIO_CMD53_IO_R_BYTE_EXTENDED, SDIO_CMD53_IO_W_BYTE_EXTENDED, SDIO_CMD53_OP_CODE, SDIO_CMD53_READ_FLAG, SDIO_CMD53_REG_ADDR, and SDIO_CMD53_RW_FLAG.
Referenced by sdio_read_extended(), and sdio_write_extended().
|
static |
Get SDIO max transfer speed in Hz.
Note: A combo card shall be a Full-Speed SDIO card which supports upto 25MHz. A SDIO card alone can be:
References sd_mmc_card::clock, sd_mmc_trans_units, sd_trans_multipliers, SDIO_CCCR_CIS_PTR, SDIO_CIA, SDIO_CISTPL_END, SDIO_CISTPL_FUNCE, sdio_cmd52(), and SDIO_CMD52_READ_FLAG.
Referenced by sd_mmc_mci_card_init(), and sd_mmc_spi_card_init().
|
static |
Try to get the SDIO card's operating condition.
References CARD_TYPE_SD_COMBO, CARD_TYPE_SDIO, driver_get_response, driver_send_cmd, OCR_POWER_UP_BUSY, OCR_SDIO_MP, OCR_SDIO_NF, sd_mmc_debug, SD_MMC_VOLTAGE_SUPPORT, SDIO_CMD5_SEND_OP_COND, and sd_mmc_card::type.
Referenced by sd_mmc_mci_card_init(), and sd_mmc_spi_card_init().
sd_mmc_err_t sdio_read_direct | ( | uint8_t | slot, |
uint8_t | func_num, | ||
uint32_t | addr, | ||
uint8_t * | dest | ||
) |
Read one byte from SDIO using RW_DIRECT command.
slot | Card slot to use |
func_num | Function number. |
addr | Register address to read from. |
dest | Pointer to read buffer. |
References sd_mmc_deselect_slot(), SD_MMC_ERR_COMM, SD_MMC_ERR_PARAM, SD_MMC_OK, sd_mmc_select_slot(), sdio_cmd52(), and SDIO_CMD52_READ_FLAG.
sd_mmc_err_t sdio_read_extended | ( | uint8_t | slot, |
uint8_t | func_num, | ||
uint32_t | addr, | ||
uint8_t | inc_addr, | ||
uint8_t * | dest, | ||
uint16_t | size | ||
) |
Read bytes from SDIO using RW_EXTENDED command.
slot | Card slot to use |
func_num | Function number. |
addr | First register address to read from. |
inc_addr | 0 - The data address is fixed. 1 - The data address increase automatically. |
dest | Pointer to read buffer. |
size | Number of bytes to read (1 ~ 512). |
References driver_start_read_blocks, driver_wait_end_of_read_blocks, sd_mmc_deselect_slot(), SD_MMC_ERR_COMM, SD_MMC_ERR_PARAM, SD_MMC_OK, sd_mmc_select_slot(), sdio_cmd53(), and SDIO_CMD53_READ_FLAG.
sd_mmc_err_t sdio_write_direct | ( | uint8_t | slot, |
uint8_t | func_num, | ||
uint32_t | addr, | ||
uint8_t | data | ||
) |
Write one byte to SDIO using RW_DIRECT command.
slot | Card slot to use |
func_num | Function number. |
addr | Register address to read from. |
data | Data to be written. |
References sd_mmc_deselect_slot(), SD_MMC_ERR_COMM, SD_MMC_OK, sd_mmc_select_slot(), sdio_cmd52(), and SDIO_CMD52_WRITE_FLAG.
sd_mmc_err_t sdio_write_extended | ( | uint8_t | slot, |
uint8_t | func_num, | ||
uint32_t | addr, | ||
uint8_t | inc_addr, | ||
uint8_t * | src, | ||
uint16_t | size | ||
) |
Write bytes to SDIO using RW_EXTENDED command.
slot | Card slot to use |
func_num | Function number. |
addr | First register address to write to. |
inc_addr | 0 - The data address is fixed. 1 - The data address increase automatically. |
src | Pointer to write buffer. |
size | Number of bytes to read (1 ~ 512). |
References driver_start_write_blocks, driver_wait_end_of_write_blocks, sd_mmc_deselect_slot(), SD_MMC_ERR_COMM, SD_MMC_ERR_PARAM, SD_MMC_OK, sd_mmc_select_slot(), sdio_cmd53(), and SDIO_CMD53_WRITE_FLAG.
const uint32_t mmc_trans_multipliers[16] |
MMC transfer multiplier factor codes (1/10) list.
Referenced by mmc_decode_csd().
|
static |
Pointer on current slot configurated.
|
static |
SD/MMC card list Note: Initialize card detect pin fields if present.
Referenced by sd_mmc_is_write_protected(), and sd_mmc_select_slot().
|
static |
Number of block remaining to read or write on the current transfer.
Referenced by sd_mmc_init_read_blocks(), sd_mmc_init_write_blocks(), sd_mmc_select_slot(), sd_mmc_start_read_blocks(), sd_mmc_start_write_blocks(), sd_mmc_wait_end_of_read_blocks(), and sd_mmc_wait_end_of_write_blocks().
|
static |
Number of block to read or write on the current transfer.
Referenced by sd_mmc_init_read_blocks(), sd_mmc_init_write_blocks(), sd_mmc_wait_end_of_read_blocks(), and sd_mmc_wait_end_of_write_blocks().
|
static |
|
static |
Index of current slot configurated.
Referenced by sd_mmc_configure_slot(), sd_mmc_deselect_slot(), sd_mmc_mci_card_init(), sd_mmc_mci_install_mmc(), and sd_mmc_select_slot().
const uint32_t sd_mmc_trans_units[7] |
SD/MMC transfer rate unit codes (10K) list.
Referenced by mmc_decode_csd(), sd_decode_csd(), and sdio_get_max_speed().
const uint32_t sd_trans_multipliers[16] |
SD transfer multiplier factor codes (1/10) list.
Referenced by sd_decode_csd(), and sdio_get_max_speed().
|
static |