Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
MCI - MultiMedia Card Interface

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
Value:
(MCI_DEFAULT_DTOLMUL<<AVR32_MCI_DTOR_DTOMUL_OFFSET) | \
(MCI_DEFAULT_DTOLCYC<<AVR32_MCI_DTOR_DTOCYC_OFFSET)
#define MCI_DEFAULT_DTOLMUL
Data Timeout Multiplier.
Definition: mci.h:99
#define MCI_DEFAULT_DTOLCYC
Data Timeout Cycle Number.
Definition: mci.h:101

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_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_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 __always_inline int mci_cmd_ready ( volatile avr32_mci_t *  mci)
static

Tests if the MCI is able to take a new command.

Parameters
mciBase address of the MCI instance.
Returns
1 if the MCI can take a new command, otherwise 0.

References mci_get_sr().

Referenced by mci_send_cmd().

static __always_inline int mci_crc_error ( volatile avr32_mci_t *  mci)
static

Tests if the MCI Status detects a CRC error.

Parameters
mciBase address of the MCI instance.
Returns
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 __always_inline int mci_data_block_ended ( volatile avr32_mci_t *  mci)
static

Tests if the MCI has ended the block Transmission/ Reception.

Parameters
mciBase address of the MCI instance.
Returns
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.

Parameters
mciBase address of the MCI instance.
Return values

Referenced by mci_init(), and mci_stop().

void mci_enable ( volatile avr32_mci_t *  mci)

Enables the MCI controller.

Parameters
mciBase address of the MCI instance.
Return values

Referenced by mci_init().

static __always_inline int mci_get_sr ( volatile avr32_mci_t *  mci)
static

Return the status register and cache in a shadow variable bits that are cleared when reading the status register.

Parameters
mciBase 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.

Parameters
mciBase address of the MCI instance.
card_slotCard slot number
pbb_hzPBB Frequency
Return values
MCI_SUCCESSInitialization successfully done.
MCI_INVALID_INPUTOne 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.

Referenced by sd_mmc_mci_card_init(), and sd_mmc_mci_init().

static __always_inline int mci_overrun_error ( volatile avr32_mci_t *  mci)
static

Tests if an overrun occur.

Parameters
mciBase address of the MCI instance.
Returns
1 if the MCI overrun flag is set, otherwise 0.

References mci_get_sr().

static __always_inline uint32_t mci_rd_data ( volatile avr32_mci_t *  mci)
static

Mci Read data.

Parameters
mciBase address of the MCI instance.
Return values
dataData 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.

Parameters
mciBase address of the MCI instance.
Return values
argumentReturn 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.

Parameters
mciBase address of the MCI instance.
Return values

Referenced by mci_init(), and mci_stop().

static __always_inline int mci_rx_ready ( volatile avr32_mci_t *  mci)
static

Tests if the MCI is ready to receive data.

Parameters
mciBase address of the MCI instance.
Returns
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.

Parameters
mciBase address of the MCI instance.
card_slotSlot number.
bus_widthBus Width .
Return values
dataData 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.

Parameters
mciBase address of the MCI instance.
cmdCommand Value.
argArgument Value.
Return values
MCI_SUCCESSCommand Successfully sent
errorError value

References arg, 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.

Referenced by 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_read_close(), sd_mmc_mci_read_open(), sd_mmc_mci_write_close(), sd_mmc_mci_write_open(), and sd_mmc_set_block_len().

void mci_set_block_count ( volatile avr32_mci_t *  mci,
uint16_t  cnt 
)

Set Block Count.

Parameters
mciBase address of the MCI instance.
lengthBlock Count Value
Return values

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.

Parameters
mciBase address of the MCI instance.
lengthBlock Length Value
Return values

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.

Parameters
mciBase address of the MCI instance.
busWidthBus Width Value
Return values
MCI_SUCCESSCommand successfully done.
MCI_INVALID_INPUTOne 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.

Parameters
mciBase address of the MCI instance.
pbb_hzPBB Frequency
card_speedCard Frequency
Return values
MCI_SUCCESSInitialization successfully done.
MCI_INVALID_INPUTOne or more of the arguments is out of valid range.

Referenced by mci_init(), and sd_mmc_mci_card_init().

void mci_stop ( volatile avr32_mci_t *  mci)

Stop the MCI controller.

Parameters
mciBase address of the MCI instance.
Return values

References mci_disable(), and mci_reset().

static __always_inline int mci_tx_ready ( volatile avr32_mci_t *  mci)
static

Tests if the MCI is ready to transmit data.

Parameters
mciBase address of the MCI instance.
Returns
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 __always_inline int mci_underrun_error ( volatile avr32_mci_t *  mci)
static

Tests if an underrun occur.

Parameters
mciBase address of the MCI instance.
Returns
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.

Parameters
mciBase address of the MCI instance.
Return values

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 __always_inline void mci_wr_data ( volatile avr32_mci_t *  mci,
uint32_t  data 
)
static

Mci Write data.

Parameters
mciBase address of the MCI instance.
dataData to write
Return values

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().