📄 sdcarddriver.h
字号:
#include "SPCE3200_Register.h"
#include "SPCE3200_Constant.h"
#define SDCARD 0
#define MMCCARD 1
#define C_SD_CLR_AllBIT 0xffff
#define C_INIT_CLOCK_SPEED 0x0080
#define C_MIN_CLOCK_SPEED 0x0000
#define C_MMC_CLOCK_SPEED 0x0001
#define C_BLOCKLEN_256BYTE 0x01000000
#define C_BLOCKLEN_512BYTE 0x02000000
#define C_BLOCKLEN_8BYTE 0x00080000
extern unsigned int gui_RCA;
extern int gi_SDCardTotalSector;
extern int gi_CardType;
#define SDDrv_CheckCard ((*P_SD_INT_STATUS & C_SD_CARD_PRESENT) != 0)
extern int SDDrv_ReadSector(unsigned int addr, unsigned int blocknum, unsigned char *outaddr);
extern int SDDrv_WriteSector(unsigned int addr, unsigned int blocknum, unsigned char *outaddr);
extern int SDDrv_Initial(void);
extern int SDDrv_GetMemSize(void);
extern int SDDrv_GetSpeed(void);
extern int DrvSDCReadMulCommand(unsigned int block);
extern int DrvSDCReadMulData(unsigned char *outaddr);
extern int DrvSDCReadMulData_INT(unsigned char *outaddr);
extern int DrvSDCReadMulStop(void);
extern int DrvSDCWriteMulCommand(unsigned int block);
extern int DrvSDCWriteMulData(unsigned char *outaddr);
extern int DrvSDCWriteMulData_INT(unsigned char *outaddr);
extern int DrvSDCWriteMulStop(void);
/* Command List */
/* Basic commands (class 0) */
#define C_SD_CMD0 (0x00000000 | C_SD_RSP_R0 | C_SD_CMD_START) // GO_IDLE_STATE
#define C_SD_CMD1 (0x00000001 | C_SD_RSP_R3 | C_SD_CMD_START) // Reserved, use for MMC
#define C_SD_CMD2 (0x00000002 | C_SD_RSP_R2 | C_SD_CMD_START) // ALL_SEND_CID
#define C_SD_CMD3 (0x00000003 | C_SD_RSP_R6 | C_SD_CMD_START) // SEND_RELATIVE_ADDR
#define C_SD_CMD4 (0x00000004 | C_SD_RSP_R0 | C_SD_CMD_START) // SEND_RELATIVE_ADDR?
#define C_SD_CMD5 // Reserved
#define C_SD_CMD6 // Reserved
#define C_SD_CMD7 (0x00000007 | C_SD_RSP_R1B | C_SD_CMD_START) // SELECT/DESELECT_CARD?
#define C_SD_CMD8 // Reserved
#define C_SD_CMD9 (0x00000009 | C_SD_RSP_R2 | C_SD_CMD_START) // SEND_CSD?
#define C_SD_CMD10 (0x0000000a | C_SD_RSP_R2 | C_SD_CMD_START) // SEND_CID?
#define C_SD_CMD11 // Reserved
//#define C_SD_CMD12 (0x0000000c | C_SD_RSP_R1B | C_SD_CMD_START)// STOP_TRANSMISSION?
#define C_SD_CMD12 (0x0000000c | C_SD_RSP_R1 | C_SD_CMD_START) // STOP_TRANSMISSION?
#define C_SD_CMD13 (0x0000000d | C_SD_RSP_R1 | C_SD_CMD_START) // SEND_STATUS?
#define C_SD_CMD14 // Reserved
#define C_SD_CMD15 (0x0000000f | C_SD_RSP_R0 | C_SD_CMD_START) // GO_INACTIVE_STATE?
/* Block oriented read commands (class 2) */
#define C_SD_CMD16 (0x00000010 | C_SD_RSP_R1 | C_SD_CMD_START) // SET_BLOCKLEN
#define C_SD_CMD17 (0x00000011 | C_SD_RSP_R1 | C_SD_CMD_START | C_SD_CMD_WITHDATA)
// READ_SINGLE_BLOCK
#define C_SD_CMD18 (0x00000012 | C_SD_RSP_R1 | C_SD_CMD_START | C_SD_CMD_WITHDATA | C_SD_MULTI_BLOCK)
// READ_MULTIPLE_BLOCK
#define C_SD_CMD19 // Reserved
#define C_SD_CMD20 // Reserved
#define C_SD_CMD21 // Reserved
#define C_SD_CMD22 // Reserved
#define C_SD_CMD23 // Reserved
/* Block oriented write commands (class 4) */
#define C_SD_CMD24 (0x00000018 | C_SD_RSP_R1 | C_SD_CMD_START | C_SD_CMD_WITHDATA | C_SD_DATA_TRANFER)
// WRITE_BLOCK
#define C_SD_CMD25 (0x00000019 | C_SD_RSP_R1 | C_SD_CMD_START | C_SD_CMD_WITHDATA | C_SD_DATA_TRANFER | C_SD_MULTI_BLOCK)
// WRITE_MULTIPLE_BLOCK
#define C_SD_CMD26 // Reserved for Manfacturer
#define C_SD_CMD27 (0x0000001b | C_SD_RSP_R1 | C_SD_CMD_START | C_SD_CMD_WITHDATA | C_SD_DATA_TRANFER)
// PROGRAM_CSD
/* Block oriented write protection commands (class 6) */
#define C_SD_CMD28 (0x0000001c | C_SD_RSP_R1B | C_SD_CMD_START) // SET_WRITE_PROT
#define C_SD_CMD29 (0x0000001d | C_SD_RSP_R1B | C_SD_CMD_START) // CLR_WRITE_PROT
#define C_SD_CMD30 (0x0000001e | C_SD_RSP_R1 | C_SD_CMD_START | C_SD_CMD_WITHDATA | C_SD_DATA_TRANFER)
// SEND_WRITE_PROT
#define C_SD_CMD31 // reserved
/* Erase commands (class 5) */
#define C_SD_CMD32 (0x00000020 | C_SD_RSP_R1 | C_SD_CMD_START) // ERASE_WR_BLK_START
#define C_SD_CMD33 (0x00000021 | C_SD_RSP_R1 | C_SD_CMD_START) // ERASE_WR_BLK_END
#define C_SD_CMD34 // Reserved
#define C_SD_CMD35 // Reserved
#define C_SD_CMD36 // Reserved
#define C_SD_CMD37 // Reserved
#define C_SD_CMD38 (0x00000026 | C_SD_RSP_R1 | C_SD_CMD_START) // ERASE
#define C_SD_CMD39 // Reserved
#define C_SD_CMD40 // Reserved
#define C_SD_CMD41 // Reserved
/* Lock card (class 7) */
#define C_SD_CMD42 (0x0000002a | C_SD_RSP_R1 | C_SD_CMD_START | C_SD_CMD_WITHDATA | C_SD_DATA_TRANFER)
// LOCK_UNLOCK
#define C_SD_CMD43 // Reserved
#define C_SD_CMD44 // Reserved
#define C_SD_CMD45 // Reserved
#define C_SD_CMD46 // Reserved
#define C_SD_CMD47 // Reserved
#define C_SD_CMD48 // Reserved
#define C_SD_CMD49 // Reserved
#define C_SD_CMD50 // Reserved
#define C_SD_CMD51 // Reserved
#define C_SD_CMD52 // Reserved
#define C_SD_CMD53 // Reserved
#define C_SD_CMD54 // Reserved
/* Application specific commands (class 8) */
#define C_SD_CMD55 (0x00000037 | C_SD_RSP_R1 | C_SD_CMD_START) // APP_CMD
#define C_SD_CMD56 (0x00000038 | C_SD_RSP_R1 | C_SD_CMD_START | C_SD_CMD_WITHDATA | C_SD_DATA_TRANFER)
// GEN_CMD ?
#define C_SD_CMD57 // Reserved
#define C_SD_CMD58 // Reserved
#define C_SD_CMD59 // Reserved
#define C_SD_CMD60 // Reserved for manfacturer
#define C_SD_CMD61 // Reserved for manfacturer
#define C_SD_CMD62 // Reserved for manfacturer
#define C_SD_CMD63 // Reserved for manfacturer
/* Application specific commands used/reserved only by SD memory card,
* but not by MultiMediaCard.
* All the following ACMDs shall be preceded with APP_CMD command (CMD55).
*/
#define C_SD_ACMD6 (0x00000006 | C_SD_RSP_R1 | C_SD_CMD_START) // SET_BUS_WIDTH
#define C_SD_ACMD13 (0x0000000d | C_SD_RSP_R1 | C_SD_CMD_START | C_SD_CMD_WITHDATA)
// SD_STATUS
#define C_SD_ACMD17 // Reserved
#define C_SD_ACMD18 // Reserved for SD security application
#define C_SD_ACMD19 // Reserved
#define C_SD_ACMD20 // Reserved
#define C_SD_ACMD21 // Reserved
#define C_SD_ACMD22 (0x00000016 | C_SD_RSP_R1 | C_SD_CMD_START | C_SD_CMD_WITHDATA | C_SD_DATA_TRANFER)
// SEND_NUM_WR_BLOCKS
#define C_SD_ACMD23 (0x00000017 | C_SD_RSP_R1 | C_SD_CMD_START | C_SD_CMD_WITHDATA)
// SET_WR_BLK_ERASE_COUNT
#define C_SD_ACMD24 // Reserved
#define C_SD_ACMD25 // Reserved for SD security application
#define C_SD_ACMD26 // Reserved for SD security application
#define C_SD_ACMD38 // Reserved for SD security application
#define C_SD_ACMD39 // Reserved
#define C_SD_ACMD40 // Reserved
#define C_SD_ACMD41 (0x00000029 | C_SD_RSP_R3 | C_SD_CMD_START) // SD_APP_OP_COND
#define C_SD_ACMD42 (0x0000002a | C_SD_RSP_R1 | C_SD_CMD_START) // SET_CLR_CARD_DETECT
#define C_SD_ACMD43 // Reserved for SD security application
#define C_SD_ACMD49 // Reserved for SD security application
#define C_SD_ACMD51 (0x00000033 | C_SD_RSP_R1 | C_SD_CMD_START | C_SD_CMD_WITHDATA)
// SEND_SCR
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -