Microchip® Advanced Software Framework

sd_mmc_spi.c File Reference

Common SPI interface for SD/MMC stack.

Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.

#include <compiler.h>
#include <status_codes.h>
#include <board.h>
#include <string.h>
#include "conf_board.h"
#include "conf_sd_mmc.h"
#include "sd_mmc_protocol.h"
#include "sd_mmc_spi.h"
#include "sd_mmc.h"
#include "ioport.h"
#include <spi_master.h>

Macros

#define driver   spi
 
#define SD_MMC_SPI_CS(slot, unused)   { .id = SD_MMC_SPI_##slot##_CS},
 
#define sd_mmc_spi_debug(...)
 
#define sd_mmc_spi_drv_deselect_device   ATPASTE2(driver, _deselect_device)
 
#define sd_mmc_spi_drv_device   ATPASTE2(driver, _device)
 
#define sd_mmc_spi_drv_read_packet   ATPASTE2(driver, _read_packet)
 
#define sd_mmc_spi_drv_select_device   ATPASTE2(driver, _select_device)
 
#define sd_mmc_spi_drv_setup_device   ATPASTE2(driver, _setup_device)
 
#define sd_mmc_spi_drv_write_packet   ATPASTE2(driver, _write_packet)
 
#define spi_setup_device   spi_master_setup_device
 

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 uint16_t sd_mmc_spi_block_size
 Size block requested by last mci_adtc_start() More...
 
static struct sd_mmc_spi_drv_device sd_mmc_spi_devices []
 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...
 

#define SD_MMC_SPI_CS (   slot,
  unused 
)    { .id = SD_MMC_SPI_##slot##_CS},