Microchip® Advanced Software Framework

sd_mmc_mci.c File Reference
#include "conf_access.h"
#include <stdio.h>
#include "gpio.h"
#include "mci.h"
#include "conf_sd_mmc_mci.h"
#include "sd_mmc_mci.h"
#include "cycle_counter.h"
#include "conf_usb.h"
#include "usb_drv.h"
#include "scsi_decoder.h"

Macros

#define SDMMC_SWITCH_FUNC_G1_KEEP   (0xf << 0)
 
#define SDMMC_SWITCH_FUNC_G2_KEEP   (0xf << 4)
 
#define SDMMC_SWITCH_FUNC_G3_KEEP   (0xf << 8)
 
#define SDMMC_SWITCH_FUNC_G4_KEEP   (0xf << 12)
 
#define SDMMC_SWITCH_FUNC_G5_KEEP   (0xf << 16)
 
#define SDMMC_SWITCH_FUNC_G6_KEEP   (0xf << 20)
 
#define SDMMC_SWITCH_FUNC_HIGH_SPEED   (1 << 0)
 
#define SDMMC_SWITCH_FUNC_MODE_CHECK   (0 << 31)
 
#define SDMMC_SWITCH_FUNC_MODE_SWITCH   (1 << 31)
 

Functions

static void dma_mci_2_ram (void *ram, size_t size)
 
static void dma_ram_2_mci (const void *ram, size_t size)
 
static void dma_ram_2_usb (const void *ram, size_t size)
 
static void dma_usb_2_ram (void *ram, size_t size)
 
static bool is_dma_mci_2_ram_complete (void)
 
static bool is_dma_ram_2_mci_complete (void)
 
static bool is_dma_ram_2_usb_complete (void)
 
static bool is_dma_usb_2_ram_complete (void)
 
bool is_sd_mmc_mci_card_present (uint8_t slot)
 Performs a card check presence. More...
 
bool is_sd_mmc_mci_card_protected (uint8_t slot)
 Performs a card check protection. More...
 
static bool sd_mmc_get_ext_csd (uint8_t slot)
 
bool sd_mmc_mci_card_init (unsigned char slot)
 Initializes the SD/MMC card. More...
 
bool sd_mmc_mci_cmd_send_status (uint8_t slot)
 ask mmc status register. More...
 
bool sd_mmc_mci_dma_read_multiple_sector_2_ram (uint8_t slot, void *ram, uint32_t nb_sector)
 Reads nb_sector SD/MMC sector to a RAM buffer, using the DMA. More...
 
bool sd_mmc_mci_dma_read_open (uint8_t slot, uint32_t pos, void *ram, uint16_t nb_sector)
 Opens a DF memory in read mode at a given sector. DMA will be used. More...
 
bool sd_mmc_mci_dma_read_sector_2_ram (uint8_t slot, void *ram)
 Reads 1 SD/MMC sector to a RAM buffer, using the DMA. More...
 
bool sd_mmc_mci_dma_write_multiple_sector_from_ram (uint8_t slot, const void *ram, uint32_t nb_sector)
 Writes nb_sector SD/MMC sector from a RAM buffer, using the DMA. More...
 
bool sd_mmc_mci_dma_write_open (uint8_t slot, uint32_t pos, const void *ram, uint16_t nb_sector)
 This function opens a DF memory in write mode at a given sector. DMA will be used. More...
 
bool sd_mmc_mci_dma_write_sector_from_ram (uint8_t slot, const void *ram)
 Writes 1 SD/MMC sector from a RAM buffer, using the DMA. More...
 
static bool sd_mmc_mci_get_csd (uint8_t slot)
 
bool sd_mmc_mci_init (unsigned char card_slot, long pbb_hz, long cpu_hz)
 Initializes the MCI driver. More...
 
bool sd_mmc_mci_mem_check (uint8_t slot)
 Performs a memory check. More...
 
bool sd_mmc_mci_read_close (uint8_t slot)
 Unselects the current DF memory. More...
 
bool sd_mmc_mci_read_multiple_sector (uint8_t slot, uint16_t nb_sector)
 Reads nb_sector sectors from DF memory. More...
 
bool sd_mmc_mci_read_multiple_sector_2_ram (uint8_t slot, void *ram, uint32_t nb_sector)
 Reads nb_sector SD/MMC sector to a RAM buffer. More...
 
bool sd_mmc_mci_read_open (uint8_t slot, uint32_t pos, uint16_t nb_sector)
 Opens a DF memory in read mode at a given sector. More...
 
bool sd_mmc_mci_read_sector_2_ram (uint8_t slot, void *ram)
 Reads 1 SD/MMC sector to a RAM buffer. More...
 
bool sd_mmc_mci_write_close (uint8_t slot)
 Fills the end of the current logical sector and launches page programming. More...
 
bool sd_mmc_mci_write_multiple_sector (uint8_t slot, uint16_t nb_sector)
 Writes nb_sector sectors to SD/MMC memory. More...
 
bool sd_mmc_mci_write_multiple_sector_from_ram (uint8_t slot, const void *ram, uint32_t nb_sector)
 Writes nb_sector SD/MMC sector from a RAM buffer. More...
 
bool sd_mmc_mci_write_open (uint8_t slot, uint32_t pos, uint16_t nb_sector)
 This function opens a DF memory in write mode at a given sector. More...
 
bool sd_mmc_mci_write_sector_from_ram (uint8_t slot, const void *ram)
 Writes 1 SD/MMC sector from a RAM buffer. More...
 
static bool sd_mmc_set_block_len (uint8_t slot, uint16_t length)
 

Variables

uint8_t g_card_bus_width [MCI_NR_SLOTS]
 
uint16_t g_card_freq [MCI_NR_SLOTS]
 
uint32_t g_card_rca [MCI_NR_SLOTS]
 
uint32_t g_card_size [MCI_NR_SLOTS]
 SD/MMC Card Size per Slot. More...
 
uint8_t g_card_type [MCI_NR_SLOTS]
 
static uint32_t g_cpu_hz = 0
 
static uint32_t g_pbb_hz = 0
 
volatile uint32_t gl_ptr_mem [MCI_NR_SLOTS] ={0, 0}
 
volatile avr32_mci_t * mci = &AVR32_MCI
 
bool sd_mmc_mci_init_done [MCI_NR_SLOTS] = {false, false}
 Initialization sequence status per Slot. More...
 
COMPILER_WORD_ALIGNED uint8_t sector_buf_0 [SD_MMC_SECTOR_SIZE]
 
COMPILER_WORD_ALIGNED uint8_t sector_buf_1 [SD_MMC_SECTOR_SIZE]
 

#define SDMMC_SWITCH_FUNC_G1_KEEP   (0xf << 0)
#define SDMMC_SWITCH_FUNC_G2_KEEP   (0xf << 4)

Referenced by sd_mmc_mci_card_init().

#define SDMMC_SWITCH_FUNC_G3_KEEP   (0xf << 8)

Referenced by sd_mmc_mci_card_init().

#define SDMMC_SWITCH_FUNC_G4_KEEP   (0xf << 12)

Referenced by sd_mmc_mci_card_init().

#define SDMMC_SWITCH_FUNC_G5_KEEP   (0xf << 16)

Referenced by sd_mmc_mci_card_init().

#define SDMMC_SWITCH_FUNC_G6_KEEP   (0xf << 20)

Referenced by sd_mmc_mci_card_init().

#define SDMMC_SWITCH_FUNC_HIGH_SPEED   (1 << 0)

Referenced by sd_mmc_mci_card_init().

#define SDMMC_SWITCH_FUNC_MODE_CHECK   (0 << 31)

Referenced by sd_mmc_mci_card_init().

#define SDMMC_SWITCH_FUNC_MODE_SWITCH   (1 << 31)

Referenced by sd_mmc_mci_card_init().

static void dma_mci_2_ram ( void *  ram,
size_t  size 
)
static
static void dma_ram_2_mci ( const void *  ram,
size_t  size 
)
static
static bool is_dma_mci_2_ram_complete ( void  )
static
static bool is_dma_ram_2_mci_complete ( void  )
static
static bool is_dma_ram_2_usb_complete ( void  )
static
static bool is_dma_usb_2_ram_complete ( void  )
static

uint32_t g_card_size[MCI_NR_SLOTS]

SD/MMC Card Size per Slot.

Referenced by sd_mmc_get_ext_csd(), sd_mmc_mci_get_csd(), and sd_mmc_mci_read_capacity().

uint32_t g_cpu_hz = 0
static
uint32_t g_pbb_hz = 0
static
bool sd_mmc_mci_init_done[MCI_NR_SLOTS] = {false, false}

Initialization sequence status per Slot.

Referenced by sd_mmc_mci_card_init(), sd_mmc_mci_mem_check(), and sd_mmc_mci_test_unit_ready().