Microchip® Advanced Software Framework

sd_mmc_mci.h File Reference
#include "conf_access.h"
#include "compiler.h"
#include "mci.h"
#include "sd_mmc_cmd.h"

Data Structures

struct  card_status_t
 
struct  cid_t
 
struct  csd_t
 
struct  csd_v1_t
 
struct  csd_v2_t
 
struct  ocr_t
 
struct  rep1_t
 
struct  rep2_t
 
struct  rep3_t
 

Macros

#define CARD_INSTALLED   1
 
#define CARD_UNINSTALLED   0
 Card state. More...
 
#define CMD_CLEAR   0x02
 
#define CMD_FULL_ERASE   0x08
 
#define CMD_LOCK   0x01
 
#define CMD_UNLOCK   0x00
 
#define CS_ADR_MISALIGN   (1<<30)
 
#define CS_ADR_OUT_OF_RANGE   (1<<31)
 
#define CS_APP_CMD   (1<<5)
 
#define CS_BLOCK_LEN_ERROR   (1<<29)
 
#define CS_CARD_ECC_FAILED   (1<<21)
 
#define CS_CARD_ERROR   (1<<20)
 
#define CS_CARD_IS_LOCKED   (1<<25)
 
#define CS_CIDCSD_OVERWRITE   (1<<16)
 
#define CS_COM_CRC_ERROR   (1<<23)
 
#define CS_ERASE_PARAM   (1<<27)
 
#define CS_ERASE_RESET   (1<<13)
 
#define CS_ERASE_SEQ_ERROR   (1<<28)
 
#define CS_EXEC_ERROR   (1<<19)
 
#define CS_FLAGERROR_RD_WR   (CS_ADR_OUT_OF_RANGE|CS_ADR_MISALIGN|CS_BLOCK_LEN_ERROR|CS_ERASE_SEQ_ERROR|CS_ILLEGAL_COMMAND|CS_CARD_ERROR)
 Flag error of "Card Status" in R1. More...
 
#define CS_ILLEGAL_COMMAND   (1<<22)
 
#define CS_LOCK_UNLOCK_   (1<<24)
 
#define CS_OVERRUN   (1<<17)
 
#define CS_READY_FOR_DATA   (1<<8)
 
#define CS_SWITCH_ERROR   (1<<7)
 
#define CS_UNDERRUN   (1<<18)
 
#define CS_WP_ERASE_SKIP   (1<<15)
 
#define CS_WP_VIOLATION   (1<<26)
 
#define CSD_BLEN_2048   11
 
#define CSD_BLEN_512   9
 
#define CSD_MSK_CSH   0x03
 
#define CSD_MSK_CSL   0xC0
 
#define CSD_MSK_CSM   0x07
 
#define CSD_MSK_CSMH   0x03
 
#define CSD_MSK_CSML   0x80
 
#define CSD_MSK_RBL   0x0F
 
#define CSD_MSK_RBM   0x20
 
#define CSD_MSK_RBP   0x80
 
#define CSD_MSK_SPEC_VER   0x3C
 
#define CSD_MSK_STRUCT   0xC0
 
#define CSD_MSK_WBH   0xC0
 
#define CSD_MSK_WBL   0x03
 
#define CSD_MSK_WBM   0x40
 
#define CSD_MSK_WBP   0x20
 
#define CSD_REG_SIZE   0x10
 CSD register. More...
 
#define CSD_SPEC_VER_1_0   0x00
 
#define CSD_SPEC_VER_1_4   0x04
 
#define CSD_SPEC_VER_2_0   0x08
 
#define CSD_SPEC_VER_3_1   0x0C
 
#define CSD_SPEC_VER_4_0   0x10
 
#define CSD_STRUCT_1_0   0x00
 
#define CSD_STRUCT_1_1   0x40
 
#define CSD_STRUCT_1_2   0x80
 
#define CSD_STRUCT_SUP   0xC0
 
#define MMC_CARD   0x01
 
#define MMC_CARD_HC   0x20
 
#define MMC_CARD_V4   0x04
 
#define MMC_CLR_WRITE_PROT   29
 
#define MMC_CMD2   2
 illegal in SPI mode ! More...
 
#define MMC_CRC_ON_OFF   59
 Turns CRC check on/off. More...
 
#define MMC_DATA_STATE   ((uint32_t)0x00000A00)
 
