mmcsd.h
来自「老外的一个开源项目」· C头文件 代码 · 共 611 行 · 第 1/2 页
H
611 行
RES2,
RES3,
RES4,
RES5,
RES6,
RES7
} CARD_STATE;
#define OUT_OF_RANGE_ERROR 0x80000000 /* Bit 31 */
#define ADDRESS_ERROR 0x40000000 /* Bit 30 */
#define BLK_LENGTH_ERROR 0x20000000 /* Bit 29 */
#define ERASE_SEQ_ERROR 0x10000000 /* Bit 28 */
#define ERASE_PARAM 0x08000000 /* Bit 27 */
#define WP_VIOLATION 0x04000000 /* Bit 26 */
#define CARD_IS_LOCKED 0x02000000 /* Bit 25 */
#define LOCK_UNLOCK_FAILED 0x01000000 /* Bit 24 */
#define CMD_CRC_ERROR 0x00800000 /* Bit 23 */
#define COMUNC_ILLEG_COM 0x00400000 /* Bit 22 */
#define CARD_ECC_FAILED 0x00200000 /* Bit 21 */
#define CONTROLLER_ERROR 0x00100000 /* Bit 20 */
#define EERROR 0x00080000 /* Bit 19 */
#define UNDERRUN 0x00040000 /* Bit 18 */
#define OVERRUN 0x00020000 /* Bit 17 */
#define CIDCSD_OVERWRITE 0x00010000 /* Bit 16 */
#define WP_ERASE_SKIP 0x00008000 /* Bit 15 */
#define CARD_ECC_DISABLED 0x00004000 /* Bit 14 */
#define ERASE_RESET 0x00002000 /* Bit 13 */
/* MMC Card specific Data structure */
typedef struct _mmcCSD
{
unsigned CSD_Structure : 2;
unsigned MMC_Protocol_Ver : 4;
unsigned CSD_reserved0 : 2;
unsigned CSD_TimeAccess1 : 8;
unsigned CSD_TimeAccess2 : 8;
unsigned CSD_TransferRate : 8;
unsigned CSD_BlockLength : 4;
unsigned CSD_CmdClass : 12;
unsigned CSD_CSize1: 10;
unsigned CSD_reserved1 : 2;
unsigned CSD_DSR : 1;
unsigned CSD_ReadMisalign : 1;
unsigned CSD_WriteMisalign : 1;
unsigned CSD_PartialSize : 1;
unsigned CSD_EraseSecSize : 1;
unsigned CSD_VDDReadMin1 : 2;
unsigned CSD_VDDReadMax : 3;
unsigned CSD_VDDWriteMin : 3;
unsigned CSD_VDDWriteMax : 3;
unsigned CSD_CSizeMult : 3;
unsigned CSD_CSize2: 2;
unsigned CSD_WPGrpSize : 5;
unsigned CSD_EraseGrpSize : 5;
unsigned CSD_SectorSize : 5;
unsigned CSD_VDDReadMin2 : 1;
unsigned CSD_Res2 : 5;
unsigned CSD_WrBlockPartial : 1;
unsigned CSD_WrDataBlockLn : 4;
unsigned CSD_WrSpeedFactor : 3;
unsigned CSD_DefaultECC : 2;
unsigned CSD_WPGrpEnable : 1;
unsigned CSD_Error : 1;
unsigned CSD_CRC : 7;
unsigned CSD_Res3 : 2;
unsigned CSD_FileFmt : 2;
unsigned CSD_TempWRProtect : 1;
unsigned CSD_PermWRProtect : 1;
unsigned CSD_Copy : 1;
unsigned CSD_FileFmtGrp : 1;
} MMCCSDFields;
/* MMC Card identification structure */
typedef struct _mmcCID
{
unsigned manufact_ID0 : 8; /* Manufacturer ID */
unsigned manufact_ID1 : 16; /* Manufacturer ID */
unsigned product_name0 : 8; /* Card product name */
unsigned product_name1 : 16;
unsigned product_name2 : 16;
unsigned product_name3 : 16;
unsigned fw_revision : 4; /* Firmware revision */
unsigned hw_revision : 4; /* Hardware revision */
unsigned ser_numb0 :8; /* serial number */
unsigned ser_numb1 :16;
unsigned year_code : 4; /* date manufacture */
unsigned month_code : 4; /* date manufacture */
unsigned stop_bit : 1; /* Always 1 */
unsigned crc7: 7; /* CRC7 checksum */
} MMCCIDFields;
/* SD Card specific Data structure. Align on 16-bit length */
typedef struct _sdCSD
{
unsigned CSD_Structure : 2;
unsigned CSD_reserved0 : 6;
unsigned CSD_TimeAccess1 : 8;
unsigned CSD_TimeAccess2 : 8;
unsigned CSD_TransferRate : 8;
unsigned CSD_CmdClass0 : 8;
unsigned CSD_BlockLength : 4;
unsigned CSD_CmdClass1 : 4;
unsigned CSD_CSize0: 2;
unsigned CSD_reserved1 : 2;
unsigned CSD_DSR : 1;
unsigned CSD_ReadMisalign : 1;
unsigned CSD_WriteMisalign : 1;
unsigned CSD_PartialSize : 1;
unsigned CSD_CSize1: 10;
unsigned CSD_VDDReadMax : 3;
unsigned CSD_VDDReadMin1 : 3;
unsigned CSD_VDDWriteMax : 3;
unsigned CSD_VDDWriteMin : 3;
unsigned CSD_CSizeMult : 2;
unsigned CSD_SectorSize : 7;
unsigned CSD_EraseBlkEn : 1;
unsigned CSD_CSizeMultL : 1;
unsigned CSD_WPGrpSize : 7;
unsigned CSD_SectorSizeL : 1;
unsigned CSD_WrDataBlockLnH : 2;
unsigned CSD_WrSpeedFactor : 3;
unsigned CSD_Res2 : 2;
unsigned CSD_WPGrpEnable : 1;
unsigned CSD_WrDataBlockLnL : 2;
unsigned CSD_WrBlockPartial : 1;
unsigned CSD_Res3 : 5;
unsigned CSD_Res4 : 2;
unsigned CSD_FileFmt : 2;
unsigned CSD_TempWRProtect : 1;
unsigned CSD_PermWRProtect : 1;
unsigned CSD_Copy : 1;
unsigned CSD_FileFmtGrp : 1;
unsigned CSD_Error : 1;
unsigned CSD_CRC : 7;
} SDCSDFields;
typedef struct _sdCID
{
unsigned manufact_ID : 8; /* Manufacturer ID */
unsigned OEM_ID0 : 16; /* OEM/Application ID */
unsigned product_name0 : 8; /* Card product name */
unsigned product_name1 : 16;
unsigned product_name2 : 16;
unsigned product_revision : 8; /* Hardware and firmware revision */
unsigned ser_numb0 :16; /* serial number */
unsigned ser_numb1 :16;
unsigned stop_bit : 1; /* Always 1 */
unsigned crc7: 7; /* CRC7 checksum */
unsigned date_code : 8; /* date manufacture */
} SDCIDFields;
typedef union _myCIDFields {
MMCCIDFields mCID; /* MMC card */
SDCIDFields sCID; /* SD card */
} CIDFields;
typedef union _myCSDFields {
MMCCSDFields mCSD; /* MMC card */
SDCSDFields sCSD; /* SD card */
} CSDFields;
#define SINGLE_BUS_WIDTH 1
#define DOUBLE_BUS_WIDTHH 2
#define QUARUPLE_BUS_WIDTH 4
/* SD Configuration register */
typedef struct _mySCR
{
unsigned sd_spec : 4; /* SD specification */
unsigned scr_structure : 4; /* SCR structure */
unsigned sd_bwidth : 4; /* Data bus width */
unsigned sd_security : 3; /* SD security */
unsigned sd_data_stat : 1; /* Data status after erase */
unsigned scr_reserved0 : 2;
unsigned scr_reserved1 : 16;
unsigned card_manufacturer0 : 16; /* For manufacturer usage */
unsigned card_manufacturer1 : 16;
} SCRFields;
/* SD STATUS structure */
typedef struct _mySDSTATUS
{
unsigned sd_bwidth : 2; /* Data bus width */
unsigned secured_mode : 1; /* Secured mode */
unsigned sreserved0 : 5; /* Reserved */
unsigned sreserved1 : 8;
unsigned sd_type : 16;
unsigned prt_size1 : 16; /* Size of protected area */
unsigned prt_size2 : 16;
UINT16 data[28]; /* reserved */
} SDSTATUSFields;
typedef struct drive_desc
{
ULONG total_lba;
UINT16 num_heads;
UINT16 sec_p_track;
UINT16 num_cylinders;
UINT16 block_size;
UINT16 RCA; // Relative card address
UINT32 card_type; // Card type - SPI, MMC, SD etc
UINT32 securedAreaSize;
UINT16 securityDrv;
UINT16 busWidth;
UINT16 erasedSize;
} DRIVE_DESC, *PDRIVE_DESC;
typedef struct drive_control
{
/* Geometry of the drives */
DRIVE_DESC drive;
USERADDRESS user_address;/* Pointer address of the user's buffer */
BOOL command_complete; /* Set when operation is complete */
UINT16 error_code; /* Set if an error occured - This is
the error reported to the user.
*/
UINT16 timer; /* Command fails if this much time elapsed */
UINT16 block_size; /* Block size for read/write multiple cmds */
USHORT sectors_remaining;/* Sectors remaining for read/write mult */
INT16 drive_active; /* Current active drive */
UINT16 mode; /* Single or multiple transfer */
UINT16 currentState; /* Current MMC state */
UINT16 mmcRdyState; /* Card BUSY/READY state */
UINT16 tempData;
UINT16 LastResponse[8]; /* Response data */
UINT32 mmcStatus; /* Card status */
} DEVICE_CONTROLLER, *PDEVICE_CONTROLLER;
MMC_CC mmcCommandAndResponse(UINT32 Arg, UINT16 Cmd, UINT16 noBlocks, RESP_TYPE Resp);
void mmcSetupDataRegister(UINT16 cmdIndex, UINT16 *cmdDatContReg, UINT16 *noBlocks, UINT16 *blkLength);
MMC_CC mmcAnalyzeResponse(RESP_TYPE Resp);
MMC_CC mmcReceiveData(UINT16 data_length, UINT16 noBLocks, UINT16 xferMode);
MMC_CC mmcSendData(UINT16 data_length, UINT16 noBlocks, UINT16 xferMode);
MMC_CC mmcSDApplCmd(UCHAR *buff, ULONG multipp, UINT16 noBlocks, UINT16 RCA, RESP_TYPE resp, UINT16 Cmd);
MMC_CC mmcReset(void);
MMC_CC mmcIdentify(UINT32 cardType, UINT16 RCA);
MMC_CC mmcSetStandbyState(UINT16 RCA);
MMC_CC mmcSetXferState(UINT16 RCA);
MMC_CC mmcGetConfiguration(UCHAR *mmcCSD, UINT16 RCA);
MMC_CC mmcGetCardIdentification(UCHAR *mmcIdent, UINT16 RCA);
MMC_CC mmcBlkLengthConfiguration(UINT16 RCA);
MMC_CC mmcRead(ULONG dataAddress, UINT16 RCA, UINT16 noBlocks );
MMC_CC mmcWrite(ULONG dataAddress, UINT16 RCA, UINT16 noBlocks );
MMC_CC mmcReadMultiple(ULONG dataAddress, UINT16 RCA, UINT16 noBlocks );
MMC_CC mmcWriteMultiple(ULONG dataAddress, UINT16 RCA, UINT16 noBlocks );
MMC_CC mmcGetWPMap(ULONG dataAddress, UINT16 RCA );
MMC_CC mmcSetGroupWP(ULONG dataAddress, UINT16 RCA );
MMC_CC mmcClearGroupWP(ULONG groupAddress, UINT16 RCA );
MMC_CC mmcEraseSectors(UINT16 RCA, ULONG start, ULONG end, ULONG untag );
MMC_CC mmcEraseGroup(UINT16 RCA, ULONG start, ULONG end, ULONG untag );
MMC_CC mmcGetStatus(UINT16 RCA);
MMC_CC mmedia_io(ULONG sector, UCHAR *buffer, USHORT scount, INT16 op );
BOOL mmedia_drive_open(void);
BOOL mmedia_drive_close(void);
BOOL mmedia_read_serial(PDRV_GEOMETRY_DESC idDrvPtr);
BOOL mmcBusStart( void );
BOOL mmcInitSetup( void );
void MMCHwInit(void);
void MMCStart80Clocks(void);
MMC_CC MMCPrepareAndSetup(UINT32 Arg, UINT16 Cmd, UINT16 noBlocks, UINT16 Resp);
MMC_CC MMCResponseInfo(UCHAR *respBuff, UINT16 respLength);
MMC_CC MMCTransmit(UCHAR *buffer, UINT16 dataLength, UINT16 noBLocks, UINT16 xferMode);
MMC_CC MMCReceive(UCHAR *buffer, UINT16 dataLength, UINT16 noBLocks, UINT16 xferMode);
void MMCStartClock(void);
BOOL MMCStopClock(void);
BOOL MMCSetClockRate(UINT16 ClockRate);
void Stallms(UINT32 msSeconds);
void clear_controller_structure(void);
#ifdef __cplusplus
}
#endif
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?