implementation
Macros | |
#define | sd_mmc_spi_debug(...) |
Functions | |
bool | sd_mmc_spi_adtc_start (sdmmc_cmd_def_t cmd, uint32_t arg, uint16_t block_size, uint16_t nb_block, bool access_block) |
Send a adtc command on the selected slot A adtc command is used for read/write access. More... | |
static uint8_t | sd_mmc_spi_crc7 (uint8_t *buf, uint8_t size) |
Calculates the CRC7. More... | |
void | sd_mmc_spi_deselect_device (uint8_t slot) |
Deselect a slot. More... | |
sd_mmc_spi_errno_t | sd_mmc_spi_get_errno (void) |
Return the error code of last function. More... | |
uint32_t | sd_mmc_spi_get_response (void) |
Return the 32 bits response of the last command. More... | |
void | sd_mmc_spi_init (void) |
Initializes the low level driver. More... | |
bool | sd_mmc_spi_read_word (uint32_t *value) |
Read a word on the line. More... | |
void | sd_mmc_spi_select_device (uint8_t slot, uint32_t clock, uint8_t bus_width, bool high_speed) |
Select a slot and initialize it. More... | |
void | sd_mmc_spi_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 | sd_mmc_spi_send_cmd (sdmmc_cmd_def_t cmd, uint32_t arg) |
Send a command on the selected slot. More... | |
static bool | sd_mmc_spi_start_read_block (void) |
Sends the correct TOKEN on the line to start a read block transfer. More... | |
bool | sd_mmc_spi_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... | |
static void | sd_mmc_spi_start_write_block (void) |
Sends the correct TOKEN on the line to start a write block transfer. More... | |
bool | sd_mmc_spi_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... | |
static bool | sd_mmc_spi_stop_multiwrite_block (void) |
Executed the end of a multi blocks write transfer. More... | |
static void | sd_mmc_spi_stop_read_block (void) |
Executed the end of a read block transfer. More... | |
static bool | sd_mmc_spi_stop_write_block (void) |
Waits the TOKEN which notify the end of write block transfer. More... | |
static bool | sd_mmc_spi_wait_busy (void) |
Wait the end of busy on DAT0 line. More... | |
bool | sd_mmc_spi_wait_end_of_read_blocks (void) |
Wait the end of transfer initiated by mci_start_read_blocks() More... | |
bool | sd_mmc_spi_wait_end_of_write_blocks (void) |
Wait the end of transfer initiated by mci_start_write_blocks() More... | |
bool | sd_mmc_spi_write_word (uint32_t value) |
Write a word on the line. More... | |
Variables | |
static struct spi_module | sd_mmc_master |
static uint16_t | sd_mmc_spi_block_size |
Size block requested by last mci_adtc_start() More... | |
static struct spi_slave_inst | sd_mmc_spi_devices [SD_MMC_SPI_MEM_CNT] |
Slot array of SPI structures. More... | |
static sd_mmc_spi_errno_t | sd_mmc_spi_err |
Internal global error status. More... | |
static uint16_t | sd_mmc_spi_nb_block |
Total number of block requested by last mci_adtc_start() More... | |
static uint32_t | sd_mmc_spi_response_32 |
32 bits response of the last command More... | |
static uint32_t | sd_mmc_spi_transfert_pos |
Current position (byte) of the transfer started by mci_adtc_start() More... | |
static struct spi_slave_inst_config | slave_configs [SD_MMC_SPI_MEM_CNT] |
uint8_t | ss_pins [SD_MMC_SPI_MEM_CNT] = {SD_MMC_CS} |
#define sd_mmc_spi_debug | ( | ... | ) |
bool sd_mmc_spi_adtc_start | ( | sdmmc_cmd_def_t | cmd, |
uint32_t | arg, | ||
uint16_t | block_size, | ||
uint16_t | nb_block, | ||
bool | access_block | ||
) |
Send a adtc command on the selected slot A adtc 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. |
R1 response
References Assert, be32_to_cpu, le32_to_cpu, R1_SPI_COM_CRC, R1_SPI_ERROR, R1_SPI_IDLE, R1_SPI_ILLEGAL_COMMAND, sd_mmc_master, sd_mmc_spi_block_size, sd_mmc_spi_crc7(), sd_mmc_spi_debug, SD_MMC_SPI_ERR, sd_mmc_spi_err, SD_MMC_SPI_ERR_ILLEGAL_COMMAND, SD_MMC_SPI_ERR_RESP_BUSY_TIMEOUT, SD_MMC_SPI_ERR_RESP_CRC, SD_MMC_SPI_ERR_RESP_TIMEOUT, sd_mmc_spi_nb_block, SD_MMC_SPI_NO_ERR, sd_mmc_spi_response_32, sd_mmc_spi_transfert_pos, sd_mmc_spi_wait_busy(), SDMMC_CMD_GET_INDEX, SDMMC_RESP_32, SDMMC_RESP_8, SDMMC_RESP_BUSY, SDMMC_RESP_PRESENT, SPI_CMD_ENCODE, spi_read_buffer_wait(), spi_write_buffer_wait(), and UNUSED.
Referenced by sd_mmc_spi_send_cmd().
|
static |
Calculates the CRC7.
buf | Buffer data to compute |
size | Size of buffer data |
Referenced by sd_mmc_spi_adtc_start().
void sd_mmc_spi_deselect_device | ( | uint8_t | slot | ) |
Deselect a slot.
slot | Selected slot |
References sd_mmc_master, sd_mmc_spi_devices, sd_mmc_spi_err, SD_MMC_SPI_NO_ERR, and spi_select_slave().
sd_mmc_spi_errno_t sd_mmc_spi_get_errno | ( | void | ) |
uint32_t sd_mmc_spi_get_response | ( | void | ) |
Return the 32 bits response of the last command.
References sd_mmc_spi_response_32.
void sd_mmc_spi_init | ( | void | ) |
Initializes the low level driver.
This enable the clock required and the hardware interface.
References spi_master_config::baudrate, port_config::direction, spi_config::generator_source, port_config::input_pull, spi_config::master, spi_config::mode_specific, spi_config::mux_setting, spi_config::pinmux_pad0, spi_config::pinmux_pad1, spi_config::pinmux_pad2, spi_config::pinmux_pad3, port_get_config_defaults(), PORT_PIN_DIR_INPUT, PORT_PIN_PULL_UP, port_pin_set_config(), SD_MMC_0_CD_GPIO, sd_mmc_master, SD_MMC_SPI, sd_mmc_spi_devices, sd_mmc_spi_err, SD_MMC_SPI_NO_ERR, SD_MMC_SPI_PINMUX_PAD0, SD_MMC_SPI_PINMUX_PAD1, SD_MMC_SPI_PINMUX_PAD2, SD_MMC_SPI_PINMUX_PAD3, SD_MMC_SPI_PINMUX_SETTING, SD_MMC_SPI_SOURCE_CLOCK, SDMMC_CLOCK_INIT, slave_configs, spi_attach_slave(), spi_enable(), spi_get_config_defaults(), spi_init(), spi_slave_inst_get_config_defaults(), spi_slave_inst_config::ss_pin, and ss_pins.
Referenced by _sd_init().
bool sd_mmc_spi_read_word | ( | uint32_t * | value | ) |
Read a word on the line.
value | Pointer on a word to fill |
References Assert, le32_to_cpu, sd_mmc_master, sd_mmc_spi_block_size, sd_mmc_spi_err, sd_mmc_spi_nb_block, SD_MMC_SPI_NO_ERR, sd_mmc_spi_start_read_block(), sd_mmc_spi_stop_read_block(), sd_mmc_spi_transfert_pos, and spi_read_buffer_wait().
void sd_mmc_spi_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 sd_mmc_master, sd_mmc_spi_devices, sd_mmc_spi_err, SD_MMC_SPI_MAX_CLOCK, SD_MMC_SPI_NO_ERR, spi_select_slave(), spi_set_baudrate(), STATUS_ERR_INVALID_ARG, and UNUSED.
Referenced by _sd_init().
void sd_mmc_spi_send_clock | ( | void | ) |
Send 74 clock cycles on the line of selected slot Note: It is required after card plug and before card install.
Send 80 cycles
References sd_mmc_master, sd_mmc_spi_err, SD_MMC_SPI_NO_ERR, and spi_write_buffer_wait().
bool sd_mmc_spi_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 sd_mmc_spi_adtc_start().
|
static |
Sends the correct TOKEN on the line to start a read block transfer.
References Assert, sd_mmc_master, sd_mmc_spi_block_size, sd_mmc_spi_debug, sd_mmc_spi_err, SD_MMC_SPI_ERR_OUT_OF_RANGE, SD_MMC_SPI_ERR_READ_CRC, SD_MMC_SPI_ERR_READ_TIMEOUT, sd_mmc_spi_transfert_pos, spi_read_buffer_wait(), SPI_TOKEN_DATA_ERROR_CC_ERROR, SPI_TOKEN_DATA_ERROR_ECC_ERROR, SPI_TOKEN_DATA_ERROR_ERROR, SPI_TOKEN_DATA_ERROR_ERRORS, SPI_TOKEN_DATA_ERROR_VALID, and SPI_TOKEN_SINGLE_MULTI_READ.
Referenced by sd_mmc_spi_read_word(), and sd_mmc_spi_start_read_blocks().
bool sd_mmc_spi_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, sd_mmc_master, sd_mmc_spi_block_size, sd_mmc_spi_err, sd_mmc_spi_nb_block, SD_MMC_SPI_NO_ERR, sd_mmc_spi_start_read_block(), sd_mmc_spi_stop_read_block(), sd_mmc_spi_transfert_pos, and spi_read_buffer_wait().
|
static |
Sends the correct TOKEN on the line to start a write block transfer.
References Assert, sd_mmc_master, sd_mmc_spi_block_size, sd_mmc_spi_nb_block, sd_mmc_spi_transfert_pos, SPI_TOKEN_MULTI_WRITE, SPI_TOKEN_SINGLE_WRITE, and spi_write_buffer_wait().
Referenced by sd_mmc_spi_start_write_blocks(), and sd_mmc_spi_write_word().
bool sd_mmc_spi_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, sd_mmc_master, sd_mmc_spi_block_size, sd_mmc_spi_debug, sd_mmc_spi_err, SD_MMC_SPI_ERR_WRITE_TIMEOUT, sd_mmc_spi_nb_block, SD_MMC_SPI_NO_ERR, sd_mmc_spi_start_write_block(), sd_mmc_spi_stop_write_block(), sd_mmc_spi_transfert_pos, sd_mmc_spi_wait_busy(), and spi_write_buffer_wait().
|
static |
Executed the end of a multi blocks write transfer.
References sd_mmc_master, sd_mmc_spi_block_size, sd_mmc_spi_debug, sd_mmc_spi_err, SD_MMC_SPI_ERR_WRITE_TIMEOUT, sd_mmc_spi_nb_block, sd_mmc_spi_transfert_pos, sd_mmc_spi_wait_busy(), SPI_TOKEN_STOP_TRAN, and spi_write_buffer_wait().
Referenced by sd_mmc_spi_wait_end_of_write_blocks(), and sd_mmc_spi_write_word().
|
static |
Executed the end of a read block transfer.
References sd_mmc_master, and spi_read_buffer_wait().
Referenced by sd_mmc_spi_read_word(), and sd_mmc_spi_start_read_blocks().
|
static |
Waits the TOKEN which notify the end of write block transfer.
CRC is disabled in SPI mode
References sd_mmc_master, sd_mmc_spi_debug, SD_MMC_SPI_ERR, sd_mmc_spi_err, SD_MMC_SPI_ERR_WRITE, SD_MMC_SPI_ERR_WRITE_CRC, spi_read_buffer_wait(), SPI_TOKEN_DATA_RESP_ACCEPTED, SPI_TOKEN_DATA_RESP_CODE, SPI_TOKEN_DATA_RESP_CRC_ERR, SPI_TOKEN_DATA_RESP_VALID, SPI_TOKEN_DATA_RESP_WRITE_ERR, and spi_write_buffer_wait().
Referenced by sd_mmc_spi_start_write_blocks(), and sd_mmc_spi_write_word().
|
static |
Wait the end of busy on DAT0 line.
References sd_mmc_master, and spi_read_buffer_wait().
Referenced by sd_mmc_spi_adtc_start(), sd_mmc_spi_start_write_blocks(), sd_mmc_spi_stop_multiwrite_block(), sd_mmc_spi_wait_end_of_write_blocks(), and sd_mmc_spi_write_word().
bool sd_mmc_spi_wait_end_of_read_blocks | ( | void | ) |
Wait the end of transfer initiated by mci_start_read_blocks()
bool sd_mmc_spi_wait_end_of_write_blocks | ( | void | ) |
Wait the end of transfer initiated by mci_start_write_blocks()
References sd_mmc_spi_debug, sd_mmc_spi_err, SD_MMC_SPI_ERR_WRITE_TIMEOUT, sd_mmc_spi_stop_multiwrite_block(), and sd_mmc_spi_wait_busy().
bool sd_mmc_spi_write_word | ( | uint32_t | value | ) |
Write a word on the line.
value | Word to send |
References Assert, cpu_to_le32, sd_mmc_master, sd_mmc_spi_block_size, sd_mmc_spi_debug, sd_mmc_spi_err, SD_MMC_SPI_ERR_WRITE_TIMEOUT, sd_mmc_spi_nb_block, SD_MMC_SPI_NO_ERR, sd_mmc_spi_start_write_block(), sd_mmc_spi_stop_multiwrite_block(), sd_mmc_spi_stop_write_block(), sd_mmc_spi_transfert_pos, sd_mmc_spi_wait_busy(), and spi_write_buffer_wait().
|
static |
Referenced by sd_mmc_spi_adtc_start(), sd_mmc_spi_deselect_device(), sd_mmc_spi_init(), sd_mmc_spi_read_word(), sd_mmc_spi_select_device(), sd_mmc_spi_send_clock(), sd_mmc_spi_start_read_block(), sd_mmc_spi_start_read_blocks(), sd_mmc_spi_start_write_block(), sd_mmc_spi_start_write_blocks(), sd_mmc_spi_stop_multiwrite_block(), sd_mmc_spi_stop_read_block(), sd_mmc_spi_stop_write_block(), sd_mmc_spi_wait_busy(), and sd_mmc_spi_write_word().
|
static |
Size block requested by last mci_adtc_start()
Referenced by sd_mmc_spi_adtc_start(), sd_mmc_spi_read_word(), sd_mmc_spi_start_read_block(), sd_mmc_spi_start_read_blocks(), sd_mmc_spi_start_write_block(), sd_mmc_spi_start_write_blocks(), sd_mmc_spi_stop_multiwrite_block(), and sd_mmc_spi_write_word().
|
static |
Slot array of SPI structures.
Referenced by sd_mmc_spi_deselect_device(), sd_mmc_spi_init(), and sd_mmc_spi_select_device().
|
static |
Internal global error status.
Referenced by sd_mmc_spi_adtc_start(), sd_mmc_spi_deselect_device(), sd_mmc_spi_get_errno(), sd_mmc_spi_init(), sd_mmc_spi_read_word(), sd_mmc_spi_select_device(), sd_mmc_spi_send_clock(), sd_mmc_spi_start_read_block(), sd_mmc_spi_start_read_blocks(), sd_mmc_spi_start_write_blocks(), sd_mmc_spi_stop_multiwrite_block(), sd_mmc_spi_stop_write_block(), sd_mmc_spi_wait_end_of_write_blocks(), and sd_mmc_spi_write_word().
|
static |
Total number of block requested by last mci_adtc_start()
Referenced by sd_mmc_spi_adtc_start(), sd_mmc_spi_read_word(), sd_mmc_spi_start_read_blocks(), sd_mmc_spi_start_write_block(), sd_mmc_spi_start_write_blocks(), sd_mmc_spi_stop_multiwrite_block(), and sd_mmc_spi_write_word().
|
static |
32 bits response of the last command
Referenced by sd_mmc_spi_adtc_start(), and sd_mmc_spi_get_response().
|
static |
Current position (byte) of the transfer started by mci_adtc_start()
Referenced by sd_mmc_spi_adtc_start(), sd_mmc_spi_read_word(), sd_mmc_spi_start_read_block(), sd_mmc_spi_start_read_blocks(), sd_mmc_spi_start_write_block(), sd_mmc_spi_start_write_blocks(), sd_mmc_spi_stop_multiwrite_block(), and sd_mmc_spi_write_word().
|
static |
Referenced by sd_mmc_spi_init().
uint8_t ss_pins[SD_MMC_SPI_MEM_CNT] = {SD_MMC_CS} |
Referenced by sd_mmc_spi_init().