#define MMC_DATA_STATE_MSK   ((uint32_t)0xE0040E00)
 
#define MMC_DE_CARD_LOCKED   0x04
 
#define MMC_DE_CC_ERROR   0x02
 
#define MMC_DE_ECC_FAIL   0x04
 
#define MMC_DE_ERROR   0x01
 
#define MMC_DE_MASK   0x1F
 
#define MMC_DE_OUT_OF_RANGE   0x04
 
#define MMC_DR_ACCEPT   0x05
 
#define MMC_DR_MASK   0x1F
 
#define MMC_DR_REJECT_CRC   0x0B
 
#define MMC_DR_REJECT_WRITE_ERROR   0x0D
 
#define MMC_ERASE   38
 Perform block/mass erase. More...
 
#define MMC_GO_IDLE_STATE   0
 initialize card to SPI-type access More...
 
#define MMC_LOCK_UNLOCK   42
 To start a lock/unlock/pwd operation. More...
 
#define MMC_PROGRAM_CSD   27
 
#define MMC_R1_ADDRESS   0x20
 
#define MMC_R1_BUSY   0x80
 R1 response: bit indicates card is busy. More...
 
#define MMC_R1_COM_CRC   0x08
 
#define MMC_R1_ERASE_RESET   0x02
 
#define MMC_R1_ERASE_SEQ   0x10
 
#define MMC_R1_IDLE_STATE   0x01
 
#define MMC_R1_ILLEGAL_COM   0x04
 
#define MMC_R1_PARAMETER   0x40
 
#define MMC_RCV_STATE   ((uint32_t)0x00000A00)
 
#define MMC_RCV_STATE_MSK   ((uint32_t)0xE0020E00)
 
#define MMC_READ_SINGLE_BLOCK   17
 read a block More...
 
#define MMC_SEND_CID   10
 get card's CID More...
 
#define MMC_SEND_CSD   9
 get card's CSD More...
 
#define MMC_SEND_OP_COND   1
 set card operational mode More...
 
#define MMC_SEND_STATUS   13
 
#define MMC_SEND_WRITE_PROT   30
 
#define MMC_SET_BLOCKLEN   16
 Set number of bytes to transfer per block. More...
 
#define MMC_SET_WRITE_PROT   28
 
#define MMC_STARTBLOCK_MWRITE   0xFC
 
#define MMC_STARTBLOCK_READ   0xFE
 when received from card, indicates that a block of data will follow More...
 
#define MMC_STARTBLOCK_WRITE   0xFE
 when sent to card, indicates that a block of data will follow More...
 
#define MMC_STBY_STATE   ((uint32_t)0x00000600)
 
#define MMC_STBY_STATE_MSK   ((uint32_t)0x01D81E00)
 MMC Status Mask. More...
 
#define MMC_STOPTRAN_WRITE   0xFD
 
#define MMC_SWITCH_BUS_WIDTH   ((uint8_t)183)
 
#define MMC_SWITCH_CMD_SET   ((uint8_t)03)
 
#define MMC_SWITCH_HIGH_SPEED   ((uint8_t)185)
 
#define MMC_SWITCH_VAL_1BIT   ((uint8_t)00)
 
#define MMC_SWITCH_VAL_4BIT   ((uint8_t)01)
 
#define MMC_SWITCH_VAL_8BIT   ((uint8_t)02)
 
#define MMC_SWITCH_VAL_HS   ((uint8_t)01)
 
#define MMC_SWITCH_VAL_LS   ((uint8_t)00)
 
#define MMC_SWITCH_WRITE   ((uint8_t)03)
 
#define MMC_TAG_ERASE_GROUP_END   36
 Sets end of erase group (mass erase) More...
 
#define MMC_TAG_ERASE_GROUP_START   35
 Sets beginning of erase group (mass erase) More...
 
#define MMC_TAG_SECTOR_END   33
 
#define MMC_TAG_SECTOR_START   32
 
#define MMC_TRAN_STATE   ((uint32_t)0x00000800)
 
#define MMC_TRAN_STATE_MSK   ((uint32_t)0xE0020E00)
 
#define MMC_UNTAG_ERASE_GROUP   37
 Untag (unset) erase group (mass erase) More...
 
#define MMC_UNTAG_SECTOR   34
 
