📄 mmc_base.h
字号:
#define SPI_GO_IDLE_STATE (MMC_CMD0 | MMC_RSP1 |MMC_AC)
#define SPI_SEND_OP_COND (MMC_CMD1 | MMC_RSP1 |MMC_AC)
#define SPI_SEND_CSD (MMC_CMD9 | MMC_RSP1 |MMC_ADTC)
#define SPI_SEND_CID (MMC_CMD10 | MMC_RSP1 |MMC_ADTC)
#define SPI_STOP_TRANSMISSION (MMC_CMD12 | MMC_RSP1 |MMC_AC)
#define SPI_SEND_STATUS (MMC_CMD13 | MMC_RSP2 |MMC_AC)
/* ============================================================== */
/* Default MMCCON register value */
#define MMC_MMCCON_DEFAULT (0X0000)
/* MMCCON field values */
//#define MMCCON_CLK_400K (0x005D) //VALUE OF CLK DIV//400Khz
#define MMCCON_CLK_400K (0x0078) //VALUE OF CLK DIV//400Khz
#define MMCCON_CLK_200K (0x00F0) //VALUE OF CLK DIV//200Khz
#define MMCCON_CLK_24M (0X0002) //VALUE OF CLK DIV24Mhz
#define MMCCON_CLK_16M (0X0003) //VALUE OF CLK DIV16Mhz
#define MMCCON_BE (0X0400) //Big Endian Mode
#define MMCCON_PWRUP (0X0800) //MMC Powered Up
#define MMCCON_NATIVE (0X0000) //MMC MODE PROTOCOL
#define MMCCON_SPI1 (0X1000) //SERIAL FLASH OR SPI SLAVE DEVICES
#define MMCON_SYSTEST (0X2000) //SYSTEST MODE USING DMA
#define MMCON_SPI2 (0X3000) //MMC/SD CARDS USING SPI PROTOCOL
#define MMCCON_DW1 (0X0000) //Data Bus Width =1
#define MMCCON_DW4 (0X8000) //Data Bus Width =4
/* Default MMCCTO register value */
#define MMC_MMCCTO_DIS (0X0000) //NO TIME OUT CONDITION
#define MMC_MMCCTO_MAX (0x00FD)
/* Default MMCDTO register value */
#define MMC_MMCDTO_DIS (0X0000)
/* Default MMCIE register value */
#define MMC_MMCIE_DEFAULT (0x0000)
/* MMCIE field values */
#define MMC_MMCIE_EOCIE (0X0001)
#define MMC_MMCIE_CARDETECTIE (0X0002) //NEW
#define MMC_MMCIE_ENTR_BSYIE (0X0004)
#define MMC_MMCIE_BLK_RSIE (0X0008)
#define MMC_MMCIE_EXT_BSYIE (0X0010)
#define MMC_MMCIE_DAT_TOIE (0X0020)
#define MMC_MMCIE_DATCRC_ERRIE (0X0040)
#define MMC_MMCIE_CMD_TOIE (0X0080)
#define MMC_MMCIE_CMDCRC_ERRIE (0X0100)
#define MMC_MMCIE_SDIO_WAITIE (0X0200)
#define MMC_MMCIE_BUF_AFIE (0X0400)
#define MMC_MMCIE_BUF_AEIE (0X0800)
#define MMC_MMCIE_OCR_BSYIE (0X1000)
#define MMC_MMCIE_CRDIRQ_RCVIE (0X2000)
#define MMC_MMCIE_CRD_ERRIE (0X4000)
#define MMC_MMCIE_SDIRQIE (0X8000)//NEW
/* Default MMCNBLK register value */
#define MMC_MMCNBLK_ONE (0x0000)
/* Default MMCSPI register value */
#define MMC_MMCSPI_DEFAULT (0x0000)
/* MMCSPI field values */
#define MMC_MMCSPI_POL_FALL (0x0001)
#define MMC_MMCSPI_PHA_0 (0x0002)
#define MMC_MMCSPI_CS_HIGH (0x0004)
#define MMC_MMCSPI_CSMODE_MANUAL (0x0008)
#define MMC_MMCSPI_CSCTRL_CS0 (0x0000)
#define MMC_MMCSPI_TCSS_1 (0x0000)
#define MMC_MMCSPI_TCSH_HALF (0x0000)
#define MMC_MMCSPI_DEC_ON_READ (0x0000)
#define MMC_MMCSPI_DEC_ON_WRITE (0x0400)
#define MMC_MMCSPI_START_SPI (0x8000)
/* Default MMCSTAT register value */
#define MMC_MMCSTAT_DEFAULT (0X0000)
/* MMCSTAT field values */
#define MMC_MMCSTAT_CRD_ERR (0X4000)
#define MMC_MMCSTAT_CRDIRQ_RCV (0X2000)
#define MMC_MMCSTAT_OCR_BSY (0X1000)
#define MMC_MMCSTAT_BUF_AE (0X0800)
#define MMC_MMCSTAT_BUF_AF (0X0400)
#define MMC_MMCSTAT_SDIO_WAIT (0X0200)
#define MMC_MMCSTAT_CMDCRC_ERR (0X0100)
#define MMC_MMCSTAT_CMD_TO (0X0080)
#define MMC_MMCSTAT_DATCRC_ERR (0X0040)
#define MMC_MMCSTAT_DAT_TO (0X0020)
#define MMC_MMCSTAT_EXT_BSY (0X0010)
#define MMC_MMCSTAT_BLK_RS (0X0008)
#define MMC_MMCSTAT_ENTR_BSY (0X0004)
#define MMC_MMCSTAT_CRDDETECT (0X0002)
#define MMC_MMCSTAT_EOC (0X0001)
/*================================================*/
struct MMC_CardId{
Uint8 mfgId; /* 8 bit Manufacturer抯 ID */
char productName[6]; /* 7 character Product Name */
Uint16 hwRev; /* 4 bit Hardware Revision Number */
Uint16 fwRev; /* 4 bit Firmware Revision Number */
char serialNumber[4]; /* 24 bit Serial Number */
Uint16 monthCode; /* 4 bit Manufacturing Date (Month) */
Uint16 yearCode; /* 4 bit Manufacturing Date (Year) */
Uint16 dayCode; /* 4 bit Manufacturing Date (Day) */
Uint16 CRC; /* 7 bit crc */
Uint32 AppID;
Uint32 SDuniqueID;
Uint32 MMCv3uniqueID;
} ;
struct MMC_CardCsd{
Uint16 eraseBlkLen;
Uint16 eraseSectorSize;
Uint16 csdStructure; /* 2 bit structure type field */
Uint16 mmcProt; /* 2 bit MMC protocol */
Uint16 taac; /* 8 bit TAAC */
Uint16 nsac; /* 8 bit NSAC */
Uint16 tranSpeed; /* 8 bit max data transmission speed */
Uint16 ccc; /* 12 bit card command classes */
Uint16 readBlLen; /* 4 bit maximum Read Block Length */
Uint16 readBlPartial; /* 1 bit indicates if partial read blocks allowed */
Uint16 writeBlkMisalign; /* 1 bit flag indicates write block misalignment */
Uint16 readBlkMisalign; /* 1 bit flag indicates read block misalignment */
Uint16 dsrImp; /* 1 bit flag indicates whether card has DSR reg */
Uint16 cSize; /* 12 bit device size */
Uint16 vddRCurrMin; /* 3 bit Max. Read Current @ Vdd Min */
Uint16 vddRCurrMax; /* 3 bit Max. Read Current @ Vdd Max */
Uint16 vddWCurrMin; /* 3 bit Max. Write Current @ Vdd Min */
Uint16 vddWCurrMax; /* 3 bit Max. Write Current @ Vdd Max */
Uint16 cSizeMult; /* 3 bit device size multiplier */
Uint16 eraseGrpMult; /* 5 bit erase sector size */
Uint16 eraseGrpSize; /* 5 bit erase group size */
Uint16 wpGrpSize; /* 5 bit write protect group size */
Uint16 wpGrpEnable; /* 1 bit write protect enable flag */
Uint16 defaultEcc; /* 2 bit Manufacturer Default ECC */
Uint16 r2wFactor; /* 3 bit stream write factor */
Uint16 writeBlLen; /* 4 bit maximum write block length */
Uint16 writeBlPartial; /* 1 bit indicates if partial write blocks allowed */
Uint16 copy; /* 1 bit copy flag */
Uint16 permWriteProtect; /* 1 bit to dis/en-able permanent write protection */
Uint16 tmpWriteProtect; /* 1 bit to dis/en-able temporary write protection */
//Uint16 ecc; /* 2 bit ECC code */
Uint16 crc; /* 7 bit r/w/e redundancy check */
} ;
struct MMC_CardXCsd {
Uint16 securitySysId; /* Security System ID */
Uint16 securitySysVers; /* Security System Version */
Uint16 maxLicenses; /* Maximum number of storable licenses */
Uint32 xStatus; /* Extended status bits */
} ;
//typedef enum
//{idle=0, ready, ident, stby, tran, data, rcv, prg, dis ,resv }CARD_STATE;
//card_status
struct MMC_CardStatus{
Uint16 ready; /*ready for data correspondence?*/
//CARD_STATE state; /*current card state*/
Uint16 state; /*current card state*/
Uint16 erase_clrd;
Uint16 erase_partial; /*only partial address space was cleaned
because of some write prot in b/w ?*/
Uint16 error_flags; /*SD specific error flags*/
Uint16 error_auth; /*SD specific error flags*/
} ;
/*
//SD Card Status
struct SD_CardStatus{
Uint16 BusWidth ;
Uint16 SecuredMode ;
Uint16 CardType ;
Uint32 ProtAreaSize;
};
struct SD_Scr{
Uint16 SCR_Ver ;
Uint16 SD_Ver;
Uint16 Post_eraseState;
Uint16 SecurityAlgo;
Uint16 BusWidth;
};
*/
typedef enum
{CARD_TYPE_MMC=0, CARD_TYPE_SD, SCARD_TYPE_DLV, CARD_TYPE_SDIO, CARD_TYPE_COMBO}CARD_TYPE;
struct MMC_Card {
CARD_TYPE cardtype; /* media type MMC ,SD, SDLV,SDIO,COMBO*/
Uint32 cardRCA; /* User/Card assigned relative card address (RCA)*/
Uint16 status; /* Last read status value */
//Uint16 cardIndex; /* MMC module assignd index for card */
Uint32 maxXfrRate; /* Maximum transfer rate */
Uint32 readAccessTime; /* TAAC - exp * mantissa */
Uint32 cardCapacity; /* Total memory available on card */
Uint32 lastAddrRead; /* Last Address Read from memory card */
Uint32 cardOCR; /*OCR Register*/
Uint32 lastAddrWritten; /* Last Address written to on memory card */
struct MMC_CardId cidptr; /* Manufacturers Card ID */
struct MMC_CardCsd csdptr; /* Card specific data */
struct MMC_CardXCsd xcsd; /* Extended CSD */
struct MMC_CardStatus cstatus; /*Card_staus*/
} ;
struct MMC_Cfg
{
Uint16 mmccmd;
Uint16 mmccon;
Uint16 mmcie;
Uint16 mmcdto;
Uint16 mmccto;
Uint16 mmcblen;
Uint16 mmcnblk;
Uint16 mmcbuf;
};
/*
* MMC error codes
*/
#define MMC_ERR_OK 0 /* OK! go ahead */
#define MMC_ERR_CRC 2000 /* CRC error */
#define MMC_ERR_TIMEOUT 2001 /* overrun out of max. of Number of cycles */
#define MMC_ERR_R1 2002 /* R1 error */
#define MMC_ERR_BUSY 2003 /* busy! waiting... */
#endif /* _MMC_BASE_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -