implementation
Macros | |
#define | AVR32_MCI_MR_FBYTE_MASK AVR32_MCI_MR_PDCFBYTE_MASK |
static uint32_t | mci_transfert_pos |
static uint16_t | mci_block_size |
static uint16_t | mci_nb_block |
static void | mci_reset (void) |
Reset the MCI interface. More... | |
static void | mci_set_speed (uint32_t speed, uint32_t pbb_hz) |
Set speed of the MCI clock. More... | |
static bool | mci_wait_busy (void) |
Wait the end of busy signal on data line. More... | |
static bool | mci_wait_busy_on_line (void) |
Wait the end of busy signal on data line through GPIO. More... | |
static bool | mci_send_cmd_execute (uint32_t cmdr, sdmmc_cmd_def_t cmd, uint32_t arg) |
Send a command. More... | |
void | mci_init (void) |
Initialize the low level driver. More... | |
uint8_t | mci_get_bus_width (uint8_t slot) |
Return the maximum bus width of a slot. More... | |
bool | mci_is_high_speed_capable (void) |
Return the high speed capability of the driver. More... | |
void | mci_select_device (uint8_t slot, uint32_t clock, uint8_t bus_width, bool high_speed) |
Select a slot and initialize it. More... | |
void | mci_deselect_device (uint8_t slot) |
Deselect a slot. More... | |
void | mci_send_clock (void) |
Send 74 clock cycles on the line of selected slot Note: It is required after card plug and before card install. More... | |
bool | mci_send_cmd (sdmmc_cmd_def_t cmd, uint32_t arg) |
Send a command on the selected slot. More... | |
uint32_t | mci_get_response (void) |
Return the 32 bits response of the last command. More... | |
void | mci_get_response_128 (uint8_t *response) |
Return the 128-bits response of the last command. More... | |
bool | mci_adtc_start (sdmmc_cmd_def_t cmd, uint32_t arg, uint16_t block_size, uint16_t nb_block, bool access_block) |
Send an ADTC command on the selected slot An ADTC (Addressed Data Transfer Commands) command is used for read/write access. More... | |
bool | mci_adtc_stop (sdmmc_cmd_def_t cmd, uint32_t arg) |
Send a command to stop an ADTC command on the selected slot. More... | |
bool | mci_read_word (uint32_t *value) |
Read a word on the line. More... | |
bool | mci_write_word (uint32_t value) |
Write a word on the line. More... | |
bool | mci_start_read_blocks (void *dest, uint16_t nb_block) |
Start a read blocks transfer on the line Note: The driver will use the DMA available to speed up the transfer. More... | |
bool | mci_wait_end_of_read_blocks (void) |
Wait the end of transfer started by mci_start_read_blocks() More... | |
bool | mci_start_write_blocks (const void *src, uint16_t nb_block) |
Start a write blocks transfer on the line Note: The driver will use the DMA available to speed up the transfer. More... | |
bool | mci_wait_end_of_write_blocks (void) |
Wait the end of transfer started by mci_start_write_blocks() More... | |
#define | AVR32_MCI_DTOR_DTOMUL_1048576_MASK (AVR32_MCI_DTOR_DTOMUL_1048576 << AVR32_MCI_DTOR_DTOMUL_OFFSET) |
Registers masks definitions. More... | |
#define | AVR32_MCI_CSTOR_CSTOMUL_1048576_MASK (AVR32_MCI_CSTOR_CSTOMUL_1048576 << AVR32_MCI_CSTOR_CSTOMUL_OFFSET) |
#define | AVR32_MCI_CSTOR_CSTOCYC_2_MASK ( 2 << AVR32_MCI_CSTOR_CSTOCYC_OFFSET) |
#define | AVR32_MCI_DTOR_DTOCYC_2_MASK ( 2 << AVR32_MCI_DTOR_DTOCYC_OFFSET) |
#define | AVR32_MCI_SDCR_SDCBUS_1_BIT_MASK ( AVR32_MCI_SDCR_SDCBUS_1_BIT << AVR32_MCI_SDCR_SDCBUS_OFFSET) |
#define | AVR32_MCI_SDCR_SDCBUS_4_BIT_MASK ( AVR32_MCI_SDCR_SDCBUS_4_BIT << AVR32_MCI_SDCR_SDCBUS_OFFSET) |
#define | AVR32_MCI_SDCR_SDCBUS_8_BIT_MASK ( AVR32_MCI_SDCR_SDCBUS_8_BIT << AVR32_MCI_SDCR_SDCBUS_OFFSET) |
#define | AVR32_MCI_SDCR_SDCSEL_0_MASK ( 0 << AVR32_MCI_SDCR_SDCSEL_OFFSET) |
#define | AVR32_MCI_SDCR_SDCSEL_1_MASK ( 1 << AVR32_MCI_SDCR_SDCSEL_OFFSET) |
#define | AVR32_MCI_CMDR_TRCMD_START_TRANS_MASK ( AVR32_MCI_CMDR_TRCMD_START_TRANS << AVR32_MCI_CMDR_TRCMD_OFFSET) |
#define | AVR32_MCI_CMDR_TRDIR_READ_MASK ( AVR32_MCI_CMDR_TRDIR_READ << AVR32_MCI_CMDR_TRDIR_OFFSET) |
#define | AVR32_MCI_CMDR_TRTYP_SDIO_BYTE_MASK ( AVR32_MCI_CMDR_TRTYP_SDIO_BYTE << AVR32_MCI_CMDR_TRTYP_OFFSET) |
#define | AVR32_MCI_CMDR_TRTYP_SDIO_BLOCK_MASK ( AVR32_MCI_CMDR_TRTYP_SDIO_BLOCK << AVR32_MCI_CMDR_TRTYP_OFFSET) |
#define | AVR32_MCI_CMDR_TRTYP_STREAM_MASK ( AVR32_MCI_CMDR_TRTYP_STREAM << AVR32_MCI_CMDR_TRTYP_OFFSET) |
#define | AVR32_MCI_CMDR_TRTYP_BLOCK_MASK ( AVR32_MCI_CMDR_TRTYP_BLOCK << AVR32_MCI_CMDR_TRTYP_OFFSET) |
#define | AVR32_MCI_CMDR_TRTYP_MULTI_BLOCK_MASK ( AVR32_MCI_CMDR_TRTYP_MULTI_BLOCK << AVR32_MCI_CMDR_TRTYP_OFFSET) |
#define | SD_MMC_MCI_MEM_CNT 1 |
#define | SD_MMC_MCI_SLOT_0_SIZE 1 |
#define | SD_MMC_MCI_SLOT_0_DATA0_PIN 0 |
#define | SD_MMC_MCI_SLOT_0_DATA3_PIN 0 |
#define | mci_debug(...) |
#define | CONF_MCI_DMACA_CHANNEL 1 |
#define AVR32_MCI_CMDR_TRCMD_START_TRANS_MASK ( AVR32_MCI_CMDR_TRCMD_START_TRANS << AVR32_MCI_CMDR_TRCMD_OFFSET) |
Referenced by mci_adtc_start().
#define AVR32_MCI_CMDR_TRDIR_READ_MASK ( AVR32_MCI_CMDR_TRDIR_READ << AVR32_MCI_CMDR_TRDIR_OFFSET) |
Referenced by mci_adtc_start().
#define AVR32_MCI_CMDR_TRTYP_BLOCK_MASK ( AVR32_MCI_CMDR_TRTYP_BLOCK << AVR32_MCI_CMDR_TRTYP_OFFSET) |
Referenced by mci_adtc_start().
#define AVR32_MCI_CMDR_TRTYP_MULTI_BLOCK_MASK ( AVR32_MCI_CMDR_TRTYP_MULTI_BLOCK << AVR32_MCI_CMDR_TRTYP_OFFSET) |
Referenced by mci_adtc_start().
#define AVR32_MCI_CMDR_TRTYP_SDIO_BLOCK_MASK ( AVR32_MCI_CMDR_TRTYP_SDIO_BLOCK << AVR32_MCI_CMDR_TRTYP_OFFSET) |
Referenced by mci_adtc_start().
#define AVR32_MCI_CMDR_TRTYP_SDIO_BYTE_MASK ( AVR32_MCI_CMDR_TRTYP_SDIO_BYTE << AVR32_MCI_CMDR_TRTYP_OFFSET) |
Referenced by mci_adtc_start().
#define AVR32_MCI_CMDR_TRTYP_STREAM_MASK ( AVR32_MCI_CMDR_TRTYP_STREAM << AVR32_MCI_CMDR_TRTYP_OFFSET) |
Referenced by mci_adtc_start().
#define AVR32_MCI_CSTOR_CSTOCYC_2_MASK ( 2 << AVR32_MCI_CSTOR_CSTOCYC_OFFSET) |
Referenced by mci_init().
#define AVR32_MCI_CSTOR_CSTOMUL_1048576_MASK (AVR32_MCI_CSTOR_CSTOMUL_1048576 << AVR32_MCI_CSTOR_CSTOMUL_OFFSET) |
Referenced by mci_init().
#define AVR32_MCI_DTOR_DTOCYC_2_MASK ( 2 << AVR32_MCI_DTOR_DTOCYC_OFFSET) |
Referenced by mci_init().
#define AVR32_MCI_DTOR_DTOMUL_1048576_MASK (AVR32_MCI_DTOR_DTOMUL_1048576 << AVR32_MCI_DTOR_DTOMUL_OFFSET) |
Registers masks definitions.
Referenced by mci_init().
#define AVR32_MCI_MR_FBYTE_MASK AVR32_MCI_MR_PDCFBYTE_MASK |
Referenced by mci_adtc_start(), mci_send_clock(), mci_send_cmd(), mci_start_read_blocks(), and mci_start_write_blocks().
#define AVR32_MCI_SDCR_SDCBUS_1_BIT_MASK ( AVR32_MCI_SDCR_SDCBUS_1_BIT << AVR32_MCI_SDCR_SDCBUS_OFFSET) |
Referenced by mci_deselect_device(), mci_init(), and mci_select_device().
#define AVR32_MCI_SDCR_SDCBUS_4_BIT_MASK ( AVR32_MCI_SDCR_SDCBUS_4_BIT << AVR32_MCI_SDCR_SDCBUS_OFFSET) |
Referenced by mci_select_device().
#define AVR32_MCI_SDCR_SDCBUS_8_BIT_MASK ( AVR32_MCI_SDCR_SDCBUS_8_BIT << AVR32_MCI_SDCR_SDCBUS_OFFSET) |
Referenced by mci_select_device().
#define AVR32_MCI_SDCR_SDCSEL_0_MASK ( 0 << AVR32_MCI_SDCR_SDCSEL_OFFSET) |
Referenced by mci_select_device().
#define AVR32_MCI_SDCR_SDCSEL_1_MASK ( 1 << AVR32_MCI_SDCR_SDCSEL_OFFSET) |
Referenced by mci_select_device().
#define CONF_MCI_DMACA_CHANNEL 1 |
#define mci_debug | ( | ... | ) |
#define SD_MMC_MCI_MEM_CNT 1 |
#define SD_MMC_MCI_SLOT_0_DATA0_PIN 0 |
Referenced by mci_wait_busy_on_line().
#define SD_MMC_MCI_SLOT_0_DATA3_PIN 0 |
Referenced by mci_send_cmd_execute().
#define SD_MMC_MCI_SLOT_0_SIZE 1 |
Referenced by mci_get_bus_width().
bool mci_adtc_start | ( | sdmmc_cmd_def_t | cmd, |
uint32_t | arg, | ||
uint16_t | block_size, | ||
uint16_t | nb_block, | ||
bool | access_block | ||
) |
Send an ADTC command on the selected slot An ADTC (Addressed Data Transfer Commands) command is used for read/write access.
cmd | Command definition |
arg | Argument of the command |
block_size | Block size used for the transfer |
nb_block | Total number of block for this transfer |
access_block | if true, the x_read_blocks() and x_write_blocks() functions must be used after this function. If false, the mci_read_word() and mci_write_word() functions must be used after this function. |
References Assert, AVR32_MCI_CMDR_TRCMD_START_TRANS_MASK, AVR32_MCI_CMDR_TRDIR_READ_MASK, AVR32_MCI_CMDR_TRTYP_BLOCK_MASK, AVR32_MCI_CMDR_TRTYP_MULTI_BLOCK_MASK, AVR32_MCI_CMDR_TRTYP_SDIO_BLOCK_MASK, AVR32_MCI_CMDR_TRTYP_SDIO_BYTE_MASK, AVR32_MCI_CMDR_TRTYP_STREAM_MASK, AVR32_MCI_MR_FBYTE_MASK, mci_block_size, mci_nb_block, mci_send_cmd_execute(), mci_transfert_pos, SDMMC_CMD_MULTI_BLOCK, SDMMC_CMD_SDIO_BLOCK, SDMMC_CMD_SDIO_BYTE, SDMMC_CMD_SINGLE_BLOCK, SDMMC_CMD_STREAM, and SDMMC_CMD_WRITE.
bool mci_adtc_stop | ( | sdmmc_cmd_def_t | cmd, |
uint32_t | arg | ||
) |
Send a command to stop an ADTC command on the selected slot.
cmd | Command definition |
arg | Argument of the command |
References mci_send_cmd_execute(), and mci_wait_busy_on_line().
void mci_deselect_device | ( | uint8_t | slot | ) |
Deselect a slot.
slot | Selected slot |
References AVR32_MCI_SDCR_SDCBUS_1_BIT_MASK, and UNUSED.
uint8_t mci_get_bus_width | ( | uint8_t | slot | ) |
Return the maximum bus width of a slot.
slot | Selected slot |
References SD_MMC_MCI_SLOT_0_SIZE, and SD_MMC_MCI_SLOT_1_SIZE.
uint32_t mci_get_response | ( | void | ) |
Return the 32 bits response of the last command.
void mci_get_response_128 | ( | uint8_t * | response | ) |
Return the 128-bits response of the last command.
response | Pointer on the array to fill with the 128-bits response |
void mci_init | ( | void | ) |
Initialize the low level driver.
This enables the required clock and the hardware interface.
References AVR32_MCI_CSTOR_CSTOCYC_2_MASK, AVR32_MCI_CSTOR_CSTOMUL_1048576_MASK, AVR32_MCI_DTOR_DTOCYC_2_MASK, AVR32_MCI_DTOR_DTOMUL_1048576_MASK, AVR32_MCI_SDCR_SDCBUS_1_BIT_MASK, SYSCLK_DMACA, sysclk_enable_hsb_module(), sysclk_enable_pbb_module(), and SYSCLK_MCI.
bool mci_is_high_speed_capable | ( | void | ) |
Return the high speed capability of the driver.
bool mci_read_word | ( | uint32_t * | value | ) |
Read a word on the line.
value | Pointer on a word to fill |
References Assert, le32_to_cpu, mci_block_size, mci_debug, mci_nb_block, mci_reset(), and mci_transfert_pos.
|
static |
Reset the MCI interface.
Referenced by mci_read_word(), mci_send_cmd_execute(), mci_wait_busy(), mci_wait_busy_on_line(), mci_wait_end_of_read_blocks(), mci_wait_end_of_write_blocks(), and mci_write_word().
void mci_select_device | ( | uint8_t | slot, |
uint32_t | clock, | ||
uint8_t | bus_width, | ||
bool | high_speed | ||
) |
Select a slot and initialize it.
slot | Selected slot |
clock | Maximum clock to use (Hz) |
bus_width | Bus width to use (1, 4 or 8) |
high_speed | true, to enable high speed mode |
References Assert, AVR32_MCI_SDCR_SDCBUS_1_BIT_MASK, AVR32_MCI_SDCR_SDCBUS_4_BIT_MASK, AVR32_MCI_SDCR_SDCBUS_8_BIT_MASK, AVR32_MCI_SDCR_SDCSEL_0_MASK, AVR32_MCI_SDCR_SDCSEL_1_MASK, mci_set_speed(), and sysclk_get_pbb_hz().
void mci_send_clock | ( | void | ) |
Send 74 clock cycles on the line of selected slot Note: It is required after card plug and before card install.
References AVR32_MCI_MR_FBYTE_MASK.
bool mci_send_cmd | ( | sdmmc_cmd_def_t | cmd, |
uint32_t | arg | ||
) |
Send a command on the selected slot.
cmd | Command definition |
arg | Argument of the command |
References AVR32_MCI_MR_FBYTE_MASK, and mci_send_cmd_execute().
|
static |
Send a command.
cmdr | CMDR register bit mask to use for this command |
cmd | Command definition |
arg | Argument of the command |
References gpio_configure_pin(), GPIO_DIR_INPUT, gpio_enable_gpio_pin(), GPIO_PULL_UP, mci_debug, mci_reset(), mci_wait_busy(), SD_MMC_MCI_SLOT_0_DATA3_PIN, SD_MMC_MCI_SLOT_1_DATA3_PIN, SDMMC_CMD_OPENDRAIN, SDMMC_MCI_CMD0_GO_IDLE_STATE, SDMMC_RESP_136, SDMMC_RESP_BUSY, SDMMC_RESP_CRC, and SDMMC_RESP_PRESENT.
Referenced by mci_adtc_start(), mci_adtc_stop(), and mci_send_cmd().
|
static |
Set speed of the MCI clock.
speed | MCI clock speed in Hz. |
pbb_hz | PBB clock speed in Hz. |
Referenced by mci_select_device().
bool mci_start_read_blocks | ( | void * | dest, |
uint16_t | nb_block | ||
) |
Start a read blocks transfer on the line Note: The driver will use the DMA available to speed up the transfer.
dest | Pointer on the buffer to fill |
nb_block | Number of block to transfer |
References Assert, AVR32_MCI_MR_FBYTE_MASK, mci_block_size, mci_nb_block, and mci_transfert_pos.
bool mci_start_write_blocks | ( | const void * | src, |
uint16_t | nb_block | ||
) |
Start a write blocks transfer on the line Note: The driver will use the DMA available to speed up the transfer.
src | Pointer on the buffer to send |
nb_block | Number of block to transfer |
References Assert, AVR32_MCI_MR_FBYTE_MASK, mci_block_size, mci_nb_block, and mci_transfert_pos.
|
static |
Wait the end of busy signal on data line.
References mci_debug, and mci_reset().
Referenced by mci_send_cmd_execute().
|
static |
Wait the end of busy signal on data line through GPIO.
References gpio_get_pin_value(), mci_debug, mci_reset(), SD_MMC_MCI_SLOT_0_DATA0_PIN, and SD_MMC_MCI_SLOT_1_DATA0_PIN.
Referenced by mci_adtc_stop().
bool mci_wait_end_of_read_blocks | ( | void | ) |
Wait the end of transfer started by mci_start_read_blocks()
References mci_block_size, mci_debug, mci_nb_block, mci_reset(), and mci_transfert_pos.
bool mci_wait_end_of_write_blocks | ( | void | ) |
Wait the end of transfer started by mci_start_write_blocks()
References Assert, mci_block_size, mci_debug, mci_nb_block, mci_reset(), and mci_transfert_pos.
bool mci_write_word | ( | uint32_t | value | ) |
Write a word on the line.
value | Word to send |
References Assert, cpu_to_le32, mci_block_size, mci_debug, mci_nb_block, mci_reset(), and mci_transfert_pos.
|
static |
|
static |
|
static |