#define MMC_WRITE_BLOCK   24
 write a block More...
 
#define OCR_MSK_BUSY   0x80000000
 OCR register. More...
 
#define OCR_MSK_HC   0x40000000
 
#define OCR_MSK_VOLTAGE_3_2V_3_3V   0x00100000
 
#define OCR_MSK_VOLTAGE_ALL   0x00FF8000
 
#define RCA_DEFAULT_ADR   0x0001FFFF
 
#define RCA_MSK_ADR   0xFFFF0000
 
#define RCA_RESERVE_ADR   0x00000000
 RCA register. More...
 
#define SD_APP_CMD55   55
 Use before any specific command (type ACMD) More...
 
#define SD_BUS_1_BIT   MCI_BUS_SIZE_1_BIT
 SD bus width. More...
 
#define SD_BUS_4_BIT   MCI_BUS_SIZE_4_BIT
 
#define SD_BUS_8_BIT   MCI_BUS_SIZE_8_BIT
 
#define SD_CARD   0x02
 
#define SD_CARD_HC   0x10
 
#define SD_CARD_V2   0x08
 
#define SD_MMC_SECTOR_BITS   9
 Number of bits for addresses within sectors. More...
 
#define SD_MMC_SECTOR_SIZE   (1 << SD_MMC_SECTOR_BITS)
 Sector size in bytes. More...
 
#define SD_SEND_OP_COND_ACMD   41
 Same as MMC_SEND_OP_COND but specific to SD (must be preceded by CMD55) More...
 
#define SD_TAG_WR_ERASE_GROUP_END   33
 
#define SD_TAG_WR_ERASE_GROUP_START   32
 
#define UNKNOWN_CARD   0x00
 Card identification. More...
 

Functions

Control Functions
bool sd_mmc_mci_init (unsigned char card_slot, long pbb_hz, long cpu_hz)
 Initializes the MCI driver. More...
 
bool sd_mmc_mci_card_init (unsigned char card_slot)
 Initializes the SD/MMC card. More...
 
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...
 
bool sd_mmc_mci_mem_check (uint8_t slot)
 Performs a memory check. More...
 
bool sd_mmc_mci_read_open (uint8_t slot, uint32_t sector, uint16_t nb_sector)
 Opens a DF memory in read mode at a given sector. More...
 
bool sd_mmc_mci_dma_read_open (uint8_t slot, uint32_t sector, 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_read_close (uint8_t slot)
 Unselects the current DF memory. More...
 
bool sd_mmc_mci_write_open (uint8_t slot, uint32_t sector, uint16_t nb_sector)
 This function opens a DF memory in write mode at a given sector. More...
 
bool sd_mmc_mci_dma_write_open (uint8_t slot, uint32_t sector, 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_write_close (uint8_t slot)
 Fills the end of the current logical sector and launches page programming. More...
 
Multiple-Sector Access Functions
bool sd_mmc_mci_read_multiple_sector (uint8_t slot, uint16_t nb_sector)
 Reads nb_sector sectors from DF memory. More...
 
void sd_mmc_mci_read_multiple_sector_callback (const void *psector)
 Callback function invoked after each sector read during sd_mmc_mci_read_multiple_sector. More...
 
bool sd_mmc_mci_write_multiple_sector (uint8_t slot, uint16_t nb_sector)
 Writes nb_sector sectors to SD/MMC memory. More...
 
void sd_mmc_mci_write_multiple_sector_callback (void *psector)
 Callback function invoked before each sector write during sd_mmc_mci_write_multiple_sector. 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_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_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_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...
 
Single-Sector Access Functions
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_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_write_sector_from_ram (uint8_t slot, const void *ram)
 Writes 1 SD/MMC sector from a RAM buffer. 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...
 
Protection Access Functions
bool sd_mmc_mci_lock_unlock (uint8_t slot, uint8_t cmd, uint8_t pwd_len, uint8_t *password)
 This function sends lock/unlock commands for sd or mmc. More...
 
bool is_sd_mmc_mci_locked (uint8_t slot)
 Get sd status register and look if card is locked by a password. More...
 
bool sd_mmc_mci_lock_unlock_failed (uint8_t slot)
 Get sd status register and look if the lock/unlock command was ok. More...
 
bool sd_mmc_mci_cmd_send_status (uint8_t slot)
 ask mmc status register. More...