This driver interfaces the MCI (MultiMedia Card Interface) module.
It will add functions for SD/MMC card reading, writing and management.
Modules | |
SD MMC Commands | |
Functions | |
static __always_inline int | mci_cmd_ready (volatile avr32_mci_t *mci) |
Tests if the MCI is able to take a new command. More... | |
static __always_inline int | mci_crc_error (volatile avr32_mci_t *mci) |
Tests if the MCI Status detects a CRC error. More... | |
static __always_inline int | mci_data_block_ended (volatile avr32_mci_t *mci) |
Tests if the MCI has ended the block Transmission/ Reception. More... | |
void | mci_disable (volatile avr32_mci_t *mci) |
Disables the MCI controller. More... | |
void | mci_enable (volatile avr32_mci_t *mci) |
Enables the MCI controller. More... | |
static __always_inline int | mci_get_sr (volatile avr32_mci_t *mci) |
Return the status register and cache in a shadow variable bits that are cleared when reading the status register. More... | |
int | mci_init (volatile avr32_mci_t *mci, uint8_t card_slot, uint32_t pbb_hz) |
Initialize the MCI controller. More... | |
static __always_inline int | mci_overrun_error (volatile avr32_mci_t *mci) |
Tests if an overrun occur. More... | |
static __always_inline uint32_t | mci_rd_data (volatile avr32_mci_t *mci) |
Mci Read data. More... | |
unsigned int | mci_read_response (volatile avr32_mci_t *mci) |
Read command argument response. More... | |
void | mci_reset (volatile avr32_mci_t *mci) |
Resets the MCI controller. More... | |
static __always_inline int | mci_rx_ready (volatile avr32_mci_t *mci) |
Tests if the MCI is ready to receive data. More... | |
int | mci_select_card (volatile avr32_mci_t *mci, uint8_t card_slot, uint8_t bus_width) |
Mci Select slot Card. More... | |
int | mci_send_cmd (volatile avr32_mci_t *mci, unsigned int cmd, unsigned int arg) |
Generic function to send a command to the MMC or SDCard. More... | |
void | mci_set_block_count (volatile avr32_mci_t *mci, uint16_t cnt) |
Set Block Count. More... | |
void | mci_set_block_size (volatile avr32_mci_t *mci, uint16_t length) |
Set Block Size. More... | |
int | mci_set_bus_size (volatile avr32_mci_t *mci, uint8_t busWidth) |
Set SDIO Bus Width. More... | |
void | mci_set_speed (volatile avr32_mci_t *mci, uint32_t pbb_hz, uint32_t card_speed) |
Set Speed Card. More... | |
void | mci_stop (volatile avr32_mci_t *mci) |
Stop the MCI controller. More... | |
static __always_inline int | mci_tx_ready (volatile avr32_mci_t *mci) |
Tests if the MCI is ready to transmit data. More... | |
static __always_inline int | mci_underrun_error (volatile avr32_mci_t *mci) |
Tests if an underrun occur. More... | |
void | mci_wait_busy_signal (volatile avr32_mci_t *mci) |
Mci Busy Status. More... | |
static __always_inline void | mci_wr_data (volatile avr32_mci_t *mci, uint32_t data) |
Mci Write data. More... | |
Variables | |
int | shadow_sr |
Return Values | |
#define | MCI_SUCCESS 0 |
Successful completion. More... | |
#define | MCI_FAILURE -1 |
Failure because of some unspecified reason. More... | |
#define | MCI_INVALID_INPUT 1 |
Input value out of range. More... | |
Controller bus width | |
#define | MCI_BUS_SIZE_1_BIT 0x00 |
Bus Width Selected 1 bit. More... | |
#define | MCI_BUS_SIZE_4_BIT 0x02 |
Bus Width Selected 4 bits. More... | |
#define | MCI_BUS_SIZE_8_BIT 0x03 |
Bus Width Selected 8 bits. More... | |
Controller slot available | |
#define | MCI_SLOT_A 0x00 |
Slot A Selected. More... | |
#define | MCI_SLOT_B 0x01 |
Slot B Selected. More... | |
#define | MCI_LAST_SLOTS MCI_SLOT_B |
Last Slot Available by the MCI. More... | |
#define | MCI_DEFAULT_SLOT MCI_SLOT_A |
Default Slot Selected. More... | |
#define | MCI_NR_SLOTS 2 |
Number of MCI slots. More... | |
Driver Default Value Configuration (should not be modified) | |
#define | MCI_DEFAULT_DTOLMUL 0x07 |
Data Timeout Multiplier. More... | |
#define | MCI_DEFAULT_DTOLCYC 0x02 |
Data Timeout Cycle Number. More... | |
#define | MCI_DEFAULT_DTOREG |
CMDR Register bits definition | |
#define | MCI_SPCMD_NONE (AVR32_MCI_CMDR_SPCMD_NO_SPEC_CMD<<AVR32_MCI_CMDR_SPCMD_OFFSET) |
#define | MCI_SPCMD_INIT (AVR32_MCI_CMDR_SPCMD_INIT_CMD <<AVR32_MCI_CMDR_SPCMD_OFFSET) |
#define | MCI_SPCMD_SYNC (AVR32_MCI_CMDR_SPCMD_SYNC_CMD <<AVR32_MCI_CMDR_SPCMD_OFFSET) |
#define | MCI_SPCMD_IT_CMD (AVR32_MCI_CMDR_SPCMD_INT_CMD <<AVR32_MCI_CMDR_SPCMD_OFFSET) |
#define | MCI_SPCMD_IT_REP (AVR32_MCI_CMDR_SPCMD_INT_RESP <<AVR32_MCI_CMDR_SPCMD_OFFSET) |
#define | MCI_TRCMD_NO (AVR32_MCI_TRCMD_NO_TRANS <<AVR32_MCI_TRCMD_OFFSET) |
#define | MCI_TRCMD_START (AVR32_MCI_TRCMD_START_TRANS<<AVR32_MCI_TRCMD_OFFSET) |
#define | MCI_TRCMD_STOP (AVR32_MCI_TRCMD_STOP_TRANS <<AVR32_MCI_TRCMD_OFFSET) |
#define | MCI_RSPTYP_NO (AVR32_MCI_RSPTYP_NO_RESP <<AVR32_MCI_RSPTYP_OFFSET) |
#define | MCI_RSPTYP_48 (AVR32_MCI_RSPTYP_48_BIT_RESP <<AVR32_MCI_RSPTYP_OFFSET) |
#define | MCI_RSPTYP_48B (AVR32_MCI_RSPTYP_48_BIT_RESP_WITH_BUSY<<AVR32_MCI_RSPTYP_OFFSET) |
#define | MCI_RSPTYP_136 (AVR32_MCI_RSPTYP_136_BIT_RESP <<AVR32_MCI_RSPTYP_OFFSET) |
#define | MCI_TRTYP_BLOCK (AVR32_MCI_TRTYP_BLOCK <<AVR32_MCI_TRTYP_OFFSET) |
#define | MCI_TRTYP_MULTIPLE (AVR32_MCI_TRTYP_MULTI_BLOCK<<AVR32_MCI_TRTYP_OFFSET) |
#define | MCI_TRTYP_STREAM (AVR32_MCI_TRTYP_STREAM <<AVR32_MCI_TRTYP_OFFSET) |
#define | MCI_TRTYP_SDIO_BYTE (AVR32_MCI_TRTYP_SDIO_BYTE <<AVR32_MCI_TRTYP_OFFSET) |
#define | MCI_TRTYP_SDIO_BLOCK (AVR32_MCI_TRTYP_SDIO_BLOCK <<AVR32_MCI_TRTYP_OFFSET) |
#define | MCI_OPDCMD (AVR32_MCI_OPDCMD_MASK) |
#define | MCI_MAXLAT (AVR32_MCI_MAXLAT_MASK) |
#define | MCI_TRDIR (AVR32_MCI_TRDIR_MASK) |
#define MCI_BUS_SIZE_1_BIT 0x00 |
Bus Width Selected 1 bit.
Referenced by mci_init(), and sd_mmc_mci_card_init().
#define MCI_BUS_SIZE_4_BIT 0x02 |
Bus Width Selected 4 bits.
Referenced by sd_mmc_mci_card_init().
#define MCI_BUS_SIZE_8_BIT 0x03 |
Bus Width Selected 8 bits.
Referenced by mci_set_bus_size(), and sd_mmc_mci_card_init().
#define MCI_DEFAULT_DTOLCYC 0x02 |
Data Timeout Cycle Number.
#define MCI_DEFAULT_DTOLMUL 0x07 |
Data Timeout Multiplier.
#define MCI_DEFAULT_DTOREG |
Referenced by mci_init().
#define MCI_DEFAULT_SLOT MCI_SLOT_A |
Default Slot Selected.
#define MCI_FAILURE -1 |
Failure because of some unspecified reason.
#define MCI_INVALID_INPUT 1 |
Input value out of range.
Referenced by mci_init(), mci_select_card(), and mci_set_bus_size().
#define MCI_LAST_SLOTS MCI_SLOT_B |
Last Slot Available by the MCI.
Referenced by is_sd_mmc_mci_card_present(), is_sd_mmc_mci_card_protected(), mci_init(), mci_select_card(), sd_mmc_get_ext_csd(), sd_mmc_mci_cmd_send_status(), sd_mmc_mci_dma_read_open(), sd_mmc_mci_dma_write_open(), sd_mmc_mci_get_csd(), sd_mmc_mci_mem_check(), sd_mmc_mci_read_open(), sd_mmc_mci_test_unit_ready(), sd_mmc_mci_write_open(), and sd_mmc_set_block_len().
#define MCI_MAXLAT (AVR32_MCI_MAXLAT_MASK) |
#define MCI_NR_SLOTS 2 |
Number of MCI slots.
#define MCI_OPDCMD (AVR32_MCI_OPDCMD_MASK) |
#define MCI_RSPTYP_136 (AVR32_MCI_RSPTYP_136_BIT_RESP <<AVR32_MCI_RSPTYP_OFFSET) |
#define MCI_RSPTYP_48 (AVR32_MCI_RSPTYP_48_BIT_RESP <<AVR32_MCI_RSPTYP_OFFSET) |
#define MCI_RSPTYP_48B (AVR32_MCI_RSPTYP_48_BIT_RESP_WITH_BUSY<<AVR32_MCI_RSPTYP_OFFSET) |
#define MCI_RSPTYP_NO (AVR32_MCI_RSPTYP_NO_RESP <<AVR32_MCI_RSPTYP_OFFSET) |
#define MCI_SLOT_A 0x00 |
Slot A Selected.
Referenced by is_sd_mmc_mci_card_present(), and is_sd_mmc_mci_card_protected().
#define MCI_SLOT_B 0x01 |
Slot B Selected.
Referenced by is_sd_mmc_mci_card_present(), and is_sd_mmc_mci_card_protected().
#define MCI_SPCMD_INIT (AVR32_MCI_CMDR_SPCMD_INIT_CMD <<AVR32_MCI_CMDR_SPCMD_OFFSET) |
#define MCI_SPCMD_IT_CMD (AVR32_MCI_CMDR_SPCMD_INT_CMD <<AVR32_MCI_CMDR_SPCMD_OFFSET) |
#define MCI_SPCMD_IT_REP (AVR32_MCI_CMDR_SPCMD_INT_RESP <<AVR32_MCI_CMDR_SPCMD_OFFSET) |
#define MCI_SPCMD_NONE (AVR32_MCI_CMDR_SPCMD_NO_SPEC_CMD<<AVR32_MCI_CMDR_SPCMD_OFFSET) |
#define MCI_SPCMD_SYNC (AVR32_MCI_CMDR_SPCMD_SYNC_CMD <<AVR32_MCI_CMDR_SPCMD_OFFSET) |
#define MCI_SUCCESS 0 |
Successful completion.
Referenced by mci_init(), mci_select_card(), mci_send_cmd(), mci_set_bus_size(), sd_mmc_get_ext_csd(), sd_mmc_mci_card_init(), sd_mmc_mci_cmd_send_status(), sd_mmc_mci_dma_read_open(), sd_mmc_mci_dma_write_open(), sd_mmc_mci_get_csd(), sd_mmc_mci_init(), sd_mmc_mci_read_close(), sd_mmc_mci_read_open(), sd_mmc_mci_write_close(), sd_mmc_mci_write_open(), and sd_mmc_set_block_len().
#define MCI_TRCMD_NO (AVR32_MCI_TRCMD_NO_TRANS <<AVR32_MCI_TRCMD_OFFSET) |
#define MCI_TRCMD_START (AVR32_MCI_TRCMD_START_TRANS<<AVR32_MCI_TRCMD_OFFSET) |
#define MCI_TRCMD_STOP (AVR32_MCI_TRCMD_STOP_TRANS <<AVR32_MCI_TRCMD_OFFSET) |
#define MCI_TRDIR (AVR32_MCI_TRDIR_MASK) |
#define MCI_TRTYP_BLOCK (AVR32_MCI_TRTYP_BLOCK <<AVR32_MCI_TRTYP_OFFSET) |
#define MCI_TRTYP_MULTIPLE (AVR32_MCI_TRTYP_MULTI_BLOCK<<AVR32_MCI_TRTYP_OFFSET) |
#define MCI_TRTYP_SDIO_BLOCK (AVR32_MCI_TRTYP_SDIO_BLOCK <<AVR32_MCI_TRTYP_OFFSET) |
#define MCI_TRTYP_SDIO_BYTE (AVR32_MCI_TRTYP_SDIO_BYTE <<AVR32_MCI_TRTYP_OFFSET) |
#define MCI_TRTYP_STREAM (AVR32_MCI_TRTYP_STREAM <<AVR32_MCI_TRTYP_OFFSET) |
|
static |
Tests if the MCI is able to take a new command.
mci | Base address of the MCI instance. |
1
if the MCI can take a new command, otherwise 0
. References mci_get_sr().
Referenced by mci_send_cmd().
|
static |
Tests if the MCI Status detects a CRC error.
mci | Base address of the MCI instance. |
1
if the MCI CRC Error Flag is set, otherwise 0
. References mci_get_sr(), and shadow_sr.
Referenced by sd_mmc_mci_read_close(), and sd_mmc_mci_write_close().
|
static |
Tests if the MCI has ended the block Transmission/ Reception.
mci | Base address of the MCI instance. |
1
if the MCI Block is ended, otherwise 0
. References mci_get_sr().
Referenced by sd_mmc_mci_write_close().
void mci_disable | ( | volatile avr32_mci_t * | mci | ) |
Disables the MCI controller.
mci | Base address of the MCI instance. |
Referenced by mci_init(), and mci_stop().
void mci_enable | ( | volatile avr32_mci_t * | mci | ) |
Enables the MCI controller.
mci | Base address of the MCI instance. |
Referenced by mci_init().
|
static |
Return the status register and cache in a shadow variable bits that are cleared when reading the status register.
mci | Base address of the MCI instance. |
References shadow_sr.
Referenced by mci_cmd_ready(), mci_crc_error(), mci_data_block_ended(), mci_overrun_error(), mci_rx_ready(), mci_send_cmd(), mci_tx_ready(), mci_underrun_error(), and mci_wait_busy_signal().
int mci_init | ( | volatile avr32_mci_t * | mci, |
uint8_t | card_slot, | ||
uint32_t | pbb_hz | ||
) |
Initialize the MCI controller.
mci | Base address of the MCI instance. |
card_slot | Card slot number |
pbb_hz | PBB Frequency |
MCI_SUCCESS | Initialization successfully done. |
MCI_INVALID_INPUT | One or more of the arguments is out of valid range. |
References MCI_BUS_SIZE_1_BIT, MCI_DEFAULT_DTOREG, MCI_DEFAULT_PWSDIV, MCI_DEFAULT_SPEED_HZ, mci_disable(), mci_enable(), MCI_INVALID_INPUT, MCI_LAST_SLOTS, mci_reset(), mci_set_speed(), MCI_SUCCESS, and shadow_sr.
|
static |
Tests if an overrun occur.
mci | Base address of the MCI instance. |
1
if the MCI overrun flag is set, otherwise 0
. References mci_get_sr().
|
static |
Mci Read data.
mci | Base address of the MCI instance. |
data | Data read |
Referenced by sd_mmc_get_ext_csd(), sd_mmc_mci_card_init(), sd_mmc_mci_read_multiple_sector_2_ram(), and sd_mmc_mci_read_sector_2_ram().
unsigned int mci_read_response | ( | volatile avr32_mci_t * | mci | ) |
Read command argument response.
mci | Base address of the MCI instance. |
argument | Return value of the previously command. |
Referenced by sd_mmc_mci_card_init(), sd_mmc_mci_dma_read_open(), sd_mmc_mci_dma_write_open(), sd_mmc_mci_get_csd(), sd_mmc_mci_read_open(), sd_mmc_mci_write_open(), and sd_mmc_set_block_len().
void mci_reset | ( | volatile avr32_mci_t * | mci | ) |
Resets the MCI controller.
mci | Base address of the MCI instance. |
|
static |
Tests if the MCI is ready to receive data.
mci | Base address of the MCI instance. |
1
if the MCI Receive Holding Register is free, otherwise 0
. References mci_get_sr().
Referenced by sd_mmc_get_ext_csd(), sd_mmc_mci_card_init(), sd_mmc_mci_read_multiple_sector_2_ram(), and sd_mmc_mci_read_sector_2_ram().
int mci_select_card | ( | volatile avr32_mci_t * | mci, |
uint8_t | card_slot, | ||
uint8_t | bus_width | ||
) |
Mci Select slot Card.
mci | Base address of the MCI instance. |
card_slot | Slot number. |
bus_width | Bus Width . |
data | Data read |
References MCI_INVALID_INPUT, MCI_LAST_SLOTS, and MCI_SUCCESS.
Referenced by sd_mmc_get_ext_csd(), sd_mmc_mci_cmd_send_status(), sd_mmc_mci_dma_read_open(), sd_mmc_mci_dma_write_open(), sd_mmc_mci_get_csd(), sd_mmc_mci_mem_check(), sd_mmc_mci_read_open(), sd_mmc_mci_write_open(), and sd_mmc_set_block_len().
int mci_send_cmd | ( | volatile avr32_mci_t * | mci, |
unsigned int | cmd, | ||
unsigned int | arg | ||
) |
Generic function to send a command to the MMC or SDCard.
mci | Base address of the MCI instance. |
cmd | Command Value. |
arg | Argument Value. |
MCI_SUCCESS | Command Successfully sent |
error | Error value |
References arg, cmd, error(), mci_cmd_ready(), mci_get_sr(), MCI_SR_ERROR, MCI_SUCCESS, SD_MMC_MMC_SEND_OP_COND_CMD, and SD_MMC_SDCARD_APP_OP_COND_CMD.
void mci_set_block_count | ( | volatile avr32_mci_t * | mci, |
uint16_t | cnt | ||
) |
Set Block Count.
mci | Base address of the MCI instance. |
length | Block Count Value |
Referenced by sd_mmc_get_ext_csd(), sd_mmc_mci_card_init(), sd_mmc_mci_dma_read_open(), sd_mmc_mci_dma_write_open(), sd_mmc_mci_read_open(), sd_mmc_mci_write_open(), and sd_mmc_set_block_len().
void mci_set_block_size | ( | volatile avr32_mci_t * | mci, |
uint16_t | length | ||
) |
Set Block Size.
mci | Base address of the MCI instance. |
length | Block Length Value |
Referenced by sd_mmc_get_ext_csd(), sd_mmc_mci_dma_read_open(), sd_mmc_mci_dma_write_open(), sd_mmc_mci_read_open(), sd_mmc_mci_write_open(), and sd_mmc_set_block_len().
int mci_set_bus_size | ( | volatile avr32_mci_t * | mci, |
uint8_t | busWidth | ||
) |
Set SDIO Bus Width.
mci | Base address of the MCI instance. |
busWidth | Bus Width Value |
MCI_SUCCESS | Command successfully done. |
MCI_INVALID_INPUT | One or more of the arguments is out of valid range. |
References MCI_BUS_SIZE_8_BIT, MCI_INVALID_INPUT, and MCI_SUCCESS.
Referenced by sd_mmc_mci_card_init().
void mci_set_speed | ( | volatile avr32_mci_t * | mci, |
uint32_t | pbb_hz, | ||
uint32_t | card_speed | ||
) |
Set Speed Card.
mci | Base address of the MCI instance. |
pbb_hz | PBB Frequency |
card_speed | Card Frequency |
MCI_SUCCESS | Initialization successfully done. |
MCI_INVALID_INPUT | One or more of the arguments is out of valid range. |
void mci_stop | ( | volatile avr32_mci_t * | mci | ) |
Stop the MCI controller.
mci | Base address of the MCI instance. |
References mci_disable(), and mci_reset().
|
static |
Tests if the MCI is ready to transmit data.
mci | Base address of the MCI instance. |
1
if the MCI Transmit Holding Register is free, otherwise 0
. References mci_get_sr().
Referenced by sd_mmc_mci_write_multiple_sector_from_ram(), and sd_mmc_mci_write_sector_from_ram().
|
static |
Tests if an underrun occur.
mci | Base address of the MCI instance. |
1
if the MCI underrun flag is set, otherwise 0
. References mci_get_sr().
void mci_wait_busy_signal | ( | volatile avr32_mci_t * | mci | ) |
Mci Busy Status.
mci | Base address of the MCI instance. |
References mci_get_sr().
Referenced by sd_mmc_mci_card_init(), sd_mmc_mci_dma_read_open(), sd_mmc_mci_dma_write_open(), sd_mmc_mci_read_close(), sd_mmc_mci_read_open(), and sd_mmc_mci_write_open().
|
static |
Mci Write data.
mci | Base address of the MCI instance. |
data | Data to write |
References data.
Referenced by sd_mmc_mci_write_multiple_sector_from_ram(), and sd_mmc_mci_write_sector_from_ram().
int shadow_sr |
Referenced by mci_crc_error(), mci_get_sr(), and mci_